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