public EmbeddedServletContainer startEmbeddedServletContainer( @SuperCall Callable<EmbeddedServletContainer> zuper) throws Exception { EmbeddedServletContainer servletContainer = zuper.call(); TestContextHolder.INSTANCE.command((Consumer<TestContext>) testContext -> testContext.addProperty(SERVER, servletContainer) ); return servletContainer; }
@Override public MethodDelegationBinder.ParameterBinding<?> bind(AnnotationDescription.Loadable<SuperCall> annotation, MethodDescription source, ParameterDescription target, Implementation.Target implementationTarget, Assigner assigner, Assigner.Typing typing) { TypeDescription targetType = target.getType().asErasure(); if (!targetType.represents(Runnable.class) && !targetType.represents(Callable.class) && !targetType.represents(Object.class)) { throw new IllegalStateException("A super method call proxy can only be assigned to Runnable or Callable types: " + target); } else if (source.isConstructor()) { return annotation.loadSilent().nullIfImpossible() ? new MethodDelegationBinder.ParameterBinding.Anonymous(NullConstant.INSTANCE) : MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } Implementation.SpecialMethodInvocation specialMethodInvocation = annotation.loadSilent().fallbackToDefault() ? implementationTarget.invokeDominant(source.asSignatureToken()) : implementationTarget.invokeSuper(source.asSignatureToken()); StackManipulation stackManipulation; if (specialMethodInvocation.isValid()) { stackManipulation = new MethodCallProxy.AssignableSignatureCall(specialMethodInvocation, annotation.loadSilent().serializableProxy()); } else if (annotation.loadSilent().nullIfImpossible()) { stackManipulation = NullConstant.INSTANCE; } else { return MethodDelegationBinder.ParameterBinding.Illegal.INSTANCE; } return new MethodDelegationBinder.ParameterBinding.Anonymous(stackManipulation); } }
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"); } }
@RuntimeType public Class<?>[] getServletConfigClasses(@SuperCall Callable<Class<?>[]> zuper, @This Object object) throws Exception { Class<?>[] result = zuper.call(); return TestContextHolder.INSTANCE.query(testContext -> { TestDescriptor testDescriptor = testContext.getTestDescriptor(); Collection<Module> modules = testDescriptor.getModules(); Stream<Class<?>> testModules = modules.stream().map(Module::value); Stream<Class<?>> productionModules = Stream.empty(); if (result != null) { productionModules = Stream.of(result); } return Stream.concat(testModules, productionModules).toArray(Class[]::new); }); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object) throws Exception { return zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object) throws Exception { return zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod(@SuperCall Callable<?> zuper, @This(optional = true) Object object) throws Exception { return zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object) throws Exception { return zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object, @AllArguments Object[] args) throws Exception { return zuper.call(); }
public EmbeddedServletContainerFactory getEmbeddedServletContainerFactory( @SuperCall Callable<EmbeddedServletContainerFactory> zuper) throws Exception { EmbeddedServletContainerFactory containerFactory = zuper.call(); TestContextHolder.INSTANCE.command(testContext -> { ConfigurableEmbeddedServletContainer servletContainer = (ConfigurableEmbeddedServletContainer) containerFactory; servletContainer.setPort(0); TestConfigurer testConfigurer = testContext.getTestConfigurer(); testConfigurer.configure(testContext, servletContainer); }); return containerFactory; }
protected void prepareEmbeddedWebApplicationContext(@SuperCall Callable<Void> zuper, @Argument(0) ServletContext servletContext) throws Exception { TestContextHolder.INSTANCE.command(testContext -> { TestConfigurer testConfigurer = testContext.getTestConfigurer(); testConfigurer.configure(testContext, servletContext); }); zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object, @AllArguments Object[] args) throws Exception { return zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object, @AllArguments Object[] args) throws Exception { return zuper.call(); }
public void prepareEmbeddedWebApplicationContext(@SuperCall Callable<Void> zuper, @AllArguments Object[] args) throws Exception { TestContextHolder.INSTANCE.command(testContext -> { LoggingUtil.INSTANCE.setTextContext(testContext); testContext.addProperty(SERVLET_CONTEXT, args[0]); }); zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object, @AllArguments Object[] args) throws Exception { return zuper.call(); }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod( @SuperCall Callable<?> zuper, @This(optional = true) Object object, @AllArguments Object[] args) throws Exception { return zuper.call(); }
public ConfigurableApplicationContext run( @SuperCall Callable<ConfigurableApplicationContext> zuper, @This Object object, @AllArguments Object[] args) throws Exception { AnnotationConfigEmbeddedWebApplicationContext applicationContext = (AnnotationConfigEmbeddedWebApplicationContext) zuper.call(); TestContextHolder.INSTANCE.command(testContext -> { testContext.addProperty(APP, object); if (args.length == 2) { testContext.addProperty(APP_ARGUMENTS, args[1]); } }); return applicationContext; }
@RuntimeType @BindingPriority(Integer.MAX_VALUE) public Object anyMethod(@SuperCall Callable<?> zuper, @Origin Method method, @This(optional = true) Object object) throws Exception { Object result = zuper.call(); if (method.getName().equals("start")) { TestContextHolder.INSTANCE.command(testContext -> { int port = ((Server) object).getPort(); testContext.addProperty(TestContextProperties.APP_PORT, port); testContext.addProperty(TestContextProperties.SERVER, object); URI baseURI = URI.create(format("grpc://localhost:%d", port)); testContext.addProperty(TestContextProperties.SERVER_BASE_URI, baseURI); }); } return result; }
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(); }
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); }); } }); }