diff options
Diffstat (limited to 'components/datalake-handler/des')
6 files changed, 525 insertions, 323 deletions
diff --git a/components/datalake-handler/des/pom.xml b/components/datalake-handler/des/pom.xml index 87ae9443..64d382f1 100644 --- a/components/datalake-handler/des/pom.xml +++ b/components/datalake-handler/des/pom.xml @@ -2,7 +2,8 @@ <!-- ~ ============LICENSE_START======================================================= ~ Copyright (c) 2020 China Mobile. All rights reserved. - ~ ================================================================================ + ~ Copyright (C) 2022 Wipro Limited. 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 @@ -15,313 +16,275 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. ~ ============LICENSE_END========================================================= - --> - +--> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onap.dcaegen2.services.components</groupId> - <artifactId>datalake-handler</artifactId> - <version>1.1.1-SNAPSHOT</version> - </parent> - - <artifactId>des</artifactId> - <packaging>jar</packaging> - <name>DataLake Extraction Service</name> - - <properties> - <swagger.version>2.9.2</swagger.version> - <dockerfile-maven.version>1.4.10</dockerfile-maven.version> - <docker.image.path>onap/org.onap.dcaegen2.services.datalake.exposure.service</docker.image.path> - <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> - </properties> - - <dependencies> - - <dependency> - <groupId>org.jdom</groupId> - <artifactId>jdom2</artifactId> - <version>2.0.6</version> - </dependency> - - <dependency> - <groupId>com.facebook.presto</groupId> - <artifactId>presto-jdbc</artifactId> - <version>0.240</version> - </dependency> - - <dependency> - <groupId>org.apache.hadoop</groupId> - <artifactId>hadoop-client</artifactId> - <version>${hadoop.version}</version> - </dependency> - - <dependency> - <groupId>org.postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>42.2.18</version> - </dependency> - - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <version>20190722</version> - </dependency> - - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <version>4.5.10</version> - </dependency> - - <dependency> - <groupId>org.apache.kafka</groupId> - <artifactId>kafka-clients</artifactId> - <version>2.3.1</version> - </dependency> - - <dependency> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.dcaegen2.services.components</groupId> + <artifactId>datalake-handler</artifactId> + <version>1.1.2-SNAPSHOT</version> + </parent> + <artifactId>des</artifactId> + <packaging>jar</packaging> + <name>DataLake Extraction Service</name> + <properties> + <swagger.version>2.9.2</swagger.version> + <dockerfile-maven.version>1.4.10</dockerfile-maven.version> + <docker.image.path>onap/org.onap.dcaegen2.services.datalake.exposure.service</docker.image.path> + <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format> + <onap-gerrit-review>-changelog-missing</onap-gerrit-review> + </properties> + <dependencies> + <dependency> + <groupId>org.jdom</groupId> + <artifactId>jdom2</artifactId> + <version>2.0.6</version> + </dependency> + <dependency> + <groupId>com.facebook.presto</groupId> + <artifactId>presto-jdbc</artifactId> + <version>0.240</version> + </dependency> + <dependency> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-client</artifactId> + <version>${hadoop.version}</version> + </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>42.2.18</version> + </dependency> + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20190722</version> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.5.10</version> + </dependency> + <dependency> + <groupId>org.apache.kafka</groupId> + <artifactId>kafka-clients</artifactId> + <version>2.3.1</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${springboot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + <version>${springboot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + <version>${springboot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-couchbase</artifactId> + <version>${springboot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <version>${springboot.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${springboot.version}</version> + </dependency> + <dependency> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> + <version>${elasticsearchjava.version}</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.6</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + <version>${jackson.version}</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-xml</artifactId> + <version>${jackson.version}</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>${jackson.version}</version> + </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.2</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.10</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>io.druid</groupId> + <artifactId>tranquility-core_2.11</artifactId> + <version>0.8.3</version> + </dependency> + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity-engine-core</artifactId> + <version>2.1</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>5.3.7.Final</version> + </dependency> + <!-- jsr303 validation --> + <dependency> + <groupId>javax.validation</groupId> + <artifactId>validation-api</artifactId> + <version>2.0.1.Final</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + <version>6.1.0.Final</version> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger2</artifactId> + <version>${swagger.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>io.springfox</groupId> + <artifactId>springfox-swagger-ui</artifactId> + <version>${swagger.version}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.mongodb</groupId> + <artifactId>mongo-java-driver</artifactId> + <version>${mongojava.version}</version> + </dependency> + <dependency> + <groupId>com.couchbase.mock</groupId> + <artifactId>CouchbaseMock</artifactId> + <version>1.5.22</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8</version> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <version>${springboot.version}</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - <version>${springboot.version}</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-jpa</artifactId> - <version>${springboot.version}</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-couchbase</artifactId> - <version>${springboot.version}</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <version>${springboot.version}</version> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-configuration-processor</artifactId> - <version>${springboot.version}</version> - </dependency> - - <dependency> - <groupId>org.elasticsearch.client</groupId> - <artifactId>elasticsearch-rest-high-level-client</artifactId> - <version>${elasticsearchjava.version}</version> - </dependency> - - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.6</version> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.dataformat</groupId> - <artifactId>jackson-dataformat-yaml</artifactId> - <version>${jackson.version}</version> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.dataformat</groupId> - <artifactId>jackson-dataformat-xml</artifactId> - <version>${jackson.version}</version> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - <version>${jackson.version}</version> - </dependency> - - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.2</version> - </dependency> - - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>1.18.10</version> - <scope>provided</scope> - </dependency> - - <dependency> - <groupId>io.druid</groupId> - <artifactId>tranquility-core_2.11</artifactId> - <version>0.8.3</version> - </dependency> - - <dependency> - <groupId>org.apache.velocity</groupId> - <artifactId>velocity-engine-core</artifactId> - <version>2.1</version> - </dependency> - - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <version>5.3.7.Final</version> - </dependency> - - <!-- jsr303 validation --> - <dependency> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - <version>2.0.1.Final</version> - </dependency> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator</artifactId> - <version>6.1.0.Final</version> - </dependency> - - <dependency> - <groupId>io.springfox</groupId> - <artifactId>springfox-swagger2</artifactId> - <version>${swagger.version}</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>io.springfox</groupId> - <artifactId>springfox-swagger-ui</artifactId> - <version>${swagger.version}</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>org.mongodb</groupId> - <artifactId>mongo-java-driver</artifactId> - <version>${mongojava.version}</version> - </dependency> - - <dependency> - <groupId>com.couchbase.mock</groupId> - <artifactId>CouchbaseMock</artifactId> - <version>1.5.22</version> - <scope>test</scope> - </dependency> - - </dependencies> - - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-deploy-plugin</artifactId> - <version>2.8</version> - <configuration> - <skip>true</skip> - </configuration> - </plugin> - - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <classifier>execute</classifier> - <executions> - <execution> - <goals> - <goal>repackage</goal> - </goals> - </execution> - </executions> - </configuration> - </plugin> - <plugin> - <groupId>com.spotify</groupId> - <artifactId>dockerfile-maven-plugin</artifactId> - <version>${dockerfile-maven.version}</version> - <configuration> - <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> - <tag>${project.version}</tag> - <dockerfile>Dockerfile</dockerfile> - <buildArgs> - <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> - </buildArgs> - </configuration> - <executions> - <execution> - <id>build-sl-des-image</id> - <phase>package</phase> - <goals> - <goal>build</goal> - </goals> - <configuration> - <useMavenSettingsForAuth>true</useMavenSettingsForAuth> - </configuration> - </execution> - <execution> - <id>tag-and-push-image-latest</id> - <phase>package</phase> - <goals> - <goal>tag</goal> - <goal>push</goal> - </goals> - <configuration> - <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> - <tag>latest</tag> - <useMavenSettingsForAuth>true</useMavenSettingsForAuth> - </configuration> - </execution> - <execution> - <id>tag-and-push-image-with-version</id> - <phase>package</phase> - <goals> - <goal>tag</goal> - <goal>push</goal> - </goals> - <configuration> - <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> - <tag>${project.version}</tag> - <useMavenSettingsForAuth>true</useMavenSettingsForAuth> - </configuration> - </execution> - <execution> - <id>tag-and-push-image-with-version-and-date</id> - <phase>package</phase> - <goals> - <goal>tag</goal> - <goal>push</goal> - </goals> - <configuration> - <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> - <tag>${project.version}-${maven.build.timestamp}Z</tag> - <useMavenSettingsForAuth>true</useMavenSettingsForAuth> - </configuration> - </execution> - </executions> - <dependencies> - <!-- To make this work on JDK 9+ --> - <dependency> - <groupId>javax.activation</groupId> - <artifactId>javax.activation-api</artifactId> - <version>1.2.0</version> - </dependency> - </dependencies> - </plugin> - </plugins> - </build> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <classifier>execute</classifier> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </configuration> + </plugin> + <plugin> + <groupId>com.spotify</groupId> + <artifactId>dockerfile-maven-plugin</artifactId> + <version>${dockerfile-maven.version}</version> + <configuration> + <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>${project.version}</tag> + <dockerfile>Dockerfile</dockerfile> + <buildArgs> + <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> + </buildArgs> + </configuration> + <executions> + <execution> + <id>build-sl-des-image</id> + <phase>package</phase> + <goals> + <goal>build</goal> + </goals> + <configuration> + <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> + </execution> + <execution> + <id>tag-and-push-image-latest</id> + <phase>package</phase> + <goals> + <goal>tag</goal> + <goal>push</goal> + </goals> + <configuration> + <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>latest</tag> + <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> + </execution> + <execution> + <id>tag-and-push-image-with-version</id> + <phase>package</phase> + <goals> + <goal>tag</goal> + <goal>push</goal> + </goals> + <configuration> + <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>${project.version}</tag> + <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> + </execution> + <execution> + <id>tag-and-push-image-with-version-and-date</id> + <phase>package</phase> + <goals> + <goal>tag</goal> + <goal>push</goal> + </goals> + <configuration> + <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <tag>${project.version}-${maven.build.timestamp}Z</tag> + <useMavenSettingsForAuth>true</useMavenSettingsForAuth> + </configuration> + </execution> + </executions> + <dependencies> + <!-- To make this work on JDK 9+ --> + <dependency> + <groupId>javax.activation</groupId> + <artifactId>javax.activation-api</artifactId> + <version>1.2.0</version> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> 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 4cadc31d..c4abac98 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 @@ -3,6 +3,7 @@ * ONAP : DATALAKE DES * ================================================================================ * Copyright (C) 2020 China Mobile. All rights reserved. + * Copyright (C) 2022 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,20 +22,28 @@ package org.onap.datalake.des.controller; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.io.IOException; import java.sql.SQLException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; 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.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.repository.DataExposureRepository; +import org.onap.datalake.des.service.DataExposureService; import org.springframework.validation.BindingResult; /** @@ -54,16 +63,157 @@ public class DataExposureControllerTest { @Mock private BindingResult mockBindingResult; + @Mock + private DataExposureService dataExposureService; + + @InjectMocks + private DataExposureController dataExposureController; + + /** + * Generate data exposure config. + * + * @return DataExposureConfig object + * + */ + public DataExposureConfig getDataExposureConfig() { + DataExposureConfig dataExposureConfig = new DataExposureConfig(); + dataExposureConfig.setDbId(1); + dataExposureConfig.setId("1"); + dataExposureConfig.setNote("note"); + dataExposureConfig.setSqlTemplate("sqlTemplate"); + return dataExposureConfig; + } + + /** + * Generate data exposure. + * + * @return DataExposure object + * + */ + public DataExposure getDataExposure() { + DbType dbType = new DbType("ES", "Elasticsearch"); + Db db = new Db(); + db.setId(1); + db.setDbType(dbType); + db.setDatabase("Elasticsearch"); + + DataExposure dataExposure = new DataExposure(); + dataExposure.setId("1"); + dataExposure.setNote("note"); + dataExposure.setSqlTemplate("sqlTemplate"); + dataExposure.setDb(db); + return dataExposure; + } + @Test(expected = NullPointerException.class) - public void testServe() - throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException { + public void testServeNull() + 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); } + + @Test(expected = SQLException.class) + public void testServeException() + throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, SQLException { + String serviceId = "test"; + Map < String, String > requestMap = new HashMap < String, String > (); + requestMap.put("name", "oteNB5309"); + + DataExposure dataExposure = getDataExposure(); + when(dataExposureService.getDataExposure(serviceId)).thenReturn(dataExposure); + dataExposureController.serve(serviceId, requestMap, mockBindingResult, + httpServletResponse); + } + + @Test + public void testQueryAllDataExposure() { + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + List < DataExposureConfig > dataExposureList = new ArrayList < > (); + dataExposureList.add(dataExposureConfig); + when(dataExposureService.queryAllDataExposure()).thenReturn(dataExposureList); + assertEquals(dataExposureList, dataExposureController.queryAllDataExposure()); + } + + @Test + public void TestQueryAllDataExposureByIdNull() throws IOException { + when(dataExposureService.getDataExposureById("1")).thenReturn(null); + assertEquals(null, dataExposureController.queryAllDataExposure("1", httpServletResponse)); + } + + @Test + public void TestQueryAllDataExposureById() throws IOException { + DataExposure dataExposure = getDataExposure(); + when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure); + dataExposureController.queryAllDataExposure("1", httpServletResponse); + } + + @Test + public void testCreateDataExposureNull() throws IOException { + DataExposure dataExposure = getDataExposure(); + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure); + assertEquals(null, dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse)); + } + + @Test + public void testCreateDataExposure() throws IOException { + DataExposure dataExposure = getDataExposure(); + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(dataExposureService.getDataExposureById("1")).thenReturn(null); + when(dataExposureService.fillDataExposureConfiguration(dataExposureConfig)).thenReturn(dataExposure); + dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse); + } + + @Test + public void testCreateDataExposureException() throws IOException { + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(dataExposureService.getDataExposureById("1")).thenReturn(null); + when(dataExposureService.fillDataExposureConfiguration(dataExposureConfig)).thenThrow(NullPointerException.class); + assertEquals(null, dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse)); + } + + @Test + public void testCreateDataExposureError() throws IOException { + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(mockBindingResult.hasErrors()).thenReturn(true); + assertEquals(null, dataExposureController.createDataExposure(dataExposureConfig, mockBindingResult, httpServletResponse)); + } + + @Test + public void testUpdateDataExposureNull() throws IOException { + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(dataExposureService.getDataExposureById("1")).thenReturn(null); + assertEquals(null, dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse)); + } + + @Test + public void testUpdateDataExposure() throws IOException { + DataExposure dataExposure = getDataExposure(); + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure); + dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse); + } + + @Test + public void testUpdateDataExposureException() throws IOException { + DataExposure dataExposure = getDataExposure(); + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(dataExposureService.getDataExposureById("1")).thenReturn(dataExposure); + doThrow(NullPointerException.class).when(dataExposureService).fillDataExposureConfiguration(dataExposureConfig, dataExposure); + assertEquals(null, dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse)); + } + + @Test + public void testUpdateDataExposureError() throws IOException { + DataExposureConfig dataExposureConfig = getDataExposureConfig(); + when(mockBindingResult.hasErrors()).thenReturn(true); + assertEquals(null, dataExposureController.updateDataExposure(dataExposureConfig, mockBindingResult, "1", httpServletResponse)); + } + } 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 cd5c6b4d..e6dba7f0 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 @@ -3,6 +3,7 @@ * ONAP : DataLake DES * ================================================================================ * Copyright 2020 China Mobile. All rights reserved. + * Copyright (C) 2022 Wipro Limited. *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +24,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.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -74,5 +76,7 @@ public class DbTest { assertTrue("property2".equals(mongoDb2.getProperty2())); assertTrue("property3".equals(mongoDb2.getProperty3())); assertEquals(mongoDb2.getDbConfig().getHost(), mongoDb2.getHost()); + assertNotNull(mongoDb1.toString()); } + } 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 4b83a03b..9f727c5c 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 @@ -3,6 +3,7 @@ * ONAP : DataLake DES * ================================================================================ * Copyright 2020 China Mobile. All rights reserved. + * Copyright (C) 2022 Wipro Limited. *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,16 +38,18 @@ public class DbTypeTest { @Test public void test() { - DbType dbType = new DbType("ES","Elasticsearch"); + DbType dbType = new DbType("ES", "Elasticsearch"); - dbType.setTool(false); + dbType.setTool(false); assertNotNull(dbType.toString()); assertEquals(dbType, dbType); assertNotEquals(dbType, null); assertNotEquals(dbType, "ES"); - DbType dbType2 = new DbType("MONGO", "MongoDB"); + DbType dbType2 = new DbType(); + dbType2.setId("MONGO"); + dbType2.setName("MongoDB"); assertNotEquals(dbType, dbType2); assertNotNull(dbType.hashCode()); @@ -59,4 +62,4 @@ public class DbTypeTest { assertNull(dbType2.getDbs()); } -}
\ No newline at end of file +} 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 index ee21f475..09f868f8 100644 --- 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 @@ -3,6 +3,7 @@ * ONAP : DATALAKE DES * ================================================================================ * Copyright (C) 2020 China Mobile. All rights reserved. + * Copyright (C) 2022 Wipro Limited. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,5 +54,7 @@ public class DbConfigTest { assertFalse("123".equals(dbConfig.getPort())); dbConfig.setPoperties("driver"); assertTrue("driver".equals(dbConfig.getPoperties())); + dbConfig.setDbTypeId("123"); + assertTrue("123".equals(dbConfig.getDbTypeId())); } } 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 index 254afcb5..9671a94b 100644 --- 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 @@ -3,6 +3,7 @@ * ONAP : DataLake DES * ================================================================================ * Copyright 2020 China Mobile. All rights reserved. + * Copyright (C) 2022 Wipro Limited. *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,9 @@ 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; @@ -40,7 +39,6 @@ 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. * @@ -100,6 +98,34 @@ public class DataExposureServiceTest { } @Test + public void testGetDataExposure() { + 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()); + + DataExposure de = new DataExposure(); + de.setId("1"); + de.setNote("note"); + de.setSqlTemplate("sqlTemplate"); + de.setDb(newdb); + when(dataExposureRepository.findById("1")).thenReturn(Optional.of(de)); + assertEquals(de, dataExposureService.getDataExposure("1")); + } + + @Test + public void testGetDataExposureNull() { + Optional < DataExposure > de = Optional.ofNullable(null); + when(dataExposureRepository.findById(null)).thenReturn(de); + assertEquals(dataExposureService.getDataExposure(null), null); + } + + @Test public void testQueryAllDataExposure() { Db newdb = new Db(); DbConfig dbConfig = getDbConfig(); @@ -110,20 +136,56 @@ public class DataExposureServiceTest { 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<>(); + List < DataExposure > deList = new ArrayList < > (); deList.add(de); when(dataExposureRepository.findAll()).thenReturn(deList); - List<DataExposureConfig> deConfigList = dataExposureService.queryAllDataExposure(); + List < DataExposureConfig > deConfigList = dataExposureService.queryAllDataExposure(); assertEquals(de.getId(), deConfigList.get(0).getId()); } @Test + public void testQueryAllDataExposureNull() { + List < DataExposure > deList = new ArrayList < > (); + when(dataExposureRepository.findAll()).thenReturn(deList); + assertEquals(dataExposureService.queryAllDataExposure(), deList); + } + + @Test + public void testGetDataExposureById() { + 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()); + + DataExposure de = new DataExposure(); + de.setId("1"); + de.setNote("note"); + de.setSqlTemplate("sqlTemplate"); + de.setDb(newdb); + when(dataExposureRepository.findById("1")).thenReturn(Optional.of(de)); + assertEquals(de, dataExposureService.getDataExposureById("1")); + } + + @Test + public void testGetDataExposureByIdNull() { + Optional < DataExposure > de = Optional.ofNullable(null); + when(dataExposureRepository.findById(null)).thenReturn(de); + assertEquals(dataExposureService.getDataExposureById(null), null); + } + + @Test public void testFillDataExposureConfiguration() { Db newdb = new Db(); DbConfig dbConfig = getDbConfig(); @@ -153,6 +215,7 @@ public class DataExposureServiceTest { 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()); @@ -161,4 +224,20 @@ public class DataExposureServiceTest { dataExposureService.fillDataExposureConfiguration(deConfig, de); } + @Test(expected = IllegalArgumentException.class) + public void testFillDataExposureException() { + DataExposureConfig deConfig = getDataExposureConfig(); + deConfig.setDbId(null); + dataExposureService.fillDataExposureConfiguration(deConfig); + } + + @Test(expected = IllegalArgumentException.class) + public void testFillDataExposureIllegalArgumentException() { + DataExposureConfig deConfig = getDataExposureConfig(); + deConfig.setDbId(1); + Optional < Db > dbOptional = Optional.ofNullable(null); + when(dbRepository.findById(deConfig.getDbId())).thenReturn(dbOptional); + dataExposureService.fillDataExposureConfiguration(deConfig); + } + } |