b6f15e470dfdc897fdb81df35f7bb96636b60fec
[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-2018 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 package org.onap.aai.introspection.tools;
21
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.onap.aai.AAISetup;
25 import org.onap.aai.introspection.*;
26 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
27
28 import static org.junit.Assert.assertFalse;
29 import static org.junit.Assert.assertTrue;
30
31 public class CreateUUIDTest extends AAISetup {
32
33     private CreateUUID createUUID;
34
35     private Loader loader;
36     private Issue issue;
37
38     @Before
39     public void setup(){
40         createUUID = new CreateUUID();
41         loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, schemaVersions.getDefaultVersion());
42     }
43
44     /**
45      * Tests to check if the issue is not resolvable since
46      * the property that is being tested doesn't have the auto generated uuid
47      * metadata set to true in the oxm xml for the version specified
48      *
49      * @throws AAIUnknownObjectException - if the object type specified is unable to be found in the oxm
50      */
51     @Test
52     public void testNonResolvableIssueIfMissingPropNameThatIsRequired() throws AAIUnknownObjectException {
53
54         Introspector introspector = loader.introspectorFromName("pserver");
55
56         issue = new Issue();
57         issue.setDetail("Some message");
58         issue.setType(IssueType.MISSING_KEY_PROP);
59         issue.setPropName("hostname");
60         issue.setIntrospector(introspector);
61
62         boolean isIssue = createUUID.resolveIssue(issue);
63
64         assertFalse(isIssue);
65     }
66
67     /**
68      * Tests when there is a resolvable issue when the property
69      * looking for, model-element-uuid, has the auto generated uuid
70      * metadata attribute associated to it if the data is missing
71      *
72      * @throws AAIUnknownObjectException - if the object type specified is unable to be found in the oxm
73      */
74     @Test
75     public void testResolvableIssueWhenMissingPropNameAllowsToUseGeneratedUUID() throws AAIUnknownObjectException {
76
77         Introspector introspector = loader.introspectorFromName("model-element");
78
79         issue = new Issue();
80         issue.setDetail("Some message");
81         issue.setType(IssueType.MISSING_KEY_PROP);
82         issue.setPropName("model-element-uuid");
83         issue.setIntrospector(introspector);
84
85         boolean isIssue = createUUID.resolveIssue(issue);
86         assertTrue(isIssue);
87     }
88
89 }