* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.
import org.junit.Test;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaWithObjectProperties;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
public class JpaToscaWithStringPropertiesTest {
private static final String SOME_DESCRIPTION = "some description";
@Test
public void testGetKeys() {
PfConceptKey key = new PfConceptKey("bye", "9.8.7");
+ PfConceptKey typeKey = new PfConceptKey("type", "6.5.4");
- jpa = new MyJpa(key);
+ jpa = new MyJpa(key, typeKey);
jpa.setDescription(SOME_DESCRIPTION);
jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
// properties should be ignored
- assertThat(jpa.getKeys()).isEqualTo(List.of(key));
+ assertThat(jpa.getKeys()).isEqualTo(List.of(key, typeKey));
}
@Test
@Test
public void testFromAuthorative() {
MyTosca tosca = new MyTosca();
+ tosca.setType("type");
+ tosca.setTypeVersion("1.2.3");
tosca.setDescription(SOME_DESCRIPTION);
jpa.fromAuthorative(tosca);
MyTosca tosca = new MyTosca();
tosca.setName("world");
tosca.setVersion("3.2.1");
+ tosca.setType("planet");
+ tosca.setTypeVersion("6.5.4");
tosca.setDescription(SOME_DESCRIPTION);
tosca.setProperties(Map.of(KEY1, INT1, KEY2, INT2));
assertEquals(SOME_DESCRIPTION, jpa.getDescription());
assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, STRING1, KEY2, STRING2));
assertEquals(new PfConceptKey("world", "3.2.1"), jpa.getKey());
+ assertEquals(new PfConceptKey("planet", "6.5.4"), jpa.getType());
}
@Test
jpa.setText("some text");
assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
- // valid
+ // not valid, type is not set
jpa.setKey(new PfConceptKey("xyz", "2.3.4"));
+ assertThat(jpa.validateWithKey("fieldB").isValid()).isFalse();
+
+ // valid, type is set
+ jpa.setType(new PfConceptKey("uvw", "5.6.7"));
assertThat(jpa.validateWithKey("fieldB").isValid()).isTrue();
// null text - bean validator should fail
assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
}
- private static class MyTosca extends ToscaWithObjectProperties {
-
+ private static class MyTosca extends ToscaWithTypeAndObjectProperties {
}
@NoArgsConstructor
- protected static class MyJpa extends JpaToscaWithStringProperties<MyTosca> {
+ protected static class MyJpa extends JpaToscaWithTypeAndStringProperties<MyTosca> {
private static final long serialVersionUID = 1L;
@NotNull
super(key);
}
+ public MyJpa(PfConceptKey key, PfConceptKey type) {
+ super(key, type);
+ }
+
public MyJpa(MyTosca tosca) {
super(tosca);
}