6a9bd61e12559cfb77e0dceac4076d60d4b55b3b
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / entity / model / ModelV8ArtifactParserTest.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.ModelV8Artifact;
35 import org.onap.aai.modelloader.entity.model.ModelV8ArtifactParser;
36
37 public class ModelV8ArtifactParserTest {
38
39   @Test
40   public void testParseModelFile() throws Exception {
41     final String MODEL_FILE = "src/test/resources/models/v8-wan-connector-model.xml";
42
43     try {
44       byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));
45
46       ModelV8ArtifactParser parser = new ModelV8ArtifactParser();
47       List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
48
49       assertTrue(modelList.size() == 1);
50
51       ModelV8Artifact model = (ModelV8Artifact) modelList.get(0);
52       System.out.println(model.toString());
53
54       assertTrue(model.getModelNameVersionId().equalsIgnoreCase("93d9d45d-7eec-4371-9083-675e4c353de3"));
55       assertTrue(model.getModelNamespace().equalsIgnoreCase("http://com.att.aai.inventory/v7"));
56       assertTrue(model.getModelNamespaceVersion().equalsIgnoreCase("v7"));                      
57       assertTrue(model.getType().toString().equalsIgnoreCase("MODEL_V8"));
58       assertTrue(model.getDependentModelIds().size() == 7);
59       assertTrue(model.getDependentModelIds().contains("d09dd9da-0148-46cd-a947-591afc844d24"));
60       assertTrue(model.getDependentModelIds().contains("997fc7-fca1-451f-b953-9a1e6197b4d6"));
61       assertTrue(model.getDependentModelIds().contains("ae16244f-4d29-4801-a559-e25f2db2a4c3"));
62       assertTrue(model.getDependentModelIds().contains("759dbd4a-2473-46f3-a932-48d987c9b4a1"));
63       assertTrue(model.getDependentModelIds().contains("a6d9de88-4046-4b78-a59e-5691243d292a"));
64       assertTrue(model.getDependentModelIds().contains("35be1acf-1298-48c6-a128-66850083b8bd"));
65     } catch (Exception e) {
66       e.printStackTrace();
67       assertTrue(false);
68     }
69   }
70
71   @Test
72   public void testParseModelFileInvalidArtifact() throws Exception {
73     final String MODEL_FILE = "src/test/resources/models/invalid-model.xml";
74
75     try {
76       byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));              
77
78       ModelV8ArtifactParser parser = new ModelV8ArtifactParser();
79       List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
80
81       assertTrue(modelList == null || modelList.isEmpty());
82     }
83     catch (Exception e) {
84       e.printStackTrace();
85       assertTrue(false);
86     }
87   }
88
89   @Test
90   public void testParseModelFileIncompleteArtifact() throws Exception {
91     final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml";
92
93     try {
94       byte[] xmlBytes = Files.readAllBytes(Paths.get(MODEL_FILE));              
95
96       ModelV8ArtifactParser parser = new ModelV8ArtifactParser();
97       List<Artifact> modelList = parser.parse(xmlBytes, "test-artifact");
98
99       assertTrue(modelList == null || modelList.isEmpty());
100     }
101     catch (Exception e) {
102       e.printStackTrace();
103       assertTrue(false);
104     }
105   }
106
107 }