Esempio n. 1
0
 /**
  * Test method for {@link JavascriptParser#parse(DefDescriptor, Source)}. The DefDescriptor is
  * referring to a Controller but the Javascript should have had only functions. In this scenario
  * there is a variable declaration which is not expected in a controller file. The JSparser will
  * flag an exception for this.
  *
  * @throws Exception
  */
 public void testInvalidJSController() throws Exception {
   DefDescriptor<ControllerDef> descriptor =
       DefDescriptorImpl.getInstance("js://test.testInvalidJSController", ControllerDef.class);
   Source<ControllerDef> source = getJavascriptSourceLoader().getSource(descriptor);
   ControllerDef cd = (ControllerDef) parser.parse(descriptor, source);
   try {
     cd.validateDefinition();
     fail("Javascript controller must only contain functions");
   } catch (Exception e) {
     this.checkExceptionContains(e, InvalidDefinitionException.class, "Expected ':'");
   }
 }
 @Override
 protected Invocation getInvocation(Object object) throws QuickFixException {
   if (object instanceof Map) {
     Map<?, ?> methodMap = (Map<?, ?>) object;
     String name = (String) methodMap.get("name");
     if (name == null) {
       throw new InvalidDefinitionException(
           "A mock action must specify the name of the action", getLocation());
     }
     String typeStr = (String) methodMap.get("type");
     Class<?> type = Object.class;
     if (typeStr != null) {
       try {
         type = classForSimpleName(typeStr);
       } catch (ClassNotFoundException e) {
       }
     }
     actionDef = controllerDef.getSubDefinition(name);
     return new ActionInvocation("createAction", ImmutableList.of(name), type);
   }
   return super.getInvocation(object);
 }