Utils.prettyPrint(request);
}
// execute the request
try {
Response response = null;
boolean success = true;
request.send();
System.out.println();
System.out.println("**** TEST: " + testName + " ****");
System.out.println("**** BEGIN CHECK ****");
response = request.waitForResponse(time);
if (response != null) {
success &= checkType(Type.ACK, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE.value, response.getCode().value, "code");
success &= hasContentType(response);
success &= checkToken(request.getToken(), response.getToken());
success &= hasObserve(response);
time = response.getOptions().getMaxAge() * 1000;
System.out.println("+++++ Max-Age: "+time+" +++++");
if (time==0) time = 5000;
}
// receive multiple responses
for (int l = 0; success && l < observeLoop; ++l) {
response = request.waitForResponse(time + 1000);
// checking the response
if (response != null) {
System.out.println("Received notification " + l);
// print response info
if (verbose) {
System.out.println("Response received");
System.out.println("Time elapsed (ms): "
+ response.getRTT());
Utils.prettyPrint(response);
}
success &= checkResponse(request, response);
if (l==1) {
System.out.println("+++++ Unrelated GET +++++");
// GET with different Token
Request asyncRequest = Request.newGet();
asyncRequest.setURI(uri);
asyncRequest.send();
response = asyncRequest.waitForResponse(time/2);
if (response!=null) {
success &= checkToken(asyncRequest.getToken(), response.getToken());
success &= hasObserve(response, true); // inverted
System.out.println("+++++ OK +++++");
} else {
System.out.println("FAIL: No response to unrelated GET");
success = false;