ClientProvider createClientProvider(TestContext testContext, Application application) { //create client supplier instance Class<? extends ClientProvider> clientProviderType = application.clientProvider(); ClientProvider clientProvider; if (clientProviderType.equals(ClientProvider.class)) { clientProvider = serviceLocatorUtil.getOne(clientProviderType); } else { clientProvider = reflectionUtil.newInstance(clientProviderType); } testContext.addProperty(TestContextProperties.CLIENT_PROVIDER, clientProvider); return clientProvider; }
.findAllWithFilter(PreVerifier.class, guidelines, UnitCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify(); resourceController = serviceLocatorUtil.getOne(ResourceController.class); resourceController.start(testContext); ServiceProvider serviceProvider = serviceLocatorUtil.getFromHintOrDefault( testContext, ServiceProvider.class, serviceLocatorUtil.findAllWithFilter(SutReifier.class, UnitCategory.class) .forEach(p -> p.reify(testContext)); serviceLocatorUtil.findAllWithFilter(InitialReifier.class, UnitCategory.class) .forEach(p -> p.reify(testContext)); .findAllWithFilter(CollaboratorReifier.class, UnitCategory.class) .forEach(p -> p.reify(testContext)); serviceLocatorUtil.findAllWithFilter(FinalReifier.class, UnitCategory.class) .forEach(p -> p.reify(testContext)); .findAllWithFilter(Verifier.class, guidelines, UnitCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify();
Collection<Class<? extends Annotation>> guidelines = testDescriptor.getGuidelines(); resourceController = serviceLocatorUtil.getOne(ResourceController.class); resourceController.start(testContext); serviceLocatorUtil.findAllWithFilter(CollaboratorReifier.class, IntegrationCategory.class) .forEach(p -> p.reify(testContext)); .findAllWithFilter(PreVerifier.class, guidelines, IntegrationCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify(); ServiceProvider serviceProvider = serviceLocatorUtil.getFromHintWithFilter( testContext, ServiceProvider.class, serviceLocatorUtil.findAllWithFilter(InitialReifier.class, IntegrationCategory.class) .forEach(p -> p.reify(testContext)); .findAllWithFilter(FinalReifier.class, IntegrationCategory.class) .forEach(p -> p.reify(testContext)); .findAllWithFilter(Verifier.class, guidelines, IntegrationCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify();
serviceLocatorUtil.findAllWithFilter( CollaboratorReifier.class, SystemCategory.class).forEach(p -> p.reify(testContext)); .findAllWithFilter(PreVerifier.class, guidelines, SystemCategory.class) .forEach(p -> p.verify(testContext)); resourceController = serviceLocatorUtil.getOne(ResourceController.class); resourceController.start(testContext); .findAllWithFilter(FinalReifier.class, SystemCategory.class) .forEach(p -> p.reify(testContext)); .findAllWithFilter(Verifier.class, guidelines, SystemCategory.class) .forEach(p -> p.verify(testContext)); testContext.verify();
Queue<Instance<?>> getInstances(TestContext testContext) { //add instances ConcurrentLinkedDeque<Instance<?>> instances = new ConcurrentLinkedDeque<>(); ServiceLocatorUtil.INSTANCE.findAllWithFilter(InstanceProvider.class) .stream() .map(p -> p.get(testContext)) .flatMap(p -> p.stream()) .forEach(p -> instances.addLast(p)); ServiceLocatorUtil.INSTANCE.findAllWithFilter(ProxyInstanceController.class) .stream() .map(p -> p.create(testContext)) .flatMap(p -> p.stream()) .forEach(p -> instances.addLast(p)); return instances; }
.getOneOrDefault(testConfigurerType, DefaultTestConfigurer.class); .getOneOrDefault(mockProviderType, MockitoMockProvider.class); } else { testRunner = ServiceLocatorUtil.INSTANCE .getOne(TestRunner.class, testSettings.getTestRunnerClass());
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; }
private void addInstances(InjectionManager injectionManager, TestContext testContext) { ConcurrentLinkedDeque<Instance<?>> instances = new ConcurrentLinkedDeque<>(); ServiceLocatorUtil.INSTANCE.findAllWithFilter(InstanceProvider.class) .stream() .map(p -> p.get(testContext)) .flatMap(p -> p.stream()) .forEach(p -> instances.addLast(p)); ServiceLocatorUtil.INSTANCE.findAllWithFilter(ProxyInstanceController.class) .stream() .map(p -> p.create(testContext)) .flatMap(p -> p.stream()) .forEach(p -> instances.addLast(p)); removeInstances(injectionManager, instances); Binder binder = JerseyAbstractBinder.of(instances); injectionManager.register(binder); }
ServerProvider createServerProvider(TestContext testContext, Application application) { Class<? extends ServerProvider> serverProviderType = application.serverProvider(); ServerProvider serverProvider; if (ServerProvider.class.equals(serverProviderType)) { String start = application.start(); String stop = application.stop(); if (!start.isEmpty() && !stop.isEmpty()) { serverProvider = new DefaultServerProvider(); } else { serverProvider = serviceLocatorUtil.getOne(serverProviderType); } } else { serverProvider = reflectionUtil.newInstance(serverProviderType); } testContext.addProperty(TestContextProperties.SERVER_PROVIDER, serverProvider); return serverProvider; }
private void addInstances(ServiceLocator serviceLocator, TestContext testContext) { ConcurrentLinkedDeque<Instance<?>> instances = new ConcurrentLinkedDeque<>(); ServiceLocatorUtil.INSTANCE.findAllWithFilter(InstanceProvider.class) .stream() .map(p -> p.get(testContext)) .flatMap(p -> p.stream()) .forEach(p -> instances.addLast(p)); ServiceLocatorUtil.INSTANCE.findAllWithFilter(ProxyInstanceController.class) .stream() .map(p -> p.create(testContext)) .flatMap(p -> p.stream()) .forEach(p -> instances.addLast(p)); removeInstances(serviceLocator, instances); Binder instanceModule = HK2AbstractBinder.of(instances); DynamicConfigurationService dcs = serviceLocator.getService(DynamicConfigurationService.class); DynamicConfiguration config = dcs.createDynamicConfiguration(); instanceModule.bind(config); config.commit(); }
public void refresh(@SuperCall Callable<Void> zuper, @Argument(0) ApplicationContext applicationContext) throws Exception { ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; TestContextHolder.INSTANCE.command(testContext -> { testContext.computeIfAbsent(SERVICE_INSTANCE, key -> { ServiceProvider<ConfigurableApplicationContext> serviceProvider = ServiceLocatorUtil.INSTANCE.getOne(ServiceProvider.class, SpringServiceProvider.class); return serviceProvider.configure(testContext, configurableApplicationContext); }); }); zuper.call(); }
@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); }
public void initialize(@SuperCall Callable<Void> zuper, @Argument(0) Object applicationConfigurator, @Argument(1) InjectionManager injectionManager, @Argument(2) Binder customBinder) throws Exception { zuper.call(); TestContextHolder.INSTANCE.command(testContext -> { if (SystemCategory.class.equals(testContext.getTestCategory())) { testContext.computeIfAbsent(SERVICE_INSTANCE, key -> { ServiceProvider<InjectionManager> serviceProvider = ServiceLocatorUtil.INSTANCE.getOne(ServiceProvider.class, JerseyServiceProvider.class); return serviceProvider.configure(testContext, injectionManager); }); } }); }
ServiceLocatorUtil.INSTANCE.findAllWithFilter(InstanceProvider.class, IntegrationCategory.class) .stream() .forEach(p -> instances.addLast(p)); ServiceLocatorUtil.INSTANCE.findAllWithFilter(ProxyInstanceController.class) .stream() .map(p -> p.create(testContext))
@Override public DeploymentInfo configure(TestContext testContext) { applicationProvider = ServiceLocatorUtil.INSTANCE .getOne(ApplicationProvider.class); ApplicationInstance applicationInstance = applicationProvider.start(testContext); testContext.addProperty(APPLICATION_INSTANCE, applicationInstance);
@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); }
ServiceLocatorUtil.INSTANCE.getOne(ServiceProvider.class, SpringServiceProvider.class);
Collection<Class<? extends Annotation>> guidelines = testDescriptor.getGuidelines(); serviceLocatorUtil.findAllWithFilter( PostVerifier.class, guidelines,
.getOne(ServiceProvider.class, HK2ServiceProvider.class);
ServiceLocatorUtil.INSTANCE.getOne(ServiceProvider.class, SpringServiceProvider.class);