summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
5b577fd)
Concenience constructor to create a TosaConceptIdentifier from a PfKey
and a method to create a PfConceptKey from a ToscaConceptIdentifier.
Issue-ID: POLICY-2971
Change-Id: I402b2e12cc11976cd7e98436eb46486c35fdaa31
Signed-off-by: liamfallon <liam.fallon@est.tech>
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
/**
* Identifies a concept. Both the name and version must be non-null.
/**
* Identifies a concept. Both the name and version must be non-null.
this.version = version;
}
this.version = version;
}
+ public ToscaConceptIdentifier(@NonNull PfKey key) {
+ this.name = key.getName();
+ this.version = key.getVersion();
+ }
+
public ToscaConceptIdentifier(ToscaConceptIdentifier source) {
this.name = source.name;
this.version = source.version;
public ToscaConceptIdentifier(ToscaConceptIdentifier source) {
this.name = source.name;
this.version = source.version;
+ /**
+ * Create a PfConcceptKey from the TOSCA identifier.
+ *
+ * @return the key
+ */
+ public PfConceptKey asConceptKey() {
+ return new PfConceptKey(name, version);
+ }
+
@Override
public int compareTo(ToscaConceptIdentifier other) {
if (this == other) {
@Override
public int compareTo(ToscaConceptIdentifier other) {
if (this == other) {
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationResult;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.models.base.PfConceptKey;
/**
* Test methods not tested by {@link PojosTest}.
/**
* Test methods not tested by {@link PojosTest}.
@Test
public void testCopyConstructor() {
@Test
public void testCopyConstructor() {
- assertThatThrownBy(() -> new ToscaConceptIdentifier(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ToscaConceptIdentifier((ToscaConceptIdentifier) null))
+ .isInstanceOf(NullPointerException.class);
ToscaConceptIdentifier orig = new ToscaConceptIdentifier();
ToscaConceptIdentifier orig = new ToscaConceptIdentifier();
assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString());
}
assertEquals(orig.toString(), new ToscaConceptIdentifier(orig).toString());
}
+
+ @Test
+ public void testPfKey() {
+ assertThatThrownBy(() -> new ToscaConceptIdentifier((PfConceptKey) null))
+ .isInstanceOf(NullPointerException.class);
+
+ PfConceptKey origKey = new PfConceptKey("Hello", "0.0.1");
+
+ assertEquals(origKey.getName(), new ToscaConceptIdentifier(origKey).getName());
+
+ assertEquals(origKey, new ToscaConceptIdentifier(origKey).asConceptKey());
+ }
+
@Test
public void testValidatePapRest() throws Exception {
ToscaConceptIdentifier ident = new ToscaConceptIdentifier(NAME, VERSION);
@Test
public void testValidatePapRest() throws Exception {
ToscaConceptIdentifier ident = new ToscaConceptIdentifier(NAME, VERSION);
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
* ============LICENSE_START=======================================================
* ONAP Policy Models
* ================================================================================
@Test
public void testCopyConstructor() {
@Test
public void testCopyConstructor() {
- assertThatThrownBy(() -> new ToscaConceptIdentifier(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new ToscaConceptIdentifier((ToscaConceptIdentifier) null))
+ .isInstanceOf(NullPointerException.class);
ToscaConceptIdentifier orig = new ToscaConceptIdentifier();
ToscaConceptIdentifier orig = new ToscaConceptIdentifier();