Optional<Field> findField(Class<?> type, String name) { try { return of(type.getDeclaredField(name)); } catch (NoSuchFieldException | SecurityException e) { LoggingUtil.INSTANCE.debug("Could not find field '{}' in type '{}'", name, type.getSimpleName(), e); return empty(); } }
void enableExtras(String methodName, ServiceLocator serviceLocator) { String className = "org.glassfish.hk2.extras.ExtrasUtilities"; try { Class<?> extrasUtilitiesClass = Class.forName(className); Method method = extrasUtilitiesClass.getMethod(methodName, ServiceLocator.class); method.invoke(null, serviceLocator); } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { LoggingUtil.INSTANCE.debug("Method '{}' not found in class {}", methodName, className, e); } } }
@Override public void fireTestStarted(Description description) { LoggingUtil.INSTANCE.debug("Test started"); runNotifier.fireTestStarted(description); }
@Override public void fireTestFinished(Description description) { LoggingUtil.INSTANCE.debug("Test finished"); runNotifier.fireTestFinished(description); }
@Override public void close() throws IOException { LoggingUtil.INSTANCE.debug("Closing pull of '{}:{}' image", virtualResource.value(), virtualResource.version()); }
@Override public void stop(ServerInstance<EmbeddedServletContainer> serverInstance) { if (serverInstance != null) { serverInstance.command((container, baseURI) -> { LoggingUtil.INSTANCE.debug("Stopping Spring Boot server"); container.stop(); }); } }
public void awaitTermination(@SuperCall Callable<?> zuper, @AllArguments Object[] args) throws InterruptedException { //for testing purpose trap calls for waitawaitTermination and do nothing LoggingUtil.INSTANCE.debug("awaitTermination intercepted and trapped"); } }
@Override public void stop(ServerInstance<Undertow> serverInstance) { if (serverInstance != null) { LoggingUtil.INSTANCE.debug("Stopping Undertow server"); serverInstance.getServer().getValue().stop(); } applicationProvider.stop(); }
@Override public void run(RunNotifier runNotifier) { Description testDescription = getDescription(); TestifyJUnit4RunNotifier notifier = TestifyJUnit4RunNotifier.of(runNotifier, testDescription); try { LoggingUtil.INSTANCE.debug("Creating Statement"); Statement statement = classBlock(notifier); LoggingUtil.INSTANCE.debug("Evaluating Statement"); statement.evaluate(); } catch (AssumptionViolatedException e) { notifier.addFailedAssumption(e); } catch (Throwable t) { Throwables.propagateIfInstanceOf(t, StoppedByUserException.class); notifier.addFailure(t); notifier.pleaseStop(); } }
instance = context.getBean(rawType); } catch (BeansException e) { LoggingUtil.INSTANCE.debug("Could not find bean", e);
TestClass testClass = getTestClass(); Class<?> javaClass = testClass.getJavaClass(); LoggingUtil.INSTANCE.debug("test class classloader: {}", javaClass .getClassLoader()); LoggingUtil.INSTANCE.debug("creating instance of test class {}", javaClass .getName()); testInstance = createTest(); LoggingUtil.INSTANCE.debug("creating test decriptor for test class {}", javaClass .getName()); TestDescriptor testDescriptor = AnalyzerUtil.INSTANCE.analyzeTestClass(javaClass); LoggingUtil.INSTANCE.debug("creating method decriptor for test method {}#{}", javaClass.getName(), method.getName()); MethodDescriptor methodDescriptor = DefaultMethodDescriptor.of(method); LoggingUtil.INSTANCE.debug( "Starting test runner '{}'", testRunner.getClass().getName() LoggingUtil.INSTANCE.debug( "Executing test method {}#{}'", javaClass.getName(), method.getName() LoggingUtil.INSTANCE.debug( "Executing statement before lifecycle methods for {}#{}'", javaClass.getName(),
@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"); }
/** * Create a new test runner instance for the system under test. * * @param testClass the test class type * @param testSettings settings for the test * * @throws InitializationError thrown if the test class is malformed */ public TestifyJUnit4TestRunner(Class<?> testClass, TestSettings testSettings) throws InitializationError { super(testClass); this.testSettings = testSettings; try { TestifyJUnit4CategoryFilter categoryFilter = TestifyJUnit4CategoryFilter.of( testSettings.getTestLevel(), SettingUtil.INSTANCE.getSystemCategories() ); filter(categoryFilter); } catch (NoTestsRemainException e) { LoggingUtil.INSTANCE.debug("No test remain", e); } }
sutValue = serviceInstance.getService(sutType, clientName); } catch (Exception e) { LoggingUtil.INSTANCE.debug("could not find client of type '{}'", clientContract); sutValue = serviceInstance.getService(sutType, clientSupplierName); } catch (Exception e) { LoggingUtil.INSTANCE.debug( "could not find client supplier of type '{}'", clientContract, e);
containerConfigBuilder.env(evaluation); } catch (Exception e) { LoggingUtil.INSTANCE.debug( "Could not evaluate env '{}' as an expression ", env);
@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(); }); } } } }
void removeContainer(String containerId, VirtualResource virtualResource) { LoggingUtil.INSTANCE.info("Stopping and Removing Docker Container {}", containerId); if (client.inspectContainerCmd(containerId).exec().getState().getRunning()) { client.stopContainerCmd(containerId).exec(); try { client.waitContainerCmd(containerId) .exec(new WaitCallback(containerId)) .awaitCompletion(); } catch (InterruptedException e) { LoggingUtil.INSTANCE.warn("wating for container interrupted", e); Thread.currentThread().interrupt(); } } RetryPolicy retryPolicy = new RetryPolicy() .retryOn(Throwable.class) .withBackoff(virtualResource.delay(), virtualResource.maxDelay(), virtualResource.unit()) .withMaxRetries(virtualResource.maxRetries()) .withMaxDuration(8000, TimeUnit.MILLISECONDS); Failsafe.with(retryPolicy) .onRetry(throwable -> LoggingUtil.INSTANCE.debug("Trying to remove Docker Container {}", containerId, throwable)) .onSuccess(result -> { LoggingUtil.INSTANCE.info("Docker Container '{}' Removed", containerId); client.removeVolumeCmd(containerId).exec(); }) .onFailure(throwable -> LoggingUtil.INSTANCE.error("Docker Container '{}' could not be removed", containerId, throwable)) .run(() -> client.removeContainerCmd(containerId).exec()); }