diff options
author | lapentafd <francesco.lapenta@est.tech> | 2021-03-23 17:46:41 +0000 |
---|---|---|
committer | lapentafd <francesco.lapenta@est.tech> | 2021-03-26 10:10:15 +0000 |
commit | 3c629ea3357cbe212db9acfcde002dac8b821ac2 (patch) | |
tree | 87e9bb113b401a4d1fc8c37346efbba0177e63f7 /models-tosca/src | |
parent | b0fc73fd9ff6d9727c0f93a7ad0a742b704b4c9d (diff) |
Fix Sonar Issues models-tosca-simple
Tests refactoring to reduce number of assertions
Issue-ID: POLICY-3094
Change-Id: I8a9a02100e5d103f574cf2cb89d2e924d0f56507
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'models-tosca/src')
9 files changed, 203 insertions, 16 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java index f0f42e647..eb050ecbe 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -63,7 +63,10 @@ public class JpaToscaModelTest { assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null)) .hasMessageMatching("copyConcept is marked .*on.*ull but is null"); + } + @Test + public void testJpaToscaModel() { PfConceptKey tstsKey = new PfConceptKey("tsts", VERSION_001); Map<PfConceptKey, JpaToscaServiceTemplate> tstMap = new TreeMap<>(); JpaToscaServiceTemplates tsts = new JpaToscaServiceTemplates(tstsKey, tstMap); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java index 15bde0b47..1c79091b1 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -43,7 +43,7 @@ public class JpaToscaPoliciesTest { private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null"; @Test - public void testPolicies() { + public void testPoliciesErrors() { assertNotNull(new JpaToscaPolicies()); assertNotNull(new JpaToscaPolicies(new PfConceptKey())); assertNotNull(new JpaToscaPolicies(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicy>())); @@ -61,7 +61,10 @@ public class JpaToscaPoliciesTest { assertThatThrownBy(() -> new JpaToscaPolicies(null, new TreeMap<PfConceptKey, JpaToscaPolicy>())) .hasMessageMatching(KEY_IS_NULL); + } + @Test + public void testToscaPolicies() { List<Map<String, ToscaPolicy>> polMapList = new ArrayList<>(); polMapList.add(new LinkedHashMap<>()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java index b9adce195..b455145d1 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java @@ -80,7 +80,10 @@ public class JpaToscaPolicyTest { }).hasMessageMatching(KEY_IS_NULL); assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null)).isInstanceOf(NullPointerException.class); + } + @Test + public void testJpaToscaPolicy() { PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001); PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001); JpaToscaPolicy tp = new JpaToscaPolicy(tpKey, ptKey); @@ -127,7 +130,11 @@ public class JpaToscaPolicyTest { new JpaToscaPolicy().clean(); tp.clean(); assertEquals(tdtClone0, tp); + } + @Test + public void testJpaToscaPolicyValidation() { + JpaToscaPolicy tp = setUpJpaToscaPolicy(); assertFalse(new JpaToscaPolicy().validate("").isValid()); assertTrue(tp.validate("").isValid()); @@ -150,7 +157,11 @@ public class JpaToscaPolicyTest { assertFalse(tp.validate("").isValid()); tp.getTargets().remove(null); assertTrue(tp.validate("").isValid()); + } + @Test + public void testJpaToscaPolicyAuthorative() { + JpaToscaPolicy tp = setUpJpaToscaPolicy(); PfConceptKey tpTypeKey = tp.getKey(); assertNotNull(tpTypeKey); tp.setType(null); @@ -222,4 +233,19 @@ public class JpaToscaPolicyTest { assertEquals(false, tpFromTo.getProperties().get("boolean")); // @formatter:on } + + private JpaToscaPolicy setUpJpaToscaPolicy() { + PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001); + PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001); + JpaToscaPolicy tp = new JpaToscaPolicy(tpKey, ptKey); + + // Maps and Lists need to be modifiable + Map<String, String> propertyMap = new HashMap<>(Map.of("Property", "\"Property Value\"")); + tp.setProperties(propertyMap); + + PfConceptKey target = new PfConceptKey("target", VERSION_001); + List<PfConceptKey> targets = new ArrayList<>(List.of(target)); + tp.setTargets(targets); + return tp; + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java index b2f59c459..5cca879c5 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -50,7 +50,7 @@ public class JpaToscaPolicyTypeTest { 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())); @@ -60,7 +60,10 @@ public class JpaToscaPolicyTypeTest { assertThatThrownBy(() -> new JpaToscaPolicyType((JpaToscaPolicyType) null)) .isInstanceOf(NullPointerException.class); + } + @Test + public void testPolicyTypePojo() { PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001); JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey); @@ -124,12 +127,17 @@ public class JpaToscaPolicyTypeTest { 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()); @@ -148,6 +156,11 @@ public class JpaToscaPolicyTypeTest { 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()); @@ -167,8 +180,15 @@ public class JpaToscaPolicyTypeTest { 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"); @@ -236,4 +256,32 @@ public class JpaToscaPolicyTypeTest { 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; + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java index 76f91c56a..2e8459bb2 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -43,7 +43,7 @@ public class JpaToscaPolicyTypesTest { private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null"; @Test - public void testPolicyTypes() { + public void testPolicyTypesNull() { assertNotNull(new JpaToscaPolicyTypes()); assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey())); assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicyType>())); @@ -61,7 +61,10 @@ public class JpaToscaPolicyTypesTest { assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, new TreeMap<PfConceptKey, JpaToscaPolicyType>())) .hasMessageMatching(KEY_IS_NULL); + } + @Test + public void testPolicyTypes() { List<Map<String, ToscaPolicyType>> ptMapList = new ArrayList<>(); ptMapList.add(new LinkedHashMap<>()); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java index b82888108..685266a9f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -32,6 +32,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.TreeMap; import org.junit.Test; import org.onap.policy.models.base.PfConceptKey; @@ -51,7 +52,7 @@ public class JpaToscaPropertyTest { private static final String VERSION_001 = "0.0.1"; @Test - public void testPropertyPojo() { + public void testPropertyNull() { assertNotNull(new JpaToscaProperty()); assertNotNull(new JpaToscaProperty(new PfReferenceKey())); assertNotNull(new JpaToscaProperty(new PfReferenceKey(), new PfConceptKey())); @@ -65,7 +66,10 @@ public class JpaToscaPropertyTest { assertThatThrownBy(() -> new JpaToscaProperty(new PfReferenceKey(), null)) .hasMessageMatching("type is marked .*on.*ull but is null"); + } + @Test + public void testProperty() { PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001); PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0"); PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001); @@ -112,13 +116,23 @@ public class JpaToscaPropertyTest { assertEquals(-1, tp.compareTo(null)); assertEquals(0, tp.compareTo(tp)); assertNotEquals(0, tp.compareTo(tp.getKey())); + } + + @Test + public void testPropertyCompareData() { + JpaToscaProperty tp = setUpJpaToscaProperty(); PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", VERSION_001, "OtherProperty"); JpaToscaProperty otherDt = new JpaToscaProperty(otherDtKey); assertNotEquals(0, tp.compareTo(otherDt)); + + PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001); + PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0"); otherDt.setKey(pkey); assertNotEquals(0, tp.compareTo(otherDt)); + + PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001); otherDt.setType(ptypeKey); assertNotEquals(0, tp.compareTo(otherDt)); otherDt.setDescription(A_DESCRIPTION); @@ -130,10 +144,21 @@ public class JpaToscaPropertyTest { otherDt.setStatus(ToscaProperty.Status.SUPPORTED); assertNotEquals(0, tp.compareTo(otherDt)); assertNotEquals(0, tp.compareTo(otherDt)); + + List<JpaToscaConstraint> constraints = new ArrayList<>(); + JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello"); + constraints.add(lsc); otherDt.setConstraints(constraints); assertNotEquals(0, tp.compareTo(otherDt)); + + PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); otherDt.setEntrySchema(tes); assertNotEquals(0, tp.compareTo(otherDt)); + + TreeMap<String, String> metadata = new TreeMap<>(); + metadata.put("metaA", "dataA"); + metadata.put("metaB", "dataB"); otherDt.setMetadata(metadata); assertEquals(0, tp.compareTo(otherDt)); @@ -152,6 +177,12 @@ public class JpaToscaPropertyTest { assertEquals(3, tp.getKeys().size()); assertEquals(2, new JpaToscaProperty().getKeys().size()); + } + + @Test + public void testPropertyCompareDescription() { + JpaToscaProperty tp = setUpJpaToscaProperty(); + JpaToscaProperty tdtClone0 = new JpaToscaProperty(tp); new JpaToscaProperty().clean(); tp.clean(); @@ -169,6 +200,12 @@ public class JpaToscaPropertyTest { tp.setType(null); assertFalse(tp.validate("").isValid()); + } + + @Test + public void testPropertyCompareMetadata() { + JpaToscaProperty tp = setUpJpaToscaProperty(); + PfConceptKey typeKey = new PfConceptKey("type", VERSION_001); tp.setType(typeKey); assertTrue(tp.validate("").isValid()); @@ -239,4 +276,29 @@ public class JpaToscaPropertyTest { assertEquals(tp.toString(), tp2.toString()); assertEquals(tp, tp2); } + + private JpaToscaProperty setUpJpaToscaProperty() { + PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001); + PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0"); + PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001); + + JpaToscaProperty tp = new JpaToscaProperty(pkey, ptypeKey); + tp.setDescription(A_DESCRIPTION); + tp.setRequired(false); + tp.setDefaultValue(DEFAULT_KEY); + tp.setStatus(ToscaProperty.Status.SUPPORTED); + + JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello"); + // Maps and Lists need to be modifiable + List<JpaToscaConstraint> constraints = new ArrayList<>(List.of(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<>(Map.of("metaA", "dataA", "metaB", "dataB")); + tp.setMetadata(metadata); + + return tp; + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java index 7248b45ec..a8d4f3487 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaSchemaDefinitionTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -43,7 +43,7 @@ public class JpaToscaSchemaDefinitionTest { private static final String A_DESCRIPTION = "A Description"; @Test - public void testEntrySchemaPojo() { + public void testEntrySchemaNull() { assertNotNull(new JpaToscaSchemaDefinition(new PfConceptKey())); assertNotNull(new JpaToscaSchemaDefinition(new JpaToscaSchemaDefinition(new PfConceptKey()))); @@ -52,7 +52,10 @@ public class JpaToscaSchemaDefinitionTest { assertThatThrownBy(() -> new JpaToscaSchemaDefinition((JpaToscaSchemaDefinition) null)) .hasMessageMatching("copyConcept is marked .*on.*ull but is null"); + } + @Test + public void testEntrySchema() { PfConceptKey typeKey = new PfConceptKey("type", "0.0.1"); JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); @@ -94,6 +97,12 @@ public class JpaToscaSchemaDefinitionTest { new JpaToscaSchemaDefinition(typeKey).clean(); tes.clean(); assertEquals(tdtClone0, tes); + } + + @Test + public void testEntrySchemaValidation() { + PfConceptKey typeKey = new PfConceptKey("type", "0.0.1"); + JpaToscaSchemaDefinition tes = setUpJpaToscaSchemaDefinition(typeKey); assertTrue(new JpaToscaSchemaDefinition(typeKey).validate("").isValid()); assertTrue(tes.validate("").isValid()); @@ -118,4 +127,16 @@ public class JpaToscaSchemaDefinitionTest { assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null"); } + + private JpaToscaSchemaDefinition setUpJpaToscaSchemaDefinition(PfConceptKey typeKey) { + JpaToscaSchemaDefinition tes = new JpaToscaSchemaDefinition(typeKey); + tes.setDescription(A_DESCRIPTION); + + List<JpaToscaConstraint> constraints = new ArrayList<>(); + JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello"); + constraints.add(lsc); + tes.setConstraints(constraints); + + return tes; + } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java index 8f366b321..c361d8632 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java @@ -1,6 +1,6 @@ /*- * ============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"); @@ -49,7 +49,7 @@ public class JpaToscaServiceTemplateTest { private static final String VERSION_001 = "0.0.1"; @Test - public void testServiceTemplatePojo() { + public void testServiceTemplateNull() { assertNotNull(new JpaToscaServiceTemplate()); assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey())); assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey(), "")); @@ -66,7 +66,10 @@ public class JpaToscaServiceTemplateTest { assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null)) .isInstanceOf(NullPointerException.class); + } + @Test + public void testServiceTemplatePojo() { PfConceptKey tstKey = new PfConceptKey("tst", VERSION_001); JpaToscaServiceTemplate tst = new JpaToscaServiceTemplate(tstKey, "Tosca Version"); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java index b0a8ab709..7e8b78109 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java @@ -72,7 +72,10 @@ public class JpaToscaTimeIntervalTest { assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null)) .isInstanceOf(NullPointerException.class); + } + @Test + public void testTimeInterval() { PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1"); PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0"); Instant startTime = Instant.ofEpochSecond(1000); @@ -108,12 +111,19 @@ public class JpaToscaTimeIntervalTest { new JpaToscaTimeInterval().clean(); tti.clean(); assertEquals(tdtClone0, tti); + } + @Test + public void testTimeIntervalValidation() { + Instant startTime = Instant.ofEpochSecond(1000); + Instant endTime = Instant.ofEpochSecond(2000); + JpaToscaTimeInterval tti = setUpJpaToscaTimeInterval(startTime, endTime); assertFalse(new JpaToscaTimeInterval().validate("").isValid()); assertTrue(tti.validate("").isValid()); tti.setStartTime(null); assertFalse(tti.validate("").isValid()); + tti.setStartTime(Timestamp.from(endTime.plusSeconds(1))); assertFalse(tti.validate("").isValid()); tti.setStartTime(Timestamp.from(startTime)); @@ -128,4 +138,12 @@ public class JpaToscaTimeIntervalTest { assertThatThrownBy(() -> tti.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null"); } + + private JpaToscaTimeInterval setUpJpaToscaTimeInterval(Instant startTime, Instant endTime) { + PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1"); + PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0"); + JpaToscaTimeInterval tti = new JpaToscaTimeInterval(ttiKey, startTime, endTime); + + return tti; + } } |