testContext.findProperty(TestContextProperties.CLIENT_INSTANCE); Optional<ClientProvider> foundClientProvider = testContext.findProperty(TestContextProperties.CLIENT_PROVIDER); testContext.<ServerInstance>findProperty(TestContextProperties.SERVER_INSTANCE); Optional<ServerProvider> foundServerProvider = testContext.findProperty(TestContextProperties.SERVER_PROVIDER);
@Override public ServerInstance<EmbeddedServletContainer> start(TestContext testContext, Application application, SpringApplicationBuilder configuration) { LoggingUtil.INSTANCE.debug("Starting Spring Boot application '{}'", testContext .getName()); SpringApplication springApplication = configuration.build(); springApplication.run(); Optional<ServletContext> servletContext = testContext.findProperty(SERVLET_CONTEXT); Optional<EmbeddedServletContainer> servletContainer = testContext.findProperty(SERVER); if (servletContext.isPresent() && servletContainer.isPresent()) { EmbeddedServletContainer server = servletContainer.get(); ServletContext context = servletContext.get(); String uri = format(DEFAULT_URI_FORMAT, server.getPort(), context .getContextPath()); URI baseURI = URI.create(uri); return ServerInstanceBuilder.builder() .baseURI(baseURI) .server(server) .property(APP, springApplication) .property(APP_NAME, testContext.getName()) .property(SERVER, server) .build("springboot", application); } throw ExceptionUtil.INSTANCE.propagate( "Could not start springboot application due to missing servlet container"); }
ServiceInstance createService(TestContext testContext, TestDescriptor testDescriptor, TestConfigurer testConfigurer) { ServiceInstance serviceInstance; Optional<ServiceInstance> foundServiceInstance = testContext.<ServiceInstance>findProperty(SERVICE_INSTANCE); if (foundServiceInstance.isPresent()) { serviceInstance = foundServiceInstance.get(); } else { ServiceProvider serviceProvider = serviceLocatorUtil.getFromHintOrDefault( testContext, ServiceProvider.class, DefaultServiceProvider.class, Hint::serviceProvider); Object serviceContext = serviceProvider.create(testContext); testConfigurer.configure(testContext, serviceContext); serviceInstance = serviceProvider.configure(testContext, serviceContext); testContext.addProperty(SERVICE_INSTANCE, serviceInstance); serviceProvider.postConfigure(testContext, serviceInstance); } return serviceInstance; }
@Override public void stop(TestContext testContext) { Object testInstance = testContext.getTestInstance(); TestDescriptor testDescriptor = testContext.getTestDescriptor(); Collection<Class<? extends Annotation>> guidelines = testDescriptor.getGuidelines(); serviceLocatorUtil .findAllWithFilter(PostVerifier.class, guidelines, UnitCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify(); //invoke destroy method on fields annotated with Fixture testDescriptor.getFieldDescriptors() .forEach(p -> p.destroy(testInstance)); //invoke destroy method on sut field annotated with Fixture testContext.getSutDescriptor() .ifPresent(p -> p.destroy(testInstance)); testContext.<ServiceInstance>findProperty(SERVICE_INSTANCE) .ifPresent(ServiceInstance::destroy); resourceController.stop(testContext); }
@Override public void stop(TestContext testContext) { Object testInstance = testContext.getTestInstance(); TestDescriptor testDescriptor = testContext.getTestDescriptor(); Collection<Class<? extends Annotation>> guidelines = testDescriptor.getGuidelines(); serviceLocatorUtil .findAllWithFilter(PostVerifier.class, guidelines, IntegrationCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify(); //invoke destroy method on fields annotated with Fixture testDescriptor.getFieldDescriptors() .forEach(p -> p.destroy(testInstance)); //invoke destroy method on sut field annotated with Fixture testContext.getSutDescriptor() .ifPresent(p -> p.destroy(testInstance)); if (resourceController != null) { resourceController.stop(testContext); } testContext.<ServiceInstance>findProperty(SERVICE_INSTANCE) .ifPresent(ServiceInstance::destroy); }
Class sutType = sutDescriptor.getType(); Optional<ClientInstance> foundClientInstance = testContext.findProperty(TestContextProperties.CLIENT_INSTANCE);