2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.authorative.concepts;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.policy.models.base.PfConceptKey;
31 import org.onap.policy.models.base.PfKey;
33 public class ToscaNameVersionTest {
35 private static final String MY_NAME = "MyName";
36 private static final String MY_VERSION = "1.2.3";
38 private ToscaNameVersion tosca;
42 tosca = new ToscaNameVersion(MY_NAME, MY_VERSION);
46 public void testToscaNameVersionPfKey() {
47 tosca = new ToscaNameVersion(new PfConceptKey(MY_NAME, MY_VERSION));
48 assertEquals(MY_NAME, tosca.getName());
49 assertEquals(MY_VERSION, tosca.getVersion());
51 assertThatThrownBy(() -> new ToscaNameVersion((PfKey) null)).isInstanceOf(NullPointerException.class)
52 .hasMessageContaining("key").hasMessageContaining("is null");
56 public void testToscaNameVersionToscaNameVersion() {
57 tosca = new ToscaNameVersion(tosca);
58 assertEquals(MY_NAME, tosca.getName());
59 assertEquals(MY_VERSION, tosca.getVersion());
63 public void testAsConceptKey() {
64 assertEquals(new PfConceptKey(MY_NAME, MY_VERSION), tosca.asConceptKey());
68 public void testCommonCompareTo() {
69 assertThat(tosca.commonCompareTo(tosca)).isZero();
70 assertThat(tosca.commonCompareTo(null)).isNotZero();
71 assertThat(tosca.commonCompareTo(new MyNameVersion(MY_NAME, MY_VERSION))).isNotZero();
72 assertThat(tosca.commonCompareTo(new ToscaNameVersion(tosca))).isZero();
73 assertThat(tosca.commonCompareTo(new ToscaNameVersion(MY_NAME, null))).isNotZero();
74 assertThat(tosca.commonCompareTo(new ToscaNameVersion(null, MY_VERSION))).isNotZero();
78 public void testToString() {
79 assertEquals(MY_NAME + " " + MY_VERSION, tosca.toString());
83 public void testToscaNameVersion() {
84 tosca = new ToscaNameVersion();
85 assertNull(tosca.getName());
86 assertNull(tosca.getVersion());
90 public void testToscaNameVersionStringString() {
91 assertEquals(MY_NAME, tosca.getName());
92 assertEquals(MY_VERSION, tosca.getVersion());
95 private static class MyNameVersion extends ToscaNameVersion {
96 public MyNameVersion(String name, String version) {