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.eventmodel.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.AxReferenceKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult;
35 import org.onap.policy.apex.model.eventmodel.concepts.AxField;
36 import org.onap.policy.apex.model.eventmodel.concepts.AxInputField;
37 import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField;
42 * @author Liam Fallon (liam.fallon@ericsson.com)
44 public class FieldTest {
47 public void testField() {
48 assertNotNull(new AxField());
49 assertNotNull(new AxField(new AxReferenceKey()));
50 assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey()));
51 assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey(), false));
52 assertNotNull(new AxField("LocalName", new AxArtifactKey(), false));
53 assertNotNull(new AxField("LocalName", new AxArtifactKey()));
54 assertNotNull(new AxField("LocalName", new AxArtifactKey(), false));
56 assertNotNull(new AxInputField());
57 assertNotNull(new AxInputField(new AxReferenceKey()));
58 assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey()));
59 assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey(), true));
60 assertNotNull(new AxInputField("LocalName", new AxArtifactKey()));
61 assertNotNull(new AxInputField(new AxInputField()));
63 assertNotNull(new AxOutputField());
64 assertNotNull(new AxOutputField(new AxReferenceKey()));
65 assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey()));
66 assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey(), false));
67 assertNotNull(new AxOutputField("LocalName", new AxArtifactKey()));
68 assertNotNull(new AxOutputField(new AxOutputField()));
70 final AxField field = new AxField();
72 final AxReferenceKey fieldKey = new AxReferenceKey("FieldName", "0.0.1", "PLN", "LN");
73 field.setKey(fieldKey);
74 assertEquals("FieldName:0.0.1:PLN:LN", field.getKey().getId());
75 assertEquals("FieldName:0.0.1:PLN:LN", field.getKeys().get(0).getId());
77 final AxArtifactKey schemaKey = new AxArtifactKey("SchemaName", "0.0.1");
78 field.setSchema(schemaKey);
79 assertEquals("SchemaName:0.0.1", field.getSchema().getId());
81 assertEquals(false, field.getOptional());
82 field.setOptional(true);
83 assertEquals(true, field.getOptional());
85 AxValidationResult result = new AxValidationResult();
86 result = field.validate(result);
87 assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult());
89 field.setKey(AxReferenceKey.getNullKey());
90 result = new AxValidationResult();
91 result = field.validate(result);
92 assertEquals(ValidationResult.INVALID, result.getValidationResult());
94 field.setKey(fieldKey);
95 result = new AxValidationResult();
96 result = field.validate(result);
97 assertEquals(ValidationResult.VALID, result.getValidationResult());
99 field.setSchema(AxArtifactKey.getNullKey());
100 result = new AxValidationResult();
101 result = field.validate(result);
102 assertEquals(ValidationResult.INVALID, result.getValidationResult());
104 field.setSchema(schemaKey);
105 result = new AxValidationResult();
106 result = field.validate(result);
107 assertEquals(ValidationResult.VALID, result.getValidationResult());
111 final AxField clonedField = new AxField(field);
112 assertEquals("AxField:(key=AxReferenceKey:(parentKeyName=FieldName,parentKeyVersion=0.0.1,"
113 + "parentLocalName=PLN,localName=LN),fieldSchemaKey="
114 + "AxArtifactKey:(name=SchemaName,version=0.0.1),optional=true)", clonedField.toString());
116 assertFalse(field.hashCode() == 0);
118 assertTrue(field.equals(field));
119 assertTrue(field.equals(clonedField));
120 assertFalse(field.equals(null));
121 assertFalse(field.equals((Object)"Hello"));
122 assertFalse(field.equals(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false)));
123 assertFalse(field.equals(new AxField(fieldKey, AxArtifactKey.getNullKey(), false)));
124 assertFalse(field.equals(new AxField(fieldKey, schemaKey, false)));
125 assertTrue(field.equals(new AxField(fieldKey, schemaKey, true)));
127 assertEquals(0, field.compareTo(field));
128 assertEquals(0, field.compareTo(clonedField));
129 assertNotEquals(0, field.compareTo(new AxArtifactKey()));
130 assertNotEquals(0, field.compareTo(null));
132 field.compareTo(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false)));
133 assertNotEquals(0, field.compareTo(new AxField(fieldKey, AxArtifactKey.getNullKey(), false)));
134 assertNotEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, false)));
135 assertEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, true)));
137 assertNotNull(field.getKeys());