Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
   *
   * This program is licensed to you under the Apache License Version 2.0,
   * and you may not use this file except in compliance with the Apache License Version 2.0.
   * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the Apache License Version 2.0 is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
  */
 package org.sonatype.sisu.bl.servlet.jetty.testsuite;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.sonatype.sisu.bl.servlet.jetty.testsuite.JettyStartAndStopStrategy.Strategy;
 import static org.sonatype.sisu.bl.servlet.jetty.testsuite.JettyStartAndStopStrategy.Strategy.EACH_METHOD;
 
 
Support class for Jetty based ITs that require a jetty running before the test.

Since:
1.4
 
 public class JettyRunningITSupport
     extends JettyITSupport
 {

    
Provider used to create Jetty bundles on demand.
 
     @Inject
     private Provider<JettyBundlejettyProvider;

    
Current running Jetty. Lazy created by jetty().
 
     private JettyBundle jetty;
 
     private static JettyBundle staticJetty;
 
     @Before
     public void beforeTestIsRunning()
     {
         final Stopwatch stopwatch = startJettyjetty() );
         testIndex().recordInfo(
             "startup time"stopwatch.elapsedMillis() == 0 ? "already running" : stopwatch.toString()
         );
 
         assertThat"Jetty is running before test starts"jetty().isRunning(), istrue ) );
     }
 
     @After
     public void afterTestWasRunning()
     {
         recordLogs );
 
         final Strategy strategy = getStartAndStopStrategy();
         if ( .equalsstrategy ) )
         {
             stopJetty );
              = null;
              = null;
         }
         else
         {
              = ;
         }
     }
 
     @AfterClass
     public static void afterAllTestsWereRun()
     {
         stopJetty );
          = null;
     }

    
Returns current Jetty. If Jetty was not yet instantiated, Jetty is created and configured.

Returns:
current Jetty
 
     protected final JettyBundle jetty()
     {
         if (  == null )
         {
             if (  == null )
             {
                 = .get();
                final JettyBundleConfiguration config = configureJetty(
                    applyDefaultConfiguration ).getConfiguration()
                );
                if ( config != null )
                {
                    .setConfigurationconfig );
                }
            }
            else
            {
                 = ;
            }
        }
        return ;
    }

    
Apply default configuration settings to specified Jetty bundle.

Parameters:
jetty to apply default configurations settings to
Returns:
passed in Jetty, for fluent API usage
    public JettyBundle applyDefaultConfigurationfinal JettyBundle jetty )
    {
        return jetty;
    }

    
Template method to be overridden by subclasses that wish to additionally configure Jetty before starting, eventually replacing it.

Parameters:
configuration Jetty configuration
Returns:
configuration that will replace current configuration. If null is returned passed in configuration will be used
    {
        return configuration;
    }

    
Determines the start and stop strategy by looking up JettyStartAndStopStrategy annotation.

Returns:
start and stop strategy to pe used. If null, Jetty will be started and stopped for each test method.
    protected Strategy getStartAndStopStrategy()
    {
        final JettyStartAndStopStrategy strategy = getClass().getAnnotationJettyStartAndStopStrategy.class );
        if ( strategy != null )
        {
            return strategy.value();
        }
        return ;
    }
New to GrepCode? Check out our FAQ X