2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.contextmodel.concepts;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
35 * Context model tests.
37 * @author Liam Fallon (liam.fallon@ericsson.com)
39 public class ContextModelTest {
43 assertNotNull(new AxContextModel());
44 assertNotNull(new AxContextModel(new AxArtifactKey()));
45 assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation()));
46 assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
47 new AxKeyInformation()));
49 final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
50 final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
51 final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
52 final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
53 final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
54 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey));
59 assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50));
61 final AxContextModel clonedModel = new AxContextModel(model);
63 assertFalse(model.hashCode() == 0);
65 assertTrue(model.equals(model));
66 assertTrue(model.equals(clonedModel));
67 assertFalse(model.equals((Object) "Hello"));
68 assertFalse(model.equals(new AxContextModel(new AxArtifactKey())));
69 assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
70 new AxKeyInformation())));
71 assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
72 new AxKeyInformation())));
73 assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
74 new AxKeyInformation(keyInfoKey))));
75 assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
76 new AxKeyInformation(keyInfoKey))));
77 assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
78 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
80 assertEquals(0, model.compareTo(model));
81 assertEquals(0, model.compareTo(clonedModel));
82 assertNotEquals(0, model.compareTo(new AxArtifactKey()));
83 assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
84 new AxContextAlbums(), new AxKeyInformation())));
85 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
86 new AxKeyInformation())));
87 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
88 new AxKeyInformation(keyInfoKey))));
89 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
90 new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
91 assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
92 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));