private static void registerInput(final ActionMapping actionMapping, String input) {
   if (isSimplePageFile(input)) {
     PartialTileDefinition tileDefinition = new PartialTileDefinition(input);
     FenixDefinitionsFactory.registerDefinition(tileDefinition);
     actionMapping.setInput(tileDefinition.getName());
   } else {
     // The input is using an existing tile definition
     actionMapping.setInput(input);
   }
 }
  public void testPerformInvalidUsername() {
    LoginAction action = new LoginAction();

    ActionMapping mapping = new ActionMapping();
    ActionForward success = new ActionForward(null, "login_failed", false);
    ActionForward failure = new ActionForward("failure", "path", false);
    PxtCookieManager pcm = new PxtCookieManager();
    RhnMockDynaActionForm form = new RhnMockDynaActionForm("loginForm");
    RhnMockHttpServletRequest request = new RhnMockHttpServletRequest();
    RhnMockHttpServletResponse response = new RhnMockHttpServletResponse();

    RequestContext requestContext = new RequestContext(request);
    request.setSession(new MockHttpSession());
    request.setupServerName("mymachine.rhndev.redhat.com");

    WebSession s = requestContext.getWebSession();
    request.addCookie(pcm.createPxtCookie(s.getId(), request, 10));

    mapping.setInput("login_failed");
    mapping.addForwardConfig(success);
    mapping.addForwardConfig(failure);
    form.set("username", "017324193274913741974");
    form.set("password", "017324193274913741974");

    ActionForward rc = action.execute(mapping, form, request, response);

    assertEquals(rc, failure);
  }
  private ActionConfig buildActionConfig(String path) {
    ActionMapping mapping = new ActionMapping();

    mapping.setName("name,{1}");
    mapping.setPath(path);
    mapping.setScope("request");
    mapping.setUnknown(false);
    mapping.setValidate(true);

    mapping.setPrefix("foo,{1}");
    mapping.setSuffix("bar,{1}");

    mapping.setType("foo.bar.{1}Action");
    mapping.setRoles("public,{1}");
    mapping.setParameter("param,{1}");
    mapping.setAttribute("attrib,{1}");
    mapping.setForward("fwd,{1}");
    mapping.setInclude("include,{1}");
    mapping.setInput("input,{1}");

    ForwardConfig cfg = new ActionForward();

    cfg.setName("name");
    cfg.setPath("path,{1}");
    cfg.setModule("mod{1}");
    cfg.setProperty("foo", "bar,{1}");
    mapping.addForwardConfig(cfg);

    cfg = new ActionForward();
    cfg.setName("name2");
    cfg.setPath("path2");
    cfg.setModule("mod{1}");
    mapping.addForwardConfig(cfg);

    ExceptionConfig excfg = new ExceptionConfig();

    excfg.setKey("foo");
    excfg.setType("foo.Bar");
    excfg.setPath("path");
    mapping.addExceptionConfig(excfg);

    excfg = new ExceptionConfig();
    excfg.setKey("foo2");
    excfg.setType("foo.Bar2");
    excfg.setPath("path2");
    mapping.addExceptionConfig(excfg);

    mapping.setProperty("testprop", "testval");
    mapping.setProperty("testprop2", "test{1}");

    mapping.freeze();

    return mapping;
  }
  @Override
  public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {

    if (!initialized) {
      loadActionsFromFile(actionClasses);
      PartialTileDefinition.init();
      initialized = true;
    }

    final String modulePrefix = StringUtils.removeStart(config.getPrefix(), "/");

    for (Class<?> actionClass : actionClasses) {
      Mapping mapping = actionClass.getAnnotation(Mapping.class);
      if (mapping == null || !modulePrefix.equals(mapping.module())) {
        continue;
      }

      final ActionMapping actionMapping = createCustomActionMapping(mapping);
      if (actionMapping == null) {
        continue;
      }

      actionMapping.setPath(mapping.path());
      actionMapping.setType(actionClass.getName());
      actionMapping.setScope(mapping.scope());
      actionMapping.setParameter(mapping.parameter());
      actionMapping.setValidate(mapping.validate());

      if (mapping.formBeanClass() != ActionForm.class) {
        final String formName = mapping.formBeanClass().getName();
        createFormBeanConfigIfNecessary(config, mapping, formName);
        actionMapping.setName(formName);
      } else if (!mapping.formBean().isEmpty()) {
        actionMapping.setName(mapping.formBean());
      }

      if (mapping.input().isEmpty()) {
        actionMapping.setInput(findInputMethod(actionClass, mapping));
      } else {
        registerInput(actionMapping, mapping.input());
      }

      String defaultResourcesName = getDefaultResourcesName(config);
      Forwards forwards = actionClass.getAnnotation(Forwards.class);
      if (forwards != null) {
        for (final Forward forward : forwards.value()) {
          registerForward(actionMapping, forward, forwards, mapping, defaultResourcesName);
        }
      }
      registerSuperclassForwards(
          actionMapping, actionClass.getSuperclass(), mapping, defaultResourcesName);

      Exceptions exceptions = actionClass.getAnnotation(Exceptions.class);
      if (exceptions != null) {
        registerExceptionHandling(actionMapping, exceptions);
      }

      initializeActionMappingProperties(actionMapping, mapping.customMappingProperties());

      config.addActionConfig(actionMapping);
    }
  }