-
Notifications
You must be signed in to change notification settings - Fork 74
v0.2.53..v0.2.54 changeset OsmApiWriterTest.cpp
Garret Voltz edited this page Mar 31, 2020
·
1 revision
diff --git a/hoot-core-test/src/test/cpp/hoot/core/io/OsmApiWriterTest.cpp b/hoot-core-test/src/test/cpp/hoot/core/io/OsmApiWriterTest.cpp
index 5cc6906..8102b2d 100644
--- a/hoot-core-test/src/test/cpp/hoot/core/io/OsmApiWriterTest.cpp
+++ b/hoot-core-test/src/test/cpp/hoot/core/io/OsmApiWriterTest.cpp
@@ -29,8 +29,9 @@
#include <hoot/core/TestUtils.h>
#include <hoot/core/io/OsmApiWriter.h>
#include <hoot/core/util/ConfigOptions.h>
-#include <hoot/core/util/Log.h>
#include <hoot/core/util/FileUtils.h>
+#include <hoot/core/util/HootNetworkUtils.h>
+#include <hoot/core/util/Log.h>
#include "OsmApiWriterTestServer.h"
@@ -53,6 +54,7 @@ class OsmApiWriterTest : public HootTestFixture
#ifdef RUN_LOCAL_TEST_SERVER
CPPUNIT_TEST(runRetryConflictsTest);
CPPUNIT_TEST(runVersionConflictResolutionTest);
+ CPPUNIT_TEST(runChangesetOutputTest);
#endif
/* These tests are for local testing and require additional resources to complete */
#ifdef RUN_LOCAL_OSM_API_SERVER
@@ -61,7 +63,6 @@ class OsmApiWriterTest : public HootTestFixture
CPPUNIT_TEST(runChangesetConflictTest);
CPPUNIT_TEST(oauthTest);
#endif
- CPPUNIT_TEST(runApplyTestTest);
CPPUNIT_TEST_SUITE_END();
public:
@@ -79,6 +80,7 @@ public:
const int PORT_PERMISSIONS = 9801;
const int PORT_CONFLICTS = 9802;
const int PORT_VERSION = 9803;
+ const int PORT_DEBUG_OUTPUT = 9804;
OsmApiWriterTest()
: HootTestFixture("test-files/io/OsmChangesetElementTest/",
@@ -124,7 +126,7 @@ public:
HootNetworkRequestPtr request(new HootNetworkRequest());
OsmApiWriter writer(osm, changesets);
CPPUNIT_ASSERT(writer.queryCapabilities(request));
- CPPUNIT_ASSERT_EQUAL(request->getHttpStatus(), 200);
+ CPPUNIT_ASSERT_EQUAL(request->getHttpStatus(), HttpResponseCode::HTTP_OK);
HOOT_STR_EQUALS(writer._capabilities.getVersion(), QString("0.6"));
CPPUNIT_ASSERT_EQUAL(writer._capabilities.getTracepoints(), static_cast<long>(5000));
CPPUNIT_ASSERT_EQUAL(writer._capabilities.getWayNodes(), static_cast<long>(2000));
@@ -160,7 +162,7 @@ public:
HootNetworkRequestPtr request(new HootNetworkRequest());
OsmApiWriter writer(osm, changesets);
CPPUNIT_ASSERT(writer.validatePermissions(request));
- CPPUNIT_ASSERT_EQUAL(request->getHttpStatus(), 200);
+ CPPUNIT_ASSERT_EQUAL(request->getHttpStatus(), HttpResponseCode::HTTP_OK);
#ifdef RUN_LOCAL_TEST_SERVER
server.shutdown();
#endif
@@ -310,8 +312,7 @@ public:
HOOT_STR_EQUALS(
FileUtils::readFully(_inputPath + "ToyTestAConflicts.osc")
.replace("timestamp=\"\"", "timestamp=\"\" changeset=\"0\"")
- .replace(" ", "\t")
- .replace("<delete>", "<delete if-unused=\"true\">"),
+ .replace(" ", "\t"),
writer.getFailedChangeset());
// Check the stats
checkStats(writer.getStats(), 3, 2, 0, 2, 1, 2, 5);
@@ -386,31 +387,45 @@ public:
#endif
}
- void runApplyTestTest()
+ void runChangesetOutputTest()
{
- QString toyInputFilename = _inputPath + "ToyTestA.osc";
- QString toyOutputFilename = _outputPath + "ApplyChangesetTest-Output-1.osc";
- std::shared_ptr<OsmApiWriter> writer(new OsmApiWriter(toyOutputFilename, toyInputFilename));
- QStringList files = writer->testApply();
+#ifdef RUN_LOCAL_TEST_SERVER
+ // Setup the test
+ QUrl osm;
+ osm.setUrl(LOCAL_TEST_API_URL.arg(PORT_DEBUG_OUTPUT));
+ osm.setUserInfo(TEST_USER_INFO);
- CPPUNIT_ASSERT_EQUAL(1, files.size());
- // Check the changeset error file
- HOOT_FILE_EQUALS( _inputPath + "ApplyChangesetTest-Expected-1-0001.osc",
- files[0]);
+ // Kick off the file output test server
+ ChangesetOutputTestServer server(PORT_DEBUG_OUTPUT);
+ server.start();
+
+ OsmApiWriter writer(osm, OsmApiSampleRequestResponse::SAMPLE_CHANGESET_REQUEST);
- toyOutputFilename = _outputPath + "ApplyChangesetTest-Output-2.osc";
- writer.reset(new OsmApiWriter(toyOutputFilename, toyInputFilename));
Settings s;
- s.set(ConfigOptions::getChangesetApidbSizeMaxKey(), 20);
- writer->setConfiguration(s);
- files = writer->testApply();
+ s.set(ConfigOptions::getChangesetApidbWritersMaxKey(), 1);
+ s.set(ConfigOptions::getChangesetApidbSizeMaxKey(), 2);
+ s.set(ConfigOptions::getChangesetApidbWriterDebugOutputKey(), true);
+ s.set(ConfigOptions::getChangesetApidbWriterDebugOutputPathKey(), _outputPath);
+ writer.setConfiguration(s);
+ writer.apply();
- CPPUNIT_ASSERT_EQUAL(2, files.size());
- // Check the changeset error file
- HOOT_FILE_EQUALS( _inputPath + "ApplyChangesetTest-Expected-2-0001.osc",
- files[0]);
- HOOT_FILE_EQUALS( _inputPath + "ApplyChangesetTest-Expected-2-0002.osc",
- files[1]);
+ // Wait for the test server to finish
+ server.shutdown();
+
+ // Make sure that none of the changes failed
+ CPPUNIT_ASSERT(!writer.containsFailed());
+ // Check the stats
+ checkStats(writer.getStats(), 0, 4, 0, 0, 4, 0, 0);
+ // Compare the files
+ HOOT_FILE_EQUALS( _inputPath + "ChangesetOutput-Request--1.osc",
+ _outputPath + "OsmApiWriter-000001-00001-Request--000.osc");
+ HOOT_FILE_EQUALS( _inputPath + "ChangesetOutput-Response-1.osc",
+ _outputPath + "OsmApiWriter-000001-00001-Response-200.osc");
+ HOOT_FILE_EQUALS( _inputPath + "ChangesetOutput-Request--2.osc",
+ _outputPath + "OsmApiWriter-000002-00001-Request--000.osc");
+ HOOT_FILE_EQUALS( _inputPath + "ChangesetOutput-Response-2.osc",
+ _outputPath + "OsmApiWriter-000002-00001-Response-200.osc");
+#endif
}
void checkStats(QList<SingleStat> stats,