src/test/java/de/blau/android/validation/ValidatorTest.java
/**
     * Test base validation stuff, age, missing tags, road names
     */
Test base validation stuff, age, missing tags, road names
Test base validation stuff age missing tags road names
@Test
    public void baseValidator() {
        readTestData("test3.osm");
        Node zumRueden = (Node) App.getDelegator().getOsmElement(Node.NAME, 370530329);
        assertNotNull(zumRueden);
        Validator validator = App.getDefaultValidator(main);
        assertEquals(Validator.AGE, zumRueden.hasProblem(main, validator) & Validator.AGE);
        assertEquals(Validator.MISSING_TAG, zumRueden.getCachedProblems() & Validator.MISSING_TAG);
        StringBuilder problemString = new StringBuilder();
        for (String s : validator.describeProblem(main, zumRueden)) {
            problemString.append(s);
        }
        assertTrue(problemString.toString().contains(main.getString(R.string.toast_needs_resurvey)));
        java.util.Map<String, String> tags = new HashMap<>(zumRueden.getTags());
        SimpleDateFormat format = new SimpleDateFormat(Tags.CHECK_DATE_FORMAT);
        tags.put(Tags.KEY_CHECK_DATE, format.format(new Date()));
        try {
            App.getLogic().setTags(main, zumRueden, tags);
        } catch (OsmIllegalOperationException oioe) {
            fail();
        }
        assertEquals(0, zumRueden.hasProblem(main, validator) & Validator.AGE);
        Way limmatQuai = (Way) App.getDelegator().getOsmElement(Way.NAME, 147759323);
        assertEquals(Validator.OK, limmatQuai.hasProblem(main, validator));
        tags = new HashMap<>(limmatQuai.getTags());
        String originalHighway = tags.get(Tags.KEY_HIGHWAY);
        tags.put(Tags.KEY_HIGHWAY, Tags.VALUE_ROAD);
        try {
            App.getLogic().setTags(main, limmatQuai, tags);
            assertEquals(Validator.HIGHWAY_ROAD, limmatQuai.hasProblem(main, validator) & Validator.HIGHWAY_ROAD);
            problemString = new StringBuilder();
            for (String s : validator.describeProblem(main, limmatQuai)) {
                problemString.append(s);
            }
            assertTrue(problemString.toString().contains(main.getString(R.string.toast_unsurveyed_road)));
            tags = new HashMap<>(limmatQuai.getTags());
            tags.put(Tags.KEY_HIGHWAY, originalHighway);
            assertNotNull(tags.remove(Tags.KEY_NAME));
            App.getLogic().setTags(main, limmatQuai, tags);
            assertEquals(Validator.MISSING_TAG, limmatQuai.hasProblem(main, validator) & Validator.MISSING_TAG);
        } catch (OsmIllegalOperationException oioe) {
            fail();
        }
        Relation rcn66 = (Relation) App.getDelegator().getOsmElement(Relation.NAME, 28059);
        assertEquals(Validator.OK, rcn66.hasProblem(main, validator));
        tags = new HashMap<>(rcn66.getTags());
        tags.remove(Tags.KEY_TYPE);
        try {
            App.getLogic().setTags(main, rcn66, tags);
            assertEquals(Validator.NO_TYPE, rcn66.hasProblem(main, validator) & Validator.NO_TYPE);
        } catch (OsmIllegalOperationException oioe) {
            fail();
        }
        problemString = new StringBuilder();
        for (String s : validator.describeProblem(main, rcn66)) {
            problemString.append(s);
        }
        assertTrue(problemString.toString().contains(main.getString(R.string.toast_notype)));
    }
@ Test public void baseValidator ( ) { readTestData ( "test3.osm" ) ; Node zumRueden = ( Node ) App . getDelegator ( ) . getOsmElement ( Node . NAME , 370530329 ) ; assertNotNull ( zumRueden ) ; Validator validator = App . getDefaultValidator ( main ) ; assertEquals ( Validator . AGE , zumRueden . hasProblem ( main , validator ) & Validator . AGE ) ; assertEquals ( Validator . MISSING_TAG , zumRueden . getCachedProblems ( ) & Validator . MISSING_TAG ) ; StringBuilder problemString = new StringBuilder ( ) ; for ( String s : validator . describeProblem ( main , zumRueden ) ) { problemString . append ( s ) ; } assertTrue ( problemString . toString ( ) . contains ( main . getString ( R . string . toast_needs_resurvey ) ) ) ; java . util . Map < String , String > tags = new HashMap < > ( zumRueden . getTags ( ) ) ; SimpleDateFormat format = new SimpleDateFormat ( Tags . CHECK_DATE_FORMAT ) ; tags . put ( Tags . KEY_CHECK_DATE , format . format ( new Date ( ) ) ) ; try { App . getLogic ( ) . setTags ( main , zumRueden , tags ) ; } catch ( OsmIllegalOperationException oioe ) { fail ( ) ; } assertEquals ( 0 , zumRueden . hasProblem ( main , validator ) & Validator . AGE ) ; Way limmatQuai = ( Way ) App . getDelegator ( ) . getOsmElement ( Way . NAME , 147759323 ) ; assertEquals ( Validator . OK , limmatQuai . hasProblem ( main , validator ) ) ; tags = new HashMap < > ( limmatQuai . getTags ( ) ) ; String originalHighway = tags . get ( Tags . KEY_HIGHWAY ) ; tags . put ( Tags . KEY_HIGHWAY , Tags . VALUE_ROAD ) ; try { App . getLogic ( ) . setTags ( main , limmatQuai , tags ) ; assertEquals ( Validator . HIGHWAY_ROAD , limmatQuai . hasProblem ( main , validator ) & Validator . HIGHWAY_ROAD ) ; problemString = new StringBuilder ( ) ; for ( String s : validator . describeProblem ( main , limmatQuai ) ) { problemString . append ( s ) ; } assertTrue ( problemString . toString ( ) . contains ( main . getString ( R . string . toast_unsurveyed_road ) ) ) ; tags = new HashMap < > ( limmatQuai . getTags ( ) ) ; tags . put ( Tags . KEY_HIGHWAY , originalHighway ) ; assertNotNull ( tags . remove ( Tags . KEY_NAME ) ) ; App . getLogic ( ) . setTags ( main , limmatQuai , tags ) ; assertEquals ( Validator . MISSING_TAG , limmatQuai . hasProblem ( main , validator ) & Validator . MISSING_TAG ) ; } catch ( OsmIllegalOperationException oioe ) { fail ( ) ; } Relation rcn66 = ( Relation ) App . getDelegator ( ) . getOsmElement ( Relation . NAME , 28059 ) ; assertEquals ( Validator . OK , rcn66 . hasProblem ( main , validator ) ) ; tags = new HashMap < > ( rcn66 . getTags ( ) ) ; tags . remove ( Tags . KEY_TYPE ) ; try { App . getLogic ( ) . setTags ( main , rcn66 , tags ) ; assertEquals ( Validator . NO_TYPE , rcn66 . hasProblem ( main , validator ) & Validator . NO_TYPE ) ; } catch ( OsmIllegalOperationException oioe ) { fail ( ) ; } problemString = new StringBuilder ( ) ; for ( String s : validator . describeProblem ( main , rcn66 ) ) { problemString . append ( s ) ; } assertTrue ( problemString . toString ( ) . contains ( main . getString ( R . string . toast_notype ) ) ) ; }
Test base validation stuff, age, missing tags, road names
Test base validation stuff age missing tags road names