Search in sources :

Example 1 with BaseTestCheck

use of org.openstreetmap.atlas.checks.base.checks.BaseTestCheck in project atlas-checks by osmlab.

the class ChallengeTest method testChallengeJSON.

@Test
public void testChallengeJSON() {
    final Configuration configuration = new StandardConfiguration(new ClassResource("org/openstreetmap/atlas/checks/base/InlineChallengeTest.json"));
    final BaseTestCheck testCheck = new BaseTestCheck(configuration);
    Assert.assertEquals("description", testCheck.getChallenge().getDescription().toLowerCase());
    Assert.assertEquals("blurb", testCheck.getChallenge().getBlurb().toLowerCase());
    Assert.assertEquals("instruction", testCheck.getChallenge().getInstruction().toLowerCase());
    Assert.assertEquals(ChallengeDifficulty.EASY, testCheck.getChallenge().getDifficulty());
    Assert.assertEquals(ChallengePriority.LOW, testCheck.getChallenge().getDefaultPriority());
    final JsonObject challengeJSON = testCheck.getChallenge().toJson("TestChallenge");
    final JsonObject highPriority = new Gson().fromJson(challengeJSON.get(Challenge.KEY_HIGH_PRIORITY).getAsString(), JsonObject.class);
    final JsonArray rules = highPriority.getAsJsonArray(Challenge.KEY_PRIORITY_RULES);
    Assert.assertEquals(4, rules.size());
    final JsonObject firstRule = rules.get(0).getAsJsonObject();
    Assert.assertEquals(Challenge.VALUE_RULE_ID, firstRule.get(Challenge.KEY_RULE_ID).getAsString());
    Assert.assertEquals(Challenge.VALUE_RULE_FIELD, firstRule.get(Challenge.KEY_RULE_FIELD).getAsString());
    Assert.assertEquals(Challenge.VALUE_RULE_OPERATOR, firstRule.get(Challenge.KEY_RULE_OPERATOR).getAsString());
    Assert.assertEquals(Challenge.VALUE_RULE_TYPE, firstRule.get(Challenge.KEY_RULE_TYPE).getAsString());
    Assert.assertEquals("highway.motorway", firstRule.get(Challenge.KEY_RULE_VALUE).getAsString());
    Assert.assertEquals("highway.motorway_link", rules.get(1).getAsJsonObject().get(Challenge.KEY_RULE_VALUE).getAsString());
    Assert.assertEquals("highway.trunk", rules.get(2).getAsJsonObject().get(Challenge.KEY_RULE_VALUE).getAsString());
    Assert.assertEquals("highway.trunk_link", rules.get(3).getAsJsonObject().get(Challenge.KEY_RULE_VALUE).getAsString());
}
Also used : ClassResource(org.openstreetmap.atlas.streaming.resource.ClassResource) JsonArray(com.google.gson.JsonArray) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) StandardConfiguration(org.openstreetmap.atlas.utilities.configuration.StandardConfiguration) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) StandardConfiguration(org.openstreetmap.atlas.utilities.configuration.StandardConfiguration) BaseTestCheck(org.openstreetmap.atlas.checks.base.checks.BaseTestCheck) Test(org.junit.Test)

Example 2 with BaseTestCheck

use of org.openstreetmap.atlas.checks.base.checks.BaseTestCheck 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 3 with BaseTestCheck

use of org.openstreetmap.atlas.checks.base.checks.BaseTestCheck in project atlas-checks by osmlab.

the class TagTest method testConfiguration.

/**
 * Private function used by all test cases to easily test the configuration instead of rewriting
 * the code constantly.
 *
 * @param config
 *            The {@link Configuration} is string form that is being test.
 * @param numberOfFlags
 *            The number of expected flags to be processed based on the provided configuration
 */
private void testConfiguration(final String config, final int numberOfFlags) {
    final Atlas atlas = setup.getAtlas();
    final Configuration configuration = ConfigurationResolver.inlineConfiguration(config);
    final List<CheckFlag> flags = Iterables.asList(new BaseTestCheck(configuration).flags(atlas));
    // will return the number of flags for the number of objects because no restrictions
    Assert.assertEquals(numberOfFlags, flags.size());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) Configuration(org.openstreetmap.atlas.utilities.configuration.Configuration) CheckFlag(org.openstreetmap.atlas.checks.flag.CheckFlag) BaseTestCheck(org.openstreetmap.atlas.checks.base.checks.BaseTestCheck)

Aggregations

BaseTestCheck (org.openstreetmap.atlas.checks.base.checks.BaseTestCheck)3 Configuration (org.openstreetmap.atlas.utilities.configuration.Configuration)3 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Test (org.junit.Test)1 CheckFlag (org.openstreetmap.atlas.checks.flag.CheckFlag)1 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)1 ClassResource (org.openstreetmap.atlas.streaming.resource.ClassResource)1 StandardConfiguration (org.openstreetmap.atlas.utilities.configuration.StandardConfiguration)1