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.hamcrest.CoreMatchers.is;
24 import static org.hamcrest.CoreMatchers.not;
25 import static org.hamcrest.CoreMatchers.nullValue;
26 import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
27 import static org.junit.Assert.assertThat;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
31 import java.util.List;
32 import org.junit.Test;
33 import org.onap.aai.modelloader.entity.Artifact;
34 import org.springframework.util.CollectionUtils;
36 public class TestModelArtifactParser {
38 private static final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
39 private static final String MODEL_FILE_SERVICE = "src/test/resources/models/AAI-stellService-service-1.xml";
40 private static final String MODEL_FILE_INCOMPLETE = "src/test/resources/models/incomplete-model.xml";
41 private static final String MODEL_FILE_INVALID = "src/test/resources/models/invalid-model.xml";
44 public void testParseModelFileNoDeps() throws Exception {
45 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE)));
47 ModelArtifactParser parser = new ModelArtifactParser();
48 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
50 assertThat(modelList.size(), is(1));
52 ModelArtifact model = (ModelArtifact) modelList.get(0);
53 assertThat(model.toString(), is(not(nullValue())));
55 assertThat(model.getModelInvariantId(), equalToIgnoringCase("3d560d81-57d0-438b-a2a1-5334dba0651a"));
56 assertThat(model.getModelNamespace(), equalToIgnoringCase("http://org.openecomp.aai.inventory/v9"));
57 assertThat(model.getModelNamespaceVersion(), equalToIgnoringCase("v9"));
58 assertThat(model.getType().toString(), equalToIgnoringCase("MODEL"));
59 assertThat(model.getDependentModelIds().size(), is(0));
63 public void testParseModelFileDeps() throws Exception {
64 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE_SERVICE)));
66 ModelArtifactParser parser = new ModelArtifactParser();
67 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
69 assertThat(modelList.size(), is(1));
71 ModelArtifact model = (ModelArtifact) modelList.get(0);
72 assertThat(model.toString(), is(not(nullValue())));
73 assertThat(model.getModelInvariantId(), equalToIgnoringCase("fedf9da3-6a74-4813-8fa2-221a98b0e7ad"));
74 assertThat(model.getModelVerId(), equalToIgnoringCase("e0373537-7f66-4094-9939-e2f5de6ff5f6"));
75 assertThat(model.getType().toString(), equalToIgnoringCase("MODEL"));
76 assertThat(model.getDependentModelIds().size(), is(3));
77 assertThat(model.getDependentModelIds()
78 .contains("5c12984d-db0f-4300-a0e0-9791775cc40f|88bdbadf-db8a-490f-881e-c8effcbc3f66"), is(true));
79 assertThat(model.getDependentModelIds()
80 .contains("959b7c09-9f34-4e5f-8b63-505381db176e|374d0899-bbc2-4403-9320-fe9bebef75c6"), is(true));
84 public void testParseModelFileInvalidArtifact() throws Exception {
85 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE_INVALID)));
87 ModelArtifactParser parser = new ModelArtifactParser();
88 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
90 assertThat(CollectionUtils.isEmpty(modelList), is(true));
94 public void testParseModelFileIncompleteArtifact() throws Exception {
95 String fileString = new String(Files.readAllBytes(Paths.get(MODEL_FILE_INCOMPLETE)));
97 ModelArtifactParser parser = new ModelArtifactParser();
98 List<Artifact> modelList = parser.parse(fileString, "test-artifact");
100 assertThat(CollectionUtils.isEmpty(modelList), is(true));