public EmbeddedServletContainer startEmbeddedServletContainer( @SuperCall Callable<EmbeddedServletContainer> zuper, @This Object object) throws Exception { EmbeddedServletContainer container = zuper.call(); SpringBootDescriptor descriptor = getDescriptor(object); descriptor.setServletContainer(container); return container; }
public void prepareEmbeddedWebApplicationContext(@SuperCall Callable<Void> zuper, @This Object object, @AllArguments Object[] args) throws Exception { zuper.call(); SpringBootDescriptor descriptor = getDescriptor(object); descriptor.setServletContext((ServletContext) args[0]); }
@Override protected void runChild(FrameworkMethod method, RunNotifier notifier) { super.runChild(method, notifier); if (method.getAnnotation(Ignore.class) == null) { SpringBootDescriptor descriptor = APPLICATION_DESCRIPTORS.get(application); clientInstance.close(); serverInstance.stop(); descriptor.getTestNeeds().destory(); descriptor.getTestContainerNeeds().destory(); } }
ServiceLocator serviceLocator = descriptor.getServiceLocator(); serviceLocator.addConstant(descriptor.getClass().getSimpleName(), descriptor); null, "0.0.0.0", descriptor.getServletContainer().getPort(), descriptor.getServletContext().getContextPath(), null, null); SpringBootClientDescriptor clientDescriptor = new SpringBootClientDescriptor(app, testContext, baseURI); ServiceLoader<ClientProvider> clientProviderLoader = ServiceLoader.load(ClientProvider.class); ArrayList<ClientProvider> clientProviders = Lists.newArrayList(clientProviderLoader); } catch (Exception e) { checkState(false, "Call to config method '%s' in test class '%s' failed due to: ", m.getName(), clientDescriptor.getTestClassName(), e.getMessage()); }); serverInstance = new SpringBootServerInstance(descriptor.getServletContainer(), baseURI); serviceLocator.addConstant(serverInstance.getClass().getSimpleName(), serverInstance); .parallelStream() .filter(p -> !p.getInstance().isPresent()) .filter(p -> p.hasAnnotations(descriptor.getServiceAnnotations().getInjectors())) .collect(toSet());
serviceAnnotations.addNamedQualifier(Named.class, Qualifier.class); serviceAnnotations.addCustomQualfier(javax.inject.Qualifier.class, Qualifier.class); descriptor.setServiceAnnotations(serviceAnnotations); descriptor.setTestContext(testContext); descriptor.setServiceLocator(serviceLocator); testNeeds.init(); descriptor.setTestNeeds(testNeeds); NeedScope.METHOD); testContainerNeeds.init(); descriptor.setTestContainerNeeds(testContainerNeeds);
public EmbeddedServletContainerFactory getEmbeddedServletContainerFactory( @SuperCall Callable<EmbeddedServletContainerFactory> zuper, @This Object object) throws Exception { EmbeddedServletContainerFactory containerFactory = zuper.call(); ConfigurableEmbeddedServletContainer configurableServletContainer = (ConfigurableEmbeddedServletContainer) containerFactory; configurableServletContainer.setPort(0); SpringBootDescriptor descriptor = getDescriptor(object); descriptor.setContainerFactory(containerFactory); descriptor.setConfigurableServletContainer(configurableServletContainer); TestContext testContext = descriptor.getTestContext(); testContext.getConfigMethod(ConfigurableEmbeddedServletContainer.class) .map(m -> m.getMethod()) .ifPresent(m -> { AccessController.doPrivileged((PrivilegedAction<Object>) () -> { try { m.setAccessible(true); m.invoke(testContext.getTestInstance(), configurableServletContainer); } catch (Exception e) { checkState(false, "Call to config method '%s' in test class '%s' failed.", m.getName(), testContext.getTestClassName()); throw Throwables.propagate(e); } return null; }); }); return containerFactory; }
public ConfigurableApplicationContext run( @SuperCall Callable<ConfigurableApplicationContext> zuper, @This Object object, @AllArguments Object[] args) throws Exception { AnnotationConfigEmbeddedWebApplicationContext context = (AnnotationConfigEmbeddedWebApplicationContext) zuper.call(); SpringBootDescriptor descriptor = descriptors.get(context); descriptor.setApplication((SpringApplication) object); descriptor.setSources(args[0]); if (args.length == 2) { descriptor.setArgs((String[]) args[1]); } return context; }
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); SpringBootInterceptor interceptor = new SpringBootInterceptor(APPLICATION_TEST_CONTEXTS, APPLICATION_DESCRIPTORS, CONTEXT_DESCRIPTORS);