Search in sources :

Example 1 with ConfigOp

use of org.locationtech.geogig.api.porcelain.ConfigOp in project GeoGig by boundlessgeo.

the class ConfigOpTest method test.

private void test(ConfigOp.ConfigScope scope) {
    final ConfigOp config = geogig.command(ConfigOp.class);
    config.setScope(scope);
    config.setAction(ConfigAction.CONFIG_SET).setName("section.string").setValue("1").call();
    Map<String, String> result = config.setAction(ConfigAction.CONFIG_GET).setName("section.string").setValue(null).call().or(new HashMap<String, String>());
    assertEquals("1", result.get("section.string"));
    // Test overwriting a value that already exists
    config.setAction(ConfigAction.CONFIG_SET).setName("section.string").setValue("2").call();
    result = config.setAction(ConfigAction.CONFIG_GET).setName("section.string").setValue(null).call().or(new HashMap<String, String>());
    assertEquals("2", result.get("section.string"));
    // Test unsetting a value that exists
    config.setAction(ConfigAction.CONFIG_UNSET).setName("section.string").setValue(null).call();
    result = config.setAction(ConfigAction.CONFIG_GET).setName("section.string").setValue(null).call().or(new HashMap<String, String>());
    assertNull(result.get("section.string"));
    // Test unsetting a value that doesn't exist
    config.setAction(ConfigAction.CONFIG_UNSET).setName("section.string").setValue(null).call();
    result = config.setAction(ConfigAction.CONFIG_GET).setName("section.string").setValue(null).call().or(new HashMap<String, String>());
    assertNull(result.get("section.string"));
    // Test removing a section that exists
    config.setAction(ConfigAction.CONFIG_SET).setName("section.string").setValue("1").call();
    config.setAction(ConfigAction.CONFIG_SET).setName("section.string2").setValue("2").call();
    config.setAction(ConfigAction.CONFIG_REMOVE_SECTION).setName("section").setValue(null).call();
    result = config.setAction(ConfigAction.CONFIG_GET).setName("section.string").setValue(null).call().or(new HashMap<String, String>());
    assertNull(result.get("section.string"));
    result = config.setAction(ConfigAction.CONFIG_GET).setName("section.string2").setValue(null).call().or(new HashMap<String, String>());
    assertNull(result.get("section.string2"));
    // Try listing the config file
    config.setAction(ConfigAction.CONFIG_SET).setName("section.string").setValue("1").call();
    config.setAction(ConfigAction.CONFIG_SET).setName("section.string2").setValue("2").call();
    result = config.setAction(ConfigAction.CONFIG_LIST).call().or(new HashMap<String, String>());
    assertEquals("1", result.get("section.string"));
    assertEquals("2", result.get("section.string2"));
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString)

Example 2 with ConfigOp

use of org.locationtech.geogig.api.porcelain.ConfigOp in project GeoGig by boundlessgeo.

the class ConfigOpTest method testGetDefaultWithNoLocalRepository.

@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();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 3 with ConfigOp

use of org.locationtech.geogig.api.porcelain.ConfigOp in project GeoGig by boundlessgeo.

the class ConfigOpTest method testNoAction.

@Test
public void testNoAction() {
    final ConfigOp config = geogig.command(ConfigOp.class);
    exception.expect(ConfigException.class);
    config.setAction(ConfigAction.CONFIG_NO_ACTION).setName("section.key").setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) Test(org.junit.Test)

Example 4 with ConfigOp

use of org.locationtech.geogig.api.porcelain.ConfigOp in project GeoGig by boundlessgeo.

the class ConfigOpTest method testListDefaultWithNoLocalRepository.

@Test
public void testListDefaultWithNoLocalRepository() {
    ConfigDatabase database = mock(ConfigDatabase.class);
    when(database.getAll()).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION));
    ConfigOp config = new ConfigOp(database);
    config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_LIST).setName(null).setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ConfigException(org.locationtech.geogig.api.porcelain.ConfigException) Test(org.junit.Test)

Example 5 with ConfigOp

use of org.locationtech.geogig.api.porcelain.ConfigOp in project GeoGig by boundlessgeo.

the class ConfigOpTest method testNullNameValuePairForGet.

@Test
public void testNullNameValuePairForGet() {
    final ConfigOp config = geogig.command(ConfigOp.class);
    exception.expect(ConfigException.class);
    config.setScope(ConfigScope.GLOBAL).setAction(ConfigAction.CONFIG_GET).setName(null).setValue(null).call();
}
Also used : ConfigOp(org.locationtech.geogig.api.porcelain.ConfigOp) Test(org.junit.Test)

Aggregations

ConfigOp (org.locationtech.geogig.api.porcelain.ConfigOp)22 Test (org.junit.Test)21 Remote (org.locationtech.geogig.api.Remote)4 ConfigException (org.locationtech.geogig.api.porcelain.ConfigException)4 RemoteAddOp (org.locationtech.geogig.api.porcelain.RemoteAddOp)4 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)4 HashMap (java.util.HashMap)3 Map (java.util.Map)2 RemoteListOp (org.locationtech.geogig.api.porcelain.RemoteListOp)2 RemoteRemoveOp (org.locationtech.geogig.api.porcelain.RemoteRemoveOp)2 Matchers.anyString (org.mockito.Matchers.anyString)1