Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9272983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:59:39+00:00 2026-06-18T15:59:39+00:00

I’m trying to wrap my head around Arquillian and perhaps even start using it

  • 0

I’m trying to wrap my head around Arquillian and perhaps even start using it in my project. I have a simple Java web app that deploys as a WAR to Tomcat.

In my project, I define a ServletContextListener impl so that I can execute code when Tomcat starts and stops the application.

I’m trying to write a super-simple Arquillian test class that uses ShrinkWrap and:

  1. Confirms that my bundled WAR can be deployed to Tomcat and started without throwing exceptions; and
  2. Can access a simple system property once the app is running (that the ServletContextListener checks for); and
  3. Confirms that when Tomcat shuts down, no exceptions are thrown (clean shutdown)

Also, my class that implements ServletContextListener is called AppLifecycleManager:

public class AppLifeCycleManager implements ServletContextListener {
    private String logLevel;

    // Injected by Guice, but that's not really relevant for this question.
    @Inject
    private Logger logger;

    // Getter and setter for logLevel and logger

    @Override
    public void contextInitialized(ServletContextEvent event) {
        logLevel = System.getProperty("log.level");
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        logger.info("Peacefully shutting down the application.");
    }
}

So far, here’s my best attempt:

@RunWith(Arquillian.class)
public class MyFirstRealIntegrationTest {
    @Deployment
    public static Archive<?> createDeployment() {
        // Haven't figured this part out yet, but for the sake of
        // this question lets pretend this returns a properly-packaged
        // WAR of my web app, the same that my Ant build currently produces.
    }

    @Test
    public void shouldBeAbleToStartTomcatWithoutExceptions() {
        // Given
        Archive war = createDeployment();

        // When - deploy war to Tomcat container
        try {
            // ??? how to access/init a Tomcat container?
            TomcatContainer tomcat = new TomcatContainer(); // this is wrong
            tomcat.start();
        } catch(Throwable throwable) {
            // Starting the container should not throw exceptions
            Assert.fail();
        }
    }

    @Test
    public void shouldBeAbleToStopTomcatWithoutExceptions {
        // Same setup as above test but stops tomcat and checks for
        // thrown exceptions. Omitted for brevity.
    }

    @Test
    public void shouldHaveAccessToSysPropsOnceRunning() {
        // Here, deploy to the container and start it.
        // Then, confirm that AppLifecycleManager correctly read
        // the log.level system property.

        // Given
        Archive war = createDeployment();
        TomcatContainer tomcat = new TomcatContainer();

        // When - AppLifeycleManager should now read the system property
        tomcat.start();

        // Then - make sure log.level was set to "DEBUG" and that it was
        // correctly read by AppLifeCycleManager.
        Assert.assertTrue(war.getClass(AppLifeCycleManager.class)
                .getLogLevel().equals("DEBUG"));
    }
}

So, given my approach here, I immediately have several problems:

  1. I’m not sure how to access/instantiate my Tomcat container so that it can even be started/stopped
  2. I’m not sure how to actually execute tests from inside my running/deployed web app. In the 3rd test above I used war.getClass(AppLifeCycleManager.class).getLogLevel() to try and get access to a “live” class instance and check its logLevel property’s runtime value, but I know this is wrong.

So I ask: how would a battle-worn Arquillian veteran write these 3 simple tests, and how do I actually go about performing tests on my “running” web app from inside the JUnit test? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:59:40+00:00Added an answer on June 18, 2026 at 3:59 pm

    You’re almost there. createDeployment manages the lifecycle of your embedded container for you (starts and stops the virtual container automatically). That way, you’re just focussing on the tests themselves. To write your integration tests, there’s no “framework” or “Arquillian API” to code against. You just call classes and methods the way your main code does.

    The key thing here is: your tests are actually running inside the container. If an exception occurs, or if your assert fails, the Arquillian runner throws an exception and stops the container. For your code example, where you’re testing to see if you can read a system property:

    @RunsWith(Arquillian.class)
    public class MyArquillianTest {
        @Deployment
        public Archive<?> createDeployment() { ... }
    
        @Test
        public void shouldBeAbleToReadSysPropAtStartup() {
            Assert.assertTrue(System.getProperty("log.level") != null);
        }
    }
    

    Remember, Assert.assertTrue(System.getProperty("log.level") != null) Arquillian is “transporting” your code inside the container you configure it for. So that assert is actually running inside your deployed container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.