summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Venkatesh Kumar <vv770d@att.com>2020-09-30 19:02:07 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-30 19:02:07 +0000
commitd75384b4c580f49981f5289665de9d5b6abda463 (patch)
tree3ade598a151e278640ffc459419c55a26d385218
parentbf08a843c270ade1ddb73c6515f8a8ec14ccb967 (diff)
parent52d24b3225dd1d8543337634146274feba70a1c9 (diff)
Merge "Extend DES UT"
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java10
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java4
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java18
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/PostReturnBodyTest.java43
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java4
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java25
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java4
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java57
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java164
9 files changed, 308 insertions, 21 deletions
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java
index eb2f57f7..6c3a963d 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java
@@ -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();
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java
index 223fb3ce..e38d79d8 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java
@@ -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/controller/DataExposureControllerTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
index b3ff026d..4cadc31d 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
@@ -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
index 00000000..4f9fcb6f
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/PostReturnBodyTest.java
@@ -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()));
+ }
+}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java
index 4b9bcb4f..2c54134b 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java
@@ -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/domain/DbTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
index 18cfa386..cd5c6b4d 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
@@ -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());
}
}
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
index a94f0482..4b83a03b 100644
--- a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
@@ -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
index 00000000..ee21f475
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/dto/DbConfigTest.java
@@ -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
index 00000000..254afcb5
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/service/DataExposureServiceTest.java
@@ -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);
+ }
+
+}