Fix broken test coverage 60/132560/1
authorvasraz <vasyl.razinkov@est.tech>
Thu, 1 Dec 2022 17:59:50 +0000 (17:59 +0000)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Thu, 1 Dec 2022 18:06:18 +0000 (18:06 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I005c1e2bd4a064118c652eff77fbe2e737995270
Issue-ID: SDC-4285

jtosca/pom.xml
pom.xml
sdc-tosca/pom.xml
sdc-tosca/src/main/java/org/onap/sdc/tosca/parser/impl/QueryProcessor.java
sdc-tosca/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java

index 041b8bb..1242668 100644 (file)
                     <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
                 </configuration>
             </plugin>
-            <!-- Test -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <argLine>${argLine} -Xmx2048m</argLine>
-                    <includes>
-                        <include>*/*</include>
-                    </includes>
-                </configuration>
-            </plugin>
             <plugin>
                 <groupId>com.github.sylvainlaurent.maven</groupId>
                 <artifactId>yaml-json-validator-maven-plugin</artifactId>
diff --git a/pom.xml b/pom.xml
index fb337db..1e69a01 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <releases.path>releases</releases.path>
 
         <!-- Sonar properties -->
+        <sonar.coverage.exclusions>pom.xml,src/test</sonar.coverage.exclusions>
+        <sonar.coverage.jacoco.xmlReportPaths>${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
+        <sonar.exclusions>**/scripts/**/*</sonar.exclusions>
+        <sonar.inclusions>app/**/*.js,server-mock/**/*.js,src/**/*.js,src/main/**/*.java</sonar.inclusions>
+        <sonar.javascript.lcov.reportPaths>${project.build.directory}/code-coverage/lcov.info</sonar.javascript.lcov.reportPaths>
         <sonar.language>java</sonar.language>
-        <sonar.coverage.jacoco.xmlReportPaths>
-            ${project.reporting.outputDirectory}/jacoco-ut/jacoco.xml
-        </sonar.coverage.jacoco.xmlReportPaths>
-        <sonar.sourceEncoding>${project.build.sourceEncoding}</sonar.sourceEncoding>
+        <sonar.nodejs.executable>${project.basedir}/node/node</sonar.nodejs.executable>
         <sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
+        <sonar.projectVersion>${project.version}</sonar.projectVersion>
+        <sonar.sourceEncoding>${project.build.sourceEncoding}</sonar.sourceEncoding>
         <sonar.sources>.</sonar.sources>
-        <sonar.exclusions>**/scripts/**/*</sonar.exclusions>
+        <sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
         <sonar.test.exclusions>**/test/**/*,**/tests/**/*</sonar.test.exclusions>
-        <sonar.inclusions>app/**/*.js,server-mock/**/*.js,src/**/*.js,src/main/**/*.java</sonar.inclusions>
 
         <lombok.version>1.18.20</lombok.version>
         <!--TESTING-->
@@ -60,6 +63,8 @@
         <mockitoJupiter.version>${mockito.version}</mockitoJupiter.version>
         <junit.platform.version>1.8.2</junit.platform.version>
         <junitJupiter.version>5.8.2</junitJupiter.version>
+        <!--jacoco-->
+        <jacoco.version>0.8.8</jacoco.version>
     </properties>
 
     <dependencyManagement>
     </dependencyManagement>
 
     <dependencies>
+        <dependency>
+            <!-- must be on the classpath -->
+            <groupId>org.jacoco</groupId>
+            <artifactId>org.jacoco.agent</artifactId>
+            <classifier>runtime</classifier>
+            <version>${jacoco.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
     <build>
         <pluginManagement>
             <plugins>
+                <plugin>
+                    <groupId>org.jacoco</groupId>
+                    <artifactId>jacoco-maven-plugin</artifactId>
+                    <version>${jacoco.version}</version>
+                </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
                     <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
                     <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
+                    <skip>true</skip>
                 </configuration>
             </plugin>
 
+            <!-- Java Code Coverage -->
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
-                <version>0.8.8</version>
+                <inherited>false</inherited>
                 <executions>
-                    <!-- Unit-Tests -->
                     <execution>
-                        <id>prepare-agent</id>
+                        <id>default-instrument</id>
+                        <goals>
+                            <goal>instrument</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>default-restore-instrumented-classes</id>
                         <goals>
-                            <goal>prepare-agent</goal>
+                            <goal>restore-instrumented-classes</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>default-report</id>
+                        <goals>
+                            <goal>report</goal>
                         </goals>
                         <configuration>
-                            <destFile>${sonar.jacoco.reportPath}</destFile>
+                            <dataFile>${project.build.directory}/jacoco.exec</dataFile>
                         </configuration>
                     </execution>
                 </executions>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.maven.surefire</groupId>
+                        <artifactId>surefire-junit-platform</artifactId>
+                        <version>2.22.2</version>
+                    </dependency>
+                </dependencies>
                 <configuration>
-                    <argLine>${argLine} -Xmx2048m</argLine>
+                    <printSummary>false</printSummary>
+                    <systemPropertyVariables>
+                        <jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
+                    </systemPropertyVariables>
                 </configuration>
             </plugin>
 
-            <plugin>
-                <groupId>org.sonarsource.scanner.maven</groupId>
-                <artifactId>sonar-maven-plugin</artifactId>
-                <version>3.7.0.1746</version>
-            </plugin>
-
             <plugin>
                 <groupId>com.github.sylvainlaurent.maven</groupId>
                 <artifactId>yaml-json-validator-maven-plugin</artifactId>
index 8bd4018..da94217 100644 (file)
                 </configuration>
             </plugin>
 
-            <plugin>
-                <groupId>org.jacoco</groupId>
-                <artifactId>jacoco-maven-plugin</artifactId>
-                <version>0.8.6</version>
-                <executions>
-                    <!-- Unit-Tests -->
-                    <execution>
-                        <id>prepare-agent</id>
-                        <goals>
-                            <goal>prepare-agent</goal>
-                        </goals>
-                        <configuration>
-                            <destFile>${sonar.jacoco.reportPath}</destFile>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-
-            <!-- Test -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <argLine>${argLine} -Xmx2048m</argLine>
-                    <includes>
-                        <include>**/ToscaParser***Test.class</include>
-                    </includes>
-                </configuration>
-            </plugin>
-
             <plugin>
                 <groupId>com.github.sylvainlaurent.maven</groupId>
                 <artifactId>yaml-json-validator-maven-plugin</artifactId>
index 5bbd2aa..bd34afe 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -20,7 +20,7 @@
 
 package org.onap.sdc.tosca.parser.impl;
 
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
  * Performs search for entity templates inside node template according to query criteria
  */
 class QueryProcessor {
+
     private static final Logger logger = LoggerFactory.getLogger(QueryProcessor.class.getName());
 
     private final EntityQuery entityQuery;
@@ -53,7 +54,7 @@ class QueryProcessor {
     }
 
     List<IEntityDetails> doQuery() {
-        final List<IEntityDetails> entityDetailsList = Collections.emptyList();
+        final List<IEntityDetails> entityDetailsList = new ArrayList<>();
         if (isServiceSearch()) {
             //search for entities inside the service
             if (logger.isDebugEnabled()) {
@@ -75,15 +76,15 @@ class QueryProcessor {
             // and search for instances of the same type
             //if the queried topology template is "SERVICE",  search for all instances of templates in the service
             List<NodeTemplate> internalTopologyTemplates = foundTopologyTemplates.stream()
-                    .filter(nt->nt.getSubMappingToscaTemplate() != null)
-                    .map(nt->getInternalTopologyTemplates(nt.getSubMappingToscaTemplate().getNodeTemplates(), true))
-                    .flatMap(List::stream)
-                    .collect(Collectors.toList());
+                .filter(nt -> nt.getSubMappingToscaTemplate() != null)
+                .map(nt -> getInternalTopologyTemplates(nt.getSubMappingToscaTemplate().getNodeTemplates(), true))
+                .flatMap(List::stream)
+                .collect(Collectors.toList());
             foundTopologyTemplates.addAll(internalTopologyTemplates);
         }
         if (logger.isDebugEnabled()) {
             logger.debug("Found topology templates {} matching following query criteria: {}",
-                    foundTopologyTemplates, topologyTemplateQuery);
+                foundTopologyTemplates, topologyTemplateQuery);
         }
         //go over all node templates found according to query criteria and recursive flag and
         // search for the requested entities.
@@ -95,16 +96,16 @@ class QueryProcessor {
     private Map<String, NodeTemplate> convertListToMap(List<NodeTemplate> nodeTemplateList) {
         // we use map to avoid duplicate search through same node templates
         return nodeTemplateList.stream()
-                .collect(Collectors.toMap(NodeTemplate::getName, nt->nt, (nt1, nt2)->nt1));
+            .collect(Collectors.toMap(NodeTemplate::getName, nt -> nt, (nt1, nt2) -> nt1));
     }
 
     private List<IEntityDetails> searchEntitiesInsideTopologyTemplates(List<NodeTemplate> foundTopologyTemplates) {
         return convertListToMap(foundTopologyTemplates)
-                .values()
-                .stream()
-                .map(entityQuery::getEntitiesFromTopologyTemplate)
-                .flatMap(List::stream)
-                .collect(Collectors.toList());
+            .values()
+            .stream()
+            .map(entityQuery::getEntitiesFromTopologyTemplate)
+            .flatMap(List::stream)
+            .collect(Collectors.toList());
     }
 
     private boolean isServiceSearch() {
@@ -119,15 +120,15 @@ class QueryProcessor {
                 .flatMap(List::stream)
                 .collect(Collectors.toList());
         }
-        return Collections.emptyList();
+        return new ArrayList<>();
     }
 
     private List<NodeTemplate> getTopologyTemplatesByQuery(NodeTemplate current, boolean isRecursive) {
-        final List<NodeTemplate> topologyTemplateList = Collections.emptyList();
+        final List<NodeTemplate> topologyTemplateList = new ArrayList<>();
 
         boolean isTopologyTemplateFound = isRecursive ?
-                SdcTypes.isComplex(current.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))
-                : topologyTemplateQuery.isMatchingSearchCriteria(current);
+            SdcTypes.isComplex(current.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE))
+            : topologyTemplateQuery.isMatchingSearchCriteria(current);
         if (isTopologyTemplateFound) {
             topologyTemplateList.add(current);
             if (!isRecursive) {
@@ -136,13 +137,13 @@ class QueryProcessor {
             }
         }
         if (SdcTypes.isComplex(current.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)) &&
-               current.getSubMappingToscaTemplate() != null) {
-           //search the node template inside a given topology template
+            current.getSubMappingToscaTemplate() != null) {
+            //search the node template inside a given topology template
             topologyTemplateList.addAll(current.getSubMappingToscaTemplate().getNodeTemplates()
-                    .stream()
-                    .map(nt->getTopologyTemplatesByQuery(nt, isRecursive))
-                    .flatMap(List::stream)
-                    .collect(Collectors.toList()));
+                .stream()
+                .map(nt -> getTopologyTemplatesByQuery(nt, isRecursive))
+                .flatMap(List::stream)
+                .collect(Collectors.toList()));
         }
         return topologyTemplateList;
     }
index afa1c64..c12dcf7 100644 (file)
@@ -128,7 +128,6 @@ public class EntityQueryTest {
                 .uUID("7890")
                 .build();
         when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
-        when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
 
         assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
     }
@@ -176,7 +175,6 @@ public class EntityQueryTest {
                 .customizationUUID("345")
                 .build();
         when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("12345");
-        when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("3456");
 
         assertFalse(entityQuery.isSearchCriteriaMatched(metadata, "a.groups.b"));
     }