Revisions made to the Model Loader to use Babel
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / EventCallbackNoMockTest.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.notification;
22
23 import java.io.IOException;
24 import java.util.List;
25 import java.util.Properties;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mockito;
30 import org.onap.aai.modelloader.config.ModelLoaderConfig;
31 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
32 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
33 import org.openecomp.sdc.api.IDistributionClient;
34 import org.openecomp.sdc.api.notification.INotificationData;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.reflect.Whitebox;
37
38 /**
39  * No-Mock tests
40  * 
41  * Because Jacoco (and other coverage tools) can't cope with mocked classes under some circumstances, coverage is/was
42  * falsely reported as < 50%. Hence these duplicated but non-mock tests to address this, for ONAP reasons.
43  * 
44  * @author andrewdo
45  *
46  */
47
48 /**
49  * Tests {@link EventCallback}
50  */
51
52 public class EventCallbackNoMockTest {
53
54     private static final String CONFIG_FILE = "model-loader.properties";
55
56     private ModelLoaderConfig config;
57     private Properties configProperties;
58     private EventCallback eventCallback;
59
60     private ArtifactDeploymentManager mockArtifactDeploymentManager;
61     private ArtifactDownloadManager mockArtifactDownloadManager;
62     private IDistributionClient mockDistributionClient;
63
64     @Before
65     public void setup() throws IOException {
66         configProperties = new Properties();
67         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
68         config = new ModelLoaderConfig(configProperties, null);
69
70         mockArtifactDeploymentManager = PowerMockito.mock(ArtifactDeploymentManager.class);
71         mockArtifactDownloadManager = PowerMockito.mock(ArtifactDownloadManager.class);
72         mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
73
74         eventCallback = new EventCallback(mockDistributionClient, config);
75
76         Whitebox.setInternalState(eventCallback, mockArtifactDeploymentManager);
77         Whitebox.setInternalState(eventCallback, mockArtifactDownloadManager);
78     }
79
80     @After
81     public void tearDown() {
82         config = null;
83         configProperties = null;
84         eventCallback = null;
85         mockArtifactDeploymentManager = null;
86         mockArtifactDownloadManager = null;
87         mockDistributionClient = null;
88     }
89
90     @Test
91     @SuppressWarnings("unchecked")
92     public void activateCallback_downloadFails() {
93         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
94
95         PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),
96                 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(false);
97
98         eventCallback.activateCallback(data);
99
100         Mockito.verify(mockArtifactDownloadManager).downloadArtifacts(Mockito.any(INotificationData.class),
101                 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));
102         Mockito.verifyZeroInteractions(mockArtifactDeploymentManager);
103     }
104
105     @SuppressWarnings("unchecked")
106     @Test
107     public void activateCallback() throws BabelArtifactParsingException {
108         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
109
110         PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),
111                 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(true);
112
113         PowerMockito.when(mockArtifactDeploymentManager.deploy(Mockito.any(INotificationData.class),
114                 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(true);
115
116         eventCallback.activateCallback(data);
117
118         Mockito.verify(mockArtifactDownloadManager).downloadArtifacts(Mockito.any(INotificationData.class),
119                 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));
120         Mockito.verify(mockArtifactDeploymentManager).deploy(Mockito.any(INotificationData.class),
121                 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));
122     }
123 }