2 * ============LICENSE_START==========================================
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
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.notification;
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;
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.
49 * Tests {@link EventCallback}
52 public class EventCallbackNoMockTest {
54 private static final String CONFIG_FILE = "model-loader.properties";
56 private ModelLoaderConfig config;
57 private Properties configProperties;
58 private EventCallback eventCallback;
60 private ArtifactDeploymentManager mockArtifactDeploymentManager;
61 private ArtifactDownloadManager mockArtifactDownloadManager;
62 private IDistributionClient mockDistributionClient;
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);
70 mockArtifactDeploymentManager = PowerMockito.mock(ArtifactDeploymentManager.class);
71 mockArtifactDownloadManager = PowerMockito.mock(ArtifactDownloadManager.class);
72 mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
74 eventCallback = new EventCallback(mockDistributionClient, config);
76 Whitebox.setInternalState(eventCallback, mockArtifactDeploymentManager);
77 Whitebox.setInternalState(eventCallback, mockArtifactDownloadManager);
81 public void tearDown() {
83 configProperties = null;
85 mockArtifactDeploymentManager = null;
86 mockArtifactDownloadManager = null;
87 mockDistributionClient = null;
91 @SuppressWarnings("unchecked")
92 public void activateCallback_downloadFails() {
93 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
95 PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),
96 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(false);
98 eventCallback.activateCallback(data);
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);
105 @SuppressWarnings("unchecked")
107 public void activateCallback() throws BabelArtifactParsingException {
108 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
110 PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),
111 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(true);
113 PowerMockito.when(mockArtifactDeploymentManager.deploy(Mockito.any(INotificationData.class),
114 Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(true);
116 eventCallback.activateCallback(data);
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));