Skip to content

Commit

Permalink
fixes 52North#197
Browse files Browse the repository at this point in the history
  • Loading branch information
ridoo committed Sep 23, 2015
1 parent bd7049b commit 7a81e49
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions 52n-wps-webapp/src/test/java/org/n52/wps/test/PostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static String sendRequest(String targetURL, String payload) throws IOExce
payloadP = "request=" + payloadP;

InputStream in = sendRequestForInputStream(targetURL, payloadP);

// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
List<String> lines= new LinkedList<String>();
Expand All @@ -78,7 +78,7 @@ public static InputStream sendRequestForInputStream(String targetURL, String pay
// Send data
URL url = new URL(targetURL);

URLConnection conn = url.openConnection();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setDoOutput(true);

Expand All @@ -87,10 +87,13 @@ public static InputStream sendRequestForInputStream(String targetURL, String pay
wr.write(payload);
wr.close();

return conn.getInputStream();

if (conn.getResponseCode() >= 400) {
return conn.getErrorStream();
} else {
return conn.getInputStream();
}
}

public static void checkForExceptionReport(String targetURL, String payload, int expectedHTTPStatusCode, String... expectedExceptionParameters) throws IOException{
// Send data
URL url = new URL(targetURL);
Expand All @@ -104,30 +107,30 @@ public static void checkForExceptionReport(String targetURL, String payload, int
wr.write(payload);
wr.close();

try {
conn.getInputStream();
try {
conn.getInputStream();
} catch (IOException e) {
/*
* expected, ignore
*/
*/
}

InputStream error = ((HttpURLConnection) conn).getErrorStream();

String exceptionReport = "";

int data = error.read();
while (data != -1) {
exceptionReport = exceptionReport + (char)data;
data = error.read();
}
error.close();
assertTrue(((HttpURLConnection) conn).getResponseCode() == expectedHTTPStatusCode);
assertTrue(((HttpURLConnection) conn).getResponseCode() == expectedHTTPStatusCode);

for (String expectedExceptionParameter : expectedExceptionParameters) {
assertTrue(exceptionReport.contains(expectedExceptionParameter));
}

assertTrue(exceptionReport.contains(expectedExceptionParameter));

}
}
}

0 comments on commit 7a81e49

Please sign in to comment.