2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.modelloader.entity.model;
23 import static org.junit.Assert.assertTrue;
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;
31 public class ModelArtifactParserTest {
34 public void testParseModelFileNoDeps() throws Exception {
35 final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
38 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE)));
40 ModelArtifactParser parser = new ModelArtifactParser();
41 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
43 assertTrue(modelList.size() == 1);
45 ModelArtifact model = (ModelArtifact) modelList.get(0);
46 System.out.println(model.toString());
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) {
61 public void testParseModelFileDeps() throws Exception {
62 final String MODEL_FILE = "src/test/resources/models/AAI-stellService-service-1.xml";
65 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE)));
67 ModelArtifactParser parser = new ModelArtifactParser();
68 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
70 assertTrue(modelList.size() == 1);
72 ModelArtifact model = (ModelArtifact) modelList.get(0);
73 System.out.println(model.toString());
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) {
90 public void testParseModelFileInvalidArtifact() throws Exception {
91 final String MODEL_FILE = "src/test/resources/models/invalid-model.xml";
94 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE)));
96 ModelArtifactParser parser = new ModelArtifactParser();
97 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
99 assertTrue(modelList == null || modelList.isEmpty());
100 } catch (Exception e) {
107 public void testParseModelFileIncompleteArtifact() throws Exception {
108 final String MODEL_FILE = "src/test/resources/models/incomplete-model.xml";
111 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE)));
113 ModelArtifactParser parser = new ModelArtifactParser();
114 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
116 assertTrue(modelList == null || modelList.isEmpty());
117 } catch (Exception e) {