bc88c857350736c9cfc18252874a23ff44a4f79a
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / EventCallbackTest.java
1 /**\r
2  * ============LICENSE_START==========================================\r
3  * org.onap.aai\r
4  * ===================================================================\r
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017-2018 Amdocs\r
7  * ===================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *        http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END============================================\r
20  */\r
21 package org.onap.aai.modelloader.notification;\r
22 \r
23 import static org.mockito.Matchers.any;\r
24 import static org.mockito.Mockito.mock;\r
25 import static org.mockito.Mockito.verify;\r
26 import static org.mockito.Mockito.when;\r
27 \r
28 import java.io.IOException;\r
29 import java.util.List;\r
30 import java.util.Properties;\r
31 import org.junit.After;\r
32 import org.junit.Before;\r
33 import org.junit.Test;\r
34 import org.mockito.Mockito;\r
35 import org.mockito.internal.util.reflection.Whitebox;\r
36 import org.onap.aai.modelloader.config.ModelLoaderConfig;\r
37 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;\r
38 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;\r
39 import org.openecomp.sdc.api.IDistributionClient;\r
40 import org.openecomp.sdc.api.notification.INotificationData;\r
41 \r
42 /**\r
43  * Tests {@link EventCallback}\r
44  */\r
45 public class EventCallbackTest {\r
46 \r
47     private static final String CONFIG_FILE = "model-loader.properties";\r
48 \r
49     private ModelLoaderConfig config;\r
50     private Properties configProperties;\r
51     private EventCallback eventCallback;\r
52 \r
53     private ArtifactDeploymentManager mockArtifactDeploymentManager;\r
54     private ArtifactDownloadManager mockArtifactDownloadManager;\r
55     private IDistributionClient mockDistributionClient;\r
56 \r
57     @Before\r
58     public void setup() throws IOException {\r
59         configProperties = new Properties();\r
60         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));\r
61         config = new ModelLoaderConfig(configProperties, null);\r
62 \r
63         mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class);\r
64         mockArtifactDownloadManager = mock(ArtifactDownloadManager.class);\r
65         mockDistributionClient = mock(IDistributionClient.class);\r
66 \r
67         eventCallback = new EventCallback(mockDistributionClient, config);\r
68 \r
69         Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager);\r
70         Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager);\r
71     }\r
72 \r
73     @After\r
74     public void tearDown() {\r
75         config = null;\r
76         configProperties = null;\r
77         eventCallback = null;\r
78         mockArtifactDeploymentManager = null;\r
79         mockArtifactDownloadManager = null;\r
80         mockDistributionClient = null;\r
81     }\r
82 \r
83     @Test\r
84     @SuppressWarnings("unchecked")\r
85     public void activateCallback_downloadFails() {\r
86         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();\r
87 \r
88         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),\r
89                 any(List.class), any(List.class))).thenReturn(false);\r
90 \r
91         eventCallback.activateCallback(data);\r
92 \r
93         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),\r
94                 any(List.class), any(List.class));\r
95         Mockito.verifyZeroInteractions(mockArtifactDeploymentManager);\r
96     }\r
97 \r
98     @SuppressWarnings("unchecked")\r
99     @Test\r
100     public void activateCallback() throws BabelArtifactParsingException {\r
101         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();\r
102 \r
103         when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),\r
104                 any(List.class), any(List.class))).thenReturn(true);\r
105 \r
106         when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class),\r
107                 any(List.class))).thenReturn(true);\r
108 \r
109         eventCallback.activateCallback(data);\r
110 \r
111         verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),\r
112                 any(List.class), any(List.class));\r
113         verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class),\r
114                 any(List.class));\r
115     }\r
116 }\r