import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class AutomationCompositionElementTest {
ace1.setDescription("Description");
ace1.setId(UUID.randomUUID());
ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- ace1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3"));
+ ace1.setParticipantId(CommonTestData.getParticipantId());
ace1.setState(AutomationCompositionState.UNINITIALISED);
var ace2 = new AutomationCompositionElement(ace1);
ace1.setDescription("Description");
ace1.setId(UUID.randomUUID());
ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- ace1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3"));
+ ace1.setParticipantId(CommonTestData.getParticipantId());
ace1.setState(AutomationCompositionState.UNINITIALISED);
assertThat(ace1.toString()).contains("AutomationCompositionElement(");
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementAck;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
removeVariableFields(new AutomationCompositionAck(orig).toString()));
// verify with all values
- var id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setAutomationCompositionId(UUID.randomUUID());
- orig.setParticipantId(id);
+ orig.setParticipantId(CommonTestData.getParticipantId());
+ var id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setParticipantType(id);
var acElementResult = new AutomationCompositionElementAck(AutomationCompositionState.UNINITIALISED,
true, "AutomationCompositionElement result");
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Test the copy constructor and other methods.
removeVariableFields(new AutomationCompositionStateChange(orig).toString()));
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setAutomationCompositionId(UUID.randomUUID());
- orig.setParticipantId(id);
+ orig.setParticipantId(CommonTestData.getParticipantId());
orig.setMessageId(UUID.randomUUID());
orig.setOrderedState(AutomationCompositionOrderedState.RUNNING);
orig.setCurrentState(AutomationCompositionState.PASSIVE);
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
acElement.setDescription("Description");
acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
acElement.setState(AutomationCompositionState.PASSIVE);
- acElement.setParticipantId(id);
+
+ var participantId = CommonTestData.getParticipantId();
+ acElement.setParticipantId(participantId);
acElement.setParticipantType(id);
var property = new ToscaProperty();
acElement.setProperties(propertiesMap);
var participantUpdates = new ParticipantUpdates();
- participantUpdates.setParticipantId(id);
+ participantUpdates.setParticipantId(participantId);
participantUpdates.setAutomationCompositionElementList(List.of(acElement));
orig.setParticipantUpdatesList(List.of(participantUpdates));
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6");
private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7");
- private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3");
- private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4");
@Test
void testCopyConstructor() throws CoderException {
assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class);
+ var participantId = CommonTestData.getParticipantId();
+ assertThatThrownBy(() -> message.appliesTo(null, participantId)).isInstanceOf(NullPointerException.class);
}
@Test
message = makeMessage();
// ParticipantId matches
- assertTrue(message.appliesTo(PTYPE_456, ID_123));
- assertFalse(message.appliesTo(PTYPE_456, ID_124));
- assertFalse(message.appliesTo(PTYPE_457, ID_123));
+ assertTrue(message.appliesTo(PTYPE_456, CommonTestData.getParticipantId()));
+ assertFalse(message.appliesTo(PTYPE_456, CommonTestData.getRndParticipantId()));
+ assertFalse(message.appliesTo(PTYPE_457, CommonTestData.getParticipantId()));
}
@Test
ToscaConceptIdentifier id = new ToscaConceptIdentifier();
id.setName("id1111");
id.setVersion("3.2.1");
- assertFalse(message.appliesTo(id, id));
+ assertFalse(message.appliesTo(id, CommonTestData.getRndParticipantId()));
message.setParticipantType(null);
- assertTrue(message.appliesTo(id, id));
+ assertTrue(message.appliesTo(id, CommonTestData.getRndParticipantId()));
}
private ParticipantAckMessage makeMessage() {
ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK);
msg.setParticipantType(PTYPE_456);
- msg.setParticipantId(ID_123);
+ msg.setParticipantId(CommonTestData.getParticipantId());
msg.setMessage("Successfull Ack");
msg.setResult(true);
msg.setResponseTo(UUID.randomUUID());
import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
id.setName("id");
id.setVersion("1.2.3");
orig.setAutomationCompositionId(UUID.randomUUID());
- orig.setParticipantId(id);
+ orig.setParticipantId(CommonTestData.getParticipantId());
orig.setParticipantType(id);
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6");
private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7");
- private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3");
- private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4");
@Test
void testCopyConstructor() throws CoderException {
// verify with null values
message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
- ParticipantMessage newmsg = new ParticipantMessage(message);
+ var newmsg = new ParticipantMessage(message);
newmsg.setMessageId(message.getMessageId());
newmsg.setTimestamp(message.getTimestamp());
assertEquals(message.toString(), newmsg.toString());
assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class);
- assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class);
+ var participantId = CommonTestData.getParticipantId();
+ assertThatThrownBy(() -> message.appliesTo(null, participantId)).isInstanceOf(NullPointerException.class);
}
@Test
message = makeMessage();
// ParticipantId matches
- assertTrue(message.appliesTo(PTYPE_456, ID_123));
- assertFalse(message.appliesTo(PTYPE_456, ID_124));
- assertFalse(message.appliesTo(PTYPE_457, ID_123));
+ assertTrue(message.appliesTo(PTYPE_456, CommonTestData.getParticipantId()));
+ assertFalse(message.appliesTo(PTYPE_456, CommonTestData.getRndParticipantId()));
+ assertFalse(message.appliesTo(PTYPE_457, CommonTestData.getParticipantId()));
}
@Test
message = makeMessage();
// ParticipantId does not match
- ToscaConceptIdentifier id = new ToscaConceptIdentifier();
+ var id = new ToscaConceptIdentifier();
id.setName("id1111");
id.setVersion("3.2.1");
- assertFalse(message.appliesTo(id, id));
+ assertFalse(message.appliesTo(id, CommonTestData.getRndParticipantId()));
message.setParticipantType(null);
- assertTrue(message.appliesTo(id, id));
+ assertTrue(message.appliesTo(id, CommonTestData.getRndParticipantId()));
}
private ParticipantMessage makeMessage() {
- ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+ var msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
msg.setParticipantType(PTYPE_456);
- msg.setParticipantId(ID_123);
+ msg.setParticipantId(CommonTestData.getParticipantId());
msg.setMessageId(UUID.randomUUID());
msg.setTimestamp(Instant.ofEpochMilli(3000));
import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
id.setName("id");
id.setVersion("1.2.3");
orig.setAutomationCompositionId(UUID.randomUUID());
- orig.setParticipantId(id);
+ orig.setParticipantId(CommonTestData.getParticipantId());
orig.setParticipantType(id);
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Test the copy constructor.
void testCopyConstructor() throws CoderException {
assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class);
- ParticipantStatusReq orig = new ParticipantStatusReq();
+ var orig = new ParticipantStatusReq();
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setParticipantId(id);
+ orig.setParticipantId(CommonTestData.getParticipantId());
orig.setAutomationCompositionId(null);
orig.setParticipantType(null);
orig.setMessageId(UUID.randomUUID());
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
// verify with all values
var automationCompositionId = UUID.randomUUID();
orig.setAutomationCompositionId(automationCompositionId);
- var id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setParticipantId(id);
- ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4");
+ var participantId = CommonTestData.getParticipantId();
+ orig.setParticipantId(participantId);
+ var type = new ToscaConceptIdentifier("type", "2.3.4");
orig.setParticipantType(type);
orig.setMessageId(UUID.randomUUID());
orig.setState(ParticipantState.ON_LINE);
orig.setAutomationCompositionInfoList(List.of(acInfo));
var participantDefinitionUpdate = new ParticipantDefinition();
- participantDefinitionUpdate.setParticipantId(id);
+ participantDefinitionUpdate.setParticipantId(participantId);
participantDefinitionUpdate.setParticipantType(type);
- var acDefinition = getAcElementDefinition(id);
+ var acDefinition = getAcElementDefinition(new ToscaConceptIdentifier("id", "1.2.3"));
participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition));
orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate));
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
void testCopyConstructor() throws CoderException {
assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class);
- ParticipantUpdate orig = new ParticipantUpdate();
+ var orig = new ParticipantUpdate();
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setAutomationCompositionId(UUID.randomUUID());
- orig.setParticipantId(id);
- orig.setParticipantType(id);
+ orig.setParticipantId(CommonTestData.getParticipantId());
+ var type = new ToscaConceptIdentifier("id", "1.2.3");
+ orig.setParticipantType(type);
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
- ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate();
+ var toscaServiceTemplate = new ToscaServiceTemplate();
toscaServiceTemplate.setName("serviceTemplate");
toscaServiceTemplate.setDerivedFrom("parentServiceTemplate");
toscaServiceTemplate.setDescription("Description of serviceTemplate");
toscaServiceTemplate.setVersion("1.2.3");
- ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate();
+ var toscaNodeTemplate = new ToscaNodeTemplate();
toscaNodeTemplate.setName("nodeTemplate");
toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
toscaNodeTemplate.setDescription("Description of nodeTemplate");
toscaNodeTemplate.setVersion("1.2.3");
- ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition();
- participantDefinitionUpdate.setParticipantType(id);
- AutomationCompositionElementDefinition acDefinition = getAcElementDefinition(id);
+ var participantDefinitionUpdate = new ParticipantDefinition();
+ participantDefinitionUpdate.setParticipantType(type);
+ var acDefinition = getAcElementDefinition(type);
participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition));
orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate));
- ParticipantUpdate other = new ParticipantUpdate(orig);
+ var other = new ParticipantUpdate(orig);
assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
}
private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) {
- ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate();
+ var toscaNodeTemplate = new ToscaNodeTemplate();
toscaNodeTemplate.setName("nodeTemplate");
toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
toscaNodeTemplate.setDescription("Description of nodeTemplate");
toscaNodeTemplate.setVersion("1.2.3");
- AutomationCompositionElementDefinition acDefinition = new AutomationCompositionElementDefinition();
+ var acDefinition = new AutomationCompositionElementDefinition();
acDefinition.setAcElementDefinitionId(id);
acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate);
return acDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
noOrderedStateJpaAce.setInstanceId(testJpaAutomationCompositionElement.getInstanceId());
noOrderedStateJpaAce.setElementId(testJpaAutomationCompositionElement.getElementId());
+ noOrderedStateJpaAce.setParticipantId(testJpaAutomationCompositionElement.getParticipantId());
assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce);
}
ace1.setDescription("Description");
ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
ace1.setState(AutomationCompositionState.UNINITIALISED);
- ace1.setParticipantId(new PfConceptKey("participant", "0.0.1"));
+ ace1.setParticipantId(CommonTestData.getJpaParticipantId());
assertThat(ace1.toString()).contains("AutomationCompositionElement(");
assertNotEquals(0, ace1.hashCode());
automationCompositionElement.setId(UUID.fromString(ELEMENT_ID));
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1"));
+ automationCompositionElement.setParticipantId(CommonTestData.getParticipantId());
automationCompositionElement.setProperties(Map.of("key", "{}"));
return automationCompositionElement;
class AcmUtilsTest {
- private final ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.0.0");
+ private static final ToscaConceptIdentifier TYPE = new ToscaConceptIdentifier("id", "1.0.0");
@Test
void testCommonUtilsParticipantUpdate() {
assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0));
AcmUtils.prepareParticipantUpdate(acElement, participantUpdates);
- assertNotEquals(id, participantUpdates.get(0).getParticipantId());
+ var participantId = CommonTestData.getParticipantId();
+ assertNotEquals(participantId, participantUpdates.get(0).getParticipantId());
- acElement.setParticipantId(id);
- acElement.setParticipantType(id);
+ acElement.setParticipantId(participantId);
+ acElement.setParticipantType(TYPE);
AcmUtils.prepareParticipantUpdate(acElement, participantUpdates);
- assertEquals(id, participantUpdates.get(1).getParticipantId());
+ assertEquals(participantId, participantUpdates.get(1).getParticipantId());
}
@Test
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.models.acm.utils;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+/**
+ * Class to hold/create all parameters for test cases.
+ *
+ */
+public class CommonTestData {
+
+ public static final ToscaConceptIdentifier PARTCICIPANT_ID = new ToscaConceptIdentifier("id", "1.2.3");
+
+ /**
+ * Returns participantId for test cases.
+ *
+ * @return participant Id
+ */
+ public static ToscaConceptIdentifier getParticipantId() {
+ return PARTCICIPANT_ID;
+ }
+
+ /**
+ * Returns participantId for test Jpa cases.
+ *
+ * @return participant Id
+ */
+ public static PfConceptKey getJpaParticipantId() {
+ return PARTCICIPANT_ID.asConceptKey();
+ }
+
+ /**
+ * Returns second participantId for test cases.
+ *
+ * @return participant Id
+ */
+ public static ToscaConceptIdentifier getRndParticipantId() {
+ return new ToscaConceptIdentifier("idDiff", "1.2.3");
+ }
+}