bb2604eca9658be264475c88ce3f17614e265ccd
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / introspection / tools / CreateUUIDTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.introspection.tools;
23
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.aai.AAISetup;
27 import org.onap.aai.introspection.*;
28 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
29
30 import static org.junit.Assert.assertFalse;
31 import static org.junit.Assert.assertTrue;
32
33 public class CreateUUIDTest extends AAISetup {
34
35     private CreateUUID createUUID;
36
37     private Loader loader;
38     private Issue issue;
39
40     @Before
41     public void setup(){
42         createUUID = new CreateUUID();
43         loader = LoaderFactory.createLoaderForVersion(ModelType.MOXY, Version.getLatest());
44     }
45
46     /**
47      * Tests to check if the issue is not resolvable since
48      * the property that is being tested doesn't have the auto generated uuid
49      * metadata set to true in the oxm xml for the version specified
50      *
51      * @throws AAIUnknownObjectException - if the object type specified is unable to be found in the oxm
52      */
53     @Test
54     public void testNonResolvableIssueIfMissingPropNameThatIsRequired() throws AAIUnknownObjectException {
55
56         Introspector introspector = loader.introspectorFromName("pserver");
57
58         issue = new Issue();
59         issue.setDetail("Some message");
60         issue.setType(IssueType.MISSING_KEY_PROP);
61         issue.setPropName("hostname");
62         issue.setIntrospector(introspector);
63
64         boolean isIssue = createUUID.resolveIssue(issue);
65
66         assertFalse(isIssue);
67     }
68
69     /**
70      * Tests when there is a resolvable issue when the property
71      * looking for, model-element-uuid, has the auto generated uuid
72      * metadata attribute associated to it if the data is missing
73      *
74      * @throws AAIUnknownObjectException - if the object type specified is unable to be found in the oxm
75      */
76     @Test
77     public void testResolvableIssueWhenMissingPropNameAllowsToUseGeneratedUUID() throws AAIUnknownObjectException {
78
79         Introspector introspector = loader.introspectorFromName("model-element");
80
81         issue = new Issue();
82         issue.setDetail("Some message");
83         issue.setType(IssueType.MISSING_KEY_PROP);
84         issue.setPropName("model-element-uuid");
85         issue.setIntrospector(introspector);
86
87         boolean isIssue = createUUID.resolveIssue(issue);
88         assertTrue(isIssue);
89     }
90
91 }