summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder
diff options
context:
space:
mode:
authorzm330 <zhangminyj@chinamobile.com>2019-07-03 15:39:03 +0800
committerzm330 <zhangminyj@chinamobile.com>2019-07-03 15:39:11 +0800
commitb2420de5ee24b3e0d4142068278a593434989981 (patch)
tree7d08648bec69a3323c5c24087b3aa085460f669b /components/datalake-handler/feeder
parent773360d05595c3d1f8c5d55200f06b0e42e7dc3c (diff)
unit test coverage DbTypeTest and DbServiceTest and PortalDesignServiceTest
Change-Id: I4981a90d0e3fa569c2259e54501df62c95cd8cf5 Signed-off-by: zm330 <zhangminyj@chinamobile.com> Issue-ID: DCAEGEN2-1468
Diffstat (limited to 'components/datalake-handler/feeder')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java36
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DbServiceTest.java41
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java64
3 files changed, 137 insertions, 4 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java
new file mode 100644
index 00000000..37c77966
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * 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.feeder.domain;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class DbTypeTest {
+
+ @Test
+ public void test(){
+ DbType dbType = new DbType("123","Elasticsearch");
+ assertNotNull(dbType.toString());
+ assertEquals(dbType, dbType);
+ assertNotNull(dbType.hashCode());
+ }
+
+} \ No newline at end of file
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DbServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DbServiceTest.java
index df972f5f..6eda59a9 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DbServiceTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DbServiceTest.java
@@ -21,18 +21,22 @@
package org.onap.datalake.feeder.service;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.when;
-
-import java.util.Optional;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.datalake.feeder.domain.Db;
+import org.onap.datalake.feeder.domain.DbType;
import org.onap.datalake.feeder.repository.DbRepository;
+import org.onap.datalake.feeder.service.db.CouchbaseService;
+import org.onap.datalake.feeder.service.db.ElasticsearchService;
+import org.onap.datalake.feeder.service.db.HdfsService;
+import org.onap.datalake.feeder.service.db.MongodbService;
+import org.springframework.context.ApplicationContext;
+
/**
* Test Service for Dbs
@@ -44,6 +48,12 @@ import org.onap.datalake.feeder.repository.DbRepository;
public class DbServiceTest {
@Mock
+ private DbType dbType;
+
+ @Mock
+ private ApplicationContext context;
+
+ @Mock
private DbRepository dbRepository;
@InjectMocks
@@ -55,6 +65,29 @@ public class DbServiceTest {
//when(dbRepository.findByName(name)).thenReturn(new Db(name));
assertEquals("a", name);
}
+
+ @Test
+ public void testFindDbStoreService(){
+ when(dbType.getId()).thenReturn("CB","ES","HDFS","MONGO","KIBANA");
+
+ Db db = Mockito.mock(Db.class);
+ when(db.getId()).thenReturn(1,2,3,4,5,6,7,8,9);
+ when(db.getDbType()).thenReturn(dbType);
+
+ when(context.getBean(CouchbaseService.class, db)).thenReturn(new CouchbaseService(db));
+ when(context.getBean(ElasticsearchService.class, db)).thenReturn(new ElasticsearchService(db));
+ when(context.getBean(HdfsService.class, db)).thenReturn(new HdfsService(db));
+ when(context.getBean(MongodbService.class, db)).thenReturn(new MongodbService(db));
+
+ dbService.findDbStoreService(db);
+ dbService.findDbStoreService(db);
+ dbService.findDbStoreService(db);
+ dbService.findDbStoreService(db);
+ dbService.findDbStoreService(db);
+
+
+
+ }
/*
@Test
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java
new file mode 100644
index 00000000..b66c52df
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java
@@ -0,0 +1,64 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DCAE
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * 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.feeder.service;
+
+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.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.Db;
+import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.domain.Portal;
+import org.onap.datalake.feeder.domain.PortalDesign;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class PortalDesignServiceTest {
+
+ @Mock
+ private DesignType designType;
+
+ @Mock
+ private ApplicationConfiguration applicationConfiguration;
+
+ @InjectMocks
+ private PortalDesignService designService;
+
+ @Test(expected = RuntimeException.class)
+ public void testDeploy() {
+ when(designType.getId()).thenReturn("KIBANA_DB","ES_MAPPING");
+ PortalDesign portalDesign = new PortalDesign();
+ portalDesign.setDesignType(designType);
+ portalDesign.setBody("jsonString");
+
+ Portal portal = new Portal();
+ Db db = new Db();
+ db.setHost("localhost");
+ portal.setDb(db);
+ when(designType.getPortal()).thenReturn(portal);
+ when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn("/api/kibana/dashboards/import?exclude=index-pattern");
+ when(applicationConfiguration.getKibanaPort()).thenReturn(5601);
+ designService.deploy(portalDesign);
+ System.out.println();
+ }
+} \ No newline at end of file