forked from osmlab/atlas-checks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MapRouletteUploadCommand: Handle gzipped files (osmlab#138)
* Handle gzipped files cleanly * spotlessapply and factor out a constant * Address comments * Add unit tests * Remove hardcoded files
- Loading branch information
Showing
5 changed files
with
206 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.openstreetmap.atlas.checks.maproulette; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.openstreetmap.atlas.checks.event.CheckFlagEvent; | ||
import org.openstreetmap.atlas.checks.event.CheckFlagFileProcessor; | ||
import org.openstreetmap.atlas.checks.event.FileProcessor; | ||
import org.openstreetmap.atlas.checks.event.ShutdownEvent; | ||
import org.openstreetmap.atlas.checks.maproulette.data.Challenge; | ||
import org.openstreetmap.atlas.checks.maproulette.data.Project; | ||
import org.openstreetmap.atlas.generator.tools.spark.utilities.SparkFileHelper; | ||
import org.openstreetmap.atlas.streaming.resource.File; | ||
import org.openstreetmap.atlas.utilities.runtime.CommandMap; | ||
|
||
/** | ||
* Unit tests for MapRouletteUploadCommand. | ||
* | ||
* @author nachtm | ||
*/ | ||
public class MapRouletteUploadCommandTest | ||
{ | ||
private static final String MAPROULETTE_CONFIG = "-maproulette=host:2222:project:api"; | ||
private static final File FOLDER = File.temporaryFolder(); | ||
|
||
@Rule | ||
public final MapRouletteUploadCommandTestRule setup = new MapRouletteUploadCommandTestRule(); | ||
|
||
@Before | ||
public void writeFiles() | ||
{ | ||
// Create an unzipped file | ||
final FileProcessor<CheckFlagEvent> unzippedProcessor = new CheckFlagFileProcessor( | ||
new SparkFileHelper(Collections.emptyMap()), | ||
FOLDER.child("unzipped.log").toString()).withCompression(false); | ||
unzippedProcessor.process(setup.getOneBasicFlag()); | ||
unzippedProcessor.process(new ShutdownEvent()); | ||
|
||
// Create a zipped file | ||
final FileProcessor<CheckFlagEvent> zippedProcessor = new CheckFlagFileProcessor( | ||
new SparkFileHelper(Collections.emptyMap()), | ||
FOLDER.child("zipped.log.gz").toString()).withCompression(true); | ||
zippedProcessor.process(setup.getAnotherBasicFlag()); | ||
zippedProcessor.process(new ShutdownEvent()); | ||
} | ||
|
||
@After | ||
public void cleanup() | ||
{ | ||
new File(FOLDER.getPath()).deleteRecursively(); | ||
} | ||
|
||
@Test | ||
public void testExecute() | ||
{ | ||
// Set up some arguments | ||
final MapRouletteCommand command = new MapRouletteUploadCommand(); | ||
final String[] arguments = { String.format("-logfiles=%s", FOLDER.getPath()), | ||
MAPROULETTE_CONFIG }; | ||
final CommandMap map = command.getCommandMap(arguments); | ||
final TestMapRouletteConnection connection = new TestMapRouletteConnection(); | ||
|
||
// Run the command | ||
command.onRun(map, configuration -> new MapRouletteClient(configuration, connection)); | ||
|
||
// Test the results | ||
final Set<Project> projects = connection.uploadedProjects(); | ||
Assert.assertEquals(1, projects.size()); | ||
projects.forEach(project -> | ||
{ | ||
Assert.assertEquals("project", project.getName()); | ||
final Set<Challenge> challenges = connection.challengesForProject(project); | ||
Assert.assertEquals(1, challenges.size()); | ||
challenges.forEach(challenge -> Assert.assertEquals(2, | ||
connection.tasksForChallenge(challenge).size())); | ||
}); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...est/java/org/openstreetmap/atlas/checks/maproulette/MapRouletteUploadCommandTestRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.openstreetmap.atlas.checks.maproulette; | ||
|
||
import org.openstreetmap.atlas.checks.event.CheckFlagEvent; | ||
import org.openstreetmap.atlas.checks.flag.CheckFlag; | ||
import org.openstreetmap.atlas.geography.atlas.Atlas; | ||
import org.openstreetmap.atlas.utilities.testing.CoreTestRule; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas.Loc; | ||
import org.openstreetmap.atlas.utilities.testing.TestAtlas.Point; | ||
|
||
/** | ||
* Data for unit tests for MapRouletteUploadCommand | ||
* | ||
* @author nachtm | ||
*/ | ||
public class MapRouletteUploadCommandTestRule extends CoreTestRule | ||
{ | ||
private static final String CENTER = "0,0"; | ||
private static final String IDENTIFIER_1 = "1"; | ||
private static final String IDENTIFIER_2 = "2"; | ||
private static final String CHALLENGE = "SomeCheck"; | ||
private static final String INSTRUCTIONS = "Instructions."; | ||
|
||
@TestAtlas(points = { @Point(coordinates = @Loc(value = CENTER), id = "1") }) | ||
private Atlas basicAtlas; | ||
|
||
private CheckFlagEvent getBasicFlag(final String identifier) | ||
{ | ||
final CheckFlag flag = new CheckFlag(identifier); | ||
flag.addObject(this.basicAtlas.point(1L)); | ||
flag.addInstruction(INSTRUCTIONS); | ||
|
||
return new CheckFlagEvent(CHALLENGE, flag); | ||
} | ||
|
||
public CheckFlagEvent getOneBasicFlag() | ||
{ | ||
return this.getBasicFlag(IDENTIFIER_1); | ||
} | ||
|
||
public CheckFlagEvent getAnotherBasicFlag() | ||
{ | ||
return this.getBasicFlag(IDENTIFIER_2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters