import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
-import kafka.admin.TopicCommand;
-import kafka.admin.TopicCommand.TopicCommandOptions;
-import kafka.utils.ZKStringSerializer$;
-import kafka.utils.ZkUtils;
-
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.ZkConnection;
import org.iotivity.cloud.base.device.CoapDevice;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import kafka.admin.TopicCommand;
+import kafka.admin.TopicCommand.TopicCommandOptions;
+import kafka.utils.ZKStringSerializer$;
+import kafka.utils.ZkUtils;
+
public class MQBrokerResourceTest {
private final String MQ_BROKER_URI = Constants.MQ_BROKER_FULL_URI;
Object[] args = invocation.getArguments();
CoapResponse resp = (CoapResponse) args[0];
// assertion: if the response status is "CONTENT"
- // assertion: if the response payload has the "message" property
+ // assertion: if the response payload has data
assertTrue(methodCheck(resp, ResponseStatus.CONTENT));
- assertTrue(hashmapCheck(resp, "message"));
+ assertTrue(payloadCheck(resp));
return resp;
}
}).when(mockSubscriber).sendResponse(Mockito.anyObject());
CoapResponse resp = (CoapResponse) args[0];
latchSubscriber.countDown();
if (latchSubscriber.getCount() == 0) {
- // assertion: if the response payload has the "message"
- // property
+ // assertion: if the response payload has data
assertTrue(methodCheck(resp, ResponseStatus.CONTENT));
- assertTrue(hashmapCheck(resp, "message"));
+ assertTrue(payloadCheck(resp));
}
return resp;
}
// assertion for subscriber
if (latchSubscriber.getCount() == 0) {
assertTrue(methodCheck(resp, ResponseStatus.CONTENT));
- assertTrue(hashmapCheck(resp, "message"));
+ assertTrue(payloadCheck(resp));
DeleteTopic(mMockDevice, topic);
}
// read topic
ReadTopic(topic);
// assertion1 : if the response status is "CONTENT"
- // assertion2 : if the response payload has the "message" property
+ // assertion2 : if the response payload has data
assertTrue(methodCheck(mResponse, ResponseStatus.CONTENT));
- assertTrue(hashmapCheck(mResponse, "message"));
+ assertTrue(payloadCheck(mResponse));
}
@Test(expected = NotFoundException.class)
private IRequest PublishTopicRequest(String topicName) {
IRequest request = null;
- HashMap<String, Object> tags = new HashMap<String, Object>();
HashMap<String, Object> message = new HashMap<String, Object>();
message.put("status", "on");
message.put("brightness", 20);
- tags.put("message", message);
Cbor<HashMap<String, Object>> cbor = new Cbor<HashMap<String, Object>>();
String uri = MQ_BROKER_URI + "/" + topicName;
request = MessageBuilder.createRequest(RequestMethod.POST, uri, null,
ContentFormat.APPLICATION_CBOR,
- cbor.encodingPayloadToCbor(tags));
+ cbor.encodingPayloadToCbor(message));
return request;
}
mMqBrokerResource.onDefaultRequestReceived(mMockDevice, readRequest);
}
- private boolean hashmapCheck(IResponse response, String propertyName) {
+ private boolean payloadCheck(IResponse response) {
Cbor<HashMap<String, Object>> mCbor = new Cbor<>();
HashMap<String, Object> payloadData = mCbor
.parsePayloadFromCbor(response.getPayload(), HashMap.class);
- if (payloadData.get(propertyName) != null)
+ if (payloadData != null && payloadData.containsKey("status")
+ && payloadData.containsKey("brightness")) {
return true;
- else
+ } else
return false;
}