From b2420de5ee24b3e0d4142068278a593434989981 Mon Sep 17 00:00:00 2001 From: zm330 Date: Wed, 3 Jul 2019 15:39:03 +0800 Subject: unit test coverage DbTypeTest and DbServiceTest and PortalDesignServiceTest Change-Id: I4981a90d0e3fa569c2259e54501df62c95cd8cf5 Signed-off-by: zm330 Issue-ID: DCAEGEN2-1468 --- .../onap/datalake/feeder/domain/DbTypeTest.java | 36 ++++++++++++ .../datalake/feeder/service/DbServiceTest.java | 41 ++++++++++++-- .../feeder/service/PortalDesignServiceTest.java | 64 ++++++++++++++++++++++ 3 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java create mode 100644 components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java (limited to 'components/datalake-handler') 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 @@ -43,6 +47,12 @@ import org.onap.datalake.feeder.repository.DbRepository; @RunWith(MockitoJUnitRunner.class) public class DbServiceTest { + @Mock + private DbType dbType; + + @Mock + private ApplicationContext context; + @Mock private DbRepository dbRepository; @@ -54,6 +64,29 @@ public class DbServiceTest { String name = "a"; //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); + + + } /* 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 -- cgit 1.2.3-korg