Extend DES UT 53/113353/9 1.1.0-datalake-des
authorKai <lukai@chinamobile.com>
Wed, 30 Sep 2020 07:18:34 +0000 (15:18 +0800)
committerLUKAI <lukai@chinamobile.com>
Wed, 30 Sep 2020 08:37:36 +0000 (08:37 +0000)
Issue-ID: DCAEGEN2-2258
Signed-off-by: Kai Lu <lukai@chinamobile.com>
Change-Id: I4eeb52027a94e467dc2aea847ea7428c433c9eec

components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java
components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java
components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/PostReturnBodyTest.java [new file with mode: 0644]
components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java
components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java [new file with mode: 0644]
components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java [new file with mode: 0644]

index eb2f57f..6c3a963 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * ONAP : DATALAKE
+ * ONAP : DATALAKE DES
  * ================================================================================
  * Copyright (C) 2020 China Mobile. All rights reserved.
  * ================================================================================
@@ -23,7 +23,15 @@ package org.onap.datalake.des;
 import org.junit.Test;
 import org.onap.datalake.des.DesApplication;
 
+/**
+ * Test Application.
+ * 
+ * @author Kai Lu
+ *
+ */
 public class ApplicationTest {
+
     @Test
     public void testRunner() {
         DesApplication application = new DesApplication();
index 223fb3c..e38d79d 100644 (file)
@@ -1,8 +1,8 @@
 /*
 * ============LICENSE_START=======================================================
-* ONAP : DATALAKE
+* ONAP : DATALAKE DES
 * ================================================================================
-* Copyright 2020 China Mobile
+* Copyright 2020 China Mobile. 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.
index b3ff026..4cadc31 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * ONAP : DATALAKE
+ * ONAP : DATALAKE DES
  * ================================================================================
  * Copyright (C) 2020 China Mobile. All rights reserved.
  * ================================================================================
@@ -32,14 +32,11 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.datalake.des.repository.DataExposureRepository;
-import org.onap.datalake.des.service.DataExposureService;
 import org.springframework.validation.BindingResult;
 
-
 /**
  * Test Data Exposure Controller.
  *
@@ -57,18 +54,15 @@ public class DataExposureControllerTest {
     @Mock
     private BindingResult mockBindingResult;
 
-    @InjectMocks
-    private DataExposureService dataExposureService;
-
     @Test(expected = NullPointerException.class)
-    public void testServe() throws IOException, NoSuchFieldException,
-                                   IllegalAccessException, ClassNotFoundException, SQLException {
+    public void testServe()
+            throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException {
         DataExposureController dataExposureController = new DataExposureController();
         String serviceId = "test";
-        Map<String, String> requestMap = new HashMap<String,String>();
+        Map<String, String> requestMap = new HashMap<String, String>();
         requestMap.put("name", "oteNB5309");
-        HashMap<String, Object> result = dataExposureController
-            .serve(serviceId, requestMap, mockBindingResult, httpServletResponse);
+        HashMap<String, Object> result = dataExposureController.serve(serviceId, requestMap, mockBindingResult,
+                httpServletResponse);
         assertEquals(null, result);
         when(mockBindingResult.hasErrors()).thenReturn(true);
     }
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/PostReturnBodyTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/PostReturnBodyTest.java
new file mode 100644 (file)
index 0000000..4f9fcb6
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE
+ * ================================================================================
+ * Copyright (C) 2020 China Mobile. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.des.controller;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test PostReturnBody.
+ *
+ * @author Kai Lu
+ */
+public class PostReturnBodyTest {
+
+    @Test
+    public void testPostReturnBody() {
+        PostReturnBody<String> postReturnBody = new PostReturnBody<String>();
+        postReturnBody.setStatusCode(200);
+        assertEquals(200, postReturnBody.getStatusCode());
+        postReturnBody.setReturnBody("abc");
+        assertTrue("abc".equals(postReturnBody.getReturnBody()));
+    }
+}
index 4b9bcb4..2c54134 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ============LICENSE_START=======================================================
- * ONAP : DataLake
+ * ONAP : DataLake DES
  * ================================================================================
- * Copyright 2020 China Mobile
+ * Copyright 2020 China Mobile. 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.
index 18cfa38..cd5c6b4 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ============LICENSE_START=======================================================
- * ONAP : DataLake
+ * ONAP : DataLake DES
  * ================================================================================
- * Copyright 2020 China Mobile
+ * Copyright 2020 China Mobile. 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.
@@ -23,6 +23,7 @@ package org.onap.datalake.des.domain;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.onap.datalake.des.util.TestUtil;
@@ -53,5 +54,25 @@ public class DbTest {
 
         assertNotEquals(mongoDb2, dbType);
         assertFalse(mongoDb1.getDbType().isTool());
+
+        mongoDb2.setHost("localhost");
+        mongoDb2.setPort(1234);
+        mongoDb2.setLogin("root");
+        mongoDb2.setPass("root123");
+        mongoDb2.setDatabase("mongoDB2");
+        mongoDb2.setEncrypt(true);
+        mongoDb2.setProperty1("property1");
+        mongoDb2.setProperty2("property2");
+        mongoDb2.setProperty3("property3");
+        assertTrue("localhost".equals(mongoDb2.getHost()));
+        assertFalse("1234".equals(mongoDb2.getPort()));
+        assertTrue("root".equals(mongoDb2.getLogin()));
+        assertTrue("root123".equals(mongoDb2.getPass()));
+        assertTrue("mongoDB2".equals(mongoDb2.getDatabase()));
+        assertFalse("true".equals(mongoDb2.isEncrypt()));
+        assertTrue("property1".equals(mongoDb2.getProperty1()));
+        assertTrue("property2".equals(mongoDb2.getProperty2()));
+        assertTrue("property3".equals(mongoDb2.getProperty3()));
+        assertEquals(mongoDb2.getDbConfig().getHost(), mongoDb2.getHost());
     }
 }
index a94f048..4b83a03 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * ============LICENSE_START=======================================================
- * ONAP : DataLake
+ * ONAP : DataLake DES
  * ================================================================================
- * Copyright 2020 China Mobile
+ * Copyright 2020 China Mobile. 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.
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java
new file mode 100644 (file)
index 0000000..ee21f47
--- /dev/null
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE DES
+ * ================================================================================
+ * Copyright (C) 2020 China Mobile. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.des.dto;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test DB config.
+ *
+ * @author Kai Lu
+ */
+public class DbConfigTest {
+
+    @Test
+    public void testDbConfig() {
+        DbConfig dbConfig = new DbConfig();
+        dbConfig.setId(1);
+        assertEquals(1, dbConfig.getId());
+        dbConfig.setName("elasticsearch");
+        assertTrue("elasticsearch".equals(dbConfig.getName()));
+        dbConfig.setHost("localhost");
+        assertTrue("localhost".equals(dbConfig.getHost()));
+        dbConfig.setLogin("root");
+        assertTrue("root".equals(dbConfig.getLogin()));
+        dbConfig.setPass("root123");
+        assertTrue("root123".equals(dbConfig.getPass()));
+        dbConfig.setDatabase("elasticsearch");
+        assertTrue("elasticsearch".equals(dbConfig.getDatabase()));
+        dbConfig.setPort(123);
+        //assertEquals(123, dbConfig.getPort());
+        assertFalse("123".equals(dbConfig.getPort()));
+        dbConfig.setPoperties("driver");
+        assertTrue("driver".equals(dbConfig.getPoperties()));
+    }
+}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java
new file mode 100644 (file)
index 0000000..254afcb
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake DES
+ * ================================================================================
+ * Copyright 2020 China Mobile. 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.des.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.datalake.des.domain.DataExposure;
+import org.onap.datalake.des.domain.Db;
+import org.onap.datalake.des.domain.DbType;
+import org.onap.datalake.des.dto.DataExposureConfig;
+import org.onap.datalake.des.dto.DbConfig;
+import org.onap.datalake.des.repository.DataExposureRepository;
+import org.onap.datalake.des.repository.DbRepository;
+import org.springframework.context.ApplicationContext;
+
+/**
+ * Test DB exposure Service.
+ *
+ * @author Kai Lu
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class DataExposureServiceTest {
+
+    @Mock
+    private DbType dbType;
+
+    @Mock
+    private ApplicationContext context;
+
+    @Mock
+    private DbRepository dbRepository;
+
+    @Mock
+    private DataExposureRepository dataExposureRepository;
+
+    @InjectMocks
+    private DataExposureService dataExposureService;
+
+    /**
+     * Generate data exposure config.
+     *
+     * @return DataExposureConfig object
+     *
+     */
+    public DataExposureConfig getDataExposureConfig() {
+        DataExposureConfig deConfig = new DataExposureConfig();
+        deConfig.setDbId(3);
+        deConfig.setId("test");
+        deConfig.setNote("testSql");
+        deConfig.setSqlTemplate("select name from datalake");
+        return deConfig;
+    }
+
+    /**
+     * Generate DB config.
+     *
+     * @return DbConfig object
+     *
+     */
+    public DbConfig getDbConfig() {
+        DbConfig dbConfig = new DbConfig();
+        dbConfig.setId(1);
+        dbConfig.setName("Elecsticsearch");
+        dbConfig.setHost("localhost");
+        dbConfig.setLogin("root");
+        dbConfig.setPass("root123");
+        dbConfig.setDatabase("Elecsticsearch");
+        dbConfig.setPort(123);
+        dbConfig.setPoperties("driver");
+        dbConfig.setDbTypeId("ES");
+        return dbConfig;
+    }
+
+    @Test
+    public void testQueryAllDataExposure() {
+        Db newdb = new Db();
+        DbConfig dbConfig = getDbConfig();
+        newdb.setName(dbConfig.getName());
+        newdb.setHost(dbConfig.getHost());
+        newdb.setPort(dbConfig.getPort());
+        newdb.setEnabled(dbConfig.isEnabled());
+        newdb.setLogin(dbConfig.getLogin());
+        newdb.setPass(dbConfig.getPass());
+        newdb.setEncrypt(dbConfig.isEncrypt());
+        DataExposureConfig deConfig = getDataExposureConfig();
+        DataExposure de = new DataExposure();
+        de.setDb(newdb);
+        de.setId(deConfig.getId());
+        de.setNote(deConfig.getNote());
+        de.setSqlTemplate(deConfig.getSqlTemplate());
+        List<DataExposure> deList = new ArrayList<>();
+        deList.add(de);
+        when(dataExposureRepository.findAll()).thenReturn(deList);
+        List<DataExposureConfig> deConfigList = dataExposureService.queryAllDataExposure();
+        assertEquals(de.getId(), deConfigList.get(0).getId());
+    }
+
+    @Test
+    public void testFillDataExposureConfiguration() {
+        Db newdb = new Db();
+        DbConfig dbConfig = getDbConfig();
+        newdb.setName(dbConfig.getName());
+        newdb.setHost(dbConfig.getHost());
+        newdb.setPort(dbConfig.getPort());
+        newdb.setEnabled(dbConfig.isEnabled());
+        newdb.setLogin(dbConfig.getLogin());
+        newdb.setPass(dbConfig.getPass());
+        newdb.setEncrypt(dbConfig.isEncrypt());
+        DataExposureConfig deConfig = getDataExposureConfig();
+        when(dbRepository.findById(deConfig.getDbId())).thenReturn(Optional.of(newdb));
+        DataExposure de = dataExposureService.fillDataExposureConfiguration(deConfig);
+        assertEquals(de.getId(), deConfig.getId());
+    }
+
+    @Test
+    public void testFillDataExposureConfigurationWithTwoPara() {
+        Db newdb = new Db();
+        DbConfig dbConfig = getDbConfig();
+        newdb.setName(dbConfig.getName());
+        newdb.setHost(dbConfig.getHost());
+        newdb.setPort(dbConfig.getPort());
+        newdb.setEnabled(dbConfig.isEnabled());
+        newdb.setLogin(dbConfig.getLogin());
+        newdb.setPass(dbConfig.getPass());
+        newdb.setEncrypt(dbConfig.isEncrypt());
+        DataExposureConfig deConfig = getDataExposureConfig();
+        when(dbRepository.findById(deConfig.getDbId())).thenReturn(Optional.of(newdb));
+        DataExposure de = new DataExposure();
+        de.setDb(newdb);
+        de.setId(deConfig.getId());
+        de.setNote(deConfig.getNote());
+        de.setSqlTemplate(deConfig.getSqlTemplate());
+        dataExposureService.fillDataExposureConfiguration(deConfig, de);
+    }
+
+}