summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/des/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'components/datalake-handler/des/src/test')
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java31
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java47
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java75
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java52
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java57
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java62
-rw-r--r--components/datalake-handler/des/src/test/java/org/onap/datalake/des/util/TestUtil.java50
-rw-r--r--components/datalake-handler/des/src/test/resources/application.properties50
8 files changed, 424 insertions, 0 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
new file mode 100644
index 00000000..eb2f57f7
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/ApplicationTest.java
@@ -0,0 +1,31 @@
+/*-
+ * ============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;
+
+import org.junit.Test;
+import org.onap.datalake.des.DesApplication;
+
+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
new file mode 100644
index 00000000..223fb3ce
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/DesSwaggerConfigTest.java
@@ -0,0 +1,47 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : DATALAKE
+* ================================================================================
+* Copyright 2020 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.des;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.datalake.des.DesSwaggerConfig;
+
+/**
+ * Test Swagger integration.
+ *
+ * @author Kai Lu
+ *
+ */
+
+public class DesSwaggerConfigTest {
+
+ @Test
+ public void test() {
+ try {
+ DesSwaggerConfig config = new DesSwaggerConfig();
+ config.desProduceApi();
+ } catch (Exception e) {
+ fail("failed to read configure Des Swagger.");
+ }
+ }
+
+} \ No newline at end of file
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
new file mode 100644
index 00000000..b3ff026d
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/controller/DataExposureControllerTest.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+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.
+ *
+ * @author Kai Lu
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class DataExposureControllerTest {
+
+ @Mock
+ private HttpServletResponse httpServletResponse;
+
+ @Mock
+ private DataExposureRepository dataExposureRepository;
+
+ @Mock
+ private BindingResult mockBindingResult;
+
+ @InjectMocks
+ private DataExposureService dataExposureService;
+
+ @Test(expected = NullPointerException.class)
+ public void testServe() throws IOException, NoSuchFieldException,
+ IllegalAccessException, ClassNotFoundException, SQLException {
+ DataExposureController dataExposureController = new DataExposureController();
+ String serviceId = "test";
+ Map<String, String> requestMap = new HashMap<String,String>();
+ requestMap.put("name", "oteNB5309");
+ 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/domain/DataExposureTest.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java
new file mode 100644
index 00000000..4b9bcb4f
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DataExposureTest.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2020 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.des.domain;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.datalake.des.dto.DataExposureConfig;
+import org.onap.datalake.des.util.TestUtil;
+
+/**
+ * Test Data Exposure.
+ *
+ * @author Kai Lu
+ */
+public class DataExposureTest {
+
+ @Test
+ public void test() {
+ DataExposure dataExposure = new DataExposure("1",
+ " select event.commonEventHeader.sourceName as name, "
+ + " event.perf3gppFields.measDataCollection.measuredEntityDn as entity "
+ + " from datalake where event.commonEventHeader.sourceName = '${name}' ");
+
+ Db mongoDb = TestUtil.newDb("MongoDB");
+ dataExposure.setDb(mongoDb);
+ dataExposure.setNote("testsql");
+ DataExposureConfig config = dataExposure.getDataExposureConfig();
+ assertNotNull(config.getId());
+ assertNotNull(config.getSqlTemplate());
+
+ }
+
+}
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
new file mode 100644
index 00000000..18cfa386
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTest.java
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2020 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.des.domain;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+
+import org.junit.Test;
+import org.onap.datalake.des.util.TestUtil;
+
+/**
+ * Test Db.
+ *
+ * @author Kai Lu
+ */
+
+public class DbTest {
+
+ @Test
+ public void testIs() {
+
+ Db couchbase = TestUtil.newDb("Couchbase");
+ Db mongoDb1 = TestUtil.newDb("MongoDB");
+ Db mongoDb2 = TestUtil.newDb("MongoDB");
+ assertNotEquals(couchbase.hashCode(), mongoDb1.hashCode());
+ assertNotEquals(couchbase, mongoDb1);
+ assertNotEquals(mongoDb1, mongoDb2);
+ assertEquals(mongoDb1, mongoDb1);
+ assertFalse(mongoDb2.equals(null));
+
+ DbType dbType = new DbType("MONGO", "MongoDB");
+ dbType.setTool(false);
+ mongoDb1.setDbType(dbType);
+
+ assertNotEquals(mongoDb2, dbType);
+ assertFalse(mongoDb1.getDbType().isTool());
+ }
+}
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
new file mode 100644
index 00000000..a94f0482
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/domain/DbTypeTest.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2020 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.des.domain;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test Data Type.
+ *
+ * @author Kai Lu
+ */
+public class DbTypeTest {
+
+ @Test
+ public void test() {
+ DbType dbType = new DbType("ES","Elasticsearch");
+
+ dbType.setTool(false);
+
+ assertNotNull(dbType.toString());
+ assertEquals(dbType, dbType);
+ assertNotEquals(dbType, null);
+ assertNotEquals(dbType, "ES");
+
+ DbType dbType2 = new DbType("MONGO", "MongoDB");
+ assertNotEquals(dbType, dbType2);
+ assertNotNull(dbType.hashCode());
+
+ assertEquals("MongoDB", dbType2.getName());
+ dbType2.setName(null);
+ dbType2.setDefaultPort(1);
+ assertTrue(1 == dbType2.getDefaultPort());
+
+ dbType2.setDbs(null);
+ assertNull(dbType2.getDbs());
+ }
+
+} \ No newline at end of file
diff --git a/components/datalake-handler/des/src/test/java/org/onap/datalake/des/util/TestUtil.java b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/util/TestUtil.java
new file mode 100644
index 00000000..8d3cf6c9
--- /dev/null
+++ b/components/datalake-handler/des/src/test/java/org/onap/datalake/des/util/TestUtil.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DCAE
+ * ================================================================================
+ * Copyright 2020 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.des.util;
+
+import org.onap.datalake.des.domain.Db;
+import org.onap.datalake.des.domain.DbType;
+
+
+/**
+ * test utils.
+ *
+ * @author Kai Lu
+ */
+public class TestUtil {
+
+ static int i = 0;
+
+ /**
+ * getDataExposureConfig.
+ *
+ * @param name name
+ * @return data exposure config
+ *
+ */
+ public static Db newDb(String name) {
+ Db db = new Db();
+ db.setId(i++);
+ db.setName(name);
+ db.setDbType(new DbType(name, name));
+ return db;
+ }
+}
diff --git a/components/datalake-handler/des/src/test/resources/application.properties b/components/datalake-handler/des/src/test/resources/application.properties
new file mode 100644
index 00000000..64ecdee9
--- /dev/null
+++ b/components/datalake-handler/des/src/test/resources/application.properties
@@ -0,0 +1,50 @@
+#####################App general
+server.port = 1680
+server.servlet.context-path = /datalake/v1
+
+#tolerate inconsistency when system crash, see PullThread.run()
+async=true
+
+#SSL global flag, if enabled, still need to check each individual DB SSL flag
+enableSSL=false
+
+#names for extra fields that DL adds to each record
+timestampLabel=datalake_ts_
+rawDataLabel=datalake_text_
+
+defaultTopicName=_DL_DEFAULT_
+
+
+#####################DMaaP
+#dmaapZookeeperHostPort=127.0.0.1:2181
+#dmaapKafkaHostPort=127.0.0.1:9092
+dmaapZookeeperHostPort=message-router-zookeeper:2181
+dmaapKafkaHostPort=message-router-kafka:9092
+dmaapKafkaGroup=dlgroup44
+#in second
+dmaapKafkaTimeout=60
+dmaapKafkaExclude[0]=__consumer_offsets
+dmaapKafkaExclude[1]=__transaction_state
+#dmaapKafkaExclude[2]=msgrtr.apinode.metrics.dmaap
+#check for new topics , in millisecond
+dmaapCheckNewTopicInterval=60000
+
+kafkaConsumerCount=3
+
+#####################Elasticsearch
+elasticsearchType=_doc
+
+#####################HDFS
+hdfsBufferSize=4096
+#how often we flush stall updates, in millisecond
+hdfsFlushInterval=30000
+hdfsBatchSize=500
+
+#####################Logging
+logging.level.org.springframework.web=ERROR
+logging.level.com.att.nsa.apiClient.http=ERROR
+logging.level.org.onap.datalake=DEBUG
+
+#####################Verison
+datalakeVersion=0.0.1
+