@Test
  public void testHasPermissionProjectNullRole() {
    projectManagerMock.expectAndReturn(
        "getProjectObj",
        P.args(
            P.eq(
                new Long(
                    TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION.getParam1()))),
        TestProjectShareTypePermissionChecker.MOCK_PROJECT);
    final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy();

    final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy();

    projectRoleManagerMock.expectAndReturn(
        "getProjectRole",
        P.args(P.eq(TestProjectShareTypePermissionChecker.MOCK_ROLE.getId())),
        null);

    final ProjectRoleManager projectRoleManager =
        (ProjectRoleManager) projectRoleManagerMock.proxy();

    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(
            projectManager, permissionManager, projectRoleManager);
    assertFalse(
        checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_ROLE_PERMISSION));

    projectManagerMock.verify();
    permissionManagerMock.verify();
    projectRoleManagerMock.verify();
  }
 public void testDoExecute() throws Exception {
   MockHttpServletResponse response =
       JiraTestUtil.setupExpectedRedirect("ViewFieldLayoutSchemes.jspa");
   Mock mockFieldLayoutShceme = new Mock(FieldLayoutScheme.class);
   mockFieldLayoutShceme.setStrict(true);
   String name = "some name";
   mockFieldLayoutShceme.expectVoid("setName", P.args(new IsEqual(name)));
   String description = "Test Description";
   mockFieldLayoutShceme.expectVoid("setDescription", P.args(new IsEqual(description)));
   mockFieldLayoutShceme.expectVoid("store");
   Long id = new Long(1);
   mockFieldLayoutShceme.expectAndReturn("getId", id);
   FieldLayoutScheme fieldLayoutScheme = (FieldLayoutScheme) mockFieldLayoutShceme.proxy();
   mockFieldLayoutManager.expectAndReturn(
       "getFieldLayoutSchemes", EasyList.build(fieldLayoutScheme));
   mockFieldLayoutManager.expectAndReturn(
       "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), fieldLayoutScheme);
   efls.setFieldLayoutSchemeName(name);
   efls.setFieldLayoutSchemeDescription(description);
   efls.setId(id);
   assertEquals(Action.NONE, efls.execute());
   response.verify();
   mockFieldLayoutShceme.verify();
   mockFieldLayoutManager.verify();
 }
 public void testSameAliasWithDifferentClass() {
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/SimpleAction-validation.xml")),
       new ArrayList());
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/SimpleAction-validationAlias-validation.xml")),
       new ArrayList());
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/test/SimpleAction2-validation.xml")),
       new ArrayList());
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/test/SimpleAction2-validationAlias-validation.xml")),
       new ArrayList());
   actionValidatorManager.getValidators(SimpleAction.class, alias);
   actionValidatorManager.getValidators(SimpleAction2.class, alias);
   mockValidatorFileParser.verify();
 }
  @Test
  public void testHasPermissionProjectUserHasPermission() {
    projectManagerMock.expectAndReturn(
        "getProjectObj",
        P.args(
            P.eq(new Long(TestProjectShareTypePermissionChecker.PROJECT_PERMISSION.getParam1()))),
        TestProjectShareTypePermissionChecker.MOCK_PROJECT);
    final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy();

    permissionManagerMock.expectAndReturn(
        "hasPermission",
        P.args(
            P.eq(Permissions.BROWSE),
            P.eq(TestProjectShareTypePermissionChecker.MOCK_PROJECT),
            P.eq(user)),
        Boolean.TRUE);
    final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy();

    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(projectManager, permissionManager, null);
    assertTrue(
        checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_PERMISSION));

    projectManagerMock.verify();
    permissionManagerMock.verify();
  }
 public void testGetValidatorsFromInterface() {
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/SimpleAction-validation.xml")),
       new ArrayList());
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/SimpleAction-validationAlias-validation.xml")),
       new ArrayList());
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/test/DataAware-validation.xml")),
       new ArrayList());
   mockValidatorFileParser.expectAndReturn(
       "parseActionValidatorConfigs",
       C.args(
           C.IS_NOT_NULL,
           C.IS_NOT_NULL,
           C.eq("com/opensymphony/xwork2/test/DataAware-validationAlias-validation.xml")),
       new ArrayList());
   actionValidatorManager.getValidators(SimpleAction3.class, alias);
   mockValidatorFileParser.verify();
 }
 public void testDoValidationInvalidId() throws Exception {
   mockFieldLayoutManager.expectAndReturn("getFieldLayoutSchemes", Collections.EMPTY_LIST);
   Long id = new Long(1);
   mockFieldLayoutManager.expectAndReturn(
       "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), null);
   efls.setFieldLayoutSchemeName("Some Name");
   efls.setId(id);
   assertEquals(Action.INPUT, efls.execute());
   checkSingleElementCollection(efls.getErrorMessages(), "Invalid id '" + id + "'.");
   mockFieldLayoutManager.verify();
 }
 public void testDoDefault() throws Exception {
   Long id = new Long(1);
   Mock mockFieldLayoutScheme = new Mock(FieldLayoutScheme.class);
   mockFieldLayoutScheme.setStrict(true);
   String name = "Test Name";
   mockFieldLayoutScheme.expectAndReturn("getName", name);
   String description = "Test Description";
   mockFieldLayoutScheme.expectAndReturn("getDescription", description);
   mockFieldLayoutManager.expectAndReturn(
       "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), mockFieldLayoutScheme.proxy());
   efls.setId(id);
   assertEquals(Action.INPUT, efls.doDefault());
   assertEquals(name, efls.getFieldLayoutSchemeName());
   assertEquals(description, efls.getFieldLayoutSchemeDescription());
   mockFieldLayoutScheme.verify();
   mockFieldLayoutManager.verify();
 }
 public void testDoDefaultInvalidId() throws Exception {
   Long id = new Long(1);
   mockFieldLayoutManager.expectAndReturn(
       "getMutableFieldLayoutScheme", P.args(new IsEqual(id)), null);
   efls.setId(id);
   assertEquals(Action.INPUT, efls.doDefault());
   checkSingleElementCollection(efls.getErrorMessages(), "Invalid id '" + id + "'.");
   mockFieldLayoutManager.verify();
 }
  public void testAddNonExistingPet() throws Exception {
    action.setShoppingCart((ShoppingCart) mockShoppingCart.proxy());
    mockPetStore.expectAndReturn("getPet", new Long(123), null);

    action.setPetId(123);
    String result = action.execute();

    assertEquals(Action.ERROR, result);
    mockPetStore.verify();
    mockShoppingCart.verify();
  }
  @Test(expected = PluginParseException.class)
  public void testCreateBadXml() {
    XmlDynamicPluginFactory factory = new XmlDynamicPluginFactory("foo");
    Mock mockModuleDescriptorFactory = new Mock(ModuleDescriptorFactory.class);

    Mock mockArtifact = new Mock(PluginArtifact.class);
    mockArtifact.expectAndReturn("toFile", new File("sadfasdf"));
    factory.create(
        (PluginArtifact) mockArtifact.proxy(),
        (ModuleDescriptorFactory) mockModuleDescriptorFactory.proxy());
  }
Exemplo n.º 11
0
 public void testDoValidationDuplicateName() throws Exception {
   Mock mockFieldLayoutShceme = new Mock(FieldLayoutScheme.class);
   mockFieldLayoutShceme.setStrict(true);
   String name = "some name";
   mockFieldLayoutShceme.expectAndReturn("getName", name);
   // Return a different id to cause an error
   mockFieldLayoutShceme.expectAndReturn("getId", new Long(2));
   Long id = new Long(1);
   FieldLayoutScheme fieldLayoutScheme = (FieldLayoutScheme) mockFieldLayoutShceme.proxy();
   mockFieldLayoutManager.expectAndReturn(
       "getFieldLayoutSchemes", EasyList.build(fieldLayoutScheme));
   efls.setFieldLayoutSchemeName(name);
   efls.setId(id);
   assertEquals(Action.INPUT, efls.execute());
   assertEquals(1, efls.getErrors().size());
   assertEquals(
       "A field configuration scheme with this name already exists.",
       efls.getErrors().get("fieldLayoutSchemeName"));
   mockFieldLayoutShceme.verify();
   mockFieldLayoutManager.verify();
 }
Exemplo n.º 12
0
  public void testAddPet() throws Exception {
    action.setShoppingCart((ShoppingCart) mockShoppingCart.proxy());
    mockPetStore.expectAndReturn("getPet", new Long(123), pet);
    mockShoppingCart.expect("addPet", pet);

    action.setPetId(123);
    String result = action.execute();

    assertEquals(Action.SUCCESS, result);
    mockPetStore.verify();
    mockShoppingCart.verify();
  }
  @Test
  public void test_should_set_property_hello() {
    BeanPropertyExpressionEnricher propertyExpressionEnricher =
        new BeanPropertyExpressionEnricher();
    Mock muleMessageMock = new Mock(MuleMessage.class);

    TestObject testObject = new TestObject();

    muleMessageMock.expectAndReturn("getPayload", testObject);

    propertyExpressionEnricher.enrich("hello", (MuleMessage) muleMessageMock.proxy(), "Test me");
    assertEquals(testObject.getHello(), "Test me");
  }
Exemplo n.º 14
0
  public void testValidConversion() {
    Mock mockManager = new Mock(UMOManager.class);
    try {
      MuleManager.setInstance((UMOManager) mockManager.proxy());
      Object obj = getValidConvertedType();
      mockManager.expectAndReturn(getLookupMethod(), C.eq("test://Test"), obj);
      Object result = getConverter().convert(obj.getClass(), "test://Test");

      assertNotNull(result);
      mockManager.verify();
    } finally {
      MuleManager.setInstance(null);
    }
  }
  @Test
  public void test_should_set_property_third() {
    BeanPropertyExpressionEnricher propertyExpressionEnricher =
        new BeanPropertyExpressionEnricher();

    Mock muleMessageMock = new Mock(MuleMessage.class);

    TestObject testObject = new TestObject();

    muleMessageMock.expectAndReturn("getPayload", testObject);

    propertyExpressionEnricher.enrich(
        "first.second.third", (MuleMessage) muleMessageMock.proxy(), "This is a test");
    assertEquals(testObject.getFirst().getSecond().getThird(), "This is a test");
  }
Exemplo n.º 16
0
 public void testInvalidConversion() {
   Mock mockManager = new Mock(UMOManager.class);
   MuleManager.setInstance((UMOManager) mockManager.proxy());
   Object obj = getValidConvertedType();
   mockManager.expectAndReturn(getLookupMethod(), C.eq("TestBad"), null);
   try {
     getConverter().convert(obj.getClass(), "TestBad");
     fail("should throw an exception if not found");
   } catch (Exception e) {
     // exprected
     mockManager.verify();
   } finally {
     MuleManager.setInstance(null);
   }
 }
  @Test
  public void testHasPermissionNoProject() {
    projectManagerMock.expectAndReturn(
        "getProjectObj",
        P.args(
            P.eq(new Long(TestProjectShareTypePermissionChecker.PROJECT_PERMISSION.getParam1()))),
        null);
    final ProjectManager projectManager = (ProjectManager) projectManagerMock.proxy();

    final ShareTypePermissionChecker checker =
        new ProjectShareTypePermissionChecker(projectManager, null, null);
    assertFalse(
        checker.hasPermission(user, TestProjectShareTypePermissionChecker.PROJECT_PERMISSION));

    projectManagerMock.verify();
  }
Exemplo n.º 18
0
  public void testFilteringOutboundRouter() throws Exception {
    Mock session = MuleTestUtils.getMockSession();
    OutboundRouterCollection messageRouter = new OutboundRouterCollection();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOEndpoint endpoint1 = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    assertNotNull(endpoint1);

    FilteringOutboundRouter router = new FilteringOutboundRouter();
    PayloadTypeFilter filter = new PayloadTypeFilter(String.class);
    router.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    router.setEndpoints(endpoints);

    assertFalse(router.isUseTemplates());
    assertEquals(filter, router.getFilter());

    UMOMessage message = new MuleMessage("test event");

    assertTrue(router.isMatch(message));

    session.expect("dispatchEvent", C.eq(message, endpoint1));
    router.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    message = new MuleMessage("test event");

    session.expectAndReturn("sendEvent", C.eq(message, endpoint1), message);
    UMOMessage result = router.route(message, (UMOSession) session.proxy(), true);
    assertNotNull(result);
    assertEquals(message, result);
    session.verify();

    message = new MuleMessage(new Exception("test event"));

    assertTrue(!router.isMatch(message));

    router.setTransformer(
        new AbstractTransformer() {
          public Object doTransform(Object src, String encoding) throws TransformerException {
            return ((Exception) src).getMessage();
          }
        });

    assertTrue(router.isMatch(message));
  }
Exemplo n.º 19
0
  public void testSuccessfulExceptionRouter() throws Exception {
    Mock session = getMockSession();
    OutboundMessageRouter messageRouter = new OutboundMessageRouter();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOEndpoint endpoint1 = new MuleEndpoint("test://AlwaysFail", false);
    UMOEndpoint endpoint2 = new MuleEndpoint("test://AlwaysFail", false);

    UMOEndpoint endpoint3 = new MuleEndpoint("test://Dummy", false);

    ExceptionBasedRouter router = new ExceptionBasedRouter();
    RegExFilter filter = new RegExFilter("(.*) event");
    router.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    endpoints.add(endpoint2);
    endpoints.add(endpoint3);
    router.setEndpoints(endpoints);

    assertEquals(filter, router.getFilter());

    UMOMessage message = new MuleMessage("test event", null);

    assertTrue(router.isMatch(message));

    // Only one dispatch should be called as the others should fail
    session.expect("dispatchEvent", C.eq(message, endpoint1));
    router.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    message = new MuleMessage("test event", null);

    // Only one send should be called as the others should fail
    session.expectAndReturn("sendEvent", C.eq(message, endpoint1), message);
    UMOMessage result = router.route(message, (UMOSession) session.proxy(), true);
    assertNotNull(result);
    assertEquals(message, result);
    session.verify();
  }
 public void testBuildsValidatorsForAliasError() {
   boolean pass = false;
   try {
     mockValidatorFileParser.expectAndReturn(
         "parseActionValidatorConfigs",
         C.args(
             C.IS_NOT_NULL,
             C.IS_NOT_NULL,
             C.eq("com/opensymphony/xwork2/TestBean-validation.xml")),
         new ArrayList());
     mockValidatorFileParser.expectAndThrow(
         "parseActionValidatorConfigs",
         C.args(
             C.IS_NOT_NULL,
             C.IS_NOT_NULL,
             C.eq("com/opensymphony/xwork2/TestBean-badtest-validation.xml")),
         new ConfigurationException());
     List validatorList = actionValidatorManager.getValidators(TestBean.class, "badtest");
   } catch (XWorkException ex) {
     pass = true;
   }
   mockValidatorFileParser.verify();
   assertTrue("Didn't throw exception on load failure", pass);
 }
Exemplo n.º 21
0
  public void testOutboundMessageRouter() throws Exception {
    Mock session = MuleTestUtils.getMockSession();
    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));
    OutboundRouterCollection messageRouter = new OutboundRouterCollection();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());
    assertNotNull(messageRouter.getCatchAllStrategy());

    UMOEndpoint endpoint1 = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    assertNotNull(endpoint1);

    UMOEndpoint endpoint2 = getTestEndpoint("Test2Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    assertNotNull(endpoint2);

    FilteringOutboundRouter router1 = new FilteringOutboundRouter();
    PayloadTypeFilter filter = new PayloadTypeFilter(String.class);
    router1.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    router1.setEndpoints(endpoints);

    FilteringOutboundRouter router2 = new FilteringOutboundRouter();
    PayloadTypeFilter filter2 = new PayloadTypeFilter();
    filter2.setExpectedType(Exception.class);
    router2.setFilter(filter2);
    endpoints = new ArrayList();
    endpoints.add(endpoint2);
    router2.setEndpoints(endpoints);

    messageRouter.addRouter(router1);
    assertEquals(1, messageRouter.getRouters().size());
    assertNotNull(messageRouter.removeRouter(router1));
    assertEquals(0, messageRouter.getRouters().size());
    List list = new ArrayList();
    list.add(router1);
    list.add(router2);
    messageRouter.setRouters(list);

    UMOMessage message = new MuleMessage("test event");

    session.expect("dispatchEvent", C.eq(message, endpoint1));
    messageRouter.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    message = new MuleMessage(new IllegalArgumentException());

    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));
    session.expect("dispatchEvent", C.eq(message, endpoint2));
    messageRouter.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    FilteringOutboundRouter router3 = new FilteringOutboundRouter();
    router3.setFilter(new PayloadTypeFilter(Object.class));
    endpoints = new ArrayList();
    endpoints.add(endpoint2);
    router3.setEndpoints(endpoints);
    messageRouter.addRouter(router3);

    // now the message should be routed twice to different endpoints
    message = new MuleMessage("testing multiple routing");
    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));
    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));

    session.expect("dispatchEvent", C.eq(message, endpoint1));
    session.expect("dispatchEvent", C.eq(message, endpoint2));
    messageRouter.setMatchAll(true);
    messageRouter.route(message, (UMOSession) session.proxy(), false);
    session.verify();
  }