Search in sources :

Example 6 with Configuration

use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.

the class CountryTest method testConfiguration.

/**
 * Private function that does the check for all the unit tests
 *
 * @param config
 *            A stringified version of the configuration that will be resolved using the
 *            {@link ConfigurationResolver}
 * @param testCountry
 *            The country that is being tested
 * @param test
 *            Whether the country being tested should be included or excluded when running the
 *            checks
 */
private void testConfiguration(final String config, final String testCountry, final boolean test) {
    final Configuration configuration = ConfigurationResolver.inlineConfiguration(config);
    final BaseTestCheck testCheck = new BaseTestCheck(configuration);
    // BaseTestCheck will always produce a flag if everything else gets through
    if (test) {
        Assert.assertTrue(testCheck.validCheckForCountry(testCountry));
    } else {
        Assert.assertFalse(testCheck.validCheckForCountry(testCountry));
    }
}
Also used : Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) BaseTestCheck(org.openstreetmap.atlas.checks.base.checks.BaseTestCheck)

Example 7 with Configuration

use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.

the class CheckResourceLoaderTest method testGroupedCountryCheckLoading.

/**
 * Test Grouped country overrides
 */
@Test
public void testGroupedCountryCheckLoading() {
    final String configSource = "{\"CheckResourceLoader.scanUrls\": [\"org.openstreetmap.atlas.checks.base.checks\"],\"groups\":{\"beginningAlphabet\":[\"ABC\",\"DEF\"],\"alphabetEnds\":[\"ABC\",\"XYZ\"]},\"CheckResourceLoaderTestCheck\":{\"enabled\": true,\"var1\":1,\"var2\":\"Hi\",\"override.beginningAlphabet.var1\":2,\"override.alphabetEnds.var2\":\"Bye\"}}";
    final String country1 = "ABC";
    final String country2 = "DEF";
    final String country3 = "XYZ";
    final Configuration configuration = ConfigurationResolver.inlineConfiguration(configSource);
    final CheckResourceLoader checkResourceLoader = new CheckResourceLoader(configuration);
    // assert first group override worked for all 3 countries
    final long country1Var1 = checkResourceLoader.getConfigurationForCountry(country1).get("CheckResourceLoaderTestCheck.var1").value();
    final long country2Var1 = checkResourceLoader.getConfigurationForCountry(country2).get("CheckResourceLoaderTestCheck.var1").value();
    final long country3Var1 = checkResourceLoader.getConfigurationForCountry(country3).get("CheckResourceLoaderTestCheck.var1").value();
    Assert.assertEquals(2, country1Var1);
    Assert.assertEquals(2, country2Var1);
    Assert.assertEquals(1, country3Var1);
    // assert second group override worked for all 3 countries
    final String country1Var2 = checkResourceLoader.getConfigurationForCountry(country1).get("CheckResourceLoaderTestCheck.var2").value();
    final String country2Var2 = checkResourceLoader.getConfigurationForCountry(country2).get("CheckResourceLoaderTestCheck.var2").value();
    final String country3Var2 = checkResourceLoader.getConfigurationForCountry(country3).get("CheckResourceLoaderTestCheck.var2").value();
    Assert.assertEquals("Bye", country1Var2);
    Assert.assertEquals("Hi", country2Var2);
    Assert.assertEquals("Bye", country3Var2);
}
Also used : Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) Test(org.junit.Test)

Example 8 with Configuration

use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.

the class CheckResourceLoaderTest method testEnabledByPredicate.

/**
 * Test to make sure that if the default behaviour (set in configuration) is that checks are
 * enabled, that the checks are loaded when not setting any explicitly.
 */
@Test
public void testEnabledByPredicate() {
    final String configSource = "{\"CheckResourceLoader.scanUrls\": [\"org.openstreetmap.atlas.checks.base.checks\"]}";
    final Configuration configuration = ConfigurationResolver.inlineConfiguration(configSource);
    final Set<Check> loaded = new CheckResourceLoader(configuration).loadChecks(CheckResourceLoaderTestCheck.class::equals);
    Assert.assertEquals(1, loaded.size());
}
Also used : Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) CheckResourceLoaderTestCheck(org.openstreetmap.atlas.checks.base.checks.CheckResourceLoaderTestCheck) CheckResourceLoaderTestCheck(org.openstreetmap.atlas.checks.base.checks.CheckResourceLoaderTestCheck) Test(org.junit.Test)

Example 9 with Configuration

use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.

the class CheckResourceLoaderTest method testEnabledByConfiguration.

/**
 * Test to make sure that by explicitly setting the enabled function for a check that it is in
 * actual fact enabled.
 */
@Test
public void testEnabledByConfiguration() {
    final String configSource = "{\"CheckResourceLoader.scanUrls\": [\"org.openstreetmap.atlas.checks.base.checks\"],\"CheckResourceLoaderTestCheck.enabled\": true}";
    final Configuration configuration = ConfigurationResolver.inlineConfiguration(configSource);
    final Set<Check> loaded = new CheckResourceLoader(configuration).loadChecks();
    Assert.assertEquals(1, loaded.size());
}
Also used : Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) CheckResourceLoaderTestCheck(org.openstreetmap.atlas.checks.base.checks.CheckResourceLoaderTestCheck) Test(org.junit.Test)

Example 10 with Configuration

use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.

the class CheckResourceLoaderTest method testCountryKeywordCheckLoading.

/**
 * Test the check loading using country keyword specific configurations. Assert that each
 * country gets its own version of the check.
 */
@Test
public void testCountryKeywordCheckLoading() {
    final String configSource = "{\"CheckResourceLoader.scanUrls\": [\"org.openstreetmap.atlas.checks.base.checks\"],\"CheckResourceLoaderTestCheck\":{\"enabled\": true,\"var1\":1,\"override.ABC.var1\":2}}";
    final String country1 = "ABC";
    final String country2 = "XYZ";
    final List<String> countries = Arrays.asList(country1, country2);
    final Configuration configuration = ConfigurationResolver.inlineConfiguration(configSource);
    final CheckResourceLoader checkResourceLoader = new CheckResourceLoader(configuration);
    final Set<Check> loadedCountry1Checks = checkResourceLoader.loadChecksForCountry(country1);
    final Set<Check> loadedCountry2Checks = checkResourceLoader.loadChecksForCountry(country2);
    // assert both countries loaded with different check sets
    Assert.assertNotNull(loadedCountry1Checks);
    Assert.assertNotNull(loadedCountry2Checks);
    Assert.assertEquals(1, loadedCountry1Checks.size());
    Assert.assertEquals(1, loadedCountry2Checks.size());
    Assert.assertFalse(Iterables.equals(loadedCountry1Checks, loadedCountry2Checks));
    // assert both configurations overrode properly and thus initialized properly
    final long country1Var1 = checkResourceLoader.getConfigurationForCountry(country1).get("CheckResourceLoaderTestCheck.var1").value();
    final long country2Var2 = checkResourceLoader.getConfigurationForCountry(country2).get("CheckResourceLoaderTestCheck.var1").value();
    Assert.assertEquals(country1Var1, 2);
    Assert.assertEquals(country2Var2, 1);
}
Also used : Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) CheckResourceLoaderTestCheck(org.openstreetmap.atlas.checks.base.checks.CheckResourceLoaderTestCheck) Test(org.junit.Test)

Aggregations

Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)13 Test (org.junit.Test)6 List (java.util.List)4 CoreException (org.openstreetmap.atlas.exception.CoreException)4 Iterables (org.openstreetmap.atlas.utilities.collections.Iterables)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 BaseTestCheck (org.openstreetmap.atlas.checks.base.checks.BaseTestCheck)3 CheckResourceLoaderTestCheck (org.openstreetmap.atlas.checks.base.checks.CheckResourceLoaderTestCheck)3 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)3 StringList (org.openstreetmap.atlas.utilities.collections.StringList)3 CommandMap (org.openstreetmap.atlas.utilities.runtime.CommandMap)3 Objects (java.util.Objects)2