diff options
Diffstat (limited to 'runtime-controlloop')
11 files changed, 37 insertions, 32 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java index 74b5394f4..fbfc1de69 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -500,7 +501,7 @@ public class CommissioningProvider { * * @return true if exists instance properties */ - private Boolean verifyIfInstancePropertiesExists() { + private boolean verifyIfInstancePropertiesExists() { return clProvider.getNodeTemplates(null, null).stream() .anyMatch(nodeTemplate -> nodeTemplate.getKey().getName().contains("_Instance")); diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java index da85b0a83..a71772624 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -58,6 +59,8 @@ import org.springframework.stereotype.Component; @Component @AllArgsConstructor public class ControlLoopInstantiationProvider { + private static final String INSTANCE_TEXT = "_Instance"; + private final ControlLoopProvider controlLoopProvider; private final CommissioningProvider commissioningProvider; private final SupervisionHandler supervisionHandler; @@ -350,12 +353,12 @@ public class ControlLoopInstantiationProvider { int instanceNumber = nodeTemplates.stream().map(ToscaNodeTemplate::getName) - .filter(name -> name.contains("_Instance")).map(n -> { - String[] defNameArr = n.split("_Instance"); + .filter(name -> name.contains(INSTANCE_TEXT)).map(n -> { + String[] defNameArr = n.split(INSTANCE_TEXT); return Integer.parseInt(defNameArr[1]); }).reduce(0, Math::max); - return "_Instance" + (instanceNumber + 1); + return INSTANCE_TEXT + (instanceNumber + 1); } } diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java index d2a85c46d..5a8275f8a 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -186,8 +187,7 @@ public class InstantiationController extends AbstractRestController { @RequestHeader( name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body) - throws PfModelException { + @ApiParam(value = "Body of instance properties", required = true) @RequestBody ToscaServiceTemplate body) { return ResponseEntity.ok().body(provider.saveInstanceProperties(body)); } diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java index c68b7fd49..789e4fa92 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java @@ -1,8 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -217,10 +216,9 @@ public class SupervisionHandler { * Supervise a control loop, performing whatever actions need to be performed on the control loop. * * @param controlLoop the control loop to supervises - * @throws PfModelException on accessing models in the database * @throws ControlLoopException on supervision errors */ - private void superviseControlLoop(ControlLoop controlLoop) throws ControlLoopException, PfModelException { + private void superviseControlLoop(ControlLoop controlLoop) throws ControlLoopException { switch (controlLoop.getOrderedState()) { case UNINITIALISED: superviseControlLoopUninitialization(controlLoop); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java index 5c49b8523..3e038f3fc 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -231,7 +232,7 @@ class CommissioningProviderTest { mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); - Map<String, Class> sections = Map.of( + Map<String, Class<?>> sections = Map.of( "all", ToscaServiceTemplate.class, "data_types", ToscaDataType.class, "capability_types", ToscaCapabilityType.class, @@ -241,7 +242,7 @@ class CommissioningProviderTest { "topology_template", ToscaTopologyTemplate.class, "node_templates", List.class); - for (Map.Entry<String, Class> entry : sections.entrySet()) { + for (Map.Entry<String, Class<?>> entry : sections.entrySet()) { String returnedServiceTemplateSchema = provider.getToscaServiceTemplateSchema(entry.getKey()); assertThat(returnedServiceTemplateSchema).isNotNull(); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java index 58ae1f658..481192927 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -176,7 +177,10 @@ class CommissioningControllerTest extends CommonRestController { + "/getCommonOrInstanceProperties" + "?common=true&name=ToscaServiceTemplateSimple&version=1.0.0"); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); + + @SuppressWarnings("unchecked") Map<String, ToscaNodeTemplate> commonProperties = rawresp.readEntity(Map.class); + assertNotNull(commonProperties); assertThat(commonProperties).hasSize(6); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java index d1aaddc5a..f136b9f10 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -55,10 +56,8 @@ import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.provider.PolicyModelsProvider; -import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.springframework.beans.factory.annotation.Autowired; /** * Class to perform unit test of {@link ControlLoopInstantiationProvider}}. diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java index 41c55dd2d..a6756eece 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -28,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; import javax.ws.rs.core.Response; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java index 3ac6b6fa4..2fcbf1297 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/monitoring/TestMonitoringProvider.java @@ -1,8 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -25,7 +24,6 @@ package org.onap.policy.clamp.controlloop.runtime.monitoring; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import java.io.File; diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java index b31aa8e4f..f5ab9f28d 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionAspectTest.java @@ -1,8 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -22,7 +21,6 @@ package org.onap.policy.clamp.controlloop.runtime.supervision; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java index 64bf6b009..260ccfb35 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -20,6 +21,8 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm; +import static org.assertj.core.api.Assertions.assertThatCode; + import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -68,15 +71,12 @@ class SupervisionMessagesTest extends CommonRestController { private static final Object lockit = new Object(); private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; private static final String TOPIC = "my-topic"; - private static final long interval = 1000; private static SupervisionHandler supervisionHandler; private static CommissioningProvider commissioningProvider; private static ControlLoopProvider clProvider; private static PolicyModelsProvider modelsProvider; private static ParticipantProvider participantProvider; private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - private static final String TOSCA_TEMPLATE_YAML = - "src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml"; private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement"; private static final Coder CODER = new StandardCoder(); @@ -132,7 +132,8 @@ class SupervisionMessagesTest extends CommonRestController { // List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null); commissioningProvider.createControlLoopDefinitions(serviceTemplate); - participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg); + assertThatCode(() -> participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg)) + .doesNotThrowAnyException(); } } @@ -146,7 +147,7 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantRegisterAckPublisher clRegisterAckPublisher = new ParticipantRegisterAckPublisher(); clRegisterAckPublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); - clRegisterAckPublisher.send(participantRegisterAckMsg); + assertThatCode(() -> clRegisterAckPublisher.send(participantRegisterAckMsg)).doesNotThrowAnyException(); } } @@ -159,8 +160,9 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantDeregisterListener participantDeregisterListener = - new ParticipantDeregisterListener(supervisionHandler); - participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg); + new ParticipantDeregisterListener(supervisionHandler); + assertThatCode(() -> participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, + participantDeregisterMsg)).doesNotThrowAnyException(); } } @@ -174,7 +176,7 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantDeregisterAckPublisher clDeregisterAckPublisher = new ParticipantDeregisterAckPublisher(); clDeregisterAckPublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); - clDeregisterAckPublisher.send(participantDeregisterAckMsg); + assertThatCode(() -> clDeregisterAckPublisher.send(participantDeregisterAckMsg)).doesNotThrowAnyException(); } } @@ -210,7 +212,7 @@ class SupervisionMessagesTest extends CommonRestController { ParticipantUpdatePublisher participantUpdatePublisher = new ParticipantUpdatePublisher(modelsProvider); participantUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); - participantUpdatePublisher.send(participantUpdateMsg); + assertThatCode(() -> participantUpdatePublisher.send(participantUpdateMsg)).doesNotThrowAnyException(); } } @@ -260,8 +262,9 @@ class SupervisionMessagesTest extends CommonRestController { synchronized (lockit) { ParticipantUpdateAckListener participantUpdateAckListener = - new ParticipantUpdateAckListener(supervisionHandler); - participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg); + new ParticipantUpdateAckListener(supervisionHandler); + assertThatCode(() -> participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg)) + .doesNotThrowAnyException(); } } |