- try {
- tp.setStatus(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("status is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- tp.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ tp.setMetadata(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ assertThatThrownBy(() -> tp.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
+ }
+
+ @Test
+ public void testToAuthorative_testFromAuthorative() {
+ // check with empty structure
+ JpaToscaProperty tp = new JpaToscaProperty();
+ ToscaProperty auth = tp.toAuthorative();
+ JpaToscaProperty tp2 = new JpaToscaProperty();
+ tp2.fromAuthorative(auth);
+ assertEquals(tp, tp2);
+
+ // populate and try again
+ PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001);
+ PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0");
+ PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001);
+ tp = new JpaToscaProperty(pkey, ptypeKey);
+
+ tp.setDescription(A_DESCRIPTION);
+ tp.setRequired(true);
+ tp.setDefaultValue(DEFAULT_KEY);
+ tp.setStatus(ToscaProperty.Status.SUPPORTED);
+
+ List<JpaToscaConstraint> constraints = new ArrayList<>();
+ JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
+ constraints.add(lsc);
+ tp.setConstraints(constraints);
+
+ PfConceptKey typeKey = new PfConceptKey("type", VERSION_001);
+ JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey);
+ tp.setEntrySchema(tes);
+
+ TreeMap<String, String> metadata = new TreeMap<>();
+ metadata.put("metaA", "dataA");
+ metadata.put("metaB", "dataB");
+ tp.setMetadata(metadata);
+
+ auth = tp.toAuthorative();
+ tp2 = new JpaToscaProperty();
+ tp2.fromAuthorative(auth);
+
+ // note: parent key info is not copied, so we manually copy it
+ tp2.getKey().setParentConceptKey(tp.getKey().getParentConceptKey());
+
+ assertEquals(tp.toString(), tp2.toString());
+ assertEquals(tp, tp2);