@Override public JDBCDataSource configure(TestContext testContext, LocalResource localResource, PropertiesReader configReader) { JDBCDataSource dataSource = new JDBCDataSource(); dataSource.setUrl(format("jdbc:hsqldb:mem:%s?default_schema=public", testContext .getName())); dataSource.setUser("sa"); dataSource.setPassword(""); return dataSource; }
@Override public JDBCDataSource configure(TestContext testContext, LocalResource localResource, PropertiesReader configReader) { JDBCDataSource dataSource = new JDBCDataSource(); dataSource.setUrl(format("jdbc:hsqldb:mem:%s?default_schema=public", testContext .getName())); dataSource.setUser("sa"); dataSource.setPassword(""); return dataSource; }
@Override @SuppressWarnings("UseSpecificCatch") public ResourceConfig configure(TestContext testContext) { TestContextHolder.INSTANCE.set(testContext); TestDescriptor testDescriptor = testContext.getTestDescriptor(); Optional<Application> foundApplication = testDescriptor.getApplication(); ResourceConfig resourceConfig = null; if (foundApplication.isPresent()) { Application application = foundApplication.get(); resourceConfig = ReflectionUtil.INSTANCE.newInstance(application.value()); resourceConfig.setApplicationName(testContext.getName()); } return resourceConfig; }
@Override public ServiceLocator create(TestContext testContext) { TestConfigurer testConfigurer = testContext.getTestConfigurer(); ServiceLocatorFactory locatorFactory = ServiceLocatorFactory.getInstance(); ServiceLocator serviceLocator = locatorFactory.create(testContext.getName()); return testConfigurer.configure(testContext, serviceLocator); }
@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"); }
@Override public ServerInstance<HttpServer> start(TestContext testContext, Application application, ResourceConfig resourceConfig) { URI uri = URI.create(format(DEFAULT_URI_FORMAT, DEFAULT_SCHEME, DEFAULT_HOST, DEFAULT_PORT, DEFAULT_PATH)); // create and start a new instance of grizzly http server HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, resourceConfig, true); Optional<NetworkListener> foundListener = server.getListeners() .stream() .findFirst(); ServerInstance serverInstance = null; if (foundListener.isPresent()) { NetworkListener networkListener = foundListener.get(); String host = networkListener.getHost(); int port = networkListener.getPort(); URI baseURI = URI.create( format(DEFAULT_URI_FORMAT, DEFAULT_SCHEME, host, port, DEFAULT_PATH)); serverInstance = ServerInstanceBuilder.builder() .baseURI(baseURI) .server(server) .property(APP, resourceConfig) .property(APP_NAME, testContext.getName()) .property(SERVER, server) .build("jersey", application); } return serverInstance; }
? String.format("%s-%s", testContext.getName(), UUID .randomUUID().toString()) : String.format("%s-%s", virtualResource.name(), UUID } else { containerName = virtualResource.name().isEmpty() ? String.format("%s-%d-%s", testContext.getName(), i, UUID .randomUUID().toString()) : String.format("%s-%d-%s", virtualResource.name(), i,
String name = testContext.getName();
@Override protected void runChild(final FrameworkMethod method, RunNotifier runNotifier) { Description methodDescription = describeChild(method); TestClass testClass = getTestClass(); Class<?> javaClass = testClass.getJavaClass(); TestifyJUnit4RunNotifier notifier = (TestifyJUnit4RunNotifier) runNotifier; MDC.put(TEST_CLASS_KEY, javaClass.getSimpleName()); MDC.put(TEST_METHOD_KEY, method.getName()); if (isIgnored(method)) { notifier.fireTestIgnored(methodDescription); } else { try { runLeaf(methodBlock(method), methodDescription, notifier); } catch (Exception e) { notifier.addFailure(e); notifier.pleaseStop(); } finally { if (!isIgnored(method)) { TestContextHolder.INSTANCE.command(testContext -> { LoggingUtil.INSTANCE.debug("performing cleanup of '{}'", testContext.getName()); TestRunner testRunner = testContext.getTestRunner(); testRunner.stop(testContext); TestContextHolder.INSTANCE.remove(); }); } } } }
AnnotationConfigApplicationContext configContext = (AnnotationConfigApplicationContext) applicationContext; configContext.setId(testContext.getName()); configContext.setDisplayName(testContext.getName()); configContext.setAllowCircularReferences(false); configContext.setAllowBeanDefinitionOverriding(true);
void pullImage(VirtualResource virtualResource, String image, String imageName, String imageTag, TestContext testContext) { RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withBackoff(virtualResource.delay(), virtualResource.maxDelay(), virtualResource.unit()) .withMaxRetries(virtualResource.maxRetries()); Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.warn("Retrying pull request of image '{}'", image, throwable) ) .onFailure(throwable -> LoggingUtil.INSTANCE.error("Image image '{}' could not be pulled: ", image, throwable)) .run(() -> { try { CountDownLatch latch = new CountDownLatch(1); client.pullImageCmd(imageName) .withTag(imageTag) .exec(new PullCallback(virtualResource, latch)); ExceptionUtil.INSTANCE.raise(!latch.await(virtualResource.timeout(), virtualResource.unit()), "Could not start virtual resource '{}' for test '{}'", imageName, testContext.getName() ); } catch (InterruptedException e) { LoggingUtil.INSTANCE.warn("Image '{}' pull request interrupted", image); Thread.currentThread().interrupt(); } }); }
if (testContext.getName().equals(locatorName)) { testContext.computeIfAbsent(SERVICE_INSTANCE, key -> { TestDescriptor testDescriptor = testContext.getTestDescriptor();