@Test public void archiveDefinition() { AdminContextImpl impl = new AdminContextImpl(); BackupManager mgr = createMock(BackupManager.class); replay(mgr); BackupSettings settings = new BackupSettings(); settings.setModelFilesContext(TestHelper.getModelFilesContext()); Location primary = new Location("one.example.org", "1.1.1.1"); primary.setPrimary(true); ArchiveDefinition def = impl.getArchiveDefinitions(mgr, primary, settings).iterator().next(); String base = "$(sipx.SIPX_BINDIR)/sipxconfig-archive --restore %s --ipaddress $(sipx.bind_ip)"; String baseBackup = "$(sipx.SIPX_BINDIR)/sipxconfig-archive --backup %s"; assertEquals(base, def.getRestoreCommand()); assertEquals(baseBackup, def.getBackupCommand()); settings.setSettingTypedValue("backup/device", Boolean.FALSE); settings.setSettingTypedValue("restore/keepDomain", Boolean.TRUE); settings.setSettingTypedValue("restore/keepFqdn", Boolean.TRUE); settings.setSettingTypedValue("restore/decodePins", Boolean.TRUE); settings.setSettingTypedValue("restore/decodePinMaxLen", (Integer) 5); settings.setSettingTypedValue("restore/resetPin", "zzz"); settings.setSettingTypedValue("restore/resetPassword", "yyy"); def = impl.getArchiveDefinitions(mgr, primary, settings).iterator().next(); String options = " --domain $(sipx.domain) --fqdn $(sipx.host).$(sipx.net_domain) --crack-pin zzz --crack-passwd yyy --crack-pin-len 5"; String backupOptions = " --no-device-files"; assertEquals(base + options, def.getRestoreCommand()); assertEquals(baseBackup + backupOptions, def.getBackupCommand()); verify(mgr); }
/** * No matter if the user does not have blf permission, we should keep generating what speeddials * we have The BLF permission turning off only restricts the user to change his blf permission * from user-portal * * @throws Exception */ public void testGenerateNoBlfPerm() throws Exception { String json3 = "{ \"_id\" : \"User3\", \"uid\" : \"user_name_0\", \"imenbld\" : \"false\", \"ent\": \"user\"}"; String json2 = "{ \"_id\" : \"User2\", \"uid\" : \"user_c\", \"imenbld\" : \"false\", \"ent\": \"user\", " + "\"" + MongoConstants.SPEEDDIAL + "\" : { \"" + MongoConstants.USER + "\" : \"~~rl~F~user_c\", \"" + MongoConstants.USER_CONS + "\" : \"~~rl~C~user_c\", \"" + MongoConstants.BUTTONS + "\" : [ " + "{\"" + MongoConstants.URI + "\" : \"sip:[email protected]\",\"" + MongoConstants.NAME + "\" : \"delta\"}" + "]}, \"prm\" : [\"Mobile\"" + "]}"; insertJson(getEntityCollection(), json3, json2); Thread.sleep(1000); Document doc = m_rl.getDocument(); String fileContent = TestHelper.asString(doc); InputStream referenceXml = getClass().getResourceAsStream("resource-lists-noblfperm.test.xml"); assertXMLEqual(new InputStreamReader(referenceXml), new StringReader(fileContent)); }
@Test public void config() throws IOException { DhcpConfig config = new DhcpConfig(); DhcpSettings settings = new DhcpSettings(); settings.setPrimary(TestHelper.createDefaultLocation()); settings.setModelFilesContext(TestHelper.getModelFilesContext()); AddressType t = new AddressType("t"); Address tftp = new Address(t, "tftp"); Address admin = new Address(t, "admin"); Address staticHttp = new Address(t, "static"); List<Address> dns = Arrays.asList(new Address(t, "dns1"), new Address(t, "dns2")); List<Address> ntp = Arrays.asList(new Address(t, "ntp1"), new Address(t, "ntp2")); StringWriter actual = new StringWriter(); config.writeConfig(actual, settings, tftp, admin, staticHttp, dns, ntp); String expected = IOUtils.toString(getClass().getResourceAsStream("expected-dhcpd.conf")); assertEquals(expected, actual.toString()); }
public void testGenerate() throws Exception { String json1 = "{ \"_id\" : \"User1\", \"uid\" : \"user_a\", \"imenbld\" : \"false\", \"ent\": \"user\", " + "\"" + MongoConstants.SPEEDDIAL + "\": { \"" + MongoConstants.USER + "\" : \"~~rl~F~user_a\", \"" + MongoConstants.USER_CONS + "\" : \"~~rl~C~user_a\", \"" + MongoConstants.BUTTONS + "\" : [ " + "{\"" + MongoConstants.URI + "\" : \"sip:[email protected]\",\"" + MongoConstants.NAME + "\" : \"beta\"}," + "{\"" + MongoConstants.URI + "\" : \"sip:[email protected]\",\"" + MongoConstants.NAME + "\" : \"gamma\"}" + "]}, \"prm\" : [\"subscribe-to-presence\"" + "]}"; String json2 = "{ \"_id\" : \"User2\", \"uid\" : \"user_c\", \"imenbld\" : \"false\", \"ent\": \"user\"," + "\"" + MongoConstants.SPEEDDIAL + "\" : { \"" + MongoConstants.USER + "\" : \"~~rl~F~user_c\", \"" + MongoConstants.USER_CONS + "\" : \"~~rl~C~user_c\", \"" + MongoConstants.BUTTONS + "\" : [ " + "{\"" + MongoConstants.URI + "\" : \"sip:[email protected]\",\"" + MongoConstants.NAME + "\" : \"delta\"}" + "]}, \"prm\" : [\"subscribe-to-presence\"" + "]}"; String json3 = "{ \"_id\" : \"User3\", \"uid\" : \"user_name_0\", \"imenbld\" : \"true\", \"ent\": \"user\"}"; String json4 = "{ \"_id\" : \"User4\", \"uid\" : \"user_name_1\", \"imenbld\" : \"true\", ent: \"user\"}"; insertJson(getEntityCollection(), json1, json2, json3, json4); Thread.sleep(1000); // sleep 1 second. I get inconsistent results when running the tests, // as if mongo does not pick up quickly Document doc = m_rl.getDocument(); String generatedXml = TestHelper.asString(doc); InputStream referenceXml = getClass().getResourceAsStream("resource-lists.test.xml"); assertXMLEqual(new InputStreamReader(referenceXml), new StringReader(generatedXml)); }
protected Setting loadSettings() { return TestHelper.loadSettings( TestHelper.getResourceAsFile(BeanWithSettingTest.class, "birds.xml")); }