2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License
11 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing permissions and limitations under
15 * SPDX-License-Identifier: Apache-2.0
16 * ============LICENSE_END=========================================================
19 package org.onap.appc.sdc.artifacts.impl;
21 import static org.mockito.Matchers.anyObject;
22 import static org.mockito.Matchers.anyString;
23 import static org.mockito.Mockito.times;
24 import static org.mockito.Mockito.verify;
25 import static org.mockito.Mockito.when;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Mockito;
31 import org.onap.appc.adapter.message.EventSender;
32 import org.onap.appc.exceptions.APPCException;
33 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
34 import org.onap.appc.sdc.listener.ProviderOperations;
35 import org.onap.appc.sdc.listener.ProviderResponse;
36 import org.onap.appc.sdc.listener.Util;
37 import org.onap.sdc.api.IDistributionClient;
38 import org.onap.sdc.api.notification.IArtifactInfo;
39 import org.onap.sdc.api.notification.INotificationData;
40 import org.onap.sdc.api.notification.IResourceInstance;
41 import org.powermock.api.mockito.PowerMockito;
42 import org.powermock.core.classloader.annotations.PrepareForTest;
43 import org.powermock.modules.junit4.PowerMockRunner;
46 * This class contains test methods for ConfigArtifact Processor.
50 @RunWith(PowerMockRunner.class)
51 @PrepareForTest({ProviderOperations.class, Util.class})
52 public class TestConfigArtifcatProcessor {
54 private ConfigArtifactProcessor configArtifactProcessor;
56 private SDCArtifact sdcArtifact;
58 private URI uri = URI.create("http://localhost:8080");
60 private IDistributionClient client;
62 private EventSender eventSender;
64 private ProviderResponse response;
66 private INotificationData notificationData;
68 private IResourceInstance resourceInstance;
70 private IArtifactInfo artifactInfo;
73 public void setup() throws APPCException {
74 client = Mockito.mock(IDistributionClient.class);
75 notificationData = Mockito.mock(INotificationData.class);
76 resourceInstance = Mockito.mock(IResourceInstance.class);
77 artifactInfo = Mockito.mock(IArtifactInfo.class);
78 sdcArtifact = Mockito.mock(SDCArtifact.class);
79 eventSender = Mockito.mock(EventSender.class);
80 configArtifactProcessor = new ConfigArtifactProcessor(client, eventSender, notificationData,
81 resourceInstance, artifactInfo, uri);
82 response = new ProviderResponse(200, "{\"key\":\"value\"}");
86 * This method tests the process Artifacts method success scenario.
88 * @throws APPCException if the there are any exception in sdc artifacts
91 public void testProcessArtifact() throws APPCException {
92 PowerMockito.mockStatic(ProviderOperations.class);
93 PowerMockito.mockStatic(Util.class);
94 when(ProviderOperations.post(anyObject(), anyString(), anyObject())).thenReturn(response);
95 when(Util.parseResponse(anyObject())).thenReturn(true);
96 ConfigArtifactProcessor configArtifactProcessorSpy = Mockito.spy(configArtifactProcessor);
97 configArtifactProcessorSpy.processArtifact(sdcArtifact);
98 verify(configArtifactProcessorSpy, times(1)).processArtifact(sdcArtifact);
102 * This method tests the process Artifacts method failure scenario.
104 * @throws APPCException if the there are any exception in sdc artifacts
106 @Test(expected = APPCException.class)
107 public void testProcessArtifactFail() throws APPCException {
108 PowerMockito.mockStatic(ProviderOperations.class);
109 when(ProviderOperations.post(anyObject(), anyString(), anyObject())).thenReturn(response);
110 configArtifactProcessor.processArtifact(sdcArtifact);
114 * This method tests the process Artifacts method failure scenario when the uri is null.
116 * @throws APPCException if the there are any exception in sdc artifacts or in creating
117 * notification data, resource data & service artifacts
120 public void testProcessArtifactWithNoURI() throws APPCException {
121 configArtifactProcessor = new ConfigArtifactProcessor(client, eventSender, notificationData,
122 resourceInstance, artifactInfo, null);
123 ConfigArtifactProcessor configArtifactProcessorSpy = Mockito.spy(configArtifactProcessor);
124 configArtifactProcessorSpy.processArtifact(sdcArtifact);
125 verify(configArtifactProcessorSpy, times(1)).processArtifact(sdcArtifact);