Utils.prettyPrint(request);
}
// execute the request
try {
Response response = null;
boolean success = true;
System.out.println();
System.out.println("**** TEST: " + testName + " ****");
System.out.println("**** BEGIN CHECK ****");
// Part A
request.send();
response = request.waitForResponse(6000);
// checking the response
if (response != null) {
// print response info
if (verbose) {
System.out.println("Response received");
System.out.println("Time elapsed (ms): "
+ response.getRTT());
Utils.prettyPrint(response);
}
success &= checkInt(EXPECTED_RESPONSE_CODE_PREAMBLE.value,
response.getCode().value, "code");
success &= hasEtag(response);
success &= hasNonEmptyPalyoad(response);
success &= hasContentType(response);
if (success) {
etag1 = response.getOptions().getETags().get(0);
// Part A
request = new Request(Code.PUT, Type.CON);
request.getOptions().addIfMatch(etag1);
request.setPayload("TD_COAP_CORE_22 Part A",
MediaTypeRegistry.TEXT_PLAIN);
request.setURI(uri);
request.send();
response = request.waitForResponse(6000);
// checking the response
if (response != null) {
// print response info
if (verbose) {
System.out.println("Response received");
System.out.println("Time elapsed (ms): "
+ response.getRTT());
Utils.prettyPrint(response);
}
success &= checkInt(EXPECTED_RESPONSE_CODE_A.value,
response.getCode().value, "code");
success &= hasContentType(response);
// check new ETag
request = new Request(Code.GET, Type.CON);
request.setURI(uri);
request.send();
response = request.waitForResponse(6000);
// checking the response
if (response != null) {
etag2 = response.getOptions().getETags().get(0);
success &= checkInt(EXPECTED_RESPONSE_CODE_PREAMBLE.value, response.getCode().value, "code");
success &= hasEtag(response);
success &= hasNonEmptyPalyoad(response);
success &= hasContentType(response);
success &= checkDifferentOption(etag1, etag2, "ETag");
if (success) {
// change server resource
request = new Request(Code.PUT, Type.CON);
request.setURI(uri);
request.setPayload("It should change " + Math.random(), MediaTypeRegistry.TEXT_PLAIN);
request.send();
Thread.sleep(1000);
// Part B
request = new Request(Code.PUT, Type.CON);
request.getOptions().addIfMatch(etag1);
request.setPayload("TD_COAP_CORE_22 Part B", MediaTypeRegistry.TEXT_PLAIN);
request.setURI(uri);
request.send();
response = request.waitForResponse(6000);
// checking the response
if (response != null) {
// print response info
if (verbose) {
System.out.println("Response received");
System.out.println("Time elapsed (ms): " + response.getRTT());
Utils.prettyPrint(response);
}
success &= checkType(Type.ACK, response.getType());
success &= checkInt(EXPECTED_RESPONSE_CODE_B.value, response.getCode().value, "code");
}
}
}
}
}