Esempio n. 1
0
  public void testAddUser() throws Exception {
    List<Map<String, String>> items = new ArrayList<Map<String, String>>();

    PermissionManagerImpl pm = new PermissionManagerImpl();
    pm.setModelFilesContext(TestHelper.getModelFilesContext());

    User user = new User();
    user.setPermissionManager(pm);

    Group g = new Group();
    PermissionName.INTERNATIONAL_DIALING.setEnabled(g, false);
    PermissionName.LONG_DISTANCE_DIALING.setEnabled(g, false);
    PermissionName.TOLL_FREE_DIALING.setEnabled(g, false);
    PermissionName.LOCAL_DIALING.setEnabled(g, true);
    PermissionName.SIPX_VOICEMAIL.setEnabled(g, false);
    PermissionName.FREESWITH_VOICEMAIL.setEnabled(g, false);
    PermissionName.EXCHANGE_VOICEMAIL.setEnabled(g, true);

    user.addGroup(g);
    user.setUserName("goober");

    Permissions permissions = new Permissions();
    permissions.addUser(items, user, "sipx.sipfoundry.org");

    assertEquals(PERM_COUNT, items.size());
    assertEquals("sip:[email protected]", items.get(0).get("identity"));
    assertEquals("LocalDialing", items.get(0).get("permission"));

    assertEquals("sip:[email protected]", items.get(3).get("identity"));
    assertEquals("ExchangeUMVoicemailServer", items.get(3).get("permission"));

    assertEquals("sip:[email protected]", items.get(4).get("identity"));
    assertEquals("ExchangeUMVoicemailServer", items.get(4).get("permission"));
  }
Esempio n. 2
0
  public void testCallGroupPerms() throws Exception {
    PermissionManagerImpl pm = new PermissionManagerImpl();
    pm.setModelFilesContext(TestHelper.getModelFilesContext());

    User testUser = new User();
    testUser.setPermissionManager(pm);

    CoreContext coreContext = createMock(CoreContext.class);
    coreContext.getDomainName();
    expectLastCall().andReturn("host.company.com");
    coreContext.loadUsersByPage(null, null, null, 0, DaoUtils.PAGE_SIZE, "id", true);
    expectLastCall().andReturn(Collections.EMPTY_LIST);
    coreContext.newUser();
    expectLastCall().andReturn(testUser).anyTimes();

    CallGroup callGroup1 = new CallGroup();
    callGroup1.setName("sales");
    callGroup1.setEnabled(true);
    CallGroup callGroup2 = new CallGroup();
    callGroup2.setName("marketing");
    callGroup2.setEnabled(true);
    CallGroup callGroup3 = new CallGroup();
    callGroup3.setName("disabled");

    CallGroupContext callGroupContext = createMock(CallGroupContext.class);
    callGroupContext.getCallGroups();
    expectLastCall().andReturn(Arrays.asList(callGroup1, callGroup2, callGroup3));

    replay(coreContext, callGroupContext);

    Permissions permissions = new Permissions();
    permissions.setCoreContext(coreContext);
    permissions.setCallGroupContext(callGroupContext);

    List<Map<String, String>> items = permissions.generate();

    int start = SPEC_COUNT * PERM_COUNT;

    assertEquals(start + 10, items.size());

    assertEquals("sip:[email protected]", items.get(start + 0).get("identity"));
    assertEquals("sip:[email protected]", items.get(start + 4).get("identity"));
    assertEquals("sip:[email protected]", items.get(start + 5).get("identity"));
    assertEquals("sip:[email protected]", items.get(start + 9).get("identity"));

    verify(coreContext, callGroupContext);
  }
Esempio n. 3
0
  public void testGenerateEmpty() throws Exception {
    PermissionManagerImpl pm = new PermissionManagerImpl();
    pm.setModelFilesContext(TestHelper.getModelFilesContext());

    User testUser = new User();
    testUser.setPermissionManager(pm);

    CoreContext coreContext = createMock(CoreContext.class);
    coreContext.getDomainName();
    expectLastCall().andReturn("host.company.com");
    coreContext.loadUsersByPage(null, null, null, 0, DaoUtils.PAGE_SIZE, "id", true);
    expectLastCall().andReturn(Collections.EMPTY_LIST);
    coreContext.newUser();
    expectLastCall().andReturn(testUser).anyTimes();

    CallGroupContext callGroupContext = createMock(CallGroupContext.class);
    callGroupContext.getCallGroups();
    expectLastCall().andReturn(Collections.EMPTY_LIST);

    replay(coreContext, callGroupContext);

    Permissions permissions = new Permissions();
    permissions.setCoreContext(coreContext);
    permissions.setCallGroupContext(callGroupContext);

    List<Map<String, String>> items = permissions.generate();
    assertEquals(SPEC_COUNT * PERM_COUNT, items.size());
    // 5 permissions per special user

    for (SpecialUserType su : SpecialUserType.values()) {
      int i = su.ordinal();

      String name = "sip:" + su.getUserName() + "@host.company.com";
      assertEquals(name, items.get(i * PERM_COUNT).get("identity"));
      assertEquals(name, items.get((i + 1) * PERM_COUNT - 1).get("identity"));
    }
    verify(coreContext, callGroupContext);
  }