@Test
 public void testInvokeWithStorageParameterWithNullStorage() throws Exception {
   final MethodDescriptor methodDescriptor =
       new MethodDescriptorImpl(getStubMethodWithStorageParameter(), 0, true);
   methodInvoker.invoke(methodDescriptor, null);
   assertEquals(1, invokeMessageList.size());
   assertEquals("stub with storage", invokeMessageList.get(0));
 }
 @Test
 public void testInvokeWithStorageParameterWithStorage() throws Exception {
   final MethodDescriptor methodDescriptor =
       new MethodDescriptorImpl(getStubMethodWithStorageParameter(), 0, true);
   final Storage storage = new DefaultStorage();
   methodInvoker.invoke(methodDescriptor, storage);
   assertEquals(1, invokeMessageList.size());
   assertEquals("stub with storage", invokeMessageList.get(0));
   assertTrue(storage.get("store").isPresent());
   assertEquals("value", storage.get("store").get());
 }
Example #3
0
  /**
   * Method do scanning of controller's class and produce {@link ClassInvoker} object
   *
   * @param controllerClass
   * @param injector
   * @return instance of the class invoker for annotated class.
   * @throws Exception
   */
  public ClassInvoker scan(Class<?> controllerClass, Injector injector) {
    try {
      InterceptorService interceptorService = injector.getInstance(InterceptorService.class);
      if (interceptorService == null) {
        throw new IllegalStateException("The InterceptorService doesn't exists in guice module");
      }

      Controller controllerAnotation = controllerClass.getAnnotation(Controller.class);
      if (controllerAnotation == null) {
        throw new IllegalStateException(
            "Class is not defined as a controller. Missing @Controller annotation.");
      }

      // scan session attributes & default view
      List<String> sessionAttrList = Arrays.asList(controllerAnotation.sessionAttributes());

      // scan methods
      List<Method> methods = Arrays.asList(controllerClass.getMethods());
      List<MethodInvoker> scannedInvokers = new LinkedList<MethodInvoker>();
      for (Method method : methods) {
        MappingData reqMappingData = mappingDataForNewAnot(method);
        if (reqMappingData == null) {
          reqMappingData = mappingDataForNewAnot(method);
        }

        if (reqMappingData != null) {
          reqMappingData.injector = injector;
          reqMappingData.controllerClass = controllerClass;
          reqMappingData.method = method;

          // create the invoker
          MethodInvoker invoker = MethodInvokerImpl.createInvoker(reqMappingData);

          // at the end is filter decorator
          MethodInvoker filteredInvoker = new MethodInvokerFilter(reqMappingData, invoker);
          scannedInvokers.add(filteredInvoker);
        }
      }

      if (scannedInvokers != null) {
        Collections.sort(scannedInvokers);
      }

      return new ClassInvoker(controllerClass, scannedInvokers, sessionAttrList);
    } catch (Exception e) {
      throw new ScannerException(controllerClass, e);
    }
  }
 @Test
 public void testInvokeWithNullStorage() throws Exception {
   methodInvoker.invoke(methodDescriptor, null);
   assertEquals(1, invokeMessageList.size());
   assertEquals("stub", invokeMessageList.get(0));
 }