diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/Capability1Tests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/Capability1Tests.java index 039b6b341..d1e83ec0d 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/Capability1Tests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/Capability1Tests.java @@ -5,6 +5,7 @@ import de.fraunhofer.iosb.ilt.statests.util.ControlInformation; import de.fraunhofer.iosb.ilt.statests.util.EntityType; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import de.fraunhofer.iosb.ilt.statests.util.ServiceURLBuilder; import java.util.ArrayList; import java.util.HashMap; @@ -133,15 +134,15 @@ private void readPropertyOfEntityWithEntityType(EntityType entityType) { */ private void checkGetPropertyOfEntity(EntityType entityType, Object id, EntityType.EntityProperty property) { try { - Map responseMap = getEntity(entityType, id, property.name); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = getEntity(entityType, id, property.name); + int responseCode = responseMap.code; if (responseCode == 204) { // 204 is the proper response for NULL properties. return; } String message = "Reading property \"" + property.name + "\" of the existing " + entityType.name() + " with id " + id + " failed."; Assert.assertEquals(message, 200, responseCode); - String response = responseMap.get("response").toString(); + String response = responseMap.response; JSONObject entity; entity = new JSONObject(response); try { @@ -167,8 +168,8 @@ private void checkGetPropertyOfEntity(EntityType entityType, Object id, EntityTy * @param property The property to get requested */ private void checkGetPropertyValueOfEntity(EntityType entityType, Object id, EntityType.EntityProperty property) { - Map responseMap = getEntity(entityType, id, property.name + "/$value"); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = getEntity(entityType, id, property.name + "/$value"); + int responseCode = responseMap.code; if (responseCode != 200 && property.optional) { // The property is optional, and probably not present. return; @@ -179,7 +180,7 @@ private void checkGetPropertyValueOfEntity(EntityType entityType, Object id, Ent } String message = "Reading property value of \"" + property + "\" of the exitixting " + entityType.name() + " with id " + id + " failed."; Assert.assertEquals(message, 200, responseCode); - String response = responseMap.get("response").toString(); + String response = responseMap.response; if ("object".equalsIgnoreCase(property.jsonType)) { message = "Reading property value of \"" + property + "\" of \"" + entityType + "\" fails."; Assert.assertEquals(message, 0, response.indexOf("{")); @@ -232,13 +233,13 @@ private void readRelatedEntity(List entityTypes, List ids) { EntityType headEntity = EntityType.getForRelation(headName); boolean isPlural = EntityType.isPlural(headName); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityTypes, ids, null); - Map responseMap = HTTPMethods.doGet(urlString); - int code = Integer.valueOf(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + int code = responseMap.code; String message = "Reading relation of the entity failed: " + entityTypes.toString(); Assert.assertEquals(message, 200, code); - String response = responseMap.get("response").toString(); + String response = responseMap.response; Object id; if (isPlural) { id = new JSONObject(response).getJSONArray("value").getJSONObject(0).get(ControlInformation.ID); @@ -249,11 +250,11 @@ private void readRelatedEntity(List entityTypes, List ids) { //check $ref urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityTypes, ids, "$ref"); responseMap = HTTPMethods.doGet(urlString); - code = Integer.valueOf(responseMap.get("response-code").toString()); + code = responseMap.code; message = "Reading relation of the entity failed: " + entityTypes.toString(); Assert.assertEquals(message, 200, code); - response = responseMap.get("response").toString(); + response = responseMap.response; checkAssociationLinks(response, entityTypes, ids); if (entityTypes.size() == resourcePathLevel) { @@ -333,13 +334,13 @@ private String readEntityWithEntityType(EntityType entityType) { try { String response = getEntities(entityType); Object id = new JSONObject(response).getJSONArray("value").getJSONObject(0).get(ControlInformation.ID); - Map responseMap = getEntity(entityType, id, null); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = getEntity(entityType, id, null); + int responseCode = responseMap.code; String message = "Reading existing " + entityType.name() + " with id " + id + " failed."; Assert.assertEquals(message, 200, responseCode); - response = responseMap.get("response").toString(); + response = responseMap.response; return response; } catch (JSONException e) { LOGGER.error("Exception:", e); @@ -356,7 +357,7 @@ private String readEntityWithEntityType(EntityType entityType) { */ private void readNonexistentEntityWithEntityType(EntityType entityType) { long id = Long.MAX_VALUE; - int responseCode = Integer.parseInt(getEntity(entityType, id, null).get("response-code").toString()); + int responseCode = getEntity(entityType, id, null).code; String message = "Reading non-existing " + entityType.name() + " with id " + id + " failed."; Assert.assertEquals(message, 404, responseCode); } @@ -432,9 +433,9 @@ private String getEntities(EntityType entityType) { if (entityType != null) { urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); } - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; + int responseCode = responseMap.code; String message = "Error during getting entities: " + ((entityType != null) ? entityType.name() : "root URI"); Assert.assertEquals(message, 200, responseCode); @@ -458,7 +459,7 @@ private String getEntities(EntityType entityType) { * @return The response-code and response (body) of the request in Map * format. */ - private Map getEntity(EntityType entityType, Object id, String property) { + private HttpResponse getEntity(EntityType entityType, Object id, String property) { if (id == null) { return null; } diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/TestEntityCreator.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/TestEntityCreator.java index 6e62dc22b..f72408b23 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/TestEntityCreator.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c01sensingcore/TestEntityCreator.java @@ -3,8 +3,8 @@ import de.fraunhofer.iosb.ilt.statests.ServerSettings; import de.fraunhofer.iosb.ilt.statests.util.EntityType; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import de.fraunhofer.iosb.ilt.statests.util.ServiceURLBuilder; -import java.util.Map; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -128,8 +128,8 @@ private static void createTestEntities(String rootUri, boolean actuation) { + "}\n" + ""; String urlString = ServiceURLBuilder.buildURLString(rootUri, EntityType.THING, null, null, null); - Map responseMap = HTTPMethods.doPost(urlString, urlParameters); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doPost(urlString, urlParameters); + String response = responseMap.response; Object id = HTTPMethods.idFromSelfLink(response); if (actuation) { String postContent = "{\n" @@ -181,9 +181,9 @@ private static String getEntities(String rootUri, EntityType entityType) { if (entityType != null) { urlString = ServiceURLBuilder.buildURLString(rootUri, entityType, null, null, null); } - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; + int responseCode = responseMap.code; Assert.assertEquals("Error during getting entities: " + ((entityType != null) ? entityType.name() : "root URI"), 200, responseCode); if (entityType != null) { Assert.assertTrue("The GET entities response for entity type \"" + entityType + "\" does not match SensorThings API : missing \"value\" in response.", response.contains("value")); diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c02cud/Capability2Tests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c02cud/Capability2Tests.java index 67e66b82e..42879c600 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c02cud/Capability2Tests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c02cud/Capability2Tests.java @@ -6,6 +6,7 @@ import de.fraunhofer.iosb.ilt.statests.util.EntityType; import de.fraunhofer.iosb.ilt.statests.util.Extension; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import de.fraunhofer.iosb.ilt.statests.util.ServiceURLBuilder; import de.fraunhofer.iosb.ilt.statests.util.Utils; import static de.fraunhofer.iosb.ilt.statests.util.Utils.quoteIdForJson; @@ -1343,7 +1344,7 @@ private JSONObject getEntity(EntityType entityType, Object id) { } String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); try { - return new JSONObject(HTTPMethods.doGet(urlString).get("response").toString()); + return new JSONObject(HTTPMethods.doGet(urlString).response); } catch (JSONException e) { LOGGER.error("Exception: ", e); Assert.fail("An Exception occurred during testing: " + e.getMessage()); @@ -1362,21 +1363,19 @@ private JSONObject getEntity(EntityType entityType, Object id) { private JSONObject postEntity(EntityType entityType, String urlParameters) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); try { - Map responseMap = HTTPMethods.doPost(urlString, urlParameters); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse httpResponse = HTTPMethods.doPost(urlString, urlParameters); String message = "Error during creation of entity " + entityType.name(); - Assert.assertEquals(message, 201, responseCode); + Assert.assertEquals(message, 201, httpResponse.code); - String response = responseMap.get("response").toString(); - Object id = response.substring(response.indexOf("(") + 1, response.indexOf(")")); + Object id = httpResponse.response.substring(httpResponse.response.indexOf("(") + 1, httpResponse.response.indexOf(")")); urlString = urlString + "(" + id + ")"; - responseMap = HTTPMethods.doGet(urlString); - responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + int responseCode = responseMap.code; message = "The POSTed entity is not created."; Assert.assertEquals(message, 200, responseCode); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); return result; } catch (JSONException e) { LOGGER.error("Exception: ", e); @@ -1395,8 +1394,8 @@ private JSONObject postEntity(EntityType entityType, String urlParameters) { private void postInvalidEntity(EntityType entityType, String urlParameters) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doPost(urlString, urlParameters); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPost(urlString, urlParameters); + int responseCode = responseMap.code; String message = "The " + entityType.name() + " should not be created due to integrity constraints."; Assert.assertTrue(message, responseCode == 400 || responseCode == 409); @@ -1411,13 +1410,13 @@ private void postInvalidEntity(EntityType entityType, String urlParameters) { */ private static void deleteEntity(EntityType entityType, Object id) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); - Map responseMap = HTTPMethods.doDelete(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doDelete(urlString); + int responseCode = responseMap.code; String message = "DELETE does not work properly for " + entityType + " with id " + id + ". Returned with response code " + responseCode + "."; Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + responseCode = responseMap.code; message = "Deleted entity was not actually deleted : " + entityType + "(" + id + ")."; Assert.assertEquals(message, 404, responseCode); } @@ -1432,8 +1431,8 @@ private static void deleteEntity(EntityType entityType, Object id) { private void deleteNonExsistentEntity(EntityType entityType) { Object id = Long.MAX_VALUE; String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); - Map responseMap = HTTPMethods.doDelete(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doDelete(urlString); + int responseCode = responseMap.code; String message = "DELETE does not work properly for nonexistent " + entityType + " with id " + id + ". Returned with response code " + responseCode + "."; Assert.assertEquals(message, 404, responseCode); @@ -1451,13 +1450,13 @@ private void deleteNonExsistentEntity(EntityType entityType) { private JSONObject updateEntity(EntityType entityType, String urlParameters, Object id) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); try { - Map responseMap = HTTPMethods.doPut(urlString, urlParameters); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPut(urlString, urlParameters); + int responseCode = responseMap.code; String message = "Error during updating(PUT) of entity " + entityType.name(); Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); return result; } catch (JSONException e) { @@ -1480,12 +1479,12 @@ private JSONObject patchEntity(EntityType entityType, String urlParameters, Obje String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); try { - Map responseMap = HTTPMethods.doPatch(urlString, urlParameters); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPatch(urlString, urlParameters); + int responseCode = responseMap.code; String message = "Error during updating(PATCH) of entity " + entityType.name(); Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); return result; } catch (JSONException e) { @@ -1507,8 +1506,8 @@ private JSONObject patchEntity(EntityType entityType, String urlParameters, Obje private void invalidPatchEntity(EntityType entityType, String urlParameters, Object id) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); - Map responseMap = HTTPMethods.doPatch(urlString, urlParameters); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPatch(urlString, urlParameters); + int responseCode = responseMap.code; String message = "Error: Patching related entities inline must be illegal for entity " + entityType.name(); Assert.assertEquals(message, 400, responseCode); @@ -1582,11 +1581,11 @@ private void checkPut(EntityType entityType, JSONObject oldEntity, JSONObject ne private Object checkAutomaticInsertionOfFOI(Object obsId, JSONObject locationObj, Object expectedFOIId) { String urlString = serverSettings.serviceUrl + "/Observations(" + quoteIdForUrl(obsId) + ")/FeatureOfInterest"; try { - Map responseMap = HTTPMethods.doGet(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + int responseCode = responseMap.code; String message = "ERROR: FeatureOfInterest was not automatically created."; Assert.assertEquals(message, 200, responseCode); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); Object id = result.get(ControlInformation.ID); if (expectedFOIId != null) { message = "ERROR: the Observation should have linked to FeatureOfInterest with ID: " + expectedFOIId + ", but it is linked for FeatureOfInterest with Id: " + id + "."; @@ -1619,12 +1618,12 @@ private Object checkRelatedEntity(Set extensions, EntityType parentEn } try { - Map responseMap = HTTPMethods.doGet(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + int responseCode = responseMap.code; String message = "ERROR: Deep inserted " + relationEntityType + " was not created or linked to " + parentEntityType; Assert.assertEquals(message, 200, responseCode); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); if (isCollection == true) { result = result.getJSONArray("value").getJSONObject(0); } @@ -1671,9 +1670,9 @@ private void checkForObservationResultTime(JSONObject observation, String result private void checkNotExisting(List entityTypes) { for (EntityType entityType : entityTypes) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); + HttpResponse responseMap = HTTPMethods.doGet(urlString); try { - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); JSONArray array = result.getJSONArray("value"); String message = entityType + " is created although it shouldn't."; Assert.assertEquals(message, 0, array.length()); @@ -1692,9 +1691,9 @@ private void checkNotExisting(List entityTypes) { private void checkExisting(List entityTypes) { for (EntityType entityType : entityTypes) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); + HttpResponse responseMap = HTTPMethods.doGet(urlString); try { - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); JSONArray array = result.getJSONArray("value"); String message = entityType + " is created although it shouldn't."; Assert.assertTrue(message, array.length() > 0); @@ -1736,9 +1735,9 @@ private static void deleteEntityType(EntityType entityType) { do { try { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + int responseCode = responseMap.code; + JSONObject result = new JSONObject(responseMap.response); array = result.getJSONArray("value"); for (int i = 0; i < array.length(); i++) { Object id = array.getJSONObject(i).get(ControlInformation.ID); @@ -1813,34 +1812,34 @@ private void createEntitiesForDelete() { + " ]\n" + "}"; String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, null, null, null); - Map responseMap = HTTPMethods.doPost(urlString, urlParameters); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doPost(urlString, urlParameters); + String response = responseMap.response; THING_IDS.add(Utils.idObjectFromPostResult(response)); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, THING_IDS.get(0), EntityType.LOCATION, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); LOCATION_IDS.add(array.getJSONObject(0).get(ControlInformation.ID)); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, THING_IDS.get(0), EntityType.DATASTREAM, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); DATASTREAM_IDS.add(array.getJSONObject(0).get(ControlInformation.ID)); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, DATASTREAM_IDS.get(0), EntityType.SENSOR, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; SENSOR_IDS.add(new JSONObject(response).get(ControlInformation.ID)); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, DATASTREAM_IDS.get(0), EntityType.OBSERVED_PROPERTY, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; OBSPROP_IDS.add(new JSONObject(response).get(ControlInformation.ID)); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, THING_IDS.get(0), EntityType.HISTORICAL_LOCATION, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); HISTORICAL_LOCATION_IDS.add(array.getJSONObject(0).get(ControlInformation.ID)); @@ -1851,13 +1850,13 @@ private void createEntitiesForDelete() { + " \"result\": 1 \n" + " }"; responseMap = HTTPMethods.doPost(urlString, urlParameters); - response = responseMap.get("response").toString(); + response = responseMap.response; OBSERVATION_IDS.add(Utils.idObjectFromPostResult(response)); //FeatureOfInterest urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.OBSERVATION, OBSERVATION_IDS.get(0), EntityType.FEATURE_OF_INTEREST, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; FOI_IDS.add(new JSONObject(response).get(ControlInformation.ID)); } catch (JSONException e) { diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/Capability3Tests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/Capability3Tests.java index 66f73b46c..de15cbd43 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/Capability3Tests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/Capability3Tests.java @@ -10,6 +10,7 @@ import de.fraunhofer.iosb.ilt.statests.util.EntityUtils; import de.fraunhofer.iosb.ilt.statests.util.Expand; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import de.fraunhofer.iosb.ilt.statests.util.PathElement; import de.fraunhofer.iosb.ilt.statests.util.Query; import de.fraunhofer.iosb.ilt.statests.util.Request; @@ -22,7 +23,6 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.joda.time.DateTime; import org.joda.time.format.ISODateTimeFormat; import org.json.JSONArray; @@ -287,12 +287,12 @@ public void readEntitiesWithFilterQO() throws UnsupportedEncodingException { public void checkQueriesPriorityOrdering() { try { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.OBSERVATION, null, null, "?$count=true&$top=1&$skip=2&$orderby=phenomenonTime%20asc&$filter=result%20gt%20'3'"); - Map responseMap = HTTPMethods.doGet(urlString); + HttpResponse responseMap = HTTPMethods.doGet(urlString); - String message = "There is problem for GET Observations using multiple Query Options! HTTP status code: " + responseMap.get("response-code"); - Assert.assertEquals(message, 200, Integer.parseInt(responseMap.get("response-code").toString())); + String message = "There is problem for GET Observations using multiple Query Options! HTTP status code: " + responseMap.code; + Assert.assertEquals(message, 200, responseMap.code); - String response = responseMap.get("response").toString(); + String response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); message = "The query order of execution is not correct. The expected count is 6. The service returned " + new JSONObject(response).getLong("@iot.count"); @@ -389,12 +389,12 @@ public void checkArithmeticPrecendece() throws UnsupportedEncodingException { */ private void checkResults(String urlString, int expectedCount, String expectedResult, String fetchError, String resultError) { try { - Map responseMap = HTTPMethods.doGet(urlString); + HttpResponse responseMap = HTTPMethods.doGet(urlString); - String message = fetchError + ": " + responseMap.get("response-code"); - Assert.assertEquals(message, 200, Integer.parseInt(responseMap.get("response-code").toString())); + String message = fetchError + ": " + responseMap.code; + Assert.assertEquals(message, 200, responseMap.code); - String response = responseMap.get("response").toString(); + String response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); int length = array.length(); @@ -422,8 +422,8 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { List relations = entityType.getRelations(serverSettings.extensions); try { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); if (array.length() == 0) { return; @@ -443,7 +443,7 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$orderby=" + property.name); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { String message = "The ordering is not correct for EntityType " + entityType + " orderby property " + property; @@ -451,7 +451,7 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$orderby=" + property.name + "%20asc"); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { String message = "The ordering is not correct for EntityType " + entityType + " orderby asc property " + property; @@ -459,7 +459,7 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$orderby=" + property.name + "%20desc"); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { String message = "The ordering is not correct for EntityType " + entityType + " orderby desc property " + property; @@ -483,7 +483,7 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { orderbyPropeties.add(property.name); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, orderby); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { for (String orderProperty : orderbyPropeties) { @@ -501,7 +501,7 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { orderbyAsc += property + "%20asc"; urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, orderbyAsc); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { for (String orderProperty : orderbyPropeties) { @@ -519,7 +519,7 @@ private void checkOrderbyForEntityTypeRelations(EntityType entityType) { orderbyDesc += property + "%20desc"; urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, orderbyDesc); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { for (String orderProperty : orderbyPropeties) { @@ -554,8 +554,8 @@ private void checkOrderbyForEntityType(EntityType entityType) { continue; } String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$orderby=" + property.name); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { String msg = "The default ordering is not correct for EntityType " + entityType + " orderby property " + property.name; @@ -563,7 +563,7 @@ private void checkOrderbyForEntityType(EntityType entityType) { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$orderby=" + property.name + "%20asc"); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { String msg = "The ascending ordering is not correct for EntityType " + entityType + " orderby asc property " + property.name; @@ -571,7 +571,7 @@ private void checkOrderbyForEntityType(EntityType entityType) { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$orderby=" + property.name + "%20desc"); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { String msg = "The descending ordering is not correct for EntityType " + entityType + " orderby desc property " + property.name; @@ -594,8 +594,8 @@ private void checkOrderbyForEntityType(EntityType entityType) { orderby += property.name; orderbyPropeties.add(property.name); String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, orderby); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { for (String orderProperty : orderbyPropeties) { @@ -613,7 +613,7 @@ private void checkOrderbyForEntityType(EntityType entityType) { orderbyAsc += property + "%20asc"; urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, orderbyAsc); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { for (String orderProperty : orderbyPropeties) { @@ -631,7 +631,7 @@ private void checkOrderbyForEntityType(EntityType entityType) { orderbyDesc += property + "%20desc"; urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, orderbyDesc); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); for (int i = 1; i < array.length(); i++) { for (String orderProperty : orderbyPropeties) { @@ -1162,33 +1162,33 @@ private void checkFilterForEntityType(EntityType entityType) throws UnsupportedE propertyValue = URLEncoder.encode(propertyValue.toString(), "UTF-8"); String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$filter=" + property.name + "%20lt%20" + propertyValue); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, -2); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$filter=" + property.name + "%20le%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, -1); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$filter=" + property.name + "%20eq%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, 0); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$filter=" + property.name + "%20ne%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, -3); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$filter=" + property.name + "%20ge%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, 1); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, "?$filter=" + property.name + "%20gt%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, 2); } } @@ -1203,8 +1203,8 @@ private void checkFilterForEntityType(EntityType entityType) throws UnsupportedE private void checkFilterForEntityTypeRelations(EntityType entityType) throws UnsupportedEncodingException { List relations = entityType.getRelations(serverSettings.extensions); String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; JSONArray array = null; try { array = new JSONObject(response).getJSONArray("value"); @@ -1249,32 +1249,32 @@ private void checkFilterForEntityTypeRelations(EntityType entityType) throws Uns propertyValue = URLEncoder.encode(propertyValue.toString(), "UTF-8"); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$filter=" + property.name + "%20lt%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, -2); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$filter=" + property.name + "%20le%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, -1); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$filter=" + property.name + "%20eq%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, 0); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$filter=" + property.name + "%20ne%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, -3); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$filter=" + property.name + "%20ge%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, 1); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, relationEntityType, "?$filter=" + property.name + "%20gt%20" + propertyValue); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; checkPropertiesForFilter(response, filteredProperties, samplePropertyValues, 2); } } @@ -1351,8 +1351,8 @@ private void checkPropertiesForFilter(String response, List properties, } private static Object postAndGetId(String urlString, String postContent) { - Map responseMap = HTTPMethods.doPost(urlString, postContent); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doPost(urlString, postContent); + String response = responseMap.response; return Utils.idObjectFromPostResult(response); } @@ -1431,14 +1431,14 @@ private static void createEntities() { thingId1 = postAndGetId(urlString, urlParameters); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, thingId1, EntityType.LOCATION, null); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String response = responseMap.response; JSONArray array = new JSONObject(response).getJSONArray("value"); locationId1 = array.getJSONObject(0).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, thingId1, EntityType.DATASTREAM, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); // We can not assume the Datastreams are returned in the order we expect. if ("datastream 1".equals(array.getJSONObject(0).get("name"))) { @@ -1450,20 +1450,20 @@ private static void createEntities() { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId1, EntityType.SENSOR, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; sensorId1 = new JSONObject(response).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId1, EntityType.OBSERVED_PROPERTY, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; observedPropertyId1 = new JSONObject(response).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId2, EntityType.SENSOR, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; sensorId2 = new JSONObject(response).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId2, EntityType.OBSERVED_PROPERTY, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; observedPropertyId2 = new JSONObject(response).get(ControlInformation.ID); //Second Thing @@ -1535,13 +1535,13 @@ private static void createEntities() { urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, thingId2, EntityType.LOCATION, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); locationId2 = array.getJSONObject(0).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, thingId2, EntityType.DATASTREAM, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); // We can not assume the Datastreams are returned in the order we expect. if ("datastream 3".equals(array.getJSONObject(0).get("name"))) { @@ -1553,16 +1553,16 @@ private static void createEntities() { } urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId3, EntityType.SENSOR, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; sensorId3 = new JSONObject(response).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId3, EntityType.OBSERVED_PROPERTY, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; observedPropertyId3 = new JSONObject(response).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.DATASTREAM, datastreamId4, EntityType.SENSOR, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; sensorId4 = new JSONObject(response).get(ControlInformation.ID); //HistoricalLocations @@ -1584,14 +1584,14 @@ private static void createEntities() { urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, thingId1, EntityType.HISTORICAL_LOCATION, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); historicalLocationId1 = array.getJSONObject(0).get(ControlInformation.ID); historicalLocationId2 = array.getJSONObject(1).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.THING, thingId2, EntityType.HISTORICAL_LOCATION, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; array = new JSONObject(response).getJSONArray("value"); historicalLocationId3 = array.getJSONObject(0).get(ControlInformation.ID); historicalLocationId4 = array.getJSONObject(1).get(ControlInformation.ID); @@ -1668,12 +1668,12 @@ private static void createEntities() { //FeatureOfInterest urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.OBSERVATION, observationId1, EntityType.FEATURE_OF_INTEREST, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; featureOfInterestId1 = new JSONObject(response).get(ControlInformation.ID); urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.OBSERVATION, observationId7, EntityType.FEATURE_OF_INTEREST, null); responseMap = HTTPMethods.doGet(urlString); - response = responseMap.get("response").toString(); + response = responseMap.response; featureOfInterestId2 = new JSONObject(response).get(ControlInformation.ID); entityCounts.setGlobalCount(EntityType.DATASTREAM, 4); @@ -1746,9 +1746,9 @@ private static void deleteEntityType(EntityType entityType) { do { try { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + int responseCode = responseMap.code; + JSONObject result = new JSONObject(responseMap.response); array = result.getJSONArray("value"); for (int i = 0; i < array.length(); i++) { Object id = array.getJSONObject(i).get(ControlInformation.ID); @@ -1770,13 +1770,13 @@ private static void deleteEntityType(EntityType entityType) { */ private static void deleteEntity(EntityType entityType, Object id) { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, entityType, id, null, null); - Map responseMap = HTTPMethods.doDelete(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doDelete(urlString); + int responseCode = responseMap.code; String message = "DELETE does not work properly for " + entityType + " with id " + id + ". Returned with response code " + responseCode + "."; Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + responseCode = responseMap.code; message = "Deleted entity was not actually deleted : " + entityType + "(" + id + ")."; Assert.assertEquals(message, 404, responseCode); } diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java index 786c7a85c..c4d030f90 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/FilterTests.java @@ -282,9 +282,8 @@ public void testDeepIndirection() throws ServiceFailureException { @Test public void testNullEntityProperty() { String requestUrl = serverSettings.serviceUrl + "/Things(" + THINGS.get(0).getId().getUrl() + ")/properties"; - Map result = HTTPMethods.doGet(requestUrl); - int responseCode = Integer.parseInt(result.get("response-code").toString()); - if (responseCode != 204) { + HTTPMethods.HttpResponse result = HTTPMethods.doGet(requestUrl); + if (result.code != 204) { Assert.fail("Expected response code 204 on request " + requestUrl); } } @@ -292,9 +291,8 @@ public void testNullEntityProperty() { @Test public void testNullEntityPropertyValue() { String requestUrl = serverSettings.serviceUrl + "/Things(" + THINGS.get(0).getId().getUrl() + ")/properties/$value"; - Map result = HTTPMethods.doGet(requestUrl); - int responseCode = Integer.parseInt(result.get("response-code").toString()); - if (responseCode != 204) { + HTTPMethods.HttpResponse result = HTTPMethods.doGet(requestUrl); + if (result.code != 204) { Assert.fail("Expected response code 204 on request " + requestUrl); } } diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/JsonPropertiesTests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/JsonPropertiesTests.java index 731876fcd..f110426e2 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/JsonPropertiesTests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c03filtering/JsonPropertiesTests.java @@ -18,6 +18,7 @@ import de.fraunhofer.iosb.ilt.statests.TestSuite; import de.fraunhofer.iosb.ilt.statests.util.EntityUtils; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -385,14 +386,12 @@ public void test06UnitOfMeasurementFilter() throws ServiceFailureException { private JsonNode getJsonObjectForResponse(String urlString) { // Ensure [ and ] are urlEncoded. urlString = urlString.replaceAll(Pattern.quote("["), "%5B").replaceAll(Pattern.quote("]"), "%5D"); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - String message = "Incorrect response code (" + responseCode + ") for url: " + urlString; - Assert.assertEquals(message, 200, responseCode); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String message = "Incorrect response code (" + responseMap.code + ") for url: " + urlString; + Assert.assertEquals(message, 200, responseMap.code); JsonNode json; try { - json = new ObjectMapper().readTree(response); + json = new ObjectMapper().readTree(responseMap.response); } catch (IOException ex) { Assert.fail("Server returned malformed JSON for request: " + urlString + " Exception: " + ex.getMessage()); return null; diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c05multidatastream/MultiDatastreamTests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c05multidatastream/MultiDatastreamTests.java index 56976e1d0..ba9990c3e 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c05multidatastream/MultiDatastreamTests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c05multidatastream/MultiDatastreamTests.java @@ -18,6 +18,7 @@ import de.fraunhofer.iosb.ilt.statests.TestSuite; import de.fraunhofer.iosb.ilt.statests.util.EntityUtils; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -26,7 +27,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.regex.Pattern; import org.geojson.Point; import org.junit.AfterClass; @@ -320,15 +320,13 @@ public void test03ObservationInMultiDatastreamIncorrect() throws ServiceFailureE private JsonNode getJsonObject(String urlString) { urlString = urlString.replaceAll(Pattern.quote("["), "%5B").replaceAll(Pattern.quote("]"), "%5D"); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - String message = "Error getting Observations using Data Array: Code " + responseCode; - Assert.assertEquals(message, 200, responseCode); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String message = "Error getting Observations using Data Array: Code " + responseMap.code; + Assert.assertEquals(message, 200, responseMap.code); JsonNode json; try { - json = new ObjectMapper().readTree(response); + json = new ObjectMapper().readTree(responseMap.response); } catch (IOException ex) { Assert.fail("Server returned malformed JSON for request: " + urlString + " Exception: " + ex); return null; diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c06dataarrays/DataArrayTests.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c06dataarrays/DataArrayTests.java index a5f72605c..378c9e2b6 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c06dataarrays/DataArrayTests.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/c06dataarrays/DataArrayTests.java @@ -24,6 +24,7 @@ import de.fraunhofer.iosb.ilt.statests.util.EntityType; import de.fraunhofer.iosb.ilt.statests.util.EntityUtils; import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import de.fraunhofer.iosb.ilt.statests.util.ServiceURLBuilder; import java.io.IOException; import java.net.MalformedURLException; @@ -35,7 +36,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import org.geojson.Point; import org.junit.AfterClass; @@ -233,25 +233,21 @@ public void filterAndCheck(BaseDao doa, String filter, List ex @Test public void test01GetDataArray() throws ServiceFailureException { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.OBSERVATION, null, null, "?$count=true&$top=3&$resultFormat=dataArray"); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - String message = "Error getting Observations using Data Array: Code " + responseCode; - Assert.assertEquals(message, 200, responseCode); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String message = "Error getting Observations using Data Array: Code " + responseMap.response; + Assert.assertEquals(message, 200, responseMap.code); - validateGetDataArrayResponse(response, urlString, new HashSet<>(Arrays.asList(OBSERVATION_PROPERTIES))); + validateGetDataArrayResponse(responseMap.response, urlString, new HashSet<>(Arrays.asList(OBSERVATION_PROPERTIES))); } @Test public void test02GetDataArraySelect() throws ServiceFailureException { String urlString = ServiceURLBuilder.buildURLString(serverSettings.serviceUrl, EntityType.OBSERVATION, null, null, "?$count=true&$top=4&$resultFormat=dataArray&$select=result,phenomenonTime&$orderby=phenomenonTime%20desc"); - Map responseMap = HTTPMethods.doGet(urlString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - String message = "Error getting Observations using Data Array: Code " + responseCode; - Assert.assertEquals(message, 200, responseCode); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + String message = "Error getting Observations using Data Array: Code " + responseMap.response; + Assert.assertEquals(message, 200, responseMap.code); - validateGetDataArrayResponse(response, urlString, new HashSet<>(Arrays.asList("result", "phenomenonTime"))); + validateGetDataArrayResponse(responseMap.response, urlString, new HashSet<>(Arrays.asList("result", "phenomenonTime"))); } private void validateGetDataArrayResponse(String response, String urlString, Set requestedProperties) { @@ -393,9 +389,9 @@ public void test03PostDataArray() { + " }\n" + "]"; String urlString = serverSettings.serviceUrl + "/CreateObservations"; - Map responseMap = HTTPMethods.doPost(urlString, jsonString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPost(urlString, jsonString); + String response = responseMap.response; + int responseCode = responseMap.code; String message = "Error posting Observations using Data Array: Code " + responseCode; Assert.assertEquals(message, 201, responseCode); @@ -488,9 +484,9 @@ public void test04PostDataArrayMultiDatastream() { + " }" + "]"; String urlString = serverSettings.serviceUrl + "/CreateObservations"; - Map responseMap = HTTPMethods.doPost(urlString, jsonString); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPost(urlString, jsonString); + String response = responseMap.response; + int responseCode = responseMap.code; String message = "Error posting Observations using Data Array: Code " + responseCode; Assert.assertEquals(message, 201, responseCode); diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/EntityHelper.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/EntityHelper.java index db5cadf45..26c46a4d8 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/EntityHelper.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/EntityHelper.java @@ -15,6 +15,7 @@ */ package de.fraunhofer.iosb.ilt.statests.util; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import static de.fraunhofer.iosb.ilt.statests.util.Utils.quoteIdForJson; import de.fraunhofer.iosb.ilt.statests.util.mqtt.DeepInsertInfo; import java.util.HashMap; @@ -82,9 +83,8 @@ public void deleteEntityType(EntityType entityType) { do { try { String urlString = ServiceURLBuilder.buildURLString(rootUri, entityType, null, null, null); - Map responseMap = HTTPMethods.doGet(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + HttpResponse responseMap = HTTPMethods.doGet(urlString); + JSONObject result = new JSONObject(responseMap.response); array = result.getJSONArray("value"); for (int i = 0; i < array.length(); i++) { Object id = array.getJSONObject(i).get(ControlInformation.ID); @@ -356,13 +356,13 @@ public Object createThingWithDeepInsert() { public void deleteEntity(EntityType entityType, Object id) { String urlString = ServiceURLBuilder.buildURLString(rootUri, entityType, id, null, null); - Map responseMap = HTTPMethods.doDelete(urlString); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doDelete(urlString); + int responseCode = responseMap.code; String message = "DELETE does not work properly for " + entityType + " with id " + id + ". Returned with response code " + responseCode + "."; Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + responseCode = responseMap.code; message = "Deleted entity was not actually deleted : " + entityType + "(" + id + ")."; Assert.assertEquals(message, 404, responseCode); } @@ -399,7 +399,7 @@ public JSONObject getEntity(EntityType entityType, Object id) { } String urlString = ServiceURLBuilder.buildURLString(rootUri, entityType, id, null, null); try { - return new JSONObject(HTTPMethods.doGet(urlString).get("response").toString()); + return new JSONObject(HTTPMethods.doGet(urlString).response); } catch (JSONException e) { LOGGER.error("Exception:", e); Assert.fail("An Exception occurred during testing!: " + e.getMessage()); @@ -410,7 +410,7 @@ public JSONObject getEntity(EntityType entityType, Object id) { public JSONObject getEntity(String relativeUrl) { String urlString = concatOverlapping(rootUri, relativeUrl); try { - return new JSONObject(HTTPMethods.doGet(urlString).get("response").toString()); + return new JSONObject(HTTPMethods.doGet(urlString).response); } catch (JSONException e) { LOGGER.error("Exception:", e); Assert.fail("An Exception occurred during testing!: " + e.getMessage()); @@ -428,7 +428,7 @@ public JSONObject getAnyEntity(EntityType entityType, String queryOptions) { urlString += "&" + queryOptions; } try { - String json = HTTPMethods.doGet(urlString).get("response").toString(); + String json = HTTPMethods.doGet(urlString).response; return new JSONObject(json).getJSONArray("value").getJSONObject(0); } catch (JSONException e) { LOGGER.error("Exception:", e); @@ -467,13 +467,13 @@ public Map getEntityChanges(EntityType entityType) { public JSONObject patchEntity(EntityType entityType, Map changes, Object id) { String urlString = ServiceURLBuilder.buildURLString(rootUri, entityType, id, null, null); try { - Map responseMap = HTTPMethods.doPatch(urlString, new JSONObject(changes).toString()); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPatch(urlString, new JSONObject(changes).toString()); + int responseCode = responseMap.code; String message = "Error during updating(PATCH) of entity " + entityType.name(); Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); return result; } catch (JSONException e) { @@ -491,12 +491,12 @@ public JSONObject putEntity(EntityType entityType, Map changes, for (Map.Entry entry : changes.entrySet()) { entity.put(entry.getKey(), entry.getValue()); } - Map responseMap = HTTPMethods.doPut(urlString, entity.toString()); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - String message = "Error during updating(PUT) of entity " + entityType.name() + ": " + responseMap.get("response"); + HttpResponse responseMap = HTTPMethods.doPut(urlString, entity.toString()); + int responseCode = responseMap.code; + String message = "Error during updating(PUT) of entity " + entityType.name() + ": " + responseMap.response; Assert.assertEquals(message, 200, responseCode); responseMap = HTTPMethods.doGet(urlString); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); return result; } catch (JSONException e) { @@ -640,22 +640,22 @@ private Map getThingChanges() { private JSONObject postEntity(EntityType entityType, String urlParameters) { String urlString = ServiceURLBuilder.buildURLString(rootUri, entityType, null, null, null); try { - Map responseMap = HTTPMethods.doPost(urlString, urlParameters); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + HttpResponse responseMap = HTTPMethods.doPost(urlString, urlParameters); + int responseCode = responseMap.code; String message = "Error during creation of entity " + entityType.name(); Assert.assertEquals(message, 201, responseCode); - String response = responseMap.get("response").toString(); + String response = responseMap.response; Object id = response.substring(response.indexOf("(") + 1, response.indexOf(")")); urlString = urlString + "(" + id + ")"; responseMap = HTTPMethods.doGet(urlString); - responseCode = Integer.parseInt(responseMap.get("response-code").toString()); + responseCode = responseMap.code; message = "The POSTed entity is not created."; Assert.assertEquals(message, 200, responseCode); - JSONObject result = new JSONObject(responseMap.get("response").toString()); + JSONObject result = new JSONObject(responseMap.response); return result; } catch (JSONException e) { Assert.fail("An Exception occurred during testing!:\n" + e.getMessage()); diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/HTTPMethods.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/HTTPMethods.java index 6e456ffe8..fea6f93f2 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/HTTPMethods.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/HTTPMethods.java @@ -10,8 +10,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; import org.apache.http.Consts; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPatch; @@ -36,6 +34,26 @@ public class HTTPMethods { */ private static final Logger LOGGER = LoggerFactory.getLogger(HTTPMethods.class); + public static class HttpResponse { + + public final int code; + public String response; + + public HttpResponse(int code) { + this.code = code; + } + + public HttpResponse(int code, String response) { + this.code = code; + this.response = response; + } + + public void setResponse(String response) { + this.response = response; + } + + } + /** * Send HTTP GET request to the urlString and return response code and * response body @@ -45,7 +63,7 @@ public class HTTPMethods { * MAP format. If the response is not 200, the response(response body) will * be empty. */ - public static Map doGet(String urlString) { + public static HttpResponse doGet(String urlString) { HttpURLConnection connection = null; try { LOGGER.info("Getting: {}", urlString); @@ -59,12 +77,11 @@ public static Map doGet(String urlString) { connection.setUseCaches(false); connection.setDoOutput(true); - Map result = new HashMap(); - result.put("response-code", connection.getResponseCode()); + HttpResponse result = new HttpResponse(connection.getResponseCode()); if (connection.getResponseCode() == 200) { - result.put("response", responseToString(connection)); + result.setResponse(responseToString(connection)); } else { - result.put("response", ""); + result.setResponse(""); } return result; } catch (IOException e) { @@ -102,7 +119,7 @@ private static String responseToString(HttpURLConnection connection) throws IOEx * the response is 201, the response will contain the self-link to the * created entity. Otherwise, it will be empty String. */ - public static Map doPost(String urlString, String postBody) { + public static HttpResponse doPost(String urlString, String postBody) { HttpURLConnection connection = null; try { LOGGER.info("Posting: {}", urlString); @@ -122,17 +139,16 @@ public static Map doPost(String urlString, String postBody) { wr.write(postData); } - Map result = new HashMap<>(); - result.put("response-code", connection.getResponseCode()); + HttpResponse result = new HttpResponse(connection.getResponseCode()); if (connection.getResponseCode() == 201) { String locationHeader = connection.getHeaderField("location"); if (locationHeader == null || locationHeader.isEmpty()) { - result.put("response", responseToString(connection)); + result.setResponse(responseToString(connection)); } else { - result.put("response", locationHeader); + result.setResponse(locationHeader); } } else { - result.put("response", ""); + result.setResponse(""); } return result; } catch (Exception e) { @@ -155,7 +171,7 @@ public static Map doPost(String urlString, String postBody) { * MAP format. If the response is not 200, the response(response body) will * be empty. */ - public static Map doPut(String urlString, String putBody) { + public static HttpResponse doPut(String urlString, String putBody) { HttpURLConnection connection = null; try { LOGGER.info("Putting: {}", urlString); @@ -167,9 +183,8 @@ public static Map doPut(String urlString, String putBody) { StringEntity params = new StringEntity(putBody, ContentType.APPLICATION_JSON); request.setEntity(params); CloseableHttpResponse response = httpClient.execute(request); - Map result = new HashMap<>(); - result.put("response-code", response.getStatusLine().getStatusCode()); - result.put("response", EntityUtils.toString(response.getEntity())); + HttpResponse result = new HttpResponse(response.getStatusLine().getStatusCode()); + result.setResponse(EntityUtils.toString(response.getEntity())); response.close(); httpClient.close(); return result; @@ -192,7 +207,7 @@ public static Map doPut(String urlString, String putBody) { * contains an empty response, in order to be consistent with what other * HTTP requests return. */ - public static Map doDelete(String urlString) { + public static HttpResponse doDelete(String urlString) { HttpURLConnection connection = null; try { LOGGER.info("Deleting: {}", urlString); @@ -205,9 +220,8 @@ public static Map doDelete(String urlString) { connection.setRequestMethod("DELETE"); connection.connect(); - Map result = new HashMap(); - result.put("response-code", connection.getResponseCode()); - result.put("response", ""); + HttpResponse result = new HttpResponse(connection.getResponseCode()); + result.setResponse(""); return result; } catch (Exception e) { @@ -230,7 +244,7 @@ public static Map doDelete(String urlString) { * the MAP format. If the response is not 200, the response(response body) * will be empty. */ - public static Map doPatch(String urlString, String patchBody) { + public static HttpResponse doPatch(String urlString, String patchBody) { URI uri = null; try { LOGGER.info("Patching: {}", urlString); @@ -241,9 +255,8 @@ public static Map doPatch(String urlString, String patchBody) { StringEntity params = new StringEntity(patchBody, ContentType.APPLICATION_JSON); request.setEntity(params); CloseableHttpResponse response = httpClient.execute(request); - Map result = new HashMap<>(); - result.put("response-code", response.getStatusLine().getStatusCode()); - result.put("response", EntityUtils.toString(response.getEntity())); + HttpResponse result = new HttpResponse(response.getStatusLine().getStatusCode()); + result.setResponse(EntityUtils.toString(response.getEntity())); response.close(); httpClient.close(); return result; @@ -263,19 +276,18 @@ public static Map doPatch(String urlString, String patchBody) { * the MAP format. If the response is not 200, the response(response body) * will be empty. */ - public static Map doJsonPatch(String urlString, String patchBody) { + public static HttpResponse doJsonPatch(String urlString, String patchBody) { URI uri; LOGGER.info("Patching: {}", urlString); - Map result; + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { uri = new URI(urlString); HttpPatch request = new HttpPatch(uri); StringEntity params = new StringEntity(patchBody, APPLICATION_JSON_PATCH); request.setEntity(params); try (CloseableHttpResponse response = httpClient.execute(request)) { - result = new HashMap<>(); - result.put("response-code", response.getStatusLine().getStatusCode()); - result.put("response", EntityUtils.toString(response.getEntity())); + HttpResponse result = new HttpResponse(response.getStatusLine().getStatusCode()); + result.setResponse(EntityUtils.toString(response.getEntity())); return result; } } catch (URISyntaxException | IOException e) { diff --git a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/Request.java b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/Request.java index 47861ba52..fb1a1a559 100644 --- a/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/Request.java +++ b/FROST-Server.Tests/src/test/java/de/fraunhofer/iosb/ilt/statests/util/Request.java @@ -15,7 +15,7 @@ */ package de.fraunhofer.iosb.ilt.statests.util; -import java.util.Map; +import de.fraunhofer.iosb.ilt.statests.util.HTTPMethods.HttpResponse; import org.json.JSONException; import org.json.JSONObject; import org.junit.Assert; @@ -86,16 +86,14 @@ public String buildUrl() { public JSONObject executeGet() { String fetchUrl = buildUrl(); - Map responseMap = HTTPMethods.doGet(fetchUrl); - String response = responseMap.get("response").toString(); - int responseCode = Integer.parseInt(responseMap.get("response-code").toString()); - if (responseCode != 200) { + HttpResponse responseMap = HTTPMethods.doGet(fetchUrl); + if (responseMap.code != 200) { String message = "Error during request: " + fetchUrl; - Assert.assertEquals(message, 200, responseCode); + Assert.assertEquals(message, 200, responseMap.code); } JSONObject jsonResponse = null; try { - jsonResponse = new JSONObject(response); + jsonResponse = new JSONObject(responseMap.response); } catch (JSONException ex) { LOGGER.error("Failed to parse response for request: " + fetchUrl, ex); Assert.fail("Failed to parse response for request: " + fetchUrl);