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