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