2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 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.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
33 * Context model tests.
35 * @author Liam Fallon (liam.fallon@ericsson.com)
37 public class ContextModelTest {
41 assertNotNull(new AxContextModel());
42 assertNotNull(new AxContextModel(new AxArtifactKey()));
43 assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation()));
44 assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
45 new AxKeyInformation()));
47 final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
48 final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
49 final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
50 final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
51 final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
52 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey));
57 assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50));
59 final AxContextModel clonedModel = new AxContextModel(model);
61 assertNotEquals(0, model.hashCode());
63 assertEquals(model, model);
64 assertEquals(model, clonedModel);
65 assertNotEquals(model, (Object) "Hello");
66 assertNotEquals(model, new AxContextModel(new AxArtifactKey()));
67 assertNotEquals(model, new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
68 new AxKeyInformation()));
69 assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
70 new AxKeyInformation()));
71 assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
72 new AxKeyInformation(keyInfoKey)));
73 assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
74 new AxKeyInformation(keyInfoKey)));
75 assertEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
76 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)));
78 assertEquals(0, model.compareTo(model));
79 assertEquals(0, model.compareTo(clonedModel));
80 assertNotEquals(0, model.compareTo(new AxArtifactKey()));
81 assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
82 new AxContextAlbums(), new AxKeyInformation())));
83 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
84 new AxKeyInformation())));
85 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
86 new AxKeyInformation(keyInfoKey))));
87 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
88 new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
89 assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
90 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));