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();
 }
  @Test
  public void testHasPermissionProjectRoleNullUserHasNoPermission() {
    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();
    final ProjectRoleManager projectRoleManager =
        (ProjectRoleManager) projectRoleManagerMock.proxy();

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

    projectManagerMock.verify();
    permissionManagerMock.verify();
    projectRoleManagerMock.verify();
  }
  @Test
  public void testHasPermissionProjectNullUserHasPermission() {
    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.IS_NULL),
        Boolean.TRUE);
    final PermissionManager permissionManager = (PermissionManager) permissionManagerMock.proxy();

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

    projectManagerMock.verify();
    permissionManagerMock.verify();
  }
  @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();
  }
 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 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();
 }
  @Test
  public void testHasPermissionProjectRoleUserHasPermission() {
    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())),
        TestProjectShareTypePermissionChecker.MOCK_ROLE);
    projectRoleManagerMock.expectAndReturn(
        "isUserInProjectRole",
        P.args(
            P.eq(user),
            P.eq(TestProjectShareTypePermissionChecker.MOCK_ROLE),
            P.eq(TestProjectShareTypePermissionChecker.MOCK_PROJECT)),
        Boolean.TRUE);

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

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

    projectManagerMock.verify();
    permissionManagerMock.verify();
    projectRoleManagerMock.verify();
  }