3957c7ce89417732b577339f668b59033b30c9e7
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / extraction / TestArtifactInfoExtractor.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.modelloader.extraction;
22
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;
29
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;
39
40 /**
41  * Tests {@link ArtifactInfoExtractor}.
42  */
43 public class TestArtifactInfoExtractor {
44
45     private ArtifactInfoExtractor extractor;
46
47     @Before
48     public void setup() {
49         extractor = new ArtifactInfoExtractor();
50     }
51
52     @After
53     public void tearDown() {
54         extractor = null;
55     }
56
57     @Test
58     public void extract_nullDataSupplied() {
59         doEmptyArtifactsTest(null);
60     }
61
62     private void doEmptyArtifactsTest(INotificationData notificationData) {
63         assertTrue("The list returned should have been empty", extractor.extract(notificationData).isEmpty());
64     }
65
66     @Test
67     public void extract_dataHasNullArtifacts() {
68         doEmptyArtifactsTest(new MockNotificationDataImpl());
69     }
70
71     @Test
72     public void extract_dataHasNoArtifacts() {
73         doEmptyArtifactsTest(getEmptyNotificationData());
74     }
75
76     @Test
77     public void dataHasOneServiceArtifact() {
78         IArtifactInfo expected = ArtifactInfoBuilder.build("S", "service", "description of service", "s1.0");
79
80         List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneService());
81
82         assertTrue("One artifact should have been returned", artifacts.size() == 1);
83         assertEquals("The actual artifact did not match the expected one", expected, artifacts.get(0));
84     }
85
86     @Test
87     public void dataHasOneResourceArtifact() {
88         List<IArtifactInfo> expectedArtifacts = new ArrayList<>();
89         expectedArtifacts.add(ArtifactInfoBuilder.build("R", "resource", "description of resource", "r1.0"));
90
91         List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneResource());
92
93         assertTrue("One artifact should have been returned", artifacts.size() == 1);
94         assertEquals("The actual artifact did not match the expected one", expectedArtifacts, artifacts);
95     }
96
97     @Test
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"));
102
103         List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneServiceAndResources());
104
105         assertTrue("One artifact should have been returned", artifacts.size() == 2);
106         assertEquals("The actual artifact did not match the expected one", expectedArtifacts, artifacts);
107     }
108 }