Initial source code
[oam/tr069-adapter.git] / factory / src / test / java / com / commscope / tr069adapter / imports / FactoryDataAccesorApplicationTests.java
diff --git a/factory/src/test/java/com/commscope/tr069adapter/imports/FactoryDataAccesorApplicationTests.java b/factory/src/test/java/com/commscope/tr069adapter/imports/FactoryDataAccesorApplicationTests.java
new file mode 100644 (file)
index 0000000..1584d7e
--- /dev/null
@@ -0,0 +1,103 @@
+/*\r
+ * ============LICENSE_START========================================================================\r
+ * ONAP : tr-069-adapter\r
+ * =================================================================================================\r
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
+ * =================================================================================================\r
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
+ * may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
+ * either express or implied. See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ===============LICENSE_END=======================================================================\r
+ */\r
+\r
+package com.commscope.tr069adapter.imports;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.jupiter.api.Assertions.fail;\r
+\r
+import org.commscope.tr069adapter.factory.FactoryDataAccesorApplication;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\r
+import org.springframework.boot.test.context.SpringBootTest;\r
+import org.springframework.http.MediaType;\r
+import org.springframework.test.context.junit4.SpringRunner;\r
+import org.springframework.test.web.servlet.MockMvc;\r
+import org.springframework.test.web.servlet.MvcResult;\r
+import org.springframework.test.web.servlet.RequestBuilder;\r
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;\r
+\r
+@RunWith(SpringRunner.class)\r
+@SpringBootTest(classes = {FactoryDataAccesorApplication.class})\r
+@AutoConfigureMockMvc\r
+public class FactoryDataAccesorApplicationTests {\r
+\r
+  private String exampleDeviceDataJson =\r
+      "{\"serialNumber\":\"0005B95196D0\",\"autenticationString\":\"abcxyz\",\"oui\":\"0005B9\",\"productClass\":\"LTE_Enterprise_C-RANSC_Cntrl\"}";\r
+\r
+  @Autowired\r
+  private MockMvc mockMvc;\r
+\r
+  @Test\r
+  public void basicAuthenticateTest() {\r
+\r
+    RequestBuilder requestBuilder =\r
+        MockMvcRequestBuilders.post("/basicAuthenticate").accept(MediaType.APPLICATION_JSON)\r
+            .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);\r
+\r
+    MvcResult result = null;\r
+    String resultString = null;\r
+    try {\r
+      result = mockMvc.perform(requestBuilder).andReturn();\r
+      resultString = result.getResponse().getContentAsString();\r
+    } catch (Exception e) {\r
+      fail(e.getMessage());\r
+    }\r
+\r
+    assertEquals("true", resultString);\r
+  }\r
+\r
+  @Test\r
+  public void digestAuthenticateDeviceTest() {\r
+\r
+    RequestBuilder requestBuilder =\r
+        MockMvcRequestBuilders.post("/digestAuthenticate").accept(MediaType.APPLICATION_JSON)\r
+            .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);\r
+\r
+    MvcResult result = null;\r
+    String resultString = null;\r
+    try {\r
+      result = mockMvc.perform(requestBuilder).andReturn();\r
+      resultString = result.getResponse().getContentAsString();\r
+    } catch (Exception e) {\r
+      fail(e.getMessage());\r
+    }\r
+\r
+    assertEquals("true", resultString);\r
+  }\r
+\r
+  @Test\r
+  public void validateDeviceOUIPCTest() {\r
+    RequestBuilder requestBuilder =\r
+        MockMvcRequestBuilders.post("/validateDevice").accept(MediaType.APPLICATION_JSON)\r
+            .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);\r
+\r
+    MvcResult result = null;\r
+    String resultString = null;\r
+    try {\r
+      result = mockMvc.perform(requestBuilder).andReturn();\r
+      resultString = result.getResponse().getContentAsString();\r
+    } catch (Exception e) {\r
+      fail(e.getMessage());\r
+    }\r
+\r
+    assertEquals("true", resultString);\r
+  }\r
+}\r