/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
public class JpaToscaPolicyTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testPolicyPojo() {
assertNotNull(new JpaToscaPolicy());
assertThatThrownBy(() -> {
new JpaToscaPolicy((PfConceptKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(new PfConceptKey(), null);
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, new PfConceptKey());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
- assertThatThrownBy(() -> {
- new JpaToscaPolicy((JpaToscaPolicy) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null))
+ .isInstanceOf(NullPointerException.class);
- PfConceptKey tpKey = new PfConceptKey("tdt", "0.0.1");
- PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
+ PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001);
+ PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001);
JpaToscaPolicy tp = new JpaToscaPolicy(tpKey, ptKey);
Map<String, String> propertyMap = new HashMap<>();
assertEquals(propertyMap, tp.getProperties());
List<PfConceptKey> targets = new ArrayList<>();
- PfConceptKey target = new PfConceptKey("target", "0.0.1");
+ PfConceptKey target = new PfConceptKey("target", VERSION_001);
targets.add(target);
tp.setTargets(targets);
assertEquals(targets, tp.getTargets());
assertEquals(tp, tdtClone0);
assertEquals(0, tp.compareTo(tdtClone0));
- JpaToscaPolicy tdtClone1 = new JpaToscaPolicy();
- tp.copyTo(tdtClone1);
+ JpaToscaPolicy tdtClone1 = new JpaToscaPolicy(tp);
assertEquals(tp, tdtClone1);
assertEquals(0, tp.compareTo(tdtClone1));
assertEquals(0, tp.compareTo(tp));
assertFalse(tp.compareTo(tp.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
JpaToscaPolicy otherDt = new JpaToscaPolicy(otherDtKey);
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setTargets(targets);
assertEquals(0, tp.compareTo(otherDt));
- assertThatThrownBy(() -> {
- tp.copyTo(null);
- }).hasMessage("target is marked @NonNull but is null");
-
assertEquals(3, tp.getKeys().size());
assertEquals(2, new JpaToscaPolicy().getKeys().size());
assertEquals(tdtClone0, tp);
assertFalse(new JpaToscaPolicy().validate(new PfValidationResult()).isValid());
- System.err.println(tp.validate(new PfValidationResult()));
assertTrue(tp.validate(new PfValidationResult()).isValid());
tp.getProperties().put(null, null);