private ConfigGenerator createConfigGenerator() { ConfigGenerator cg = new ConfigGenerator(); DomainManager domainManager = TestUtil.getMockDomainManager(); EasyMock.replay(domainManager); AuthRules authRules = new AuthRules(); authRules.setDomainManager(domainManager); cg.setAuthRules(authRules); MappingRules mappingRules = new MappingRules(); mappingRules.setDomainManager(domainManager); cg.setMappingRules(mappingRules); FallbackRules fallbackRules = new FallbackRules(); fallbackRules.setDomainManager(domainManager); cg.setFallbackRules(fallbackRules); ForwardingRules forwardingRules = new ForwardingRules(); cg.setForwardingRules(forwardingRules); forwardingRules.setVelocityEngine(TestHelper.getVelocityEngine()); SbcManager sbcManager = createNiceMock(SbcManager.class); replay(sbcManager); forwardingRules.setSbcManager(sbcManager); SipxProxyService proxyService = new SipxProxyService(); proxyService.setModelDir("sipxproxy"); proxyService.setModelName("sipxproxy.xml"); proxyService.setModelFilesContext(TestHelper.getModelFilesContext()); proxyService.setBeanName(SipxProxyService.BEAN_ID); proxyService.setSipPort("9901"); proxyService.setDomainManager(domainManager); SipxService statusService = new SipxStatusService(); statusService.setBeanName(SipxStatusService.BEAN_ID); statusService.setModelFilesContext(TestHelper.getModelFilesContext()); statusService.setSettings(TestHelper.loadSettings("sipxstatus/sipxstatus.xml")); Setting statusConfigSettings = statusService.getSettings().getSetting("status-config"); statusConfigSettings.getSetting("SIP_STATUS_SIP_PORT").setValue("9905"); SipxRegistrarService registrarService = new SipxRegistrarService(); registrarService.setBeanName(SipxRegistrarService.BEAN_ID); registrarService.setRegistrarEventSipPort("9906"); registrarService.setSipPort("9907"); SipxServiceManager sipxServiceManager = TestUtil.getMockSipxServiceManager(true, proxyService, registrarService, statusService); forwardingRules.setSipxServiceManager(sipxServiceManager); return cg; }
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")); }
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); }
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); }