A - Application class 
        What is already implemented:
 
 public class MyClientTest extends VitamJerseyTest {
  private static final String RESOURCE_PATH = "...";
  // You own factory
  TestVitamClientFactory factory =
    new TestVitamClientFactory(8080, RESOURCE_PATH);
  // Store your own client
  TestClient client;
  // ************************************** //
  // Start of VitamJerseyTest configuration //
  // ************************************** //
  // Override the beforeTest if necessary (not mandatory)
  @Override
  public void beforeTest() throws VitamApplicationServerException {
    // anything before test
  }
  // Override the afterTest if necessary (not mandatory)
  @Override
  public void afterTest() throws VitamApplicationServerException {
   // anything after test
  }
  // This method MUST be created. Assign your own client (keep it) and returns it.
  @Override
  protected MockOrRestClient _getClient() throws VitamApplicationServerException {
    try {
       // Fix your factory
       factory.changeServerPort(getServerPort());
       client = factory.getClient();
       return client;
    } catch (final VitamClientException e) {
       throw new VitamApplicationServerException(e);
    }
  }
  // Setup test to setup anything if necessary (not mandatory)
  @Override
  public void setup() {
    // nothing
  }
  // Define the getApplication to return your Application using the correct Configuration
  @Override
  public StartApplicationResponse startVitamApplication(int reservedPort) {
    // Use your own ApplicationConfiguration if necessary, or just copy the following
    final TestVitamApplicationConfiguration configuration =
      new TestVitamApplicationConfiguration();
    // DEFAULT_XML_CONFIGURATION_FILE could be used as default XML file, but you can specify another
    configuration.setJettyConfig(DEFAULT_XML_CONFIGURATION_FILE);
    // Use your own application or just copy the following
    final AbstractApplication application = new AbstractApplication(configuration);
    // Start the application (mandatory)
    try {
       application.start();
    } catch (final VitamApplicationServerException e) {
       SysErrLogger.FAKE_LOGGER.ignoreLog(e);
       throw new IllegalStateException("Cannot start the application", e);
    }
    // Return the response as follow
    return new StartApplicationResponse()
       .setServerPort(application.getVitamServer().getPort())
       .setApplication(application);
  }
  // Define your Application class (or reuse it), in particular set your own MockResources or just copy the following
  public final class AbstractApplication
    extends AbstractVitamApplication {
    protected AbstractApplication(TestVitamApplicationConfiguration configuration) {
       super(TestVitamApplicationConfiguration.class, configuration);
    }
    @Override
    protected void registerInResourceConfig(ResourceConfig resourceConfig) {
       resourceConfig.registerInstances(new MockResource(mock));
    }
  }
  // Define your Configuration class (or reuse it) or just copy the following
  public static class TestVitamApplicationConfiguration extends DefaultVitamApplicationConfiguration {
    // Empty for this example
  }
  // Define your Resource class
  @Path(RESOURCE_PATH)
  public static class MockResource extends ApplicationStatusResource {
    private final ExpectedResults expectedResponse;
    public MockResource(ExpectedResults expectedResponse) {
       this.expectedResponse = expectedResponse;
    }
    ...
  }
  // ************************************ //
  // End of VitamJerseyTest configuration //
  // ************************************ //
  // Use client to act on AbstractApplication
 }     
        
        public abstract class VitamJerseyTest<A> extends Object implements VitamApplicationTestFactory<A>
| Modifier and Type | Class and Description | 
|---|---|
| static interface  | VitamJerseyTest.ExpectedResultsDefault ExpectedResults | 
VitamApplicationTestFactory.StartApplicationResponse<A>| Modifier and Type | Field and Description | 
|---|---|
| static String | DEFAULT_XML_CONFIGURATION_FILEDefault XML Configuration to use (from JunitHelper) | 
| static String | HOSTNAMELocalhost | 
| protected VitamJerseyTest.ExpectedResults | mock | 
| Constructor and Description | 
|---|
| VitamJerseyTest(VitamClientFactoryInterface<?> factory)Create the VitamJerseyTest, calling setup first.
 Note: will call factory.changeServerPort(getServerPort()) automatically before creating the client. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | afterTest()To be extended if necessary (equivalent to @After) | 
| void | beforeTest()To be extended if necessary (equivalent to @Before) | 
| void | endApplication()End the application only | 
| void | endTest()End the Application. | 
| VitamApplicationInterface<?,?> | getApplication() | 
| MockOrRestClient | getClient() | 
| VitamClientFactoryInterface<?> | getFactory() | 
| int | getServerPort() | 
| void | setup()Do anything necessary before starting the application and before getting the server port. | 
| void | startTest()Start the Application. | 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitstartVitamApplicationpublic static final String DEFAULT_XML_CONFIGURATION_FILE
public static final String HOSTNAME
protected VitamJerseyTest.ExpectedResults mock
public VitamJerseyTest(VitamClientFactoryInterface<?> factory)
factory - the Client Factory to useVitamApplicationServerException - when starting server exception occurredIllegalStateException - if the start is incorrectpublic VitamClientFactoryInterface<?> getFactory()
public MockOrRestClient getClient()
public void setup()
public final int getServerPort()
public final VitamApplicationInterface<?,?> getApplication()
public final void startTest()
                     throws VitamApplicationServerException
VitamApplicationServerException - when starting server exception occurredpublic void beforeTest()
                throws VitamApplicationServerException
VitamApplicationServerException - when starting server exception occurredpublic final void endApplication()
                          throws VitamApplicationServerException
VitamApplicationServerExceptionpublic final void endTest()
                   throws VitamApplicationServerException
VitamApplicationServerException - stopping server exception occurredpublic void afterTest()
               throws VitamApplicationServerException
VitamApplicationServerException - when stopping server exception occurredCopyright © 2018 Vitam. All rights reserved.