summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/pom.xml2
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java2
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java24
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java2
-rw-r--r--models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java43
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java2
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java84
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java9
-rw-r--r--models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java54
9 files changed, 212 insertions, 10 deletions
diff --git a/models/pom.xml b/models/pom.xml
index c5eea9c73..c534a16f4 100644
--- a/models/pom.xml
+++ b/models/pom.xml
@@ -27,7 +27,7 @@
<parent>
<groupId>org.onap.policy.clamp</groupId>
<artifactId>policy-clamp</artifactId>
- <version>6.1.3-SNAPSHOT</version>
+ <version>6.2.0-SNAPSHOT</version>
</parent>
<artifactId>policy-clamp-models</artifactId>
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java
index 4d3d37236..cf22b7228 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java
@@ -107,7 +107,7 @@ public class ControlLoop extends ToscaEntity implements Comparable<ControlLoop>
*/
public List<ClElementStatistics> getControlLoopElementStatisticsList(final ControlLoop controlLoop) {
if (MapUtils.isEmpty(controlLoop.elements)) {
- return null;
+ return List.of();
}
return controlLoop.elements.values().stream().map(ControlLoopElement::getClElementStatistics)
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
index 4c3dd4b06..c05311892 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java
@@ -57,6 +57,30 @@ public final class ParticipantUtils {
}
/**
+ * Get the First StartPhase
+ * it depend of the state of the Control Loop
+ * and also from the all startPhase defined into the ToscaServiceTemplate.
+ * @param controlLoop the ControlLoop
+ * @param toscaServiceTemplate the ToscaServiceTemplate
+ * @return the First StartPhase
+ */
+ public static int getFirstStartPhase(ControlLoop controlLoop, ToscaServiceTemplate toscaServiceTemplate) {
+ var minStartPhase = 1000;
+ var maxStartPhase = 0;
+ for (var element : controlLoop.getElements().values()) {
+ ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()
+ .get(element.getDefinition().getName());
+ int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
+ minStartPhase = Math.min(minStartPhase, startPhase);
+ maxStartPhase = Math.max(maxStartPhase, startPhase);
+ }
+
+ return ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())
+ || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? minStartPhase
+ : maxStartPhase;
+ }
+
+ /**
* Finds startPhase from a map of properties.
*
* @param properties Map of properties
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java
index 993c6e592..4d2dfaf01 100644
--- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java
@@ -24,8 +24,6 @@ import java.util.List;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
-import org.onap.policy.clamp.controlloop.models.messages.rest.GenericNameVersion;
import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse;
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java
new file mode 100644
index 000000000..6c12c2de7
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.rest;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse;
+import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
+import org.springframework.http.ResponseEntity;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RestUtils {
+
+ /**
+ * Convert an ErrorResponseInfo to a ResponseEntity.
+ *
+ * @param ex the ErrorResponseInfo
+ * @return the ResponseEntity
+ */
+ public static ResponseEntity<SimpleResponse> toSimpleResponse(ErrorResponseInfo ex) {
+ var resp = new SimpleResponse();
+ resp.setErrorDetails(ex.getErrorResponse().getErrorMessage());
+ return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp);
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
index 51a4fc7ae..d9c518b53 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java
@@ -107,7 +107,7 @@ class ControlLoopTest {
void testControlLoopElementStatisticsList() {
var cl = new ControlLoop();
List<ClElementStatistics> emptylist = cl.getControlLoopElementStatisticsList(cl);
- assertNull(emptylist);
+ assertEquals(List.of(), emptylist);
var cl1 = getControlLoopTest();
List<ClElementStatistics> list = cl1.getControlLoopElementStatisticsList(cl1);
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java
new file mode 100644
index 000000000..3fb8b6d7f
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.controlloop.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+
+class ParticipantUtilsTest {
+
+ private static final Coder CODER = new StandardCoder();
+ private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml";
+ private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json";
+ private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement";
+ private static final String POLICY_CONTROL_LOOP_ELEMENT =
+ "org.onap.policy.clamp.controlloop.PolicyControlLoopElement";
+ private static final String PARTICIPANT_CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.Participant";
+ private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
+
+ @Test
+ void testFindParticipantType() throws CoderException {
+ var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1");
+ var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier)));
+ assertThat(result).isEqualTo(identifier);
+ }
+
+ @Test
+ void testFindStartPhase() {
+ var identifier = 13;
+ var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier));
+ assertThat(result).isEqualTo(identifier);
+ }
+
+ @Test
+ void testGetFirstStartPhase() throws CoderException {
+ var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML),
+ ToscaServiceTemplate.class);
+ var controlLoops = CODER.decode(ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON), ControlLoops.class);
+ var result = ParticipantUtils.getFirstStartPhase(controlLoops.getControlLoopList().get(0), serviceTemplate);
+ assertThat(result).isZero();
+ }
+
+ @Test
+ void testCheckIfNodeTemplateIsControlLoopElement() throws CoderException {
+ var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML),
+ ToscaServiceTemplate.class);
+ var nodeTemplate = new ToscaNodeTemplate();
+ nodeTemplate.setType(CONTROL_LOOP_ELEMENT);
+ assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue();
+
+ nodeTemplate.setType(POLICY_CONTROL_LOOP_ELEMENT);
+ assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue();
+
+ nodeTemplate.setType(PARTICIPANT_CONTROL_LOOP_ELEMENT);
+ assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isFalse();
+ }
+}
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java
index a4cbbfb0b..7f2731abf 100644
--- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java
@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -78,7 +77,7 @@ class ServiceTemplateProviderTest {
var serviceTemplateProvider = new ServiceTemplateProvider(modelsProvider);
var serviceTemplate = new ToscaServiceTemplate();
- when(modelsProvider.createServiceTemplate(eq(serviceTemplate))).thenReturn(serviceTemplate);
+ when(modelsProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
var result = serviceTemplateProvider.createServiceTemplate(serviceTemplate);
@@ -91,7 +90,7 @@ class ServiceTemplateProviderTest {
serviceTemplate.setName("Name");
serviceTemplate.setVersion("1.0.0");
var modelsProvider = mock(PolicyModelsProvider.class);
- when(modelsProvider.deleteServiceTemplate(eq(serviceTemplate.getName()), eq(serviceTemplate.getVersion())))
+ when(modelsProvider.deleteServiceTemplate(serviceTemplate.getName(), serviceTemplate.getVersion()))
.thenReturn(serviceTemplate);
var serviceTemplateProvider = new ServiceTemplateProvider(modelsProvider);
@@ -117,7 +116,7 @@ class ServiceTemplateProviderTest {
serviceTemplate.setName("Name");
serviceTemplate.setVersion("1.0.0");
var modelsProvider = mock(PolicyModelsProvider.class);
- when(modelsProvider.getServiceTemplateList(eq(serviceTemplate.getName()), eq(serviceTemplate.getVersion())))
+ when(modelsProvider.getServiceTemplateList(serviceTemplate.getName(), serviceTemplate.getVersion()))
.thenReturn(List.of(serviceTemplate));
var serviceTemplateProvider = new ServiceTemplateProvider(modelsProvider);
@@ -133,7 +132,7 @@ class ServiceTemplateProviderTest {
serviceTemplate.setName("Name");
serviceTemplate.setVersion("1.0.0");
var modelsProvider = mock(PolicyModelsProvider.class);
- when(modelsProvider.getServiceTemplateList(eq(serviceTemplate.getName()), eq(serviceTemplate.getVersion())))
+ when(modelsProvider.getServiceTemplateList(serviceTemplate.getName(), serviceTemplate.getVersion()))
.thenReturn(List.of(serviceTemplate));
var serviceTemplateProvider = new ServiceTemplateProvider(modelsProvider);
diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java
new file mode 100644
index 000000000..4dedae200
--- /dev/null
+++ b/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.rest;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import javax.ws.rs.core.Response.Status;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.models.errors.concepts.ErrorResponse;
+import org.onap.policy.models.errors.concepts.ErrorResponseInfo;
+
+class RestUtilsTest {
+
+ private static final String MESSAGE_ERROR = "Erorr";
+ private static final Status STATUS_ERROR = Status.BAD_REQUEST;
+
+ @Test
+ void testToSimpleResponse() {
+ var ex = new ErrorResponseInfo() {
+
+ @Override
+ public ErrorResponse getErrorResponse() {
+ var er = new ErrorResponse();
+ er.setErrorMessage(MESSAGE_ERROR);
+ er.setResponseCode(STATUS_ERROR);
+ return er;
+ }
+ };
+
+ var response = RestUtils.toSimpleResponse(ex);
+
+ assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode());
+ assertThat(response.getBody()).isNotNull();
+ assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR);
+ }
+}