Allow handling of legact model artifacts
[aai/model-loader.git] / src / test / java / org / openecomp / modelloader / entity / model / ModelArtifactParserTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Model Loader
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  * http://www.apache.org/licenses/LICENSE-2.0
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 and OpenECOMP are trademarks
21  * and service marks of AT&T Intellectual Property.
22  */
23 package org.openecomp.modelloader.entity.model;
24
25 import static org.junit.Assert.assertTrue;
26
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.util.List;
30
31 import org.junit.Test;
32 import org.openecomp.modelloader.entity.Artifact;
33
34 public class ModelArtifactParserTest {
35
36         @Test
37         public void testParseModelFileNoDeps() throws Exception {
38                 final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
39
40                 try {
41                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
42
43                         ModelArtifactParser parser = new ModelArtifactParser();
44                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
45
46                         assertTrue(modelList.size() == 1);
47
48                         ModelArtifact model = (ModelArtifact) modelList.get(0);
49                         System.out.println(model.toString());
50
51                         assertTrue(model.getModelInvariantId().equalsIgnoreCase("3d560d81-57d0-438b-a2a1-5334dba0651a"));
52                         assertTrue(model.getModelNamespace().equalsIgnoreCase("http://org.openecomp.aai.inventory/v9"));
53                         assertTrue(model.getModelNamespaceVersion().equalsIgnoreCase("v9"));
54                         assertTrue(model.getType().toString().equalsIgnoreCase("MODEL"));
55                         System.out.println(model.getDependentModelIds().size());
56                         assertTrue(model.getDependentModelIds().size() == 0);
57                 } catch (Exception e) {
58                         e.printStackTrace();
59                         assertTrue(false);
60                 }
61         }
62
63         @Test
64         public void testParseModelFileDeps() throws Exception {
65                 final String MODEL_FILE = "src/test/resources/models/AAI-stellService-service-1.xml";
66
67                 try {
68                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
69
70                         ModelArtifactParser parser = new ModelArtifactParser();
71                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
72
73                         assertTrue(modelList.size() == 1);
74
75                         ModelArtifact model = (ModelArtifact) modelList.get(0);
76                         System.out.println(model.toString());
77
78                         assertTrue(model.getModelInvariantId().equalsIgnoreCase("fedf9da3-6a74-4813-8fa2-221a98b0e7ad"));
79                         assertTrue(model.getModelVerId().equalsIgnoreCase("e0373537-7f66-4094-9939-e2f5de6ff5f6"));
80                         assertTrue(model.getType().toString().equalsIgnoreCase("MODEL"));
81                         assertTrue(model.getDependentModelIds().size() == 3);
82                         assertTrue(model.getDependentModelIds().contains("5c12984d-db0f-4300-a0e0-9791775cc40f|88bdbadf-db8a-490f-881e-c8effcbc3f66"));
83                         assertTrue(model.getDependentModelIds().contains("959b7c09-9f34-4e5f-8b63-505381db176e|374d0899-bbc2-4403-9320-fe9bebef75c6"));
84                 } catch (Exception e) {
85                         e.printStackTrace();
86                         assertTrue(false);
87                 }
88         }
89
90         @Test
91         public void testParseModelFileInvalidArtifact() throws Exception {
92                 final String MODEL_FILE = "src/test/resources/models/invalid-model.xml";
93
94                 try {
95                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));            
96
97                         ModelArtifactParser parser = new ModelArtifactParser();
98                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
99
100                         assertTrue(modelList == null || modelList.isEmpty());
101                 }
102                 catch (Exception e) {
103                         e.printStackTrace();
104                         assertTrue(false);
105                 }
106         }
107
108         @Test
109         public void testParseModelFileIncompleteArtifact() throws Exception {
110                 final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml";
111
112                 try {
113                         byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));            
114
115                         ModelArtifactParser parser = new ModelArtifactParser();
116                         List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
117
118                         assertTrue(modelList == null || modelList.isEmpty());
119                 }
120                 catch (Exception e) {
121                         e.printStackTrace();
122                         assertTrue(false);
123                 }
124         }
125 }