aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-10-03 16:14:05 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-10-03 15:29:30 +0000
commitae980791d1996041592fd45a56cfdce7801cecfa (patch)
treea6dde540ff0e7c0d122eab83310787434d92dcb5
parentbb8c570ba261dedbfc9972bfb08efccd41d130d2 (diff)
Fix minor Sonar Issues for clamp/acm
Issue-ID: POLICY-4834 Change-Id: I17efea9b14bb39d7abbafa4f3b695b0451a08c68 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java11
-rwxr-xr-xmodels/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java4
-rwxr-xr-xmodels/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java3
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartStoreTest.java34
-rwxr-xr-xparticipant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java5
-rwxr-xr-xruntime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java2
-rwxr-xr-xruntime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java2
-rwxr-xr-xruntime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java23
8 files changed, 40 insertions, 44 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
index ff580c7c2..0053ca0ca 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/document/base/ToscaServiceTemplateValidation.java
@@ -38,6 +38,7 @@ import org.onap.policy.models.base.Validated;
public final class ToscaServiceTemplateValidation {
private static final String ROOT_KEY_NAME_SUFFIX = ".Root";
+ private static final String TOPOLOGY_TEMPLATE = "TopologyTemplate";
/**
* validate a serviceTemplate.
@@ -91,9 +92,9 @@ public final class ToscaServiceTemplateValidation {
/**
* Validate ToscaTopologyTemplate.
*
- * @param result
- *
+ * @param result the BeanValidationResult
* @param topologyTemplate the ToscaServiceTemplate
+ * @param toscaCompositionName the name of the ToscaComposition
*/
public static void validateToscaTopologyTemplate(BeanValidationResult result,
DocToscaTopologyTemplate topologyTemplate, String toscaCompositionName) {
@@ -106,14 +107,14 @@ public final class ToscaServiceTemplateValidation {
nodeTemplate -> toscaCompositionName.equals(nodeTemplate.getType()))
.count();
if (acNumber == 0) {
- result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, acNodeTypeNotPresent);
+ result.addResult(TOPOLOGY_TEMPLATE, nodeTemplates, ValidationStatus.INVALID, acNodeTypeNotPresent);
}
if (acNumber > 1) {
- result.addResult("TopologyTemplate", nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type "
+ result.addResult(TOPOLOGY_TEMPLATE, nodeTemplates, ValidationStatus.INVALID, "NodeTemplate with type "
+ toscaCompositionName + " not allowed to be more than one!");
}
} else {
- result.addResult("TopologyTemplate", topologyTemplate, ValidationStatus.INVALID, acNodeTypeNotPresent);
+ result.addResult(TOPOLOGY_TEMPLATE, topologyTemplate, ValidationStatus.INVALID, acNodeTypeNotPresent);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
index a518c4908..a9b9a0cfd 100755
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
@@ -72,8 +72,8 @@ public class AcDefinitionProvider {
}
acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.COMMISSIONED));
var jpaAcmDefinition = ProviderUtils.getJpaAndValidate(acmDefinition, JpaAutomationCompositionDefinition::new,
- "AutomationCompositionDefinition");
- var validationResult = new BeanValidationResult("AutomationCompositionDefinition", acmDefinition);
+ acmDefinition.getClass().getSimpleName());
+ var validationResult = new BeanValidationResult(acmDefinition.getClass().getSimpleName(), acmDefinition);
ToscaServiceTemplateValidation.validate(validationResult, jpaAcmDefinition.getServiceTemplate(),
toscaCompositionName);
if (! validationResult.isValid()) {
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
index 4d4b25b77..6ba6ac016 100755
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
-import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.onap.policy.common.parameters.BeanValidationResult;
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartStoreTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartStoreTest.java
index 70f80c8a7..b7e0f49dc 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartStoreTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/service/ChartStoreTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -88,25 +88,25 @@ class ChartStoreTest {
@Test
void test_getHelmChartFile() {
- File file = chartStore.getHelmChartFile(charts.get(0));
+ var file = chartStore.getHelmChartFile(charts.get(0));
assertNotNull(file);
assertThat(file.getPath()).endsWith(charts.get(0).getChartId().getName());
}
@Test
void test_getOverrideFile() {
- File file = chartStore.getOverrideFile(charts.get(0));
+ var file = chartStore.getOverrideFile(charts.get(0));
assertNotNull(file);
assertThat(file.getPath()).endsWith("values.yaml");
}
@Test
void test_saveChart() throws IOException, ServiceException {
- MockMultipartFile mockChartFile = new MockMultipartFile("chart", "dummy".getBytes());
- MockMultipartFile mockOverrideFile = new MockMultipartFile("override", "dummy".getBytes());
- ChartInfo testChart = charts.get(0);
+ var mockChartFile = new MockMultipartFile("chart", "dummy".getBytes());
+ var mockOverrideFile = new MockMultipartFile("override", "dummy".getBytes());
+ var testChart = charts.get(0);
testChart.setChartId(new ToscaConceptIdentifier("testChart", "1.0.0"));
- ChartInfo result = chartStore.saveChart(charts.get(0), mockChartFile, mockOverrideFile);
+ var result = chartStore.saveChart(charts.get(0), mockChartFile, mockOverrideFile);
assertThat(result.getChartId().getName()).isEqualTo("testChart");
assertThat(chartStore.getLocalChartMap()).hasSize(1);
@@ -121,7 +121,7 @@ class ChartStoreTest {
assertNull(chartStore.getChart(charts.get(0).getChartId().getName(), charts.get(0).getChartId().getVersion()));
chartStore.getLocalChartMap().put(charts.get(0).getChartId().getName() + "_" + charts.get(0).getChartId()
.getVersion(), charts.get(0));
- ChartInfo chart = chartStore.getChart(charts.get(0).getChartId().getName(),
+ var chart = chartStore.getChart(charts.get(0).getChartId().getName(),
charts.get(0).getChartId().getVersion());
assertThat(chart.getChartId().getName()).isEqualTo(charts.get(0).getChartId().getName());
}
@@ -131,13 +131,13 @@ class ChartStoreTest {
// When the chart store is empty before adding any charts
assertThat(chartStore.getAllCharts()).isEmpty();
- for (ChartInfo chart : charts) {
+ for (var chart : charts) {
chartStore.getLocalChartMap().put(chart.getChartId().getName() + "_" + chart.getChartId().getVersion(),
chart);
}
- List<ChartInfo> retrievedChartList = chartStore.getAllCharts();
- assertThat(retrievedChartList).isNotEmpty();
- assertThat(retrievedChartList).hasSameSizeAs(charts);
+ var retrievedChartList = chartStore.getAllCharts();
+ assertThat(retrievedChartList).isNotEmpty()
+ .hasSameSizeAs(charts);
}
@Test
@@ -151,7 +151,7 @@ class ChartStoreTest {
@Test
void test_getAppPath() {
- Path path = chartStore.getAppPath(charts.get(0).getChartId());
+ var path = chartStore.getAppPath(charts.get(0).getChartId());
assertNotNull(path);
assertThat(path.toString()).endsWith(charts.get(0).getChartId().getVersion());
assertThat(path.toString()).startsWith("target");
@@ -159,16 +159,16 @@ class ChartStoreTest {
@Test
void test_chartSoreInstantiationWithExistingChartFiles() throws IOException, ServiceException {
- MockMultipartFile mockChartFile = new MockMultipartFile("HelmChartFile", "dummyData".getBytes());
- MockMultipartFile mockOverrideFile = new MockMultipartFile("overrideFile.yaml", "dummyData".getBytes());
- ChartInfo testChart = charts.get(0);
+ var mockChartFile = new MockMultipartFile("HelmChartFile", "dummyData".getBytes());
+ var mockOverrideFile = new MockMultipartFile("overrideFile.yaml", "dummyData".getBytes());
+ var testChart = charts.get(0);
testChart.setChartId(new ToscaConceptIdentifier("dummyChart", "1.0.0"));
//Creating a dummy chart in local dir.
chartStore.saveChart(charts.get(0), mockChartFile, mockOverrideFile);
//Instantiating a new chartStore object with pre available chart in local.
- ChartStore chartStore2 = new ChartStore(parameters);
+ var chartStore2 = new ChartStore(parameters);
assertThat(chartStore2.getLocalChartMap()).hasSize(1).containsKey("dummyChart_" + charts.get(0).getChartId()
.getVersion());
}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java
index f0e0d65bb..6429d062e 100755
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/client/AbstractHttpClient.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
-import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
@@ -36,7 +35,7 @@ import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class AbstractHttpClient implements Closeable {
+public abstract class AbstractHttpClient implements AutoCloseable {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractHttpClient.class);
private final HttpClient httpclient;
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java
index a1ad82945..5af3ca2a1 100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/contract/ParticipantControllerStubTest.java
@@ -37,7 +37,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ "test", "stub" })
-public class ParticipantControllerStubTest extends CommonRestController {
+class ParticipantControllerStubTest extends CommonRestController {
private static final String PARTICIPANT_ENDPOINT = "participants";
private static final String PARTICIPANT_ID = "101c62b3-8918-41b9-a747-d21eb79c6c03";
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 87e00da93..06bedabde 100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -244,8 +244,6 @@ class SupervisionMessagesTest {
publisher.active(List.of(topicSink));
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
- // serviceTemplate.setName("Name");
- // serviceTemplate.setVersion("1.0.0");
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
acmDefinition.setServiceTemplate(serviceTemplate);
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java
index fec0f216e..0df9719c2 100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/rest/CommonRestController.java
@@ -20,13 +20,12 @@
package org.onap.policy.clamp.acm.runtime.util.rest;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
-import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientProperties;
@@ -53,10 +52,10 @@ public class CommonRestController {
* @param endpoint the endpoint of interest
*/
protected void testSwagger(final String endpoint) {
- // final Invocation.Builder invocationBuilder = sendActRequest("v3/api-docs");
- // final String resp = invocationBuilder.get(String.class);
+ final var invocationBuilder = sendActRequest("v3/api-docs");
+ final var resp = invocationBuilder.get(String.class);
- // assertThat(resp).contains(endpoint);
+ assertThat(resp).contains(endpoint);
}
/**
@@ -107,7 +106,7 @@ public class CommonRestController {
* @return a request builder
*/
protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
- final Client client = ClientBuilder.newBuilder().build();
+ final var client = ClientBuilder.newBuilder().build();
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
client.register(GsonMessageBodyHandler.class);
@@ -116,7 +115,7 @@ public class CommonRestController {
client.register(HttpAuthenticationFeature.basic("runtimeUser", "zb!XztG34"));
}
- final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
+ final var webTarget = client.target(fullyQualifiedEndpoint);
return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
}
@@ -128,7 +127,7 @@ public class CommonRestController {
* @param entity the entity ofthe body
*/
protected void assertUnauthorizedPost(final String endPoint, final Entity<?> entity) {
- Response rawresp = sendNoAuthRequest(endPoint).post(entity);
+ var rawresp = sendNoAuthRequest(endPoint).post(entity);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
@@ -139,7 +138,7 @@ public class CommonRestController {
* @param entity the entity ofthe body
*/
protected void assertUnauthorizedPut(final String endPoint, final Entity<?> entity) {
- Response rawresp = sendNoAuthRequest(endPoint).put(entity);
+ var rawresp = sendNoAuthRequest(endPoint).put(entity);
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
@@ -149,7 +148,7 @@ public class CommonRestController {
* @param endPoint the endpoint
*/
protected void assertUnauthorizedGet(final String endPoint) {
- Response rawresp = sendNoAuthRequest(endPoint).buildGet().invoke();
+ var rawresp = sendNoAuthRequest(endPoint).buildGet().invoke();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
@@ -159,7 +158,7 @@ public class CommonRestController {
* @param endPoint the endpoint
*/
protected void assertUnauthorizedActGet(final String endPoint) {
- Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
+ var rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}
@@ -169,7 +168,7 @@ public class CommonRestController {
* @param endPoint the endpoint
*/
protected void assertUnauthorizedDelete(final String endPoint) {
- Response rawresp = sendNoAuthRequest(endPoint).delete();
+ var rawresp = sendNoAuthRequest(endPoint).delete();
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
}