2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.simple.concepts;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
30 import java.util.TreeMap;
32 import org.junit.Test;
33 import org.onap.policy.models.base.PfConceptKey;
34 import org.onap.policy.models.base.PfModelService;
35 import org.onap.policy.models.base.PfValidationResult;
36 import org.onap.policy.models.tosca.simple.concepts.ToscaModel;
37 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
38 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplates;
41 * DAO test for ToscaDatatype.
43 * @author Liam Fallon (liam.fallon@est.tech)
45 public class ToscaModelTest {
48 public void testModelPojo() {
49 assertNotNull(new ToscaModel());
50 assertNotNull(new ToscaModel(new PfConceptKey()));
51 assertNotNull(new ToscaModel(new PfConceptKey(), new ToscaServiceTemplates()));
52 assertNotNull(new ToscaModel(new ToscaModel()));
55 new ToscaModel((PfConceptKey) null);
56 fail("test should throw an exception");
57 } catch (Exception exc) {
58 assertEquals("key is marked @NonNull but is null", exc.getMessage());
62 new ToscaModel(null, null);
63 fail("test should throw an exception");
64 } catch (Exception exc) {
65 assertEquals("key is marked @NonNull but is null", exc.getMessage());
69 new ToscaModel(null, new ToscaServiceTemplates());
70 fail("test should throw an exception");
71 } catch (Exception exc) {
72 assertEquals("key is marked @NonNull but is null", exc.getMessage());
76 new ToscaModel(new PfConceptKey(), null);
77 fail("test should throw an exception");
78 } catch (Exception exc) {
79 assertEquals("serviceTemplates is marked @NonNull but is null", exc.getMessage());
83 new ToscaModel((ToscaModel) null);
84 fail("test should throw an exception");
85 } catch (Exception exc) {
86 assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
89 PfConceptKey tstsKey = new PfConceptKey("tsts", "0.0.1");
90 Map<PfConceptKey, ToscaServiceTemplate> tstMap = new TreeMap<>();
91 ToscaServiceTemplates tsts = new ToscaServiceTemplates(tstsKey, tstMap);
92 PfConceptKey tmKey = new PfConceptKey("tst", "0.0.1");
93 ToscaModel tm = new ToscaModel(tmKey, tsts);
95 ToscaModel tttClone0 = new ToscaModel(tm);
96 assertEquals(tm, tttClone0);
97 assertEquals(0, tm.compareTo(tttClone0));
99 ToscaModel tttClone1 = new ToscaModel();
100 tm.copyTo(tttClone1);
101 assertEquals(tm, tttClone1);
102 assertEquals(0, tm.compareTo(tttClone1));
104 assertEquals(-1, tm.compareTo(null));
105 assertEquals(0, tm.compareTo(tm));
106 assertFalse(tm.compareTo(tm.getKey()) == 0);
108 PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
109 ToscaModel otherDt = new ToscaModel(otherDtKey);
111 assertFalse(tm.compareTo(otherDt) == 0);
112 otherDt.setKey(tmKey);
113 assertFalse(tm.compareTo(otherDt) == 0);
114 otherDt.setServiceTemplates(tsts);
115 assertEquals(0, tm.compareTo(otherDt));
119 fail("test should throw an exception");
120 } catch (Exception exc) {
121 assertEquals("targetObject is marked @NonNull but is null", exc.getMessage());
124 assertEquals(2, tm.getKeys().size());
125 assertEquals(2, new ToscaModel().getKeys().size());
127 new ToscaModel().clean();
129 assertEquals(tttClone0, tm);
131 assertFalse(new ToscaModel().validate(new PfValidationResult()).isValid());
132 assertFalse(tm.validate(new PfValidationResult()).isValid());
135 assertTrue(PfModelService.existsModel(tm.getServiceTemplates().getId()));
136 PfModelService.deregisterModel(tm.getServiceTemplates().getId());
140 fail("test should throw an exception");
141 } catch (Exception exc) {
142 assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());