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));
}
}
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);
}
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());
}
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());
}
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);
}
Aggregations