コード例 #1
0
  @Test
  public void testIgnoreModulesByFilter() {
    final ContainerAdaptor defaultAdaptor = mock(ContainerAdaptor.class);
    ProcessorA a = new ProcessorA();
    final ProcessorB b = new ProcessorB();
    ProcessorC c = new ProcessorC();
    List<ApplicationProcessor> processors = new ArrayList<ApplicationProcessor>();
    processors.add(a);
    processors.add(b);
    processors.add(c);
    when(defaultAdaptor.getInstancesOfType(ApplicationProcessor.class)).thenReturn(processors);
    ca = defaultAdaptor;
    builder.setModulesProviderClass(MockContainerAdaptorFactory.class);
    builder.addApplicationProcessorClass(ApplicationProcessor.class);
    MultiModule.Filter filter =
        new MultiModule.Filter() {

          @Override
          public boolean isAppreciable(MultiModule aMultiModule) {
            if (aMultiModule == b) {
              return false;
            }
            return true;
          }
        };
    builder.filter(filter);
    Modules modules = builder.buildModules(resolver, defaultAdaptor);
    List<ApplicationProcessor> actual = modules.getApplicationProcessors();
    log.debug(actual.toString());
    assertThat(actual.size(), is(2));
  }
コード例 #2
0
 @SuppressWarnings("unchecked")
 @Test
 public void testBuildModules() {
   builder.setModulesProviderClass(MockModulesProvidingContainerAdaptorFactory.class);
   builder.setInvocationFactoryClass(invocationFactory.getClass());
   builder.setInvocationInstanceProviderClass(
       (Class<? extends ContainerAdaptorFactory<? extends ContainerAdaptor>>)
           containerAdaptorFactory.getClass());
   builder.setInvokerFactoryClass(invokerFactory.getClass());
   builder.setResponseHandlerClass(directiontHandler.getClass());
   builder.setRenderableResolverClass(directionResolver.getClass());
   builder.addApplicationProcessorClass(invocationProcessor.getClass());
   builder.addInvocationInterceptorClass(invocationInterceptor.getClass());
   builder.addInvocationMetadataFactoriesClass(invocationMetadataFactory.getClass());
   builder.addAttributesHandlerClass(attributesHandler.getClass());
   builder.setExceptionHandlerClass(exceptionHandler.getClass());
   builder.setTypeMapperContextClass(typeMapperContext.getClass());
   Renderable mapToResponse = mock(Renderable.class);
   builder.addResponseFormatterClass(mapToResponse.getClass(), directionFormatter.getClass());
   Modules modules = builder.buildModules(resolver, adaptor);
   assertSame(modules.getInvocationMetadataFactories().get(0), invocationMetadataFactory);
   assertSame(modules.getInvocationInstanceProvider(), containerAdaptor);
   // same instance.
   assertSame(modules.getInvocationInstanceProvider(), containerAdaptor);
   assertSame(modules.getInvocationFactory(), invocationFactory);
   assertSame(modules.getResponseResolver(), directionResolver);
   assertSame(modules.getResponseHandler(), directiontHandler);
   assertSame(modules.getApplicationProcessors().get(0), invocationProcessor);
   assertSame(modules.getInvocationInterceptors().get(0), invocationInterceptor);
   assertSame(modules.getExceptionHandler(), exceptionHandler);
   assertSame(modules.getTypeMapperContext(), typeMapperContext);
   assertSame(modules.findResponseFormatter(mapToResponse.getClass()), directionFormatter);
 }
コード例 #3
0
 @Test
 public void testIgnoreModules() {
   final ContainerAdaptor defaultAdaptor = mock(ContainerAdaptor.class);
   List<ApplicationProcessor> processors = new ArrayList<ApplicationProcessor>();
   processors.add(new ProcessorA());
   processors.add(new ProcessorB());
   processors.add(new ProcessorC());
   when(defaultAdaptor.getInstancesOfType(ApplicationProcessor.class)).thenReturn(processors);
   ca = defaultAdaptor;
   builder.setModulesProviderClass(MockContainerAdaptorFactory.class);
   builder.addApplicationProcessorClass(ApplicationProcessor.class);
   Modules modules = builder.buildModules(resolver, defaultAdaptor);
   List<ApplicationProcessor> actual = modules.getApplicationProcessors();
   log.debug(actual.toString());
   assertThat(actual.size(), is(3));
   builder.ignore(ProcessorB.class);
   modules = builder.buildModules(resolver, defaultAdaptor);
   actual = modules.getApplicationProcessors();
   log.debug(actual.toString());
   assertThat(actual.size(), is(1));
 }
コード例 #4
0
 @Test
 public void testOptionalModulesFound() {
   ContainerAdaptor defaultAdaptor = mock(ContainerAdaptor.class);
   ApplicationProcessor foundProcessor = mock(ApplicationProcessor.class);
   List<ApplicationProcessor> processors = Arrays.asList(foundProcessor);
   when(defaultAdaptor.getInstancesOfType(ApplicationProcessor.class)).thenReturn(processors);
   builder.addApplicationProcessorClass(ApplicationProcessor.class);
   builder.setModulesProviderClass(MockModulesProvidingContainerAdaptorFactory.class);
   Modules modules = builder.buildModules(resolver, defaultAdaptor);
   adaptor.unregister(ApplicationProcessor.class);
   List<ApplicationProcessor> actual = modules.getApplicationProcessors();
   log.debug(actual.toString());
   assertThat(actual.size(), is(1));
   assertThat(actual.get(0), is(foundProcessor));
 }