Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit ba1646f

Browse files
authored
Merge pull request #96 from cloud-of-things/PBT-841-fix-integration-tests
PBT-841 fix integration tests
2 parents cea947c + fd382c8 commit ba1646f

File tree

4 files changed

+58
-22
lines changed

4 files changed

+58
-22
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ Short information about what has changed between releases.
6363
* EventApi provides the update of events as well now. ([Pull Request #95](https://github.com/cloud-of-things/cot-java-rest-sdk/pull/95))
6464
* Fixed cast in getSource() method of Alarm and Event
6565
* Added the getter as counterpart of set(Object) in ExtendedObject
66-
66+
* Includes ([Pull Request #96](https://github.com/cloud-of-things/cot-java-rest-sdk/pull/96)):
67+
- Fixed some unstable integration tests due to maybe changed behavior of the c8y API
68+
- Provided more details from the c8y error message in CotSdkException
6769
6870
### Release 1.1.0
6971

src/main/java/com/telekom/m2m/cot/restsdk/CloudOfThingsRestClient.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,13 @@ private String getErrorMessage(final Response response) throws IOException {
632632
if (e instanceof JsonObject) {
633633
JsonObject o = (JsonObject) e;
634634
if (o.has("error")) {
635-
errorMessage += " Platform provided details: '" + o.get("error") + "'";
635+
errorMessage += " Platform provided details: " + o.get("error") + "; ";
636+
}
637+
if (o.has("message")) {
638+
errorMessage += "message: " + o.get("message") + "; ";
639+
}
640+
if (o.has("info")) {
641+
errorMessage += "info: " + o.get("info");
636642
}
637643
} else if (e instanceof JsonPrimitive) {
638644
JsonPrimitive p = (JsonPrimitive) e;

src/test/java/com/telekom/m2m/cot/restsdk/inventory/InventoryApiExtendedIT.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class InventoryApiExtendedIT {
2323
private static final String PARENT_MANAGED_OBJECT_NAME = "parentTestManagedObject";
2424
private static final String CHILD_MANAGED_OBJECT_NAME = "childTestManagedObject";
2525

26-
private final CloudOfThingsPlatform cloudOfThingsPlatform = new CloudOfThingsPlatform(TestHelper.TEST_HOST, TestHelper.TEST_USERNAME, TestHelper.TEST_PASSWORD);
26+
private final CloudOfThingsPlatform cloudOfThingsPlatform = new CloudOfThingsPlatform(TestHelper.TEST_HOST, TestHelper.TEST_TENANT + "/" + TestHelper.TEST_USERNAME, TestHelper.TEST_PASSWORD);
2727
private final InventoryApi inventoryApi = cloudOfThingsPlatform.getInventoryApi();
2828
private final MeasurementApi measurementApi = cloudOfThingsPlatform.getMeasurementApi();
2929

@@ -247,6 +247,8 @@ public void testManagedObjectNotifications() throws InterruptedException {
247247

248248
List<String> notifications = inventoryApi.pullNotifications(managedObject.getId());
249249
assertNotNull(notifications);
250+
// Actually we expecting exactly one notification at all but c8y is sometimes sending two identical notifications with different notification IDs at once.
251+
// Therefore we are checking for more than 0 notification. At least there should be one.
250252
assertTrue(notifications.size() > 0);
251253

252254
String lastNotification = notifications.get(notifications.size()-1);
@@ -257,6 +259,32 @@ public void testManagedObjectNotifications() throws InterruptedException {
257259
inventoryApi.unsubscribeFromManagedObjectNotifications(managedObject.getId());
258260
}
259261

262+
@Test
263+
public void testDeleteManagedObjectNotifications() throws InterruptedException {
264+
ManagedObject managedObject = createManagedObjectInCot(PARENT_MANAGED_OBJECT_NAME);
265+
managedObjectsToDelete.add(managedObject);
266+
inventoryApi.subscribeToManagedObjectNotifications(managedObject.getId());
267+
268+
Thread.sleep(1000);
269+
270+
ManagedObject retrievedMo = inventoryApi.get(managedObject.getId());
271+
inventoryApi.delete(retrievedMo.getId());
272+
273+
Thread.sleep(1000);
274+
275+
List<String> notifications = inventoryApi.pullNotifications(managedObject.getId());
276+
assertNotNull(notifications);
277+
// Actually we expecting exactly 2 notifications at all but c8y is mostly sending two identical DELETE-notifications with different notification IDs at once.
278+
// Therefore we are checking for more than 1 notification. At least there should be two.
279+
assertTrue(notifications.size() > 0);
280+
281+
String lastNotification = notifications.get(notifications.size()-1);
282+
283+
assertTrue(lastNotification.contains("\"realtimeAction\": \"DELETE\""));
284+
285+
inventoryApi.unsubscribeFromManagedObjectNotifications(managedObject.getId());
286+
}
287+
260288
private ManagedObject createManagedObjectInCot(String name) {
261289
ManagedObject mo = new ManagedObject();
262290
mo.setName(name);

src/test/java/com/telekom/m2m/cot/restsdk/realtime/CepApiIT.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,9 @@ public void onError(String channel, Throwable error) {
580580

581581
Thread.sleep(DELAY_MILLIS);
582582

583-
assertEquals(notedInventoryObjects.size(), 2);
583+
// Actually we expecting exactly 2 notifications at all but c8y is mostly sending two identical DELETE-notifications with different notification IDs at once.
584+
// Therefore we are checking for more than 1 notification. At least there should be two.
585+
assertTrue(notedInventoryObjects.size() > 1);
584586
assertTrue(notedInventoryObjects.get(1).contains("DELETE"));
585587

586588
}
@@ -597,11 +599,11 @@ public void testConnectionAndDisconnection() throws InterruptedException {
597599
//we check that the connector is not connected before to start
598600
assertFalse(connector.isConnected(), "the cep connector should be disconnected before to start the test");
599601

600-
// connector.connect();
601-
// assertTrue(connector.isConnected());
602-
//
603-
// connector.disconnect();
604-
// assertFalse(connector.isConnected());
602+
connector.connect();
603+
assertTrue(connector.isConnected());
604+
605+
connector.disconnect();
606+
assertFalse(connector.isConnected());
605607

606608
//till here, we already verified that in case of connection or disconnection the flag is properly set
607609

@@ -611,10 +613,6 @@ public void testConnectionAndDisconnection() throws InterruptedException {
611613
connector.addListener(new SubscriptionListener() {
612614
@Override
613615
public void onNotification(String channel, Notification notification) {
614-
System.out.println(channel + ": " + notification.toString());
615-
// System.out.println(channel + ": " + notification.getPayload());
616-
// System.out.println(channel + ": " + notification.getRealtimeAction());
617-
System.out.println(channel + ": " + notification.getData().toString());
618616
notedInventoryObjects.add(notification.getData().toString());
619617
}
620618

@@ -637,22 +635,24 @@ public void onError(String channel, Throwable error) {
637635
assertEquals(notedInventoryObjects.size(), 1);
638636
assertTrue(notedInventoryObjects.get(0).contains("UPDATE"));
639637

640-
// //now we disconnect, to test the reconnection to the channel
641-
// connector.disconnect();
642-
// assertFalse(connector.isConnected());
643-
//
644-
// //we reconnect....
645-
// connector.connect();
646-
// assertTrue(connector.isConnected());
638+
//now we disconnect, to test the reconnection to the channel
639+
connector.disconnect();
640+
assertFalse(connector.isConnected());
641+
642+
//we reconnect....
643+
connector.connect();
644+
assertTrue(connector.isConnected());
647645

648646
// Now let's delete the managed object and see what happens, we should receive the notification of delete due to the
649647
// reconnection
650648
Thread.sleep(DELAY_MILLIS);
651649
invApi.delete(testObjectForConnectAndDisconnect.getId());
652650
Thread.sleep(DELAY_MILLIS);
653651

654-
//the second notification should be a delete one
655-
assertEquals(notedInventoryObjects.size(), 2);
652+
// The second notification should be a delete one
653+
// Actually we expecting exactly 2 notifications at all but c8y is mostly sending two identical DELETE-notifications with different notification IDs at once.
654+
// Therefore we are checking for more than 1 notification. At least there should be two.
655+
assertTrue(notedInventoryObjects.size() > 1);
656656
assertTrue(notedInventoryObjects.get(1).contains("DELETE"));
657657

658658
//and ... we disconnect to test again :)

0 commit comments

Comments
 (0)