Discussion:
[jboss-user] [Beginner's Corner] - getting started unit testing - embedded JBoss AS 7?
Matthew Cornell
2012-06-01 21:44:56 UTC
Permalink
Matthew Cornell [https://community.jboss.org/people/matthewcornell] created the discussion

"getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/739439#739439

--------------------------------------------------------------
Hi Folks. I'm just getting started with JBoss AS 7, having tried and ultimately failed to get GlassFish Embedded working for my Java EE 6 app's unit tests. Please tell me: How do I go about using JBoss to do unit tests without having the server up and running? I'm hoping that all I need is a) a .jar file (ideally one!) and b) some simple code for starting the in-memory server, configuring it, and then shutting it down. An example would be awesome! I've searched for "jboss embedded," but what I found was not on the mark or was outdated. I found the JBoss Embedded community at https://community.jboss.org/community/jbossas/embedded https://community.jboss.org/en/jbossas/embedded, but it's really dead, which is discouraging. The articles at https://community.jboss.org/docs/DOC-13843 https://community.jboss.org/wiki/JBossEmbeddedAS haven't been touched in two years. I found a bunch of mentions of Arquillian, but I'm not familiar with it. Finally, the ultimate icing on the cake would be to do this without Maven. Is what I'm trying to do so strange? I saw a presentation by one of the JBoss leaders, who touted its applicability specifically for embedded unit testing, so maybe I'm using the wrong terminology in my search. Thanks in advance -- matt
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/739439#739439]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Matthew Cornell
2012-06-02 18:02:28 UTC
Permalink
Matthew Cornell [https://community.jboss.org/people/matthewcornell] created the discussion

"getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/739482#739482

--------------------------------------------------------------
Hi Folks. I'm just getting started with JBoss AS 7, having tried and ultimately failed to get GlassFish Embedded working for my Java EE 6 app's unit tests. Please tell me: How do I go about using JBoss to do unit tests without having the server up and running? I'm hoping that all I need is a) a .jar file (ideally one!) and b) some simple code for starting the in-memory server, configuring it, and then shutting it down. An example would be awesome! I've searched for "jboss embedded," but what I found was not on the mark or was outdated. I found the JBoss Embedded community at https://community.jboss.org/community/jbossas/embedded https://community.jboss.org/en/jbossas/embedded, but it's really dead, which is discouraging. The articles at https://community.jboss.org/docs/DOC-13843 https://community.jboss.org/wiki/JBossEmbeddedAS haven't been touched in two years. I found a bunch of mentions of Arquillian, but I'm not familiar with it. Finally, the ultimate icing on the cake would be to do this without Maven. Is what I'm trying to do so strange? I saw a presentation by one of the JBoss leaders, who touted its applicability specifically for embedded unit testing, so maybe I'm using the wrong terminology in my search. Thanks in advance -- matt
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/739482#739482]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Matthew Cornell
2012-06-07 15:12:12 UTC
Permalink
Matthew Cornell [https://community.jboss.org/people/matthewcornell] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740467#740467

--------------------------------------------------------------
No one?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740467#740467]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
jaikiran pai
2012-06-07 15:16:05 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740470#740470

--------------------------------------------------------------
Matthew, take a look at the Arquillian guides here http://arquillian.org/ http://arquillian.org/
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740470#740470]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Matthew Cornell
2012-06-07 19:58:39 UTC
Permalink
Matthew Cornell [https://community.jboss.org/people/matthewcornell] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740524#740524

--------------------------------------------------------------
Thanks for the pointer, jaikiran. However, isn't that just adding another layter on top of the embedded code? I'd much prefer to start with using JBoss directly, instead of learning a whole new system. This is important because I'm 99% certain my very basic code is going to break JBoss embedded, just like it did to GlassFish embedded (it exposed a security-related bug that stops my code from creating users in a realm).

jaikiran, do you know anyone who can answer my question about getting started with JBoss embedded? Thank you.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740524#740524]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
jaikiran pai
2012-06-08 01:44:00 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740566#740566

--------------------------------------------------------------
Thanks for the pointer, jaikiran. I did some research and it looks like Arquillian does not support the embedded container for JBoss 7.1 - https://community.jboss.org/message/717500#717500 https://community.jboss.org/message/717500 . That makes me wonder whether the project is active...
Is there a reason why you want that "embedded" project? Arquillian has the ability to start/stop the server on it's own when you run your JUnit tests. You don't have to write a single line of code (except for adding a Maven dependency in your pom.xml) for managing the server. This is known as the "managed" server mode in Arquillian. There's also a "remote" server mode where Arquillian will auto connect to an already running server instance (which you might have started in whatever way you want) and run the JUnit tests for you. And this isn't specific to JBoss AS server, Arquillian can do the same with any other server too.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740566#740566]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Matthew Cornell
2012-06-08 12:27:37 UTC
Permalink
Matthew Cornell [https://community.jboss.org/people/matthewcornell] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740676#740676

--------------------------------------------------------------
Thank you - I'm still working on the terminology. I'm using "embedded" to mean starting a Java EE server in the same JVM as the tests then shutting it down when they're through. I understand I don't need a full blown container for unit testing (which I can do with mocks, and with properly-designed code), but I do need it for integration testing. In my case I use JAX-RS to expose my app as a REST service (it's also an EJB), and JPA to store the underlying data. My app is currently very simple, which is why I'm surprised that the tools haven't satisfied so far. Clearly my approach is talking to me, and I need to take a different tack.

I've also heard the terms "in-container" and "out-of-container" testing, "managed" from you, and "remote", so I'm still a bit confused. If Arquillian can very quickly deploy my app to a container that is not in my JVM, but is local, then I think that would satisfy my needs. If this is true, then my looking for an Arquillian container adapter for JBoss AS 7 embedded is the wrong query. However, I looked for version 7 support at http://mvnrepository.com/artifact/org.jboss.arquillian.container http://mvnrepository.com/artifact/org.jboss.arquillian.container , but I didn't find it. Is Arquillian JBoss support still active? The ones I did find were:

http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-embedded-6 http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-embedded-6
http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-managed-6 http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-managed-6
http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-embedded-60 http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-embedded-60
http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-local-60 http://mvnrepository.com/artifact/org.jboss.arquillian.container/arquillian-jbossas-local-60

Maybe my confusion is understandable! Any clarity you can provide would really help.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740676#740676]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
jaikiran pai
2012-06-10 12:57:04 UTC
Permalink
jaikiran pai [https://community.jboss.org/people/jaikiran] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740865#740865

--------------------------------------------------------------
Post by Matthew Cornell
Thank you - I'm still working on the terminology. I'm using "embedded" to mean starting a Java EE server in the same JVM as the tests then shutting it down when they're through. I understand I don't need a full blown container for unit testing (which I can do with mocks, and with properly-designed code), but I do need it for integration testing.
Okay. That's what typically "embedded" means. Arquillian has 3 server integration types, "managed" (start/stop server as a JVM process), "embedded" (start/stop server within the same process that triggers the JUnit test), "remote" (join a running instance of server). AS7 integration for Arquillian does +not+ have the "embedded" mode. *But* the use case you mention - running the tests in the same JVM as the server can still be achieved via the others 2 modes too. In fact, when you run an Arquillian test, the Arquillian infrastructure deploys the deployment to the server and depending on the "run mode" the test is either run in the same JVM process as the server or in a separate JVM as the client. By default, the tests are run on the server JVM (from your description that's what you want). If the test uses a @RunAsClient annotation for the test (the arquillian guides have more info about this) then the test is run as a remote client and does +not+ run on the server JVM. I believe, that should make this a bit clear. If you still have more questions, feel free to ask.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740865#740865]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Matthew Cornell
2012-06-11 13:07:06 UTC
Permalink
Matthew Cornell [https://community.jboss.org/people/matthewcornell] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/740985#740985

--------------------------------------------------------------
That helps, thank you. I'm starting to undrestand. What's still confusing is how my tests would do something like creating users and roles/groups programmatically. With GlassFish I was using their embedded API to do this (their interface to a command-line utility), so how I would do this in the non-embedded modes you describe? Sorry if I'm not clear, I'm still wrapping my head around all this.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/740985#740985]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Ben Software Engineer
2013-01-24 14:13:55 UTC
Permalink
Ben Software Engineer [https://community.jboss.org/people/ben.maisano] created the discussion

"Re: getting started unit testing - embedded JBoss AS 7?"

To view the discussion, visit: https://community.jboss.org/message/794062#794062

--------------------------------------------------------------
Hi,
   I'm using arquillian jboss managed setup, so I would expect it runs the tests in the server's jvm.  I cannot get a debug breakpoint to hit.  Details about debugging are here, but no answer yet on this thread:
http://stackoverflow.com/questions/13082380/debugging-remote-container-with-arquillian-fails/14490537#14490537 http://stackoverflow.com/questions/13082380/debugging-remote-container-with-arquillian-fails/14490537#14490537

I would assume an embedded is just like normal junit, debug just works.  With managed or remote it seems they both involve another JVM that must be launched in debug mode and then you remotely attach to the debugging jvm with your IDE.  I'm not sure if how maven kicks it off is playing a role, but I cannot get it to work.  I have got jvm to hault, and I connect to it, however my breakpoints do not hit.  I have breakpoints in the junit/arquillian test class as well as within an ejb method the test class is calling.  Any ideas?
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/794062#794062]

Start a new discussion in Beginner's Corner at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075]
Loading...