Skip to content

Commit

Permalink
rewriting of tests
Browse files Browse the repository at this point in the history
for /elements/count|length|perimeter
using assertEquals instead of assertTrue
and looking at all results to be independent from the order
  • Loading branch information
FabiKo117 committed Oct 10, 2018
1 parent bce3e12 commit 48d5f17
Show file tree
Hide file tree
Showing 2 changed files with 212 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,11 @@ public void getElementsCountDensityGroupByTagTest() {
@Test
public void getElementsLengthTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response =
restTemplate.getForEntity(
server + port + "/elements/length?bboxes=8.67452,49.40961,8.70392,49.41823&types=way"
+ "&time=2012-01-01&keys=highway&values=residential&showMetadata=true",
JsonNode.class);
assertTrue(response.getBody().get("result").get(0).get("value").asDouble() == 15171.81);
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/elements/length?bboxes=8.67452,49.40961,8.70392,49.41823&types=way"
+ "&time=2012-01-01&keys=highway&values=residential",
JsonNode.class);
assertEquals(15171.81, response.getBody().get("result").get(0).get("value").asDouble(), 0);
}

@Test
Expand All @@ -266,19 +265,29 @@ public void getElementsLengthGroupByBoundaryTest() {
+ "/elements/length/groupBy/boundary?bboxes=8.695443,49.408928,8.695636,49.409151|"
+ "8.699262,49.409451,8.701547,49.412205&types=way&time=2014-08-21&keys=highway",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asDouble() == 25.5);
assertEquals(25.5,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("bbox1"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
public void getElementsLengthGroupByTypeTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/elements/length/groupBy/type?bboxes=8.701665,49.408802,8.703999,49.409553"
+ "&types=way,node&time=2014-08-21&keys=highway",
+ "&types=way,relation&time=2014-08-21&keys=highway",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asInt() == 0);
assertEquals(540.52,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("way"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
Expand All @@ -288,8 +297,11 @@ public void getElementsLengthGroupByKeyTest() {
server + port + "/elements/length/groupBy/key?bboxes=8.67181,49.40434,8.67846,49.40878"
+ "&types=way&time=2016-08-21&groupByKeys=highway,railway",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asDouble() == 3132.95);
assertEquals(3132.95, StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("remainder"))
.findFirst().get().get("result").get(0).get("value").asDouble(), 0);
}

@Test
Expand All @@ -298,8 +310,11 @@ public void getElementsLengthGroupByTagTest() {
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/elements/length/groupBy/tag?bboxes=8.70773,49.40832,8.71413,49.41092&types=way"
+ "&time=2016-08-21&groupByKey=highway", JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asDouble() == 2779.09);
assertEquals(372.78, StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("highway=path"))
.findFirst().get().get("result").get(0).get("value").asDouble(), 0);
}

@Test
Expand All @@ -309,8 +324,13 @@ public void getElementsLengthGroupByUserTest() {
server + port + "/elements/length/groupBy/user?bboxes=8.68658,49.39316,8.69881,49.40511"
+ "&types=way&time=2014-04-03&keys=highway",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asDouble() == 134.65);
assertEquals(134.65,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("6654"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
Expand All @@ -320,7 +340,7 @@ public void getElementsLengthShareTest() {
server + port + "/elements/length/share?bboxes=8.68297,49.40863,8.69121,49.41016&types=way"
+ "&time=2016-07-25&keys2=highway",
JsonNode.class);
assertTrue(response.getBody().get("shareResult").get(0).get("part").asDouble() == 4233.42);
assertEquals(4233.42, response.getBody().get("shareResult").get(0).get("part").asDouble(), 0);
}

@Test
Expand All @@ -331,16 +351,22 @@ public void getElementsLengthShareGroupByBoundaryTest() {
+ "49.39871,8.68949,49.40232&types=way&time=2010-02-03&keys2=highway", JsonNode.class);
assertTrue(response.getBody().get("shareGroupByBoundaryResult").get(1).get("shareResult").get(0)
.get("part").asDouble() == 3074.8);
assertEquals(3074.8, StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("shareGroupByBoundaryResult").iterator(), Spliterator.ORDERED),
false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("bbox2"))
.findFirst().get().get("shareResult").get(0).get("part").asDouble(), 0);
}

@Test
public void getElementsLengthRatioTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/elements" + "/length/ratio?bboxes=8.67567,49.40695,8.69434,49.40882"
server + port + "/elements/length/ratio?bboxes=8.67567,49.40695,8.69434,49.40882"
+ "&types=way&time=2011-12-13&keys=highway&keys2=railway",
JsonNode.class);
assertTrue(response.getBody().get("ratioResult").get(0).get("ratio").asDouble() == 0.135225);
assertEquals(0.135225, response.getBody().get("ratioResult").get(0).get("ratio").asDouble(), 0);
}

@Test
Expand All @@ -350,8 +376,13 @@ public void getElementsLengthRatioGroupByBoundaryTest() {
+ "/length/ratio/groupBy/boundary?bboxes=8.67829,49.39807,8.69061,49.40578|"
+ "8.68306,49.42407,8.68829,49.42711&types=way&time=2012-12-22&keys=highway&keys2=railway",
JsonNode.class);
assertTrue(response.getBody().get("groupByBoundaryResult").get(0).get("ratioResult").get(0)
.get("ratio").asDouble() == 0.47867);
assertEquals(0.47867, StreamSupport
.stream(
Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByBoundaryResult").iterator(), Spliterator.ORDERED),
false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("bbox1"))
.findFirst().get().get("ratioResult").get(0).get("ratio").asDouble(), 0);
}

@Test
Expand All @@ -361,7 +392,7 @@ public void getElementsLengthDensityTest() {
server + port + "/elements/length/density?bboxes=8.70538,49.40464,8.71264,49.41042"
+ "&types=way&time=2013-01-04&keys=highway",
JsonNode.class);
assertTrue(response.getBody().get("result").get(0).get("value").asDouble() == 29022.41);
assertEquals(29022.41, response.getBody().get("result").get(0).get("value").asDouble(), 0);
}

@Test
Expand All @@ -370,8 +401,13 @@ public void getElementsLengthDensityGroupByTypeTest() {
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/elements/length/density/groupBy/type?bboxes=8.68242,49.40059,8.68732,49.4059"
+ "&types=way,node&time=2015-03-25", JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(1).get("result").get(0).get("value")
.asDouble() == 47849.51);
assertEquals(47849.51,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("way"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
Expand All @@ -380,8 +416,11 @@ public void getElementsLengthDensityGroupByTagTest() {
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/elements/length/density/groupBy/tag?bboxes=8.66972,49.40453,8.67564,49.4076"
+ "&types=way&time=2016-01-17&groupByKey=railway", JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asDouble() == 60235.78);
assertEquals(20495.63, StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("railway=tram"))
.findFirst().get().get("result").get(0).get("value").asDouble(), 0);
}

@Test
Expand All @@ -392,8 +431,13 @@ public void getElementsLengthDensityGroupByBoundaryTest() {
+ "/elements/length/density/groupBy/boundary?bboxes=8.69079,49.40129,8.69238,49.40341|"
+ "8.67504,49.4119,8.67813,49.41668&types=way&time=2017-05-30&key=highway",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(1).get("result").get(0).get("value")
.asDouble() == 74036.22);
assertEquals(74036.22,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("bbox2"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

/*
Expand All @@ -403,65 +447,83 @@ public void getElementsLengthDensityGroupByBoundaryTest() {
@Test
public void getUsersCountTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/users/count?bboxes=8.67452,49.40961,8.70392,49.41823&types=way"
+ "&time=2014-01-01,2015-01-01&keys=building&values=residential&showMetadata=true",
JsonNode.class);
assertTrue(response.getBody().get("result").get(0).get("value").asInt() == 5);
ResponseEntity<JsonNode> response =
restTemplate
.getForEntity(
server + port + "/users/count?bboxes=8.67452,49.40961,8.70392,49.41823&types=way"
+ "&time=2014-01-01,2015-01-01&keys=building&values=residential",
JsonNode.class);
assertEquals(5, response.getBody().get("result").get(0).get("value").asInt(), 0);
}

@Test
public void getUsersCountGroupByTypeTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/users/count/groupBy/type?bboxes=8.67,49.39941,8.69545,49.4096&types=way,relation"
+ "&time=2014-01-01,2015-01-01&keys=building&showMetadata=true", JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asInt() == 31);
+ "&time=2014-01-01,2015-01-01&keys=building", JsonNode.class);
assertEquals(31,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("way"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
public void getUsersCountGroupByKeyTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/users/count/groupBy/key?bboxes=8.67,49.39941,8.69545,49.4096&types=way"
+ "&time=2014-01-01,2015-01-01&groupByKeys=building&showMetadata=true",
+ "&time=2014-01-01,2015-01-01&groupByKeys=building",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(1).get("result").get(0).get("value")
.asInt() == 31);
assertEquals(31,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("building"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
public void getUsersCountGroupByTagTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/users/count/groupBy/tag?bboxes=8.67,49.39941,8.69545,49.4096&types=way"
+ "&time=2014-01-01,2015-01-01&groupByKey=building&showMetadata=true",
+ "&time=2014-01-01,2015-01-01&groupByKey=building",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asInt() == 54);
assertEquals(30, StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("building=yes"))
.findFirst().get().get("result").get(0).get("value").asDouble(), 0);
}

@Test
public void getUsersCountDensityTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port + "/users/count/density?bboxes=8.67,49.39941,8.69545,49.4096&types=way"
+ "&time=2014-01-01,2015-01-01&keys=building&showMetadata=true",
+ "&time=2014-01-01,2015-01-01&keys=building",
JsonNode.class);
assertTrue(response.getBody().get("result").get(0).get("value").asDouble() == 14.86);
assertEquals(14.86, response.getBody().get("result").get(0).get("value").asDouble(), 0);
}

@Test
public void getUsersCountDensityGroupByTypeTest() {
TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<JsonNode> response = restTemplate.getForEntity(
server + port
+ "/users/count/density/groupBy/type?bboxes=8.67,49.39941,8.69545,49.4096&types=way,"
+ "relation&time=2014-01-01,2015-01-01&keys=building&showMetadata=true",
JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(1).get("result").get(0).get("value")
.asDouble() == 3.83);
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/users/count/density/groupBy/type?bboxes=8.67,49.39941,8.69545,49.4096&types=way,"
+ "relation&time=2014-01-01,2015-01-01&keys=building", JsonNode.class);
assertEquals(3.83,
StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("relation"))
.findFirst().get().get("result").get(0).get("value").asDouble(),
0);
}

@Test
Expand All @@ -470,7 +532,10 @@ public void getUsersCountDensityGroupByTagTest() {
ResponseEntity<JsonNode> response = restTemplate.getForEntity(server + port
+ "/users/count/density/groupBy/tag?bboxes=8.67,49.39941,8.69545,49.4096&types=way"
+ "&time=2014-01-01,2015-01-01&groupByKey=building&showMetadata=true", JsonNode.class);
assertTrue(response.getBody().get("groupByResult").get(0).get("result").get(0).get("value")
.asDouble() == 25.88);
assertEquals(25.88, StreamSupport
.stream(Spliterators.spliteratorUnknownSize(
response.getBody().get("groupByResult").iterator(), Spliterator.ORDERED), false)
.filter(jsonNode -> jsonNode.get("groupByObject").asText().equalsIgnoreCase("remainder"))
.findFirst().get().get("result").get(0).get("value").asDouble(), 0);
}
}
Loading

0 comments on commit 48d5f17

Please sign in to comment.