diff options
Diffstat (limited to 'components')
34 files changed, 2413 insertions, 1509 deletions
diff --git a/components/datalake-handler/Changelog.md b/components/datalake-handler/Changelog.md index b020ac5f..247d41e1 100644 --- a/components/datalake-handler/Changelog.md +++ b/components/datalake-handler/Changelog.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.1.2] +### Changed +* CodeCoverage improvement for dcaegen2-services-data-handler (DCAEGEN2-3161) + ## [1.1.1] 2022-09-14 * DCAEGEN2-3004 - Fix DL-Admin Docker docker build issue diff --git a/components/datalake-handler/admin/pom.xml b/components/datalake-handler/admin/pom.xml index 62b574f2..305579d5 100644 --- a/components/datalake-handler/admin/pom.xml +++ b/components/datalake-handler/admin/pom.xml @@ -3,6 +3,7 @@ ============LICENSE_START======================================================= Copyright (c) 2019 QCT. All rights reserved. Copyright (c) 2022 AT&T. 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 @@ -21,7 +22,7 @@ <parent> <groupId>org.onap.dcaegen2.services.components</groupId> <artifactId>datalake-handler</artifactId> - <version>1.1.1-SNAPSHOT</version> + <version>1.1.2-SNAPSHOT</version> </parent> <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> diff --git a/components/datalake-handler/admin/src/package.json b/components/datalake-handler/admin/src/package.json index a3803f37..30b9d88c 100644 --- a/components/datalake-handler/admin/src/package.json +++ b/components/datalake-handler/admin/src/package.json @@ -1,6 +1,6 @@ { "name": "DataLake-AdminUI", - "version": "1.1.1", + "version": "1.1.2", "scripts": { "ng": "ng", "start": "ng serve --host='0.0.0.0' --proxy-config proxy.conf.json", diff --git a/components/datalake-handler/collector/pom.xml b/components/datalake-handler/collector/pom.xml deleted file mode 100644 index a3eeff15..00000000 --- a/components/datalake-handler/collector/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<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> - - <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> - <artifactId>collector</artifactId> - <packaging>pom</packaging> - <name>DataLake Collector</name> - - - -</project> 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); + } + } diff --git a/components/datalake-handler/feeder/pom.xml b/components/datalake-handler/feeder/pom.xml index 49ad6094..312e8dcc 100644 --- a/components/datalake-handler/feeder/pom.xml +++ b/components/datalake-handler/feeder/pom.xml @@ -1,299 +1,319 @@ <?xml version="1.0" encoding="UTF-8"?> -<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> - - <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> - <artifactId>feeder</artifactId> - <packaging>jar</packaging> - <name>DataLake Feeder</name> - - <properties> - <swagger.version>2.9.2</swagger.version> - <dockerfile-maven.version>1.4.5</dockerfile-maven.version> - <docker.image.path>onap/org.onap.dcaegen2.services.datalakefeeder</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.229</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> +<!-- + ~ ============LICENSE_START======================================================= + ~ Copyright (C) 2018-2019 Huawei. All rights reserved. + ~ Copyright 2018 TechMahindra. All rights reserved. + ~ Copyright (C) 2019 QCT. All rights reserved. + ~ Copyright (c) 2019-2020 China Mobile. All rights reserved. + ~ Copyright (C) 2021-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 + ~ + ~ 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========================================================= +--> +<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.2-SNAPSHOT</version> + </parent> + + <groupId>org.onap.dcaegen2.services.components.datalake-handler</groupId> + <artifactId>feeder</artifactId> + <packaging>jar</packaging> + <name>DataLake Feeder</name> + + <properties> + <swagger.version>2.9.2</swagger.version> + <dockerfile-maven.version>1.4.5</dockerfile-maven.version> + <docker.image.path>onap/org.onap.dcaegen2.services.datalakefeeder</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.229</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.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <classifier>exec</classifier> + </configuration> + </plugin> + <plugin> + <groupId>com.spotify</groupId> + <artifactId>dockerfile-maven-plugin</artifactId> + <version>${dockerfile-maven.version}</version> + <configuration> + <!-- <username>docker</username> <password>docker</password> --> + <!-- repository>repo.treescale.com/moguobiao/datalake-feeder-maven</repository --> + <!-- repository>moguobiao/datalake-feeder-maven-spotify</repository --> + <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> + <!-- <repository>mizunoami123/dl-feeder</repository> --> + <tag>${project.version}</tag> + <dockerfile>Dockerfile</dockerfile> + <!-- useMavenSettingsForAuth>true</useMavenSettingsForAuth --> + <buildArgs> + <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> + </buildArgs> + </configuration> + <executions> + <execution> + <id>build-sl-feeder-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> - - <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.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <classifier>exec</classifier> - </configuration> - </plugin> - <plugin> - <groupId>com.spotify</groupId> - <artifactId>dockerfile-maven-plugin</artifactId> - <version>${dockerfile-maven.version}</version> - <configuration> - <!-- - <username>docker</username> - <password>docker</password> --> - <!-- repository>repo.treescale.com/moguobiao/datalake-feeder-maven</repository --> - <!-- repository>moguobiao/datalake-feeder-maven-spotify</repository --> - <repository>${onap.nexus.dockerregistry.daily}/${docker.image.path}</repository> - <!-- <repository>mizunoami123/dl-feeder</repository> --> - <tag>${project.version}</tag> - <dockerfile>Dockerfile</dockerfile> - <!-- useMavenSettingsForAuth>true</useMavenSettingsForAuth --> - <buildArgs> - <JAR_FILE>${project.build.finalName}.jar</JAR_FILE> - </buildArgs> - </configuration> - <executions> - <execution> - <id>build-sl-feeder-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> + </dependencies> + </plugin> + </plugins> + </build> </project> diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java index 2e959fa2..0e617f5e 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/KafkaService.java @@ -3,6 +3,7 @@ * ONAP : DataLake * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -20,14 +21,15 @@ package org.onap.datalake.feeder.service; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import org.onap.datalake.feeder.domain.Kafka; import org.onap.datalake.feeder.dto.KafkaConfig; import org.onap.datalake.feeder.repository.KafkaRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.*; - /** * Service for kafkas * @@ -41,15 +43,15 @@ public class KafkaService { public Kafka getKafkaById(int id) { - Optional<Kafka> ret = kafkaRepository.findById(id); + Optional < Kafka > ret = kafkaRepository.findById(id); return ret.isPresent() ? ret.get() : null; } - public List<KafkaConfig> getAllKafka() { + public List < KafkaConfig > getAllKafka() { - List<KafkaConfig> kafkaConfigList = new ArrayList<>(); - Iterable<Kafka> kafkaIterable = kafkaRepository.findAll(); - for(Kafka portal : kafkaIterable) { + List < KafkaConfig > kafkaConfigList = new ArrayList < > (); + Iterable < Kafka > kafkaIterable = kafkaRepository.findAll(); + for (Kafka portal: kafkaIterable) { kafkaConfigList.add(portal.getKafkaConfig()); } return kafkaConfigList; diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java index 9318ee00..889821a6 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright (C) 2018-2019 Huawei. 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. @@ -29,9 +30,13 @@ import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.controller.domain.PostReturnBody; import org.onap.datalake.feeder.domain.Db; +import org.onap.datalake.feeder.domain.DbType; +import org.onap.datalake.feeder.domain.DesignType; import org.onap.datalake.feeder.domain.Topic; import org.onap.datalake.feeder.dto.DbConfig; import org.onap.datalake.feeder.repository.DbRepository; +import org.onap.datalake.feeder.repository.DbTypeRepository; +import org.onap.datalake.feeder.repository.DesignTypeRepository; import org.onap.datalake.feeder.service.DbService; import org.onap.datalake.feeder.util.TestUtil; import org.springframework.validation.BindingResult; @@ -62,11 +67,20 @@ public class DbControllerTest { private DbRepository dbRepository; @Mock + private DbTypeRepository dbTypeRepository; + + @Mock + private DesignTypeRepository designTypeRepository; + + @Mock private BindingResult mockBindingResult; @InjectMocks private DbService dbService1; - + + @InjectMocks + private DbController dbController; + public DbConfig getDbConfig() { DbConfig dbConfig = new DbConfig(); dbConfig.setId(1); @@ -77,16 +91,16 @@ public class DbControllerTest { dbConfig.setDatabase("Elecsticsearch"); dbConfig.setPort(123); dbConfig.setPoperties("driver"); - dbConfig.setDbTypeId("ES"); + dbConfig.setDbTypeId("ES"); return dbConfig; } public void setAccessPrivateFields(DbController dbController) throws NoSuchFieldException, - IllegalAccessException { - Field dbRepository1 = dbController.getClass().getDeclaredField("dbRepository"); - dbRepository1.setAccessible(true); - dbRepository1.set(dbController, dbRepository); - } + IllegalAccessException { + Field dbRepository1 = dbController.getClass().getDeclaredField("dbRepository"); + dbRepository1.setAccessible(true); + dbRepository1.set(dbController, dbRepository); + } @Before public void setupTest() { @@ -101,7 +115,7 @@ public class DbControllerTest { DbController dbController = new DbController(); DbConfig dbConfig = getDbConfig(); setAccessPrivateFields(dbController); - PostReturnBody<DbConfig> db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); + PostReturnBody < DbConfig > db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); assertEquals(200, db.getStatusCode()); when(mockBindingResult.hasErrors()).thenReturn(true); db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); @@ -113,8 +127,8 @@ public class DbControllerTest { DbController dbController = new DbController(); DbConfig dbConfig = getDbConfig(); when(mockBindingResult.hasErrors()).thenReturn(true); - PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult, - httpServletResponse); + PostReturnBody < DbConfig > db = dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult, + httpServletResponse); assertEquals(null, db); //when(mockBindingResult.hasErrors()).thenReturn(false); setAccessPrivateFields(dbController); @@ -135,12 +149,12 @@ public class DbControllerTest { DbController dbController = new DbController(); String name = "Elecsticsearch"; int testId = 1234; - List<Db> dbs = new ArrayList<>(); + List < Db > dbs = new ArrayList < > (); dbs.add(TestUtil.newDb(name)); setAccessPrivateFields(dbController); when(dbRepository.findAll()).thenReturn(dbs); - List<Integer> list = dbController.list(); - for (int id : list) { + List < Integer > list = dbController.list(); + for (int id: list) { assertNotEquals(1234, id); } //dbController.deleteDb("Elecsticsearch", httpServletResponse); @@ -155,18 +169,18 @@ public class DbControllerTest { Topic topic = TestUtil.newTopic(topicName); topic.setEnabled(true); topic.setId(1); - Set<Topic> topics = new HashSet<>(); + Set < Topic > topics = new HashSet < > (); topics.add(topic); Db db1 = TestUtil.newDb(dbName); db1.setTopics(topics); setAccessPrivateFields(dbController); - Set<Topic> elecsticsearch = dbController.getDbTopics(dbName, httpServletResponse); + Set < Topic > elecsticsearch = dbController.getDbTopics(dbName, httpServletResponse); assertEquals(Collections.emptySet(), elecsticsearch); when(dbRepository.findByName(dbName)).thenReturn(db1); elecsticsearch = dbController.getDbTopics(dbName, httpServletResponse); - for (Topic anElecsticsearch : elecsticsearch) { - Topic tmp = TestUtil.newTopic(topicName); - tmp.setId(2); + for (Topic anElecsticsearch: elecsticsearch) { + Topic tmp = TestUtil.newTopic(topicName); + tmp.setId(2); assertNotEquals(tmp, anElecsticsearch); } //dbController.deleteDb(dbName, httpServletResponse); @@ -177,7 +191,7 @@ public class DbControllerTest { DbController dbController = new DbController(); DbConfig dbConfig = getDbConfig(); setAccessPrivateFields(dbController); - PostReturnBody<DbConfig> db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); + PostReturnBody < DbConfig > db = dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); assertNotNull(db); } @@ -185,8 +199,102 @@ public class DbControllerTest { public void testVerifyConnection() throws IOException { DbController dbController = new DbController(); DbConfig dbConfig = getDbConfig(); - PostReturnBody<DbConfig> dbConfigPostReturnBody = dbController.verifyDbConnection(dbConfig, httpServletResponse); + PostReturnBody < DbConfig > dbConfigPostReturnBody = dbController.verifyDbConnection(dbConfig, httpServletResponse); assertEquals(null, dbConfigPostReturnBody); } + @Test + public void testDeleteDbNull() throws IOException { + Optional < Db > dbOptional = Optional.ofNullable(null); + when(dbRepository.findById(1)).thenReturn(dbOptional); + dbController.deleteDb(1, httpServletResponse); + } + + @Test + public void deleteDbTest() throws IOException { + Db db = TestUtil.newDb("Elecsticsearch"); + Topic topic = TestUtil.newTopic("Elecsticsearch"); + topic.setEnabled(true); + topic.setId(1); + Set < Topic > topics = new HashSet < > (); + topics.add(topic); + db.setTopics(topics); + Optional < Db > dbOptional = Optional.ofNullable(db); + when(dbRepository.findById(1)).thenReturn(dbOptional); + dbController.deleteDb(1, httpServletResponse); + } + + @Test + public void testUpdateDbNull() throws IOException { + DbConfig dbConfig = getDbConfig(); + Db db = TestUtil.newDb("Elecsticsearch"); + Optional < Db > dbOptional = Optional.ofNullable(db); + when(dbRepository.findById(dbConfig.getId())).thenReturn(dbOptional); + dbController.updateDb(dbConfig.getId(), dbConfig, mockBindingResult, httpServletResponse); + } + + @Test + public void testDblistByTool() { + List < DbType > dbTypeList = new ArrayList < > (); + DbType dbType = new DbType("ES", "Elasticsearch"); + Set < Db > dbs = new HashSet < > (); + dbs.add(TestUtil.newDb("MongoDB")); + dbType.setDbs(dbs); + dbTypeList.add(dbType); + when(dbTypeRepository.findByTool(false)).thenReturn(dbTypeList); + dbController.dblistByTool(true); + } + + @Test + public void testListIdAndName() { + DesignType designType = new DesignType(); + DbType dbType = new DbType("ES", "Elasticsearch"); + Set < Db > dbs = new HashSet < > (); + dbs.add(TestUtil.newDb("MongoDB")); + dbType.setDbs(dbs); + designType.setName("Kibana"); + designType.setDbType(dbType); + when(designTypeRepository.findById("1")).thenReturn(Optional.of(designType)); + dbController.listIdAndName("1"); + } + + @Test + public void testCreateDbError() throws IOException { + when(mockBindingResult.hasErrors()).thenReturn(true); + assertEquals(null, dbController.createDb(getDbConfig(), mockBindingResult, httpServletResponse)); + } + + @Test(expected = NullPointerException.class) + public void testCreateDbException() throws IOException { + DbConfig dbConfig = getDbConfig(); + dbConfig.setDbTypeId(""); + dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); + } + + @Test + public void createDbTest() throws IOException { + DbConfig dbConfig = getDbConfig(); + DbType dbType = new DbType("ES", "Elasticsearch"); + when(dbTypeRepository.findById(dbConfig.getDbTypeId())).thenReturn(Optional.of(dbType)); + dbController.createDb(dbConfig, mockBindingResult, httpServletResponse); + } + + @Test + public void testGetDb() throws IOException { + DbConfig elecsticsearch = dbController.getDb(1, httpServletResponse); + assertEquals(null, elecsticsearch); + } + + @Test + public void testGetDbTypes() throws IOException { + List < DbType > dbTypeList = new ArrayList < > (); + DbType dbType = new DbType("ES", "Elasticsearch"); + Set < Db > dbs = new HashSet < > (); + dbs.add(TestUtil.newDb("MongoDB")); + dbType.setDbs(dbs); + dbTypeList.add(dbType); + when(dbTypeRepository.findAll()).thenReturn(dbTypeList); + dbController.getDbTypes(httpServletResponse); + } + } diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java index 4b933bee..ca670998 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignControllerTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -29,10 +30,12 @@ import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; import org.onap.datalake.feeder.controller.domain.PostReturnBody; -import org.onap.datalake.feeder.domain.*; import org.onap.datalake.feeder.domain.Design; +import org.onap.datalake.feeder.domain.DesignType; +import org.onap.datalake.feeder.domain.TopicName; import org.onap.datalake.feeder.dto.DesignConfig; import org.onap.datalake.feeder.repository.DesignTypeRepository; +import org.onap.datalake.feeder.repository.TopicNameRepository; import org.onap.datalake.feeder.repository.DesignRepository; import org.onap.datalake.feeder.service.DesignService; import org.onap.datalake.feeder.service.TopicService; @@ -46,12 +49,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class DesignControllerTest { - + //static String Kibana_Dashboard_Import_Api = "/api/kibana/dashboards/import?exclude=index-pattern"; @Mock @@ -72,9 +77,14 @@ public class DesignControllerTest { @Mock private DesignTypeRepository designTypeRepository; - @InjectMocks + @Mock + private TopicNameRepository topicNameRepository; + + @Mock private DesignService designService; + @InjectMocks + private DesignController testDesignController; @Before public void setupTest() { @@ -85,40 +95,82 @@ public class DesignControllerTest { @Test public void testCreateDesign() throws NoSuchFieldException, IllegalAccessException, IOException { - DesignController testDesignController = new DesignController(); - setAccessPrivateFields(testDesignController); Design testDesign = fillDomain(); + DesignConfig designConfig = new DesignConfig(); + when(designService.fillDesignConfiguration(designConfig)).thenReturn(testDesign); + testDesignController.createDesign(designConfig, mockBindingResult, httpServletResponse); + } + + @Test + public void testCreateDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException { + + DesignConfig designConfig = new DesignConfig(); + when(designService.fillDesignConfiguration(designConfig)).thenThrow(NullPointerException.class); + testDesignController.createDesign(designConfig, mockBindingResult, httpServletResponse); + } + + @Test + public void testCreateDesignError() throws NoSuchFieldException, IllegalAccessException, IOException { + + DesignConfig designConfig = new DesignConfig(); + when(mockBindingResult.hasErrors()).thenReturn(true); + assertEquals(null, testDesignController.createDesign(designConfig, mockBindingResult, httpServletResponse)); + } + + @Test + public void testUpdateDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException { + + Design testDesign = fillDomain(); + Integer id = 1; //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT")); -// when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType())); - PostReturnBody<DesignConfig> postPortal = testDesignController.createDesign(testDesign.getDesignConfig(), mockBindingResult, httpServletResponse); + // when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType())); + PostReturnBody < DesignConfig > postPortal = testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse); //assertEquals(postPortal.getStatusCode(), 200); assertNull(postPortal); } @Test + public void testUpdateDesignError() throws NoSuchFieldException, IllegalAccessException, IOException { + Design testDesign = fillDomain(); + Integer id = 1; + when(mockBindingResult.hasErrors()).thenReturn(true); + assertEquals(null, testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse)); + } + + @Test public void testUpdateDesign() throws NoSuchFieldException, IllegalAccessException, IOException { + Design testDesign = fillDomain(); + Integer id = 1; + when(designService.getDesign(id)).thenReturn(testDesign); + testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse); + } - DesignController testDesignController = new DesignController(); - setAccessPrivateFields(testDesignController); + @Test + public void testUpdateDesignException() throws NoSuchFieldException, IllegalAccessException, IOException { Design testDesign = fillDomain(); + DesignConfig designConfig = new DesignConfig(); Integer id = 1; - when(designRepository.findById(id)).thenReturn((Optional.of(testDesign))); - //when(topicService.getTopic(0)).thenReturn(new Topic("unauthenticated.SEC_FAULT_OUTPUT")); - // when(designTypeRepository.findById("Kibana Dashboard")).thenReturn(Optional.of(testDesign.getDesignType())); - PostReturnBody<DesignConfig> postPortal = testDesignController.updateDesign(testDesign.getDesignConfig(), mockBindingResult, id, httpServletResponse); - //assertEquals(postPortal.getStatusCode(), 200); - assertNull(postPortal); + when(designService.getDesign(id)).thenReturn(testDesign); + doThrow(NullPointerException.class).when(designService).fillDesignConfiguration(designConfig, testDesign); + testDesignController.updateDesign(designConfig, mockBindingResult, id, httpServletResponse); + } + + @Test + public void testDeleteDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException { + + Design testDesign = fillDomain(); + Integer id = 1; + testDesign.setId(1); + testDesignController.deleteDesign(id, httpServletResponse); } @Test public void testDeleteDesign() throws NoSuchFieldException, IllegalAccessException, IOException { - DesignController testDesignController = new DesignController(); - setAccessPrivateFields(testDesignController); Design testDesign = fillDomain(); Integer id = 1; testDesign.setId(1); - when(designRepository.findById(id)).thenReturn((Optional.of(testDesign))); + when(designService.getDesign(id)).thenReturn(testDesign); testDesignController.deleteDesign(id, httpServletResponse); } @@ -128,22 +180,27 @@ public class DesignControllerTest { DesignController testDesignController = new DesignController(); setAccessPrivateFields(testDesignController); Design testDesign = fillDomain(); - List<Design> designList = new ArrayList<>(); + List < Design > designList = new ArrayList < > (); designList.add(testDesign); - when(designRepository.findAll()).thenReturn(designList); - assertEquals(1, testDesignController.queryAllDesign().size()); + assertEquals(0, testDesignController.queryAllDesign().size()); + } + + @Test + public void testDeployDesignNull() throws NoSuchFieldException, IllegalAccessException, IOException { + + Design testDesign = fillDomain(); + Integer id = 1; + testDesign.setId(1); + testDesignController.deployDesign(id, httpServletResponse); } - @Test(expected = NullPointerException.class) + @Test public void testDeployDesign() throws NoSuchFieldException, IllegalAccessException, IOException { - DesignController testDesignController = new DesignController(); - setAccessPrivateFields(testDesignController); Design testDesign = fillDomain(); Integer id = 1; testDesign.setId(1); - //when(applicationConfiguration.getKibanaDashboardImportApi()).thenReturn(Kibana_Dashboard_Import_Api); - when(designRepository.findById(id)).thenReturn((Optional.of(testDesign))); + when(designRepository.findById(id)).thenReturn(Optional.of(new Design())); testDesignController.deployDesign(id, httpServletResponse); } @@ -158,16 +215,18 @@ public class DesignControllerTest { } - public Design fillDomain(){ + public Design fillDomain() { Design design = new Design(); + design.setId(1); design.setName("Kibana"); design.setBody("jsonString"); design.setSubmitted(false); design.setNote("test"); DesignType designType = new DesignType(); + designType.setId("1"); designType.setName("Kibana Dashboard"); design.setDesignType(designType); design.setTopicName(new TopicName("unauthenticated.SEC_FAULT_OUTPUT")); return design; } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java index 91af11ca..531b0b28 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DesignTypeControllerTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -24,50 +25,51 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.domain.DesignType; +import org.onap.datalake.feeder.dto.DesignTypeConfig; +import org.onap.datalake.feeder.repository.DesignTypeRepository; import org.onap.datalake.feeder.service.DesignTypeService; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class DesignTypeControllerTest { - @InjectMocks + @Mock + private DesignTypeRepository designTypeRepository; + + @Mock private DesignTypeService designTypeService; + @InjectMocks + private DesignTypeController designTypeController; + @Before public void setupTest() { MockitoAnnotations.initMocks(this); } - @Test(expected = NullPointerException.class) - public void getTemplateTypeName() throws NoSuchFieldException, IllegalAccessException { - - DesignTypeController testDesignTypeController = new DesignTypeController(); - setAccessPrivateFields(testDesignTypeController); - DesignType testDesignType = fillDomain(); - List<String> designTypeNamesList = new ArrayList<>(); - designTypeNamesList.add(testDesignType.getName()); - assertEquals(1, testDesignTypeController.getDesignType().size()); - } - - public void setAccessPrivateFields(DesignTypeController designTypeController) throws NoSuchFieldException, IllegalAccessException { - - Field testDesignTypeService = designTypeController.getClass().getDeclaredField("designTypeService"); - testDesignTypeService.setAccessible(true); - testDesignTypeService.set(designTypeController, designTypeService); - } - - - public DesignType fillDomain(){ + public DesignType fillDomain() { DesignType designType = new DesignType(); designType.setName("Kibana Dashboard"); return designType; } -}
\ No newline at end of file + + @Test + public void testGetDesignType() { + List < DesignTypeConfig > designTypeNamesList = new ArrayList < > (); + List < DesignType > designTypeList = new ArrayList < > (); + DesignType designType = fillDomain(); + designTypeList.add(designType); + when(designTypeService.getDesignTypes()).thenReturn(designTypeNamesList); + assertNotNull(designTypeController.getDesignType()); + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java index 06aa61db..fd685fef 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/KafkaControllerTest.java @@ -3,6 +3,7 @@ * ONAP : DataLake * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -35,7 +36,8 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -68,17 +70,74 @@ public class KafkaControllerTest { when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null).thenReturn(kafka); when(kafkaRepository.save(kafka)).thenReturn(null); when(kafkaService.fillKafkaConfiguration(kafkaConfig)).thenReturn(kafka); - when(mockBindingResult.hasErrors()).thenReturn(false,true,false,true); + when(mockBindingResult.hasErrors()).thenReturn(false, true, false, true); - kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse); - kafkaController.createKafka(kafkaConfig,mockBindingResult,httpServletResponse); + kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse); + kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse); - kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse); - kafkaController.updateKafka(kafkaConfig,mockBindingResult,id,httpServletResponse); + kafkaController.updateKafka(kafkaConfig, mockBindingResult, id, httpServletResponse); + kafkaController.updateKafka(kafkaConfig, mockBindingResult, id, httpServletResponse); - kafkaController.deleteKafka(id,httpServletResponse); + kafkaController.deleteKafka(id, httpServletResponse); when(kafkaService.getAllKafka()).thenReturn(null); kafkaController.queryAllKafka(); } -}
\ No newline at end of file + + @Test + public void testCreateKafkaNull() throws IOException { + KafkaConfig kafkaConfig = new KafkaConfig(); + kafkaConfig.setId(1); + kafkaConfig.setName("123"); + when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(kafka); + assertEquals(null, kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse)); + } + + @Test + public void testCreateKafkaException() throws IOException { + KafkaConfig kafkaConfig = new KafkaConfig(); + kafkaConfig.setId(1); + kafkaConfig.setName("123"); + when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null); + when(kafkaService.fillKafkaConfiguration(kafkaConfig)).thenThrow(NullPointerException.class); + assertEquals(null, kafkaController.createKafka(kafkaConfig, mockBindingResult, httpServletResponse)); + } + + @Test + public void testUpdateKafkaNull() throws IOException { + KafkaConfig kafkaConfig = new KafkaConfig(); + kafkaConfig.setId(1); + kafkaConfig.setName("123"); + when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(null); + assertEquals(null, kafkaController.updateKafka(kafkaConfig, mockBindingResult, 1, httpServletResponse)); + } + + @Test + public void testUpdateKafkaException() throws IOException { + KafkaConfig kafkaConfig = new KafkaConfig(); + kafkaConfig.setId(1); + kafkaConfig.setName("123"); + when(kafkaService.getKafkaById(kafkaConfig.getId())).thenReturn(kafka); + doThrow(NullPointerException.class).when(kafkaService).fillKafkaConfiguration(kafkaConfig, kafka); + assertEquals(null, kafkaController.updateKafka(kafkaConfig, mockBindingResult, 1, httpServletResponse)); + } + + @Test + public void testDeleteKafkaNull() throws IOException { + when(kafkaService.getKafkaById(1)).thenReturn(null); + kafkaController.deleteKafka(1, httpServletResponse); + } + + @Test + public void testGetKafkaDetailNull() throws IOException { + when(kafkaService.getKafkaById(1)).thenReturn(null); + kafkaController.getKafkaDetail(1, httpServletResponse); + } + + @Test + public void testGetKafkaDetail() throws IOException { + when(kafkaService.getKafkaById(1)).thenReturn(kafka); + assertEquals(null, kafkaController.getKafkaDetail(1, httpServletResponse)); + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java index 988010ec..17107120 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicControllerTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright (C) 2018-2019 Huawei. 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. @@ -27,145 +28,185 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; import org.onap.datalake.feeder.controller.domain.PostReturnBody; +import org.onap.datalake.feeder.domain.Kafka; import org.onap.datalake.feeder.domain.Topic; import org.onap.datalake.feeder.dto.TopicConfig; +import org.onap.datalake.feeder.repository.KafkaRepository; import org.onap.datalake.feeder.repository.TopicNameRepository; import org.onap.datalake.feeder.repository.TopicRepository; import org.onap.datalake.feeder.service.DbService; import org.onap.datalake.feeder.service.DmaapService; import org.onap.datalake.feeder.service.TopicService; import org.onap.datalake.feeder.util.TestUtil; +import org.springframework.context.ApplicationContext; import org.springframework.validation.BindingResult; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class TopicControllerTest { - static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_"; + static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_"; - @Mock - private HttpServletResponse httpServletResponse; + @Mock + private HttpServletResponse httpServletResponse; - @Mock - private BindingResult mockBindingResult; + @Mock + private BindingResult mockBindingResult; - @Mock - private TopicRepository topicRepository; + @Mock + private TopicRepository topicRepository; - @Mock - private TopicService topicService; + @Mock + private TopicService topicService; - @Mock - private TopicNameRepository topicNameRepository; + @Mock + private TopicNameRepository topicNameRepository; + + @Mock + private KafkaRepository kafkaRepository; + + @InjectMocks + TopicController topicController; + + @Mock + private ApplicationConfiguration config; + + @Mock + private ApplicationContext context; + + @Mock + private DbService dbService; + + @Mock + private DmaapService dmaapService; + + @Before + public void setupTest() throws NoSuchFieldException, IllegalAccessException { + // While the default boolean return value for a mock is 'false', + // it's good to be explicit anyway: + when(mockBindingResult.hasErrors()).thenReturn(false); + } + + @Test + public void testListTopic() throws IOException, NoSuchFieldException, IllegalAccessException {} + + @Test + public void testCreateTopic() throws IOException { + Topic a = TestUtil.newTopic("a"); + a.setId(1); + a.setEnabled(true); + + TopicConfig ac = a.getTopicConfig(); + + when(topicService.fillTopicConfiguration(ac)).thenReturn(a); + PostReturnBody < TopicConfig > postTopic = topicController.createTopic(ac, mockBindingResult, httpServletResponse); + assertEquals(postTopic.getStatusCode(), 200); + + when(topicService.fillTopicConfiguration(ac)).thenReturn(a); + a.setTtl(0); + PostReturnBody < TopicConfig > postTopicConfig = topicController.createTopic(ac, mockBindingResult, httpServletResponse); + assertEquals(postTopicConfig.getStatusCode(), 200); + + when(mockBindingResult.hasErrors()).thenReturn(true); + PostReturnBody < TopicConfig > topicConfig = topicController.createTopic(ac, mockBindingResult, httpServletResponse); + assertEquals(null, topicConfig); + } + + @Test + public void testUpdateTopic() throws IOException { + Topic a = TestUtil.newTopic("a"); + a.setId(1); + a.setEnabled(true); + + TopicConfig ac = a.getTopicConfig(); + + when(topicService.getTopic(1)).thenReturn(a); + PostReturnBody < TopicConfig > postConfig1 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse); + assertEquals(200, postConfig1.getStatusCode()); + TopicConfig ret = postConfig1.getReturnBody(); + assertEquals("a", ret.getName()); + assertEquals(true, ret.isEnabled()); + + topicController.updateTopic(0, ac, mockBindingResult, httpServletResponse); + + when(topicService.getTopic(1)).thenReturn(null); + topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse); + + when(mockBindingResult.hasErrors()).thenReturn(true); + PostReturnBody < TopicConfig > postConfig2 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse); + assertNull(postConfig2); + + } + + @Test + public void testGetTopic() throws IOException { + Topic a = TestUtil.newTopic("a"); + a.setId(1); + a.setEnabled(true); + + when(topicService.getTopic(1)).thenReturn(a); + TopicConfig ac = topicController.getTopic(1, httpServletResponse); + when(topicService.getTopic(1)).thenReturn(null); + ac = topicController.getTopic(1, httpServletResponse); + } + + @Test + public void testDeleteTopic() throws IOException { + Topic a = TestUtil.newTopic("a"); + a.setId(1); + a.setEnabled(true); + + when(topicService.getTopic(1)).thenReturn(a); + topicController.deleteTopic(1, httpServletResponse); + when(topicService.getTopic(1)).thenReturn(null); + topicController.deleteTopic(1, httpServletResponse); + } + + @Test + public void testList() { + ArrayList < Topic > topics = new ArrayList < > (); + topics.add(TestUtil.newTopic("a")); + topics.add(TestUtil.newTopic(DEFAULT_TOPIC_NAME)); + when(topicRepository.findAll()).thenReturn(topics); + + List < Integer > ids = topicController.list(); + for (Integer topic: ids) { + System.out.println(topic); + } + } + + @Test + public void testGetDefaultConfigNull() throws IOException { + Topic topic = null; + when(topicService.getDefaultTopicFromFeeder()).thenReturn(topic); + assertEquals(null, topicController.getDefaultConfig(httpServletResponse)); + } + + @Test + public void testGetDefaultConfig() throws IOException { + Topic topic = TestUtil.newTopic(DEFAULT_TOPIC_NAME); + when(topicService.getDefaultTopicFromFeeder()).thenReturn(topic); + assertEquals(topic.getName(), topicController.getDefaultConfig(httpServletResponse).getName()); + } + + @Test + public void testListDmaapTopics() { + Kafka kafka = TestUtil.newKafka("test"); + when(kafkaRepository.findById(1)).thenReturn(Optional.of(kafka)); + DmaapService dmaapService = mock(DmaapService.class); + when(context.getBean(DmaapService.class, kafka)).thenReturn(dmaapService); + when(dmaapService.getTopics()).thenReturn(null); + assertEquals(null, topicController.listDmaapTopics(1)); + } - @InjectMocks - TopicController topicController; - - @Mock - private ApplicationConfiguration config; - - @Mock - private DbService dbService; - - @Mock - private DmaapService dmaapService; - - @Before - public void setupTest() throws NoSuchFieldException, IllegalAccessException { - // While the default boolean return value for a mock is 'false', - // it's good to be explicit anyway: - when(mockBindingResult.hasErrors()).thenReturn(false); - } - - @Test - public void testListTopic() throws IOException, NoSuchFieldException, IllegalAccessException { - } - - @Test - public void testCreateTopic() throws IOException { - Topic a = TestUtil.newTopic("a"); - a.setId(1); - a.setEnabled(true); - - TopicConfig ac = a.getTopicConfig(); - - when(topicService.fillTopicConfiguration(ac)).thenReturn(a); - PostReturnBody<TopicConfig> postTopic = topicController.createTopic(ac, mockBindingResult, httpServletResponse); - assertEquals(postTopic.getStatusCode(), 200); - - when(mockBindingResult.hasErrors()).thenReturn(true); - PostReturnBody<TopicConfig> topicConfig = topicController.createTopic(ac, mockBindingResult, httpServletResponse); - assertEquals(null, topicConfig); - } - - @Test - public void testUpdateTopic() throws IOException { - Topic a = TestUtil.newTopic("a"); - a.setId(1); - a.setEnabled(true); - - TopicConfig ac = a.getTopicConfig(); - - when(topicService.getTopic(1)).thenReturn(a); - PostReturnBody<TopicConfig> postConfig1 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse); - assertEquals(200, postConfig1.getStatusCode()); - TopicConfig ret = postConfig1.getReturnBody(); - assertEquals("a", ret.getName()); - assertEquals(true, ret.isEnabled()); - - topicController.updateTopic(0, ac, mockBindingResult, httpServletResponse); - - when(topicService.getTopic(1)).thenReturn(null); - topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse); - - when(mockBindingResult.hasErrors()).thenReturn(true); - PostReturnBody<TopicConfig> postConfig2 = topicController.updateTopic(1, ac, mockBindingResult, httpServletResponse); - assertNull(postConfig2); - - } - - @Test - public void testGetTopic() throws IOException { - Topic a = TestUtil.newTopic("a"); - a.setId(1); - a.setEnabled(true); - - when(topicService.getTopic(1)).thenReturn(a); - TopicConfig ac = topicController.getTopic(1, httpServletResponse); - when(topicService.getTopic(1)).thenReturn(null); - ac = topicController.getTopic(1, httpServletResponse); - } - - @Test - public void testDeleteTopic() throws IOException { - Topic a = TestUtil.newTopic("a"); - a.setId(1); - a.setEnabled(true); - - when(topicService.getTopic(1)).thenReturn(a); - topicController.deleteTopic(1, httpServletResponse); - when(topicService.getTopic(1)).thenReturn(null); - topicController.deleteTopic(1, httpServletResponse); - } - - @Test - public void testList() { - ArrayList<Topic> topics = new ArrayList<>(); - topics.add(TestUtil.newTopic("a")); - topics.add(TestUtil.newTopic(DEFAULT_TOPIC_NAME)); - when(topicRepository.findAll()).thenReturn(topics); - - List<Integer> ids = topicController.list(); - for (Integer topic : ids) { - System.out.println(topic); - } - } } diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java new file mode 100644 index 00000000..9ac5f1b3 --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/TopicNameControllerTest.java @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * 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. + * 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.controller; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +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.domain.Topic; +import org.onap.datalake.feeder.domain.TopicName; +import org.onap.datalake.feeder.repository.TopicNameRepository; + +@RunWith(MockitoJUnitRunner.class) +public class TopicNameControllerTest { + + @Mock + private TopicNameRepository topicNameRepository; + + @InjectMocks + TopicNameController topicNameController; + + @Test + public void testList() throws IOException { + List < TopicName > topicNameList = new ArrayList < > (); + + TopicName topicName = new TopicName(); + topicName.setId("1"); + topicName.setDesigns(null); + Topic topic = new Topic(); + topic.setId(1); + Set < Topic > topics = new HashSet < > (); + topics.add(topic); + topicName.setTopics(topics); + topicNameList.add(topicName); + + when(topicNameRepository.findAll()).thenReturn(topicNameList); + List < String > retString = topicNameController.list(); + assertEquals("1", retString.get(0)); + + } + +} 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 index 4a75df17..11432e16 100644 --- 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 @@ -3,6 +3,7 @@ * ONAP : DataLake * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -19,20 +20,23 @@ */ package org.onap.datalake.feeder.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; -import static org.junit.Assert.*; - public class DbTypeTest { @Test - public void test(){ - DbType dbType = new DbType("ES","Elasticsearch"); - + public void test() { + DbType dbType = new DbType("ES", "Elasticsearch"); + DbType dbType2 = new DbType("MONGO", "MongoDB"); - dbType.setTool(false); - + dbType.setTool(false); + assertNotNull(dbType.toString()); assertEquals(dbType, dbType); @@ -44,10 +48,10 @@ public class DbTypeTest { assertEquals("MongoDB", dbType2.getName()); dbType2.setName(null); dbType2.setDefaultPort(1); - assertTrue(1==dbType2.getDefaultPort()); + assertTrue(1 == dbType2.getDefaultPort()); dbType2.setDbs(null); assertNull(dbType2.getDbs()); } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java index de6fec27..efc49bf9 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -20,11 +21,12 @@ package org.onap.datalake.feeder.domain; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import org.junit.Test; import org.onap.datalake.feeder.util.TestUtil; -import static org.junit.Assert.*; - public class DesignTest { @Test @@ -53,4 +55,4 @@ public class DesignTest { assertNull(design.getDbs()); } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java index e02c2d1c..da1c5ec1 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/domain/DesignTypeTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -20,10 +21,9 @@ package org.onap.datalake.feeder.domain; +import static org.junit.Assert.assertEquals; import org.junit.Test; -import static org.junit.Assert.*; - public class DesignTypeTest { @Test @@ -40,4 +40,4 @@ public class DesignTypeTest { designType.getDesigns(); designType.getDesignTypeConfig(); } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java index 22ebe4f1..6b0b006f 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignConfigTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -20,13 +21,13 @@ package org.onap.datalake.feeder.dto; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.junit.Test; import org.onap.datalake.feeder.domain.Design; import org.onap.datalake.feeder.domain.DesignType; import org.onap.datalake.feeder.domain.TopicName; -import static org.junit.Assert.*; - public class DesignConfigTest { @Test @@ -58,4 +59,4 @@ public class DesignConfigTest { assertEquals(testDesignConfig.getDesignType(), null); } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java new file mode 100644 index 00000000..a7253ae8 --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DesignTypeConfigTest.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * 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. + * 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.dto; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class DesignTypeConfigTest { + + @Test + public void testDesignTypeConfig() { + DesignTypeConfig designTypeConfig = new DesignTypeConfig(); + designTypeConfig.setId("123"); + designTypeConfig.setName("test"); + assertEquals("123", designTypeConfig.getId()); + assertEquals("test", designTypeConfig.getName()); + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java index b2104177..2d38f532 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/KafkaConfigTest.java @@ -3,6 +3,7 @@ * ONAP : DataLake * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -19,12 +20,12 @@ */ package org.onap.datalake.feeder.dto; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.junit.Test; import org.onap.datalake.feeder.domain.Kafka; import org.onap.datalake.feeder.util.TestUtil; -import static org.junit.Assert.*; - /** * Test Kafka * @@ -76,4 +77,4 @@ public class KafkaConfigTest { assertNotEquals(null, testKafkaConfig.getTimeout()); } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java index 65b373f5..cdc8c42a 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignServiceTest.java @@ -3,6 +3,7 @@ * ONAP : DCAE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -25,11 +26,27 @@ 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.Design; import org.onap.datalake.feeder.domain.DesignType; +import org.onap.datalake.feeder.domain.TopicName; +import org.onap.datalake.feeder.dto.DesignConfig; +import org.onap.datalake.feeder.repository.DbRepository; +import org.onap.datalake.feeder.repository.DesignRepository; +import org.onap.datalake.feeder.repository.DesignTypeRepository; +import org.onap.datalake.feeder.repository.TopicNameRepository; +import org.onap.datalake.feeder.util.TestUtil; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + @RunWith(MockitoJUnitRunner.class) public class DesignServiceTest { @@ -37,14 +54,26 @@ public class DesignServiceTest { private DesignType designType; @Mock + private DesignRepository designRepository; + + @Mock + private TopicNameRepository topicNameRepository; + + @Mock + private DbRepository dbRepository; + + @Mock private ApplicationConfiguration applicationConfiguration; + @Mock + private DesignTypeRepository designTypeRepository; + @InjectMocks private DesignService designService; @Test(expected = RuntimeException.class) - public void testDeploy() { - when(designType.getId()).thenReturn("KIBANA_DB","ES_MAPPING"); + public void testDeployException() { + when(designType.getId()).thenReturn("KIBANA_DB", "ES_MAPPING"); Design design = new Design(); design.setDesignType(designType); design.setBody("jsonString"); @@ -53,4 +82,96 @@ public class DesignServiceTest { designService.deploy(design); System.out.println(); } -}
\ No newline at end of file + + @Test + public void testFillDesignConfigurationNull() { + DesignConfig designConfig = new DesignConfig(); + designConfig.setTopicName("topic"); + designConfig.setDesignType("designType"); + TopicName topicName = new TopicName("test"); + Optional < TopicName > topicNameOptional = Optional.of(topicName); + when(topicNameRepository.findById(designConfig.getTopicName())).thenReturn(topicNameOptional); + when(designTypeRepository.findById(designConfig.getDesignType())).thenReturn(Optional.of(new DesignType())); + assertNull(designService.fillDesignConfiguration(designConfig).getName()); + } + + @Test + public void testFillDesignConfiguration() { + DesignConfig designConfig = new DesignConfig(); + designConfig.setTopicName("topic"); + designConfig.setDesignType("designType"); + + List < Integer > dbs = new ArrayList < > (); + dbs.add(1); + designConfig.setDbs(dbs); + when(topicNameRepository.findById(designConfig.getTopicName())).thenReturn(Optional.of(new TopicName())); + when(designTypeRepository.findById(designConfig.getDesignType())).thenReturn(Optional.of(new DesignType())); + when(dbRepository.findById(designConfig.getDbs().get(0))).thenReturn(Optional.of(new Db())); + designService.fillDesignConfiguration(designConfig).getName(); + } + + @Test(expected = IllegalArgumentException.class) + public void testFillDesign() { + Design design = new Design(); + design.setDesignType(designType); + DesignConfig designConfig = new DesignConfig(); + designService.fillDesignConfiguration(designConfig, design); + } + + @Test + public void testGetDesignNull() { + Optional < Design > testDesign = Optional.ofNullable(null); + when(designRepository.findById(1)).thenReturn(testDesign); + assertNull(designService.getDesign(1)); + } + + @Test + public void testDeploy() { + when(designType.getId()).thenReturn("KIBANA_DB"); + Design design = getDesign(); + assertNotNull(designService.deploy(design)); + } + + @Test + public void testDeployESMappingCase() { + when(designType.getId()).thenReturn("ES_MAPPING"); + Design design = getDesign(); + assertNotNull(designService.deploy(design)); + } + + @Test + public void testDeployDefault() { + when(designType.getId()).thenReturn("KIBANA_SEARCH"); + Design design = getDesign(); + assertNull(designService.deploy(design)); + } + + @Test(expected = NullPointerException.class) + public void testQueryAllDesignNull() { + when(designRepository.findAll()).thenReturn(null); + designService.queryAllDesign(); + } + + @Test + public void testQueryAllDesign() { + List < Design > designList = new ArrayList < > (); + Design design = getDesign(); + designList.add(design); + when(designRepository.findAll()).thenReturn(designList); + designService.queryAllDesign(); + } + + public Design getDesign() { + Design design = new Design(); + design.setDesignType(designType); + design.setBody("jsonString"); + design.setTopicName(new TopicName("1")); + Set < Db > dbs = new HashSet < > (); + Db db = TestUtil.newDb("MongoDB"); + db.setEnabled(true); + dbs.add(db); + design.setDbs(dbs); + return design; + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java index 5879deb6..28c84750 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/DesignTypeServiceTest.java @@ -3,6 +3,7 @@ * ONAP : DataLake * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -25,13 +26,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.domain.DesignType; -import org.onap.datalake.feeder.dto.DesignTypeConfig; import org.onap.datalake.feeder.repository.DesignTypeRepository; - import java.util.ArrayList; import java.util.List; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -44,16 +43,19 @@ public class DesignTypeServiceTest { private DesignTypeService designTypeService; @Test - public void testDesignTypeService(){ - List<DesignType> designTypeList = new ArrayList<>(); + public void testDesignTypeService() { + List < DesignType > designTypeList = new ArrayList < > (); DesignType designType = new DesignType(); designType.setName("test"); - //DesignTypeConfig designTypeConfig = new DesignTypeConfig(); - //designTypeConfig.setDesignType("test"); - //designTypeConfig.setDisplay("test"); designTypeList.add(designType); when(designTypeRepository.findAll()).thenReturn(designTypeList); assertNotNull(designTypeService.getDesignTypes()); } -}
\ No newline at end of file + @Test + public void testDesignTypeServiceNull() { + when(designTypeRepository.findAll()).thenReturn(null); + assertEquals(0, designTypeService.getDesignTypes().size()); + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java index 0274d309..2cb0740c 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/KafkaServiceTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -28,12 +29,11 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.domain.Kafka; import org.onap.datalake.feeder.dto.KafkaConfig; import org.onap.datalake.feeder.repository.KafkaRepository; - import java.util.ArrayList; import java.util.List; import java.util.Optional; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -67,4 +67,4 @@ public class KafkaServiceTest { kafkaService.fillKafkaConfiguration(kafkaConfig); } -}
\ No newline at end of file +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java index d6298b87..f587f358 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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. @@ -27,74 +28,72 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; import org.springframework.context.ApplicationContext; - import java.lang.reflect.Field; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.locks.ReentrantReadWriteLock; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class PullServiceTest { - @InjectMocks - private PullService pullService; + @InjectMocks + private PullService pullService; - @Mock - private ApplicationContext context; + @Mock + private ApplicationContext context; - @Mock - private ApplicationConfiguration config; + @Mock + private ApplicationConfiguration config; - @Mock - private ExecutorService executorService; + @Mock + private ExecutorService executorService; - @Mock - private List<Puller> consumers; + @Mock + private List < Puller > consumers; - @Test - public void isRunning() { - assertFalse(pullService.isRunning()); - } + @Test + public void isRunning() { + assertFalse(pullService.isRunning()); + } - @Test(expected = NullPointerException.class) - public void start() { - setRunning(false); - pullService.start(); - setRunning(true); - pullService.start(); - } + @Test(expected = NullPointerException.class) + public void start() { + setRunning(false); + pullService.start(); + setRunning(true); + pullService.start(); + } - @Test - public void shutdown() { - when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock()); - setRunning(false); - pullService.shutdown(); - setRunning(true); - pullService.shutdown(); - } + @Test + public void shutdown() { + when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock()); + setRunning(false); + pullService.shutdown(); + setRunning(true); + pullService.shutdown(); + } - private void setRunning(boolean running) { - Field configField; - try { - configField = PullService.class.getDeclaredField("isRunning"); - configField.setAccessible(true); - configField.set(pullService, running); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + private void setRunning(boolean running) { + Field configField; + try { + configField = PullService.class.getDeclaredField("isRunning"); + configField.setAccessible(true); + configField.set(pullService, running); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); - } catch (NoSuchFieldException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } -}
\ No newline at end of file + } catch (NoSuchFieldException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java index bd26519b..e30aa7b8 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicConfigPollingServiceTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright 2019 China Mobile + * 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,6 +22,7 @@ package org.onap.datalake.feeder.service; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; @@ -30,6 +32,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -40,6 +43,7 @@ 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.EffectiveTopic; import org.onap.datalake.feeder.domain.Kafka; import org.onap.datalake.feeder.util.TestUtil; @@ -51,73 +55,87 @@ import org.onap.datalake.feeder.util.TestUtil; */ @RunWith(MockitoJUnitRunner.class) public class TopicConfigPollingServiceTest { - @Mock - private ApplicationConfiguration config; - @Mock - private DmaapService dmaapService; + @Mock + private ApplicationConfiguration config; - @InjectMocks - private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService(); + @Mock + private DmaapService dmaapService; - static String KAFKA_NAME = "kafka1"; + @Mock + private Map < Integer, Map < String, List < EffectiveTopic >>> effectiveTopicMap = new HashMap < > (); - @Before - public void init() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException { - Method init = topicConfigPollingService.getClass().getDeclaredMethod("init"); - init.setAccessible(true); - init.invoke(topicConfigPollingService); + @InjectMocks + private TopicConfigPollingService topicConfigPollingService = new TopicConfigPollingService(); - Set<String> activeTopics = new HashSet<>(Arrays.asList("test")); - Map<Integer, Set<String>> activeTopicMap = new HashMap<>(); - activeTopicMap.put(1, activeTopics); + static String KAFKA_NAME = "kafka1"; - Field activeTopicsField = TopicConfigPollingService.class.getDeclaredField("activeTopicMap"); - activeTopicsField.setAccessible(true); - activeTopicsField.set(topicConfigPollingService, activeTopicMap); + @Before + public void init() + throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException { + Method init = topicConfigPollingService.getClass().getDeclaredMethod("init"); + init.setAccessible(true); + init.invoke(topicConfigPollingService); - Method initMethod = TopicConfigPollingService.class.getDeclaredMethod("init"); - initMethod.setAccessible(true); - initMethod.invoke(topicConfigPollingService); - } + Set < String > activeTopics = new HashSet < > (Arrays.asList("test")); + Map < Integer, Set < String >> activeTopicMap = new HashMap < > (); + activeTopicMap.put(1, activeTopics); - @Test - public void testRun() throws InterruptedException { + Field activeTopicsField = TopicConfigPollingService.class.getDeclaredField("activeTopicMap"); + activeTopicsField.setAccessible(true); + activeTopicsField.set(topicConfigPollingService, activeTopicMap); - when(config.getCheckTopicInterval()).thenReturn(1L); + Method initMethod = TopicConfigPollingService.class.getDeclaredMethod("init"); + initMethod.setAccessible(true); + initMethod.invoke(topicConfigPollingService); + } - Thread thread = new Thread(topicConfigPollingService); - thread.start(); + @Test + public void testRun() throws InterruptedException { - Thread.sleep(50); - topicConfigPollingService.shutdown(); - thread.join(); + when(config.getCheckTopicInterval()).thenReturn(1L); - assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka())); - } + Thread thread = new Thread(topicConfigPollingService); + thread.start(); - @Test - public void testRunNoChange() throws InterruptedException { + Thread.sleep(50); + topicConfigPollingService.shutdown(); + thread.join(); - when(config.getCheckTopicInterval()).thenReturn(1L); + assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka())); + } - Thread thread = new Thread(topicConfigPollingService); - thread.start(); + @Test + public void testRunNoChange() throws InterruptedException { - Thread.sleep(50); - topicConfigPollingService.shutdown(); - thread.join(); + when(config.getCheckTopicInterval()).thenReturn(1L); - assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka())); - } + Thread thread = new Thread(topicConfigPollingService); + thread.start(); - @Test - public void testGet() { - Kafka kafka = TestUtil.newKafka(KAFKA_NAME); - kafka.setId(1); - //assertNull(topicConfigPollingService.getEffectiveTopic (kafka, "test")); - assertNotNull(topicConfigPollingService.getActiveTopics(kafka)); + Thread.sleep(50); + topicConfigPollingService.shutdown(); + thread.join(); - } + assertTrue(topicConfigPollingService.isActiveTopicsChanged(new Kafka())); + } -}
\ No newline at end of file + @Test + public void testGet() { + Kafka kafka = TestUtil.newKafka(KAFKA_NAME); + kafka.setId(1); + //assertNull(topicConfigPollingService.getEffectiveTopic (kafka, "test")); + assertNotNull(topicConfigPollingService.getActiveTopics(kafka)); + + } + + @Test + public void testGetEffectiveTopic() { + Kafka kafka = TestUtil.newKafka(KAFKA_NAME); + kafka.setId(1); + Map < String, List < EffectiveTopic >> effectiveTopicMapKafka = new HashMap < > (); + when(effectiveTopicMap.get(kafka.getId())).thenReturn(effectiveTopicMapKafka); + assertNull(topicConfigPollingService.getEffectiveTopic(kafka, "test")); + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java new file mode 100644 index 00000000..f040261c --- /dev/null +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicNameServiceTest.java @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * 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. + * 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 static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +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.domain.TopicName; +import org.onap.datalake.feeder.repository.TopicNameRepository; + +@RunWith(MockitoJUnitRunner.class) +public class TopicNameServiceTest { + + @Mock + private TopicNameRepository topicNameRepository; + + @InjectMocks + private TopicNameService topicNameService; + + @Test + public void testUpdate() { + List < TopicName > topicNameList = new ArrayList < > (); + topicNameList.add(new TopicName("test")); + Collection < String > allTopicNames = new ArrayList < > (); + allTopicNames.add("MONGODB"); + when(topicNameRepository.findAll()).thenReturn(topicNameList); + topicNameService.update(allTopicNames); + } + +} diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java index eea47501..3c03f14e 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/TopicServiceTest.java @@ -1,53 +1,51 @@ /* -* ============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========================================================= -*/ + * ============LICENSE_START======================================================= + * ONAP : DATALAKE + * ================================================================================ + * Copyright 2019 China Mobile + * 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. + * 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 static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; -import org.elasticsearch.client.IndicesClient; -import org.elasticsearch.client.RequestOptions; -import org.elasticsearch.client.RestHighLevelClient; -import org.elasticsearch.client.indices.GetIndexRequest; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; import org.onap.datalake.feeder.config.ApplicationConfiguration; -import org.onap.datalake.feeder.domain.*; +import org.onap.datalake.feeder.domain.Db; +import org.onap.datalake.feeder.domain.DbType; +import org.onap.datalake.feeder.domain.Kafka; +import org.onap.datalake.feeder.domain.Topic; +import org.onap.datalake.feeder.domain.TopicName; import org.onap.datalake.feeder.dto.TopicConfig; -import org.onap.datalake.feeder.enumeration.DbTypeEnum; import org.onap.datalake.feeder.repository.DbRepository; +import org.onap.datalake.feeder.repository.KafkaRepository; import org.onap.datalake.feeder.repository.TopicNameRepository; import org.onap.datalake.feeder.repository.TopicRepository; import org.onap.datalake.feeder.service.db.ElasticsearchService; @@ -61,127 +59,210 @@ import org.onap.datalake.feeder.service.db.ElasticsearchService; @RunWith(MockitoJUnitRunner.class) public class TopicServiceTest { - static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_"; - - @Mock - private ApplicationConfiguration config; - - @Mock - private TopicRepository topicRepository; - - @Mock - private ElasticsearchService elasticsearchService; - - @Mock - private DbService dbService; - - @Mock - private DbRepository dbRepository; - - @Mock - private TopicNameRepository topicNameRepository; - - @InjectMocks - private TopicService topicService; - - @Test(expected = NullPointerException.class) - public void testGetTopic() throws IOException{ - List<Topic> topics = new ArrayList<>(); - Topic topic = new Topic(); - DbType dbType = new DbType(); - Set<Kafka> kafkas = new HashSet<>(); - Set<Db> dbs = new HashSet<>(); - Db db = new Db(); - db.setName("Elasticsearch"); - dbs.add(db); - - dbType.setId("ES"); - db.setDbType(dbType); - - Kafka kafka = new Kafka(); - kafka.setName("1234"); - kafkas.add(kafka); - - TopicName topicName = new TopicName(); - topicName.setId("1234"); - - topic.setTopicName(topicName); - topic.setKafkas(kafkas); - topic.setEnabled(true); - topic.setDbs(dbs); - topics.add(topic); - when(topicRepository.findAll()).thenReturn(topics); - when((ElasticsearchService)dbService.findDbStoreService(db)).thenReturn(new ElasticsearchService(db)); - topicService.findTopics(kafka,topicName.getId()); - topicService.getEnabledEffectiveTopic(kafka,topicName.getId(),true); - - } - @Test - public void testGetTopicNull() { - Topic topic = new Topic(); - TopicName topicName = new TopicName(); - topicName.setId("_DL_DEFAULT_"); - topic.setId(1234); - topic.setTopicName(topicName); - Optional<Topic> optional = Optional.of(topic); - when(topicRepository.findById(0)).thenReturn(optional); - when(config.getDefaultTopicName()).thenReturn("_DL_DEFAULT_"); - assertEquals(topic,topicService.getTopic(0)); - assertTrue(topicService.isDefaultTopic(topic)); - } - - @Test - public void testFillTopic(){ - TopicConfig tConfig = new TopicConfig(); - tConfig.setId(1234); - tConfig.setName("1234"); - tConfig.setLogin("1234"); - tConfig.setPassword("1234"); - tConfig.setEnabled(true); - tConfig.setSaveRaw(true); - tConfig.setDataFormat("1234"); - tConfig.setTtl(1234); - tConfig.setCorrelateClearedMessage(true); - tConfig.setMessageIdPath("1234"); - tConfig.setAggregateArrayPath("1234"); - tConfig.setFlattenArrayPath("1234"); - List<Integer> sinkdbs = new ArrayList<>(); - sinkdbs.add(1234); - tConfig.setSinkdbs(sinkdbs); - - Db db = new Db(); - db.setId(1234); - - TopicName topicName = new TopicName(); - topicName.setId("1234"); - - Optional<TopicName> optional = Optional.of(topicName); - when(dbRepository.findById(1234)).thenReturn(Optional.of(db)); - when(topicNameRepository.findById(tConfig.getName())).thenReturn(optional); - - topicService.fillTopicConfiguration(tConfig); - } + static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_"; -/* - @Test - public void testGetEffectiveTopic() throws IOException { - String name = "a"; - Topic topic = new Topic(name); - topic.setEnabled(true); - Set<Db> dbSet = new HashSet<>(); - dbSet.add(new Db("Elasticsearch")); - topic.setDbs(dbSet); - - when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME); - when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(topic)); - when(topicRepository.findById(name)).thenReturn(Optional.of(topic)); - when(topicRepository.findById(null)).thenReturn(Optional.empty()); - - assertEquals(topicService.getEffectiveTopic(name), topicService.getEffectiveTopic(name, false)); - - assertNotNull(topicService.getEffectiveTopic(null)); - - topicService.getEffectiveTopic(name, true); - } -*/ + @Mock + private ApplicationConfiguration config; + + @Mock + private TopicRepository topicRepository; + + @Mock + private ElasticsearchService elasticsearchService; + + @Mock + private DbService dbService; + + @Mock + private DbRepository dbRepository; + + @Mock + private TopicNameRepository topicNameRepository; + + @Mock + private KafkaRepository kafkaRepository; + + @InjectMocks + private TopicService topicService; + + @Test(expected = NullPointerException.class) + public void testGetTopicException() throws IOException { + List < Topic > topics = new ArrayList < > (); + Topic topic = new Topic(); + DbType dbType = new DbType(); + Set < Kafka > kafkas = new HashSet < > (); + Set < Db > dbs = new HashSet < > (); + Db db = new Db(); + db.setName("Elasticsearch"); + dbs.add(db); + + dbType.setId("ES"); + db.setDbType(dbType); + + Kafka kafka = new Kafka(); + kafka.setName("1234"); + kafkas.add(kafka); + + TopicName topicName = new TopicName(); + topicName.setId("1234"); + + topic.setTopicName(topicName); + topic.setKafkas(kafkas); + topic.setEnabled(true); + topic.setDbs(dbs); + topics.add(topic); + when(topicRepository.findAll()).thenReturn(topics); + when((ElasticsearchService) dbService.findDbStoreService(db)).thenReturn(new ElasticsearchService(db)); + topicService.findTopics(kafka, topicName.getId()); + topicService.getEnabledEffectiveTopic(kafka, topicName.getId(), true); + + } + + @Test + public void testGetTopic() throws IOException { + ArrayList < Topic > topics = new ArrayList < > (); + Topic topic = new Topic(); + Set < Kafka > kafkas = new HashSet < > (); + Kafka kafka = new Kafka(); + kafka.setName("1234"); + kafkas.add(kafka); + TopicName topicName = new TopicName(); + topicName.setId(DEFAULT_TOPIC_NAME); + topic.setTopicName(topicName); + topic.setKafkas(kafkas); + topics.add(topic); + when(topicRepository.findAll()).thenReturn(topics); + when(config.getDefaultTopicName()).thenReturn("_DL_DEFAULT_"); + topicService.getEnabledEffectiveTopic(new Kafka(), "test", true); + } + + @Test + public void testFindTopics() { + ArrayList < Topic > topics = new ArrayList < > (); + Topic topic = new Topic(); + Set < Kafka > kafkas = new HashSet < > (); + Kafka kafka = new Kafka(); + kafka.setName("1234"); + kafkas.add(kafka); + TopicName topicName = new TopicName(); + topicName.setId(DEFAULT_TOPIC_NAME); + topic.setTopicName(topicName); + topic.setKafkas(kafkas); + topics.add(topic); + when(topicRepository.findAll()).thenReturn(topics); + topicService.findTopics(kafka, topicName.getId()); + } + + @Test + public void testGetTopicNull() { + Topic topic = new Topic(); + TopicName topicName = new TopicName(); + topicName.setId("_DL_DEFAULT_"); + topic.setId(1234); + topic.setTopicName(topicName); + Optional < Topic > optional = Optional.of(topic); + when(topicRepository.findById(0)).thenReturn(optional); + when(config.getDefaultTopicName()).thenReturn("_DL_DEFAULT_"); + assertEquals(topic, topicService.getTopic(0)); + assertTrue(topicService.isDefaultTopic(topic)); + } + + @Test + public void testFillTopic() { + TopicConfig tConfig = new TopicConfig(); + tConfig.setId(1234); + tConfig.setName("1234"); + tConfig.setLogin("1234"); + tConfig.setPassword("1234"); + tConfig.setEnabled(true); + tConfig.setSaveRaw(true); + tConfig.setDataFormat("1234"); + tConfig.setTtl(1234); + tConfig.setCorrelateClearedMessage(true); + tConfig.setMessageIdPath("1234"); + tConfig.setAggregateArrayPath("1234"); + tConfig.setFlattenArrayPath("1234"); + List < Integer > sinkdbs = new ArrayList < > (); + sinkdbs.add(1234); + tConfig.setSinkdbs(sinkdbs); + List < Integer > kafkas = new ArrayList < > (); + kafkas.add(1); + tConfig.setKafkas(kafkas); + + Db db = new Db(); + db.setId(1234); + + TopicName topicName = new TopicName(); + topicName.setId("1234"); + + Optional < TopicName > optional = Optional.of(topicName); + when(dbRepository.findById(1234)).thenReturn(Optional.of(db)); + when(kafkaRepository.findById(1)).thenReturn(Optional.of(new Kafka())); + when(topicNameRepository.findById(tConfig.getName())).thenReturn(optional); + topicService.fillTopicConfiguration(tConfig); + } + + @Test + public void testGetDefaultTopicFromFeeder() { + when(topicRepository.findByTopicName_Id(config.getDefaultTopicName())).thenReturn(new Topic()); + topicService.getDefaultTopicFromFeeder(); + } + + @Test + public void testGetDefaultTopic() { + List < Topic > topics = new ArrayList < > (); + Topic topic = new Topic(); + DbType dbType = new DbType(); + Set < Kafka > kafkas = new HashSet < > (); + Set < Db > dbs = new HashSet < > (); + Db db = new Db(); + db.setName("Elasticsearch"); + dbs.add(db); + + dbType.setId("ES"); + db.setDbType(dbType); + + Kafka kafka = new Kafka(); + kafka.setName("1234"); + kafkas.add(kafka); + + TopicName topicName = new TopicName(); + topicName.setId(DEFAULT_TOPIC_NAME); + topic.setTopicName(topicName); + topic.setKafkas(kafkas); + topic.setEnabled(true); + topic.setDbs(dbs); + topics.add(topic); + when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME); + when(topicRepository.findAll()).thenReturn(topics); + topicService.getDefaultTopic(kafka); + } + + @Test + public void testIsDefaultTopic() { + assertEquals(false, topicService.isDefaultTopic(null)); + } + + /* + @Test + public void testGetEffectiveTopic() throws IOException { + String name = "a"; + Topic topic = new Topic(name); + topic.setEnabled(true); + Set<Db> dbSet = new HashSet<>(); + dbSet.add(new Db("Elasticsearch")); + topic.setDbs(dbSet); + + when(config.getDefaultTopicName()).thenReturn(DEFAULT_TOPIC_NAME); + when(topicRepository.findById(DEFAULT_TOPIC_NAME)).thenReturn(Optional.of(topic)); + when(topicRepository.findById(name)).thenReturn(Optional.of(topic)); + when(topicRepository.findById(null)).thenReturn(Optional.empty()); + + assertEquals(topicService.getEffectiveTopic(name), topicService.getEffectiveTopic(name, false)); + + assertNotNull(topicService.getEffectiveTopic(null)); + + topicService.getEffectiveTopic(name, true); + } + */ } diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java index 2a7745b4..0abee7fc 100755..100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/db/CouchbaseServiceTest.java @@ -3,6 +3,7 @@ * ONAP : DATALAKE * ================================================================================ * Copyright (C) 2018-2019 Huawei. 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. @@ -20,8 +21,12 @@ package org.onap.datalake.feeder.service.db; +import static org.mockito.Mockito.when; + +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantReadWriteLock; import org.jetbrains.annotations.NotNull; import org.json.JSONObject; @@ -29,6 +34,8 @@ import org.junit.After; import org.junit.Before; 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; @@ -46,111 +53,129 @@ import com.couchbase.mock.client.MockClient; @RunWith(MockitoJUnitRunner.class) public class CouchbaseServiceTest { - protected final BucketConfiguration bucketConfiguration = new BucketConfiguration(); - protected MockClient mockClient; - protected CouchbaseMock couchbaseMock; - protected Cluster cluster; - protected com.couchbase.client.java.Bucket bucket; - protected int carrierPort; - protected int httpPort; - - protected void getPortInfo(String bucket) throws Exception { - httpPort = couchbaseMock.getHttpPort(); - carrierPort = couchbaseMock.getCarrierPort(bucket); - } - - protected void createMock(@NotNull String name, @NotNull String password) throws Exception { - bucketConfiguration.numNodes = 1; - bucketConfiguration.numReplicas = 1; - bucketConfiguration.numVBuckets = 1024; - bucketConfiguration.name = name; - bucketConfiguration.type = Bucket.BucketType.COUCHBASE; - bucketConfiguration.password = password; - ArrayList<BucketConfiguration> configList = new ArrayList<BucketConfiguration>(); - configList.add(bucketConfiguration); - couchbaseMock = new CouchbaseMock(0, configList); - couchbaseMock.start(); - couchbaseMock.waitForStartup(); - } - - protected void createClient() { - cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder().bootstrapCarrierDirectPort(carrierPort).bootstrapHttpDirectPort(httpPort).build(), "couchbase://127.0.0.1"); - bucket = cluster.openBucket("default"); - } - - @Before - public void setUp() throws Exception { - createMock("default", ""); - getPortInfo("default"); - createClient(); - } - - @After - public void tearDown() { - if (cluster != null) { - cluster.disconnect(); - } - if (couchbaseMock != null) { - couchbaseMock.stop(); - } - if (mockClient != null) { - mockClient.shutdown(); - } - } - - @Test - public void testSaveJsonsWithTopicId() { - ApplicationConfiguration appConfig = new ApplicationConfiguration(); - appConfig.setTimestampLabel("datalake_ts_"); - - String text = "{ data: { data2 : { value : 'hello'}}}"; - - JSONObject json = new JSONObject(text); - - Topic topic = TestUtil.newTopic("test getMessageId"); - topic.setMessageIdPath("/data/data2/value"); - List<JSONObject> jsons = new ArrayList<>(); - json.put(appConfig.getTimestampLabel(), 1234); - jsons.add(json); - CouchbaseService couchbaseService = new CouchbaseService(new Db()); - couchbaseService.bucket = bucket; - couchbaseService.config = appConfig; - - couchbaseService.init(); - EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test"); - couchbaseService.saveJsons(effectiveTopic, jsons); - - } - - @Test - public void testSaveJsonsWithOutTopicId() { - ApplicationConfiguration appConfig = new ApplicationConfiguration(); - appConfig.setTimestampLabel("datalake_ts_"); - - String text = "{ data: { data2 : { value : 'hello'}}}"; - - JSONObject json = new JSONObject(text); - - Topic topic = TestUtil.newTopic("test getMessageId"); - List<JSONObject> jsons = new ArrayList<>(); - json.put(appConfig.getTimestampLabel(), 1234); - jsons.add(json); - CouchbaseService couchbaseService = new CouchbaseService(new Db()); - couchbaseService.bucket = bucket; - couchbaseService.config = appConfig; - - couchbaseService.init(); - EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test"); - couchbaseService.saveJsons(effectiveTopic, jsons); - } - - @Test - public void testCleanupBucket() { - // CouchbaseService couchbaseService = new CouchbaseService(new Db()); - // couchbaseService.bucket = bucket; - // ApplicationConfiguration appConfig = new ApplicationConfiguration(); - // couchbaseService.config = appConfig; - // couchbaseService.cleanUp(); - } - -}
\ No newline at end of file + protected final BucketConfiguration bucketConfiguration = new BucketConfiguration(); + protected MockClient mockClient; + protected CouchbaseMock couchbaseMock; + protected Cluster cluster; + protected com.couchbase.client.java.Bucket bucket; + protected int carrierPort; + protected int httpPort; + + @InjectMocks + private CouchbaseService couchbaseService; + + @Mock + private ApplicationConfiguration config; + + @Before + public void init() throws NoSuchFieldException, IllegalAccessException { + Db db = TestUtil.newDb("Couchbasedb"); + db.setDatabase("database"); + db.setLogin("login"); + couchbaseService = new CouchbaseService(db); + + Field configField = CouchbaseService.class.getDeclaredField("config"); + configField.setAccessible(true); + configField.set(couchbaseService, config); + couchbaseService.bucket = bucket; + couchbaseService.init(); + } + + protected void getPortInfo(String bucket) throws Exception { + httpPort = couchbaseMock.getHttpPort(); + carrierPort = couchbaseMock.getCarrierPort(bucket); + } + + protected void createMock(@NotNull String name, @NotNull String password) throws Exception { + bucketConfiguration.numNodes = 1; + bucketConfiguration.numReplicas = 1; + bucketConfiguration.numVBuckets = 1024; + bucketConfiguration.name = name; + bucketConfiguration.type = Bucket.BucketType.COUCHBASE; + bucketConfiguration.password = password; + ArrayList < BucketConfiguration > configList = new ArrayList < BucketConfiguration > (); + configList.add(bucketConfiguration); + couchbaseMock = new CouchbaseMock(0, configList); + couchbaseMock.start(); + couchbaseMock.waitForStartup(); + } + + protected void createClient() { + cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment.builder().bootstrapCarrierDirectPort(carrierPort) + .bootstrapHttpDirectPort(httpPort).build(), "couchbase://127.0.0.1"); + bucket = cluster.openBucket("default"); + } + + @Before + public void setUp() throws Exception { + createMock("default", ""); + getPortInfo("default"); + createClient(); + } + + @After + public void tearDown() { + if (cluster != null) { + cluster.disconnect(); + } + if (couchbaseMock != null) { + couchbaseMock.stop(); + } + if (mockClient != null) { + mockClient.shutdown(); + } + } + + @Test + public void testSaveJsonsWithTopicId() { + ApplicationConfiguration appConfig = new ApplicationConfiguration(); + appConfig.setTimestampLabel("datalake_ts_"); + + String text = "{ data: { data2 : { value : 'hello'}}}"; + + JSONObject json = new JSONObject(text); + + Topic topic = TestUtil.newTopic("test getMessageId"); + topic.setMessageIdPath("/data/data2/value"); + List < JSONObject > jsons = new ArrayList < > (); + json.put(appConfig.getTimestampLabel(), 1234); + jsons.add(json); + CouchbaseService couchbaseService = new CouchbaseService(new Db()); + couchbaseService.bucket = bucket; + couchbaseService.config = appConfig; + + couchbaseService.init(); + EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test"); + couchbaseService.saveJsons(effectiveTopic, jsons); + + } + + @Test + public void testSaveJsonsWithOutTopicId() { + ApplicationConfiguration appConfig = new ApplicationConfiguration(); + appConfig.setTimestampLabel("datalake_ts_"); + + String text = "{ data: { data2 : { value : 'hello'}}}"; + + JSONObject json = new JSONObject(text); + + Topic topic = TestUtil.newTopic("test getMessageId"); + List < JSONObject > jsons = new ArrayList < > (); + json.put(appConfig.getTimestampLabel(), 1234); + jsons.add(json); + CouchbaseService couchbaseService = new CouchbaseService(new Db()); + couchbaseService.bucket = bucket; + couchbaseService.config = appConfig; + + couchbaseService.init(); + EffectiveTopic effectiveTopic = new EffectiveTopic(topic, "test"); + couchbaseService.saveJsons(effectiveTopic, jsons); + } + + @Test + public void testCleanupBucket() { + when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock()); + couchbaseService.cleanUp(); + } + +} diff --git a/components/datalake-handler/pom.xml b/components/datalake-handler/pom.xml index 2a45c023..0db38d14 100644 --- a/components/datalake-handler/pom.xml +++ b/components/datalake-handler/pom.xml @@ -1,267 +1,280 @@ <?xml version="1.0" encoding="UTF-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 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========================================================= +--> <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.oparent</groupId> - <artifactId>oparent</artifactId> - <version>2.0.0</version> - </parent> - - <groupId>org.onap.dcaegen2.services.components</groupId> - <artifactId>datalake-handler</artifactId> - <version>1.1.1-SNAPSHOT</version> - <packaging>pom</packaging> - - <name>dcaegen2-service-datalake-handler</name> - - <modules> - <module>feeder</module> - <module>admin</module> - <module>collector</module> - <module>des</module> - </modules> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <java.version>11</java.version> - - <mongojava.version>3.10.1</mongojava.version> - <springboot.version>2.1.0.RELEASE</springboot.version> - <springcouchbase.version>3.1.2.RELEASE</springcouchbase.version> - <jackson.version>2.9.8</jackson.version> - <kafka.version>2.0.0</kafka.version> - <elasticsearchjava.version>7.1.1</elasticsearchjava.version> - <hadoop.version>3.2.0</hadoop.version> - - <sonar.coverage.jacoco.xmlReportPaths> - ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml - </sonar.coverage.jacoco.xmlReportPaths> - </properties> - - <dependencyManagement> - <dependencies> - - <dependency> - <groupId>org.apache.hadoop</groupId> - <artifactId>hadoop-client</artifactId> - <version>${hadoop.version}</version> - </dependency> - - <dependency> - <groupId>org.mariadb.jdbc</groupId> - <artifactId>mariadb-java-client</artifactId> - <version>2.4.1</version> - </dependency> - - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.6</version> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-core</artifactId> - <version>${jackson.version}</version> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</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.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.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>2.8.2</version> - </dependency> - - <dependency> - <groupId>io.druid</groupId> - <artifactId>tranquility-core_2.11</artifactId> - <version>0.8.3</version> - </dependency> - - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - <version>4.0.1</version> - <!--scope>provided</scope --> - </dependency> - - <dependency> - <groupId>org.apache.kafka</groupId> - <artifactId>kafka-clients</artifactId> - <version>${kafka.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.velocity</groupId> - <artifactId>velocity-engine-core</artifactId> - <version>2.0</version> - </dependency> - - <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <version>20180813</version> - </dependency> - - <dependency> - <groupId>org.mongodb</groupId> - <artifactId>mongo-java-driver</artifactId> - <version>${mongojava.version}</version> - </dependency> - - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <version>1.18.2</version> - </dependency> - - <dependency> - <groupId>org.springframework.data</groupId> - <artifactId>spring-data-couchbase</artifactId> - <version>${springcouchbase.version}</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - <version>${springboot.version}</version> - </dependency> - - <!-- tag::actuator[] --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-actuator</artifactId> - <version>${springboot.version}</version> - </dependency> - <!-- end::actuator[] --> - - <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-data-mongodb</artifactId> - <version>${springboot.version}</version> - </dependency> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-data-rest</artifactId> - <version>${springboot.version}</version> - </dependency> - <!-- tag::tests[] --> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-test</artifactId> - <version>${springboot.version}</version> - <scope>test</scope> - </dependency> - <!-- end::tests[] --> - - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-configuration-processor</artifactId> - <version>${springboot.version}</version> - <optional>true</optional> - </dependency> - - <dependency> - <groupId>org.elasticsearch.client</groupId> - <artifactId>elasticsearch-rest-high-level-client</artifactId> - <version>${elasticsearchjava.version}</version> - </dependency> - - </dependencies> - </dependencyManagement> - - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <version>${springboot.version}</version> - <executions> - <execution> - <goals> - <goal>repackage</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-failsafe-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>integration-test</goal> - <goal>verify</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-eclipse-plugin</artifactId> - <configuration> - <downloadSources>true</downloadSources> - <downloadJavadocs>true</downloadJavadocs> - </configuration> - </plugin> - - <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.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.8.0</version> - </plugin> - - </plugins> - </build> + 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.oparent</groupId> + <artifactId>oparent</artifactId> + <version>2.0.0</version> + </parent> + + <groupId>org.onap.dcaegen2.services.components</groupId> + <artifactId>datalake-handler</artifactId> + <version>1.1.2-SNAPSHOT</version> + <packaging>pom</packaging> + + <name>dcaegen2-service-datalake-handler</name> + + <modules> + <module>feeder</module> + <module>admin</module> + <module>des</module> + </modules> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>11</java.version> + + <mongojava.version>3.10.1</mongojava.version> + <springboot.version>2.1.0.RELEASE</springboot.version> + <springcouchbase.version>3.1.2.RELEASE</springcouchbase.version> + <jackson.version>2.9.8</jackson.version> + <kafka.version>2.0.0</kafka.version> + <elasticsearchjava.version>7.1.1</elasticsearchjava.version> + <hadoop.version>3.2.0</hadoop.version> + + <sonar.coverage.jacoco.xmlReportPaths> + ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml + </sonar.coverage.jacoco.xmlReportPaths> + </properties> + + <dependencyManagement> + <dependencies> + + <dependency> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-client</artifactId> + <version>${hadoop.version}</version> + </dependency> + + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + <version>2.4.1</version> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.6</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <version>${jackson.version}</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</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.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.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.2</version> + </dependency> + + <dependency> + <groupId>io.druid</groupId> + <artifactId>tranquility-core_2.11</artifactId> + <version>0.8.3</version> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>4.0.1</version> + <!--scope>provided</scope --> + </dependency> + + <dependency> + <groupId>org.apache.kafka</groupId> + <artifactId>kafka-clients</artifactId> + <version>${kafka.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity-engine-core</artifactId> + <version>2.0</version> + </dependency> + + <dependency> + <groupId>org.json</groupId> + <artifactId>json</artifactId> + <version>20180813</version> + </dependency> + + <dependency> + <groupId>org.mongodb</groupId> + <artifactId>mongo-java-driver</artifactId> + <version>${mongojava.version}</version> + </dependency> + + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.2</version> + </dependency> + + <dependency> + <groupId>org.springframework.data</groupId> + <artifactId>spring-data-couchbase</artifactId> + <version>${springcouchbase.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${springboot.version}</version> + </dependency> + + <!-- tag::actuator[] --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + <version>${springboot.version}</version> + </dependency> + <!-- end::actuator[] --> + + <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-data-mongodb</artifactId> + <version>${springboot.version}</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-rest</artifactId> + <version>${springboot.version}</version> + </dependency> + <!-- tag::tests[] --> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <version>${springboot.version}</version> + <scope>test</scope> + </dependency> + <!-- end::tests[] --> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${springboot.version}</version> + <optional>true</optional> + </dependency> + + <dependency> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> + <version>${elasticsearchjava.version}</version> + </dependency> + + </dependencies> + </dependencyManagement> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${springboot.version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-failsafe-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-eclipse-plugin</artifactId> + <configuration> + <downloadSources>true</downloadSources> + <downloadJavadocs>true</downloadJavadocs> + </configuration> + </plugin> + + <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.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + </plugin> + + </plugins> + </build> </project> diff --git a/components/datalake-handler/version.properties b/components/datalake-handler/version.properties index 9461aa95..e6eb586c 100644 --- a/components/datalake-handler/version.properties +++ b/components/datalake-handler/version.properties @@ -1,6 +1,6 @@ major=1 minor=1 -patch=1 +patch=2 base_version=${major}.${minor}.${patch} release_version=${base_version} snapshot_version=${base_version}-SNAPSHOT |