unit test coverage DbTypeTest and DbServiceTest and PortalDesignServiceTest 22/90822/1
authorzm330 <zhangminyj@chinamobile.com>
Wed, 3 Jul 2019 07:39:03 +0000 (15:39 +0800)
committerzm330 <zhangminyj@chinamobile.com>
Wed, 3 Jul 2019 07:39:11 +0000 (15:39 +0800)
Change-Id: I4981a90d0e3fa569c2259e54501df62c95cd8cf5
Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Issue-ID: DCAEGEN2-1468

components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DbTypeTest.java [new file with mode: 0644]
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DbServiceTest.java
components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PortalDesignServiceTest.java [new file with mode: 0644]

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 (file)
index 0000000..37c7796
--- /dev/null
@@ -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
index df972f5..6eda59a 100644 (file)
 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 (file)
index 0000000..b66c52d
--- /dev/null
@@ -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