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