Revisions made to the Model Loader to use Babel
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / extraction / ArtifactInfoExtractorTest.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 Amdocs
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.extraction.ArtifactInfoExtractor;
36 import org.onap.aai.modelloader.fixture.ArtifactInfoBuilder;
37 import org.onap.aai.modelloader.fixture.TestNotificationDataImpl;
38 import org.openecomp.sdc.api.notification.IArtifactInfo;
39 import org.openecomp.sdc.api.notification.INotificationData;
40
41 /**
42  * Tests {@link ArtifactInfoExtractor}
43  */
44 public class ArtifactInfoExtractorTest {
45
46     private ArtifactInfoExtractor extractor;
47
48     @Before
49     public void setup() {
50         extractor = new ArtifactInfoExtractor();
51     }
52
53     @After
54     public void tearDown() {
55         extractor = null;
56     }
57
58     @Test
59     public void extract_nullDataSupplied() {
60         doEmptyArtifactsTest(null);
61     }
62
63     private void doEmptyArtifactsTest(INotificationData notificationData) {
64         assertTrue("The list returned should have been empty", extractor.extract(notificationData).isEmpty());
65     }
66
67     @Test
68     public void extract_dataHasNullArtifacts() {
69         doEmptyArtifactsTest(new TestNotificationDataImpl());
70     }
71
72     @Test
73     public void extract_dataHasNoArtifacts() {
74         doEmptyArtifactsTest(getEmptyNotificationData());
75     }
76
77     @Test
78     public void dataHasOneServiceArtifact() {
79         IArtifactInfo expected = ArtifactInfoBuilder.build("S", "service", "description of service", "s1.0");
80
81         List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneService());
82
83         assertTrue("One artifact should have been returned", artifacts.size() == 1);
84         assertEquals("The actual artifact did not match the expected one", expected, artifacts.get(0));
85     }
86
87     @Test
88     public void dataHasOneResourceArtifact() {
89         List<IArtifactInfo> expectedArtifacts = new ArrayList<>();
90         expectedArtifacts.add(ArtifactInfoBuilder.build("R", "resource", "description of resource", "r1.0"));
91
92         List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneResource());
93
94         assertTrue("One artifact should have been returned", artifacts.size() == 1);
95         assertEquals("The actual artifact did not match the expected one", expectedArtifacts, artifacts);
96     }
97
98     @Test
99     public void dataHasOneServiceAndTwoResources() {
100         List<IArtifactInfo> expectedArtifacts = new ArrayList<>();
101         expectedArtifacts.add(ArtifactInfoBuilder.build("TOSCA_CSAR", "service", "description of service", "s1.0"));
102         expectedArtifacts.add(ArtifactInfoBuilder.build("TOSCA_CSAR", "resource", "description of resource", "r1.0"));
103
104         List<IArtifactInfo> artifacts = extractor.extract(getNotificationDataWithOneServiceAndResources());
105
106         assertTrue("One artifact should have been returned", artifacts.size() == 2);
107         assertEquals("The actual artifact did not match the expected one", expectedArtifacts, artifacts);
108     }
109 }