[SECIOTSRK-649] REST getDevices by iotCloudUserUuId function: +tests
authorm.dalakov <m.dalakov@samsung.com>
Fri, 20 Oct 2017 15:23:54 +0000 (18:23 +0300)
committerm.dalakov <m.dalakov@samsung.com>
Fri, 20 Oct 2017 15:23:54 +0000 (18:23 +0300)
servers/api-integration-tests/src/main/java/com/samsung/ci/basic/api/Rest.java
servers/api-integration-tests/src/test/java/com/samsung/ci/test/mq/PolicyWitoutCloudTest.java
servers/api-integration-tests/src/test/java/com/samsung/ci/test/mq/ReportsWithOutCloudTest.java
servers/api-integration-tests/src/test/java/com/samsung/ci/test/reports/RestRuleReportsTest.java [moved from servers/api-integration-tests/src/test/java/com/samsung/ci/test/reports/TestRestRuleReports.java with 97% similarity]
servers/api-integration-tests/src/test/java/com/samsung/ci/test/reports/TIAReportsTest.java [moved from servers/api-integration-tests/src/test/java/com/samsung/ci/test/reports/TIAReports.java with 98% similarity]
servers/api-integration-tests/src/test/java/com/samsung/ci/test/useractions/AuthorizedUsingCloudTest.java
servers/api-integration-tests/src/test/java/com/samsung/ci/test/useractions/DeviceApiWithoutCloudTest.java [new file with mode: 0644]
servers/api-integration-tests/src/test/java/com/samsung/ci/test/useractions/IotAliveStatusTest.java
servers/dsm/src/test/java/com/samsung/dsm/rest/DeviceApiTest.java

index ab8728c..31c882a 100644 (file)
@@ -178,4 +178,10 @@ public final class Rest {
         return resp;
     }
 
+    public static Response findDeviceByCloudUserUuidExceptModelStandard(String uuid) {
+        Response resp = given().when().get(RestAssured.baseURI + "/dsm/restapi/device/" + uuid + "/byCloudUserUuidNotStandard");
+        resp.then().log().all();
+        return resp;
+    }
+
 }
index b5d6f80..f115ca0 100644 (file)
@@ -31,7 +31,9 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.junit.Ignore;
 import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import com.samsung.ci.basic.api.MQListenerAPI;
@@ -52,6 +54,8 @@ import com.samsung.ci.test.useractions.BasicUserAction;
  * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
  * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
  */
+@Disabled
+@Ignore
 public class PolicyWitoutCloudTest extends BasicUserAction {
 
     private static final String DEVICE_DUID = "00000000-1111-2222-3333-4444444444444";
index 88a9605..f879cb6 100644 (file)
@@ -29,7 +29,9 @@ import com.samsung.ci.basic.utils.Utils;
 import com.samsung.ci.test.useractions.BasicUserAction;
 import io.restassured.response.Response;
 import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.junit.Ignore;
 import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
@@ -53,6 +55,8 @@ import static org.junit.Assert.assertTrue;
  * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
  * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
  */
+@Disabled
+@Ignore
 public class ReportsWithOutCloudTest extends BasicUserAction {
 
     private static final String SMACK = "smack";
@@ -10,7 +10,9 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.kafka.clients.consumer.KafkaConsumer;
+import org.junit.Ignore;
 import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 
 import com.google.gson.Gson;
@@ -25,7 +27,9 @@ import io.restassured.response.Response;
 /**
  * The type Test rest rule reports.
  */
-public class TestRestRuleReports extends BasicUserAction {
+@Disabled
+@Ignore
+public class RestRuleReportsTest extends BasicUserAction {
 
     private static final String SYSCALL = "syscall";
     private static final String DEVICE_DUID = "00000000-1111-2222-3333-4444444444444";
@@ -39,11 +39,11 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 /**
- * The type TIAReports.
+ * The type TIAReportsTest.
  *
  * @author Mail to: <A HREF="mailto:m.dalakov@samsung.com">Mikhail Dalakov</A>
  * @version 1.0
- * @file TIAReports
+ * @file TIAReportsTest
  * @brief Base class for Reports
  * @date Created : 10/3/2017
  * @date Modified : 10/3/2017
@@ -51,7 +51,7 @@ import static org.junit.Assert.assertTrue;
  * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
  * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
  */
-public class TIAReports extends BasicUserAction {
+public class TIAReportsTest extends BasicUserAction {
 
     private static final String DEVICE_DUID = "TIA-0000000-1111-2222-3333-4444444444444";
     private static final String DEVICE_UNREGISTER_ACTION = "unregister";
index 5c11b36..1c192c3 100644 (file)
@@ -28,7 +28,9 @@ import java.net.URISyntaxException;
 
 import org.iotivity.base.OcException;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
@@ -47,6 +49,8 @@ import io.restassured.response.Response;
  * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
  * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
  */
+@Disabled
+@Ignore
 @RunWith(SpringJUnit4ClassRunner.class)
 public class AuthorizedUsingCloudTest extends BasicUserAction {
 
diff --git a/servers/api-integration-tests/src/test/java/com/samsung/ci/test/useractions/DeviceApiWithoutCloudTest.java b/servers/api-integration-tests/src/test/java/com/samsung/ci/test/useractions/DeviceApiWithoutCloudTest.java
new file mode 100644 (file)
index 0000000..17076d1
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * //******************************************************************
+ * //
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ * //
+ * // Licensed under the Apache License, Version 2.0 (the "License");
+ * // you may not use this file except in compliance with the License.
+ * // You may obtain a copy of the License at
+ * //
+ * //      http://www.apache.org/licenses/LICENSE-2.0
+ * //
+ * // Unless required by applicable law or agreed to in writing, software
+ * // distributed under the License is distributed on an "AS IS" BASIS,
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * // See the License for the specific language governing permissions and
+ * // limitations under the License.
+ * //
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+package com.samsung.ci.test.useractions;
+
+import com.google.gson.Gson;
+import com.samsung.ci.basic.api.MQPublisherAPI;
+import com.samsung.ci.basic.api.Rest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Map;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class DeviceApiWithoutCloudTest extends BasicUserAction {
+
+    private static final String DEVICE_DUID = "D-0000000-1111-2222-3333-4444444444444";
+    private static final String DEVICE_DUID2 = "D2-0000000-1111-2222-3333-4444444444444";
+    private static final String DEVICE_UNREGISTER_ACTION = "unregister";
+    private static final String DEVICE_NAME = "TV";
+    private static final String DEVICE_TYPE = "tv";
+    private static final String DEVICE_MODEL1 = "standard";
+    private static final String DEVICE_MODEL2 = "standard-new";
+    private static final String DEVICE_PARENT_DUID = "D-55555555-6666-7777-8888-999999999999";
+
+    @BeforeAll
+    public static void info() {
+        //@formatter:off
+        log("Positive case for DeviceApiWithoutCloudTest:\n" +
+                "1. Create new user \n" +
+                "2. Create IoTCloud User\n" +
+                "3. Register device\n" +
+                "4. checkfindByCloudUserUuidExceptModelStandard\n" +
+                "5. Unregister device\n" +
+                "6. Delete IoTCloud User\n");
+        //@formatter:on
+    }
+
+    private void registerDevices(String uuid) {
+        log("Device registration");
+        assertTrue(MQPublisherAPI
+                .deviceRegistrationInDSM(DEVICE_DUID, uuid, DEVICE_NAME, DEVICE_TYPE, DEVICE_MODEL1, DEVICE_PARENT_DUID));
+        assertTrue(MQPublisherAPI
+                .deviceRegistrationInDSM(DEVICE_DUID2, uuid, DEVICE_NAME, DEVICE_TYPE, DEVICE_MODEL2, DEVICE_PARENT_DUID));
+    }
+
+    private void unregisterDevices(String uuid) {
+        log("Device unregistration");
+        assertTrue(MQPublisherAPI.deviceUnRegistrationInDSM(DEVICE_DUID, DEVICE_UNREGISTER_ACTION));
+        assertTrue(MQPublisherAPI.deviceUnRegistrationInDSM(DEVICE_DUID2, DEVICE_UNREGISTER_ACTION));
+    }
+
+    private void checkfindByCloudUserUuidExceptModelStandard(String uuid) {
+        log("checkfindByCloudUserUuidExceptModelStandard");
+        Response resp = Rest.findDeviceByCloudUserUuidExceptModelStandard(uuid);
+        final int size = 1;
+        checkResponseSize(resp, size);
+    }
+
+    private void checkResponseSize(Response resp, int size) {
+        String response = resp.getBody().asString();
+        assertNotNull(response);
+        Gson gson = new Gson();
+        @SuppressWarnings("unchecked")
+        List<Map<String, String>> list = (List<Map<String, String>>) gson.fromJson(response, List.class);
+        assertTrue(list.size() == size);
+    }
+
+    @Test
+    public void testDeviceApiWithoutCloud() throws InterruptedException {
+        log("Create new user for testDeviceApiWithoutCloud scenario");
+        createNewUser();
+        String uuid = "iot-cloud-user-uuid";
+        createIoTUser(USER_EMAIL, uuid);
+
+        registerDevices(uuid);
+        Thread.sleep(TIMEOUT);
+
+        checkfindByCloudUserUuidExceptModelStandard(uuid);
+
+        unregisterDevices(uuid);
+        deleteIoTUser(uuid);
+    }
+
+}
index 0e25d29..4afa703 100644 (file)
@@ -2,7 +2,9 @@ package com.samsung.ci.test.useractions;
 
 import org.iotivity.base.OcException;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
 
 import java.net.URISyntaxException;
 
@@ -19,6 +21,8 @@ import java.net.URISyntaxException;
  * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
  * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
  */
+@Disabled
+@Ignore
 public class IotAliveStatusTest extends BasicUserAction {
 
     /**
index 897ed01..1c8b6a4 100644 (file)
@@ -1,5 +1,6 @@
 package com.samsung.dsm.rest;
 
+import static java.lang.String.format;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -257,4 +258,19 @@ public class DeviceApiTest {
     public void findPolicyByUuidNotFound() throws Exception {
         mockMvc.perform(get(ROOT_URL + "/device/1238/policy")).andExpect(status().isNotFound());
     }
+
+    /**
+     * Find by cloud user uuid except model standard.
+     *
+     * @throws Exception the exception
+     */
+    @Test
+    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
+    public void findByCloudUserUuidExceptModelStandard() throws Exception {
+        mockMvc
+                .perform(get(ROOT_URL
+                        + format("/device/1234/byCloudUserUuidNotStandard")))
+                .andExpect(status().isOk());
+    }
+
 }
\ No newline at end of file