protected Optional<String> getConfig(String key, ConfigDatabase config) { Optional<String> val = config.get(key); if (!val.isPresent()) { val = config.getGlobal(key); } return val; } }
@Override public String toString() { return String.format("%s[uri: %s]", getClass().getSimpleName(), config == null ? "<unknown>" : config.get("mongodb.uri").or("<unset>")); } }
@Test public void testGlobalOnly() { ConfigDatabase globalOnly = IniFileConfigDatabase.globalOnly(platform); testGlobalOnly(() -> globalOnly.get("section.key")); testGlobalOnly(() -> globalOnly.getAll()); testGlobalOnly(() -> globalOnly.get("section.key", String.class)); testGlobalOnly(() -> globalOnly.getAllSection("section")); testGlobalOnly(() -> globalOnly.getAllSubsections("section.sub")); testGlobalOnly(() -> globalOnly.put("section.key", "val")); testGlobalOnly(() -> globalOnly.remove("section.key")); testGlobalOnly(() -> globalOnly.removeSection("section")); }
@Override public synchronized void open() { if (client != null) { return; } String uri = config.get("mongodb.uri").get(); String database = config.get("mongodb.database").get(); client = manager.acquire(new MongoAddress(uri)); db = client.getDB(database); collection = db.getCollection(getCollectionName()); collection.ensureIndex("oid"); }
protected Optional<String> getConfig(String key, ConfigDatabase config) { Optional<String> val = config.get(key); if (!val.isPresent()) { val = config.getGlobal(key); } return val; } }
@Test public void testNoValue() { Optional<String> str = config.get("doesnt.exist"); assertFalse(str.isPresent()); }
@Override public void configure() throws RepositoryConnectionException { RepositoryConnectionException.StorageType.OBJECT.configure(config, "mongodb", "0.1"); String uri = config.get("mongodb.uri").or(config.getGlobal("mongodb.uri")) .or("mongodb://localhost:27017/"); String database = config.get("mongodb.database").or(config.getGlobal("mongodb.database")) .or("geogig"); config.put("mongodb.uri", uri); config.put("mongodb.database", database); }
@Test public void testNoDot() { exception.expect(ConfigException.class); config.get("nodot"); }
@Test public void testGetDefaultWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); when(database.getGlobal(anyString())).thenReturn(Optional.of("value")); ConfigOp config = new ConfigOp(database); config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_GET) .setName("section.key").setValue(null).call(); }
@Test public void testNullSectionKeyPair() { exception.expect(ConfigException.class); config.get(null); }
@Test public void testNoSection() { exception.expect(ConfigException.class); config.get(".int"); }
@Test public void testNoKey() { exception.expect(ConfigException.class); config.get("section."); }
@Test public void testNoSection() { exception.expect(ConfigException.class); config.get(".int"); }
@Test public void testNoKey() { exception.expect(ConfigException.class); config.get("section."); }
@Test public void testNullValue() { config.put("section.null", null); Optional<String> str = config.get("section.null"); assertFalse(str.isPresent()); }
@Test public void testNullValue() { config.put("section.null", null); Optional<String> str = config.get("section.null"); assertFalse(str.isPresent()); }
@Test public void testNumberFormatException() { config.put("section.string", "notanumber"); exception.expect(IllegalArgumentException.class); config.get("section.string", Integer.class); }
@Test public void testNumberFormatException() { config.put("section.string", "notanumber"); exception.expect(IllegalArgumentException.class); config.get("section.string", Integer.class); }
@Test public void testGetLocalWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); exception.expect(ConfigException.class); config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_GET).setName("section.key") .setValue(null).call(); }
@Test public void testGetLocalWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); ConfigOp config = new ConfigOp(database); exception.expect(ConfigException.class); config.setScope(ConfigScope.LOCAL).setAction(ConfigAction.CONFIG_GET).setName("section.key") .setValue(null).call(); }