/*-
* ============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");
import static org.junit.Assert.assertTrue;
import java.time.Duration;
-import java.util.Date;
+import java.time.Instant;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
.hasMessageMatching("eventType is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null)).isInstanceOf(NullPointerException.class);
+ }
+ @Test
+ public void testTriggerConstraints() {
PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, EVENT_TYPE, ACTION);
JpaToscaTimeInterval schedule =
- new JpaToscaTimeInterval(new PfReferenceKey(tkey, "sched"), new Date(), new Date());
+ new JpaToscaTimeInterval(new PfReferenceKey(tkey, "sched"), Instant.now(), Instant.now());
tdt.setSchedule(schedule);
JpaToscaEventFilter targetFilter =
assertEquals(A_METHOD, tdt.getMethod());
JpaToscaTrigger tdtClone0 = new JpaToscaTrigger(tdt);
- assertEquals(tdt, tdtClone0);
- assertEquals(0, tdt.compareTo(tdtClone0));
+ checkEqualsToscaTriggers(tdt, tdtClone0);
JpaToscaTrigger tdtClone1 = new JpaToscaTrigger(tdt);
- assertEquals(tdt, tdtClone1);
- assertEquals(0, tdt.compareTo(tdtClone1));
+ checkEqualsToscaTriggers(tdt, tdtClone1);
assertEquals(-1, tdt.compareTo(null));
assertEquals(0, tdt.compareTo(tdt));
assertEquals(4, tdt.getKeys().size());
assertEquals(1, new JpaToscaTrigger().getKeys().size());
+ }
+
+ @Test
+ public void testCloneToscaTrigger() {
+ PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
+ PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
+ JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, EVENT_TYPE, ACTION);
+
+ JpaToscaTrigger tdtClone0 = new JpaToscaTrigger(tdt);
new JpaToscaTrigger().clean();
tdt.clean();
assertThatThrownBy(() -> tdt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
+
+ private void checkEqualsToscaTriggers(JpaToscaTrigger tdt1, JpaToscaTrigger tdt2) {
+ assertEquals(tdt1, tdt2);
+ assertEquals(0, tdt1.compareTo(tdt2));
+ }
}