/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
private static final String VERSION_001 = "0.0.1";
@Test
- public void testPolicyTypePojo() {
+ public void testPolicyTypeNull() {
assertNotNull(new JpaToscaPolicyType());
assertNotNull(new JpaToscaPolicyType(new PfConceptKey()));
assertNotNull(new JpaToscaPolicyType(new JpaToscaPolicyType()));
assertThatThrownBy(() -> new JpaToscaPolicyType((JpaToscaPolicyType) null))
.isInstanceOf(NullPointerException.class);
+ }
+ @Test
+ public void testPolicyTypePojo() {
PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey);
otherDt.setTriggers(triggers);
assertEquals(0, tpt.compareTo(otherDt));
- assertEquals(6, tpt.getKeys().size());
- assertEquals(1, new JpaToscaPolicyType().getKeys().size());
-
new JpaToscaPolicyType().clean();
tpt.clean();
assertEquals(tdtClone0, tpt);
+ }
+
+ @Test
+ public void testPolicyTypeValidation() {
+ JpaToscaPolicyType tpt = setUpJpaToscaPolicyType();
+
+ assertEquals(6, tpt.getKeys().size());
+ assertEquals(1, new JpaToscaPolicyType().getKeys().size());
assertFalse(new JpaToscaPolicyType().validate("").isValid());
assertTrue(tpt.validate("").isValid());
assertFalse(tpt.validate("").isValid());
tpt.getTriggers().remove(null);
assertTrue(tpt.validate("").isValid());
+ }
+
+ @Test
+ public void testPolicyTypeValidation2() {
+ JpaToscaPolicyType tpt = setUpJpaToscaPolicyType();
tpt.getMetadata().put(null, null);
assertFalse(tpt.validate("").isValid());
tpt.setDerivedFrom(PfConceptKey.getNullKey());
assertFalse(tpt.validate("").isValid());
+
+ PfConceptKey derivedFromKey = new PfConceptKey("deriveFrom", VERSION_001);
tpt.setDerivedFrom(derivedFromKey);
assertTrue(tpt.validate("").isValid());
+ }
+
+ @Test
+ public void testPolicyTypeEntity() {
+ JpaToscaPolicyType tpt = setUpJpaToscaPolicyType();
assertThatThrownBy(() -> tpt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
pt0.getProperties().put(prop4.getKey().getLocalName(), prop4);
assertEquals(3, pt0.getReferencedDataTypes().size());
}
+
+ private JpaToscaPolicyType setUpJpaToscaPolicyType() {
+ PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001);
+ JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey);
+
+ PfConceptKey derivedFromKey = new PfConceptKey("deriveFrom", VERSION_001);
+ tpt.setDerivedFrom(derivedFromKey);
+ // Maps and Lists need to be modifiable
+ Map<String, String> metadata = new HashMap<>(Map.of("key", "value"));
+ tpt.setMetadata(metadata);
+
+ tpt.setDescription(A_DESCRIPTION);
+
+ PfConceptKey propTypeKey = new PfConceptKey("propType", VERSION_001);
+ JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey);
+ Map<String, JpaToscaProperty> properties = new LinkedHashMap<>(Map.of(tp.getKey().getLocalName(), tp));
+ tpt.setProperties(properties);
+
+ PfConceptKey target = new PfConceptKey("target", VERSION_001);
+ List<PfConceptKey> targets = new ArrayList<>(List.of(target));
+ tpt.setTargets(targets);
+
+ JpaToscaTrigger trigger = new JpaToscaTrigger(new PfReferenceKey(ptKey, "aTrigger"), "EventType", "Action");
+ List<JpaToscaTrigger> triggers = new ArrayList<>(List.of(trigger));
+ tpt.setTriggers(triggers);
+
+ return tpt;
+ }
}