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.extraction;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getEmptyNotificationData;
26 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneResource;
27 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneService;
28 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneServiceAndResources;
30 import java.util.ArrayList;
31 import java.util.List;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aai.modelloader.fixture.ArtifactInfoBuilder;
36 import org.onap.aai.modelloader.fixture.MockNotificationDataImpl;
37 import org.onap.sdc.api.notification.IArtifactInfo;
38 import org.onap.sdc.api.notification.INotificationData;
41 * Tests {@link ArtifactInfoExtractor}.
43 public class TestArtifactInfoExtractor {
45 private ArtifactInfoExtractor extractor;
49 extractor = new ArtifactInfoExtractor();
53 public void tearDown() {
58 public void extract_nullDataSupplied() {
59 doEmptyArtifactsTest(null);
62 private void doEmptyArtifactsTest(INotificationData notificationData) {
63 assertTrue("The list returned should have been empty", extractor.extract(notificationData).isEmpty());
67 public void extract_dataHasNullArtifacts() {
68 doEmptyArtifactsTest(new MockNotificationDataImpl());
72 public void extract_dataHasNoArtifacts() {
73 doEmptyArtifactsTest(getEmptyNotificationData());
77 public void dataHasOneServiceArtifact() {
78 IArtifactInfo expected = ArtifactInfoBuilder.build("S", "service", "description of service", "s1.0");
80 List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneService());
82 assertEquals("One artifact should have been returned", 1, artifacts.size());
83 assertEquals("The actual artifact did not match the expected one", expected, artifacts.get(0));
87 public void dataHasOneResourceArtifact() {
88 List<IArtifactInfo> expectedArtifacts = new ArrayList<>();
89 expectedArtifacts.add(ArtifactInfoBuilder.build("R", "resource", "description of resource", "r1.0"));
91 List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneResource());
93 assertEquals("One artifact should have been returned", 1, artifacts.size());
94 assertEquals("The actual artifact did not match the expected one", expectedArtifacts, artifacts);
98 public void dataHasOneServiceAndTwoResources() {
99 List<IArtifactInfo> expectedArtifacts = new ArrayList<>();
100 expectedArtifacts.add(ArtifactInfoBuilder.build("TOSCA_CSAR", "service", "description of service", "s1.0"));
101 expectedArtifacts.add(ArtifactInfoBuilder.build("TOSCA_CSAR", "resource", "description of resource", "r1.0"));
103 List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneServiceAndResources());
105 assertEquals("Two artifact should have been returned", 2, artifacts.size());
106 assertEquals("The actual artifact did not match the expected one", expectedArtifacts, artifacts);