Renaming openecomp to onap
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / entity / model / ModelArtifactParserTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23  */
24 package org.onap.aai.modelloader.entity.model;
25
26 import static org.junit.Assert.assertTrue;
27
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.List;
31
32 import org.junit.Test;
33 import org.onap.aai.modelloader.entity.Artifact;
34 import org.onap.aai.modelloader.entity.model.ModelArtifact;
35 import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
36
37 public class ModelArtifactParserTest {
38
39         @Test
40         public void testParseModelFileNoDeps() throws Exception {
41                 final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
42
43                 try {
44                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
45
46                         ModelArtifactParser parser = new ModelArtifactParser();
47                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
48
49                         assertTrue(modelList.size() == 1);
50
51                         ModelArtifact model = (ModelArtifact) modelList.get(0);
52                         System.out.println(model.toString());
53
54                         assertTrue(model.getModelInvariantId().equalsIgnoreCase("3d560d81-57d0-438b-a2a1-5334dba0651a"));
55                         assertTrue(model.getModelNamespace().equalsIgnoreCase("http://org.openecomp.aai.inventory/v9"));
56                         assertTrue(model.getModelNamespaceVersion().equalsIgnoreCase("v9"));
57                         assertTrue(model.getType().toString().equalsIgnoreCase("MODEL"));
58                         System.out.println(model.getDependentModelIds().size());
59                         assertTrue(model.getDependentModelIds().size() == 0);
60                 } catch (Exception e) {
61                         e.printStackTrace();
62                         assertTrue(false);
63                 }
64         }
65
66         @Test
67         public void testParseModelFileDeps() throws Exception {
68                 final String MODEL_FILE = "src/test/resources/models/AAI-stellService-service-1.xml";
69
70                 try {
71                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
72
73                         ModelArtifactParser parser = new ModelArtifactParser();
74                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
75
76                         assertTrue(modelList.size() == 1);
77
78                         ModelArtifact model = (ModelArtifact) modelList.get(0);
79                         System.out.println(model.toString());
80
81                         assertTrue(model.getModelInvariantId().equalsIgnoreCase("fedf9da3-6a74-4813-8fa2-221a98b0e7ad"));
82                         assertTrue(model.getModelVerId().equalsIgnoreCase("e0373537-7f66-4094-9939-e2f5de6ff5f6"));
83                         assertTrue(model.getType().toString().equalsIgnoreCase("MODEL"));
84                         assertTrue(model.getDependentModelIds().size() == 3);
85                         assertTrue(model.getDependentModelIds().contains("5c12984d-db0f-4300-a0e0-9791775cc40f|88bdbadf-db8a-490f-881e-c8effcbc3f66"));
86                         assertTrue(model.getDependentModelIds().contains("959b7c09-9f34-4e5f-8b63-505381db176e|374d0899-bbc2-4403-9320-fe9bebef75c6"));
87                 } catch (Exception e) {
88                         e.printStackTrace();
89                         assertTrue(false);
90                 }
91         }
92
93         @Test
94         public void testParseModelFileInvalidArtifact() throws Exception {
95                 final String MODEL_FILE = "src/test/resources/models/invalid-model.xml";
96
97                 try {
98                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));            
99
100                         ModelArtifactParser parser = new ModelArtifactParser();
101                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
102
103                         assertTrue(modelList == null || modelList.isEmpty());
104                 }
105                 catch (Exception e) {
106                         e.printStackTrace();
107                         assertTrue(false);
108                 }
109         }
110
111         @Test
112         public void testParseModelFileIncompleteArtifact() throws Exception {
113                 final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml";
114
115                 try {
116                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));            
117
118                         ModelArtifactParser parser = new ModelArtifactParser();
119                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
120
121                         assertTrue(modelList == null || modelList.isEmpty());
122                 }
123                 catch (Exception e) {
124                         e.printStackTrace();
125                         assertTrue(false);
126                 }
127         }
128 }