1 package com.samsung.ci.test.mq;
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertTrue;
6 import org.junit.jupiter.api.BeforeAll;
7 import org.junit.jupiter.api.Test;
9 import com.google.gson.Gson;
10 import com.samsung.ci.basic.api.MQPublisherAPI;
11 import com.samsung.ci.basic.api.Rest;
12 import com.samsung.ci.basic.model.Device;
13 import com.samsung.ci.test.useractions.BasicUserAction;
15 import io.restassured.response.Response;
17 public class DeviceRegistrationAndUnregistrationWithoutCloudTest extends BasicUserAction{
19 private static final String DEVICE_DUID = "00000000-1111-2222-3333-4444444444444";
20 private static final String DEVICE_NAME = "TV";
21 private static final String DEVICE_TYPE = "tv";
22 private static final String DEVICE_MODEL = "standard";
23 private static final String DEVICE_PARENT_DUID = "55555555-6666-7777-8888-999999999999";
24 private static final String DEVICE_UNREGISTER_ACTION = "unregister";
25 private static final String DEVICE_DELETE_ACTION = "delete";
28 public static void info() {
29 log("Device registration/unregistration without cloud scenario:\n"
30 + "1. Register user;\n"
31 + "2. Register device;\n"
32 + "3. Check device;\n"
33 + "4. Remove device\n"
34 + "5. Remove user\n");
37 private void registerDevice(String uuid) {
38 log("Device registration");
39 assertTrue(MQPublisherAPI.deviceRegistrationInDSM(DEVICE_DUID, uuid, DEVICE_NAME, DEVICE_TYPE, DEVICE_MODEL, DEVICE_PARENT_DUID));
42 private void checkDevice() {
44 Response resp = Rest.getDeviceByDUID(DEVICE_DUID);
45 assertTrue(resp.getStatusCode() == 200);
46 Gson gson = new Gson();
47 Device device = gson.fromJson(resp.getBody().asString(), Device.class);
48 log(device.toString());
49 assertTrue(device.getUuid().equals(DEVICE_DUID));
50 assertTrue(device.getModel().equals(DEVICE_MODEL));
51 assertTrue(device.getName().equals(DEVICE_NAME));
52 assertTrue(device.getStatus() == 1);
53 assertTrue(device.getParentUuid().equals(DEVICE_PARENT_DUID));
56 private void checkDeviceOnList(String uuid) {
57 log("Check device on list");
58 Response resp = Rest.getDeviceByCloudUUID(uuid);
59 assertTrue(resp.getBody().asString().contains(DEVICE_DUID));
63 private void lastCheck(String uuid) {
64 log("Last check device");
65 Response resp = Rest.getDeviceByDUID(DEVICE_DUID);
66 assertTrue(resp.getStatusCode() == 404);
67 assertFalse(resp.getBody().asString().contains(DEVICE_DUID));
68 resp = Rest.getDeviceByCloudUUID(uuid);
69 assertFalse(resp.getBody().asString().contains(DEVICE_DUID));
74 * 1. Create new user "userApiIntegrationTest"
79 * 6. Create IoTCloud User
82 * 9. Unregister device
83 * 10. Delete IoTCloud User
84 * @throws InterruptedException
87 public void T01registerAndUnregisterDevice() throws InterruptedException{
88 log("Authorized without cloud scenario");
89 Thread.sleep(TIMEOUT);
92 String authcode = getAuthCode(USER_EMAIL, USER_PASSWORD);
93 String token = getToken(authcode);
95 String uuid = "test-uuid";
96 createIoTUser(USER_EMAIL, uuid);
98 Thread.sleep(TIMEOUT);
100 checkDeviceOnList(uuid);
101 assertTrue(MQPublisherAPI.deviceUnRegistrationInDSM(DEVICE_DUID, DEVICE_DELETE_ACTION));
102 Thread.sleep(TIMEOUT);
104 assertTrue(MQPublisherAPI.deviceUnRegistrationInDSM(DEVICE_DUID, DEVICE_UNREGISTER_ACTION));
105 Thread.sleep(TIMEOUT);