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=========================================================
18 package org.onap.appc.sdc.artifacts.impl;
20 import static org.mockito.Matchers.anyString;
21 import static org.mockito.Mockito.times;
22 import static org.mockito.Mockito.verify;
23 import static org.mockito.Mockito.when;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.appc.adapter.message.EventSender;
28 import org.onap.appc.exceptions.APPCException;
29 import org.onap.appc.sdc.artifacts.helper.ArtifactStorageService;
30 import org.onap.appc.sdc.artifacts.helper.DependencyModelGenerator;
31 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
32 import org.onap.sdc.api.IDistributionClient;
33 import org.onap.sdc.api.notification.IArtifactInfo;
34 import org.onap.sdc.api.notification.INotificationData;
35 import org.onap.sdc.api.notification.IResourceInstance;
36 import org.onap.sdc.api.results.IDistributionClientDownloadResult;
37 import org.powermock.reflect.Whitebox;
40 * This class contains test methods for ToscaCsarArtifact Processor
44 public class TestToscaCsarArtifactProcessor {
46 private ToscaCsarArtifactProcessor toscaCsarArtifactProcessor;
48 private DependencyModelGenerator dependencyModelGenerator;
50 private ArtifactStorageService storageService;
52 private SDCArtifact sdcArtifact;
54 private IDistributionClientDownloadResult distributionClientDownloadResult;
56 private IDistributionClient client;
58 private EventSender eventSender;
60 private INotificationData notificationData;
62 private IResourceInstance resourceInstance;
64 private IArtifactInfo artifactInfo;
67 public void setup() throws Exception {
68 client = Mockito.mock(IDistributionClient.class);
69 eventSender = Mockito.mock(EventSender.class);
70 storageService = Mockito.mock(ArtifactStorageService.class);
71 distributionClientDownloadResult = Mockito.mock(IDistributionClientDownloadResult.class);
72 dependencyModelGenerator = Mockito.mock(DependencyModelGenerator.class);
73 toscaCsarArtifactProcessor = new ToscaCsarArtifactProcessor(client, eventSender,
74 notificationData, resourceInstance, artifactInfo, null);
75 Whitebox.setInternalState(toscaCsarArtifactProcessor, "artifactStorageService", storageService);
76 Whitebox.setInternalState(toscaCsarArtifactProcessor, "dependencyModelGenerator",
77 dependencyModelGenerator);
81 * This method tests the process Artifacts method success scenario.
83 * @throws APPCException if the there are any exception in sdc artifacts
86 public void testProcessArtifact() throws APPCException {
87 ToscaCsarArtifactProcessor toscaCsarArtifactProcessorSpy =
88 Mockito.spy(toscaCsarArtifactProcessor);
89 sdcArtifact = new SDCArtifact();
90 sdcArtifact.setResourceVersion("RESOURCE VERSION");
91 sdcArtifact.setArtifactUUID("123-456-789");
92 sdcArtifact.setResourceName("Resource Name");
93 when(dependencyModelGenerator.getDependencyModel(anyString(), anyString()))
94 .thenReturn("dependencyModel");
95 toscaCsarArtifactProcessorSpy.processArtifact(sdcArtifact);
96 verify(toscaCsarArtifactProcessorSpy, times(1)).processArtifact(sdcArtifact);
100 * This method tests the process Artifacts method failure scenario.
102 * @throws APPCException if the there are any exception in sdc artifacts
104 @Test(expected = APPCException.class)
105 public void testProcessArtifactFailWithNullValues() throws APPCException {
106 sdcArtifact = new SDCArtifact();
107 toscaCsarArtifactProcessor.processArtifact(sdcArtifact);
111 * This method tests the process Artifacts method failure scenario
113 * @throws Exception if the there are any exception in sdc artifacts or in creating notification
114 * data, resource data & service artifacts
116 @Test(expected = APPCException.class)
117 public void testProcessArtifactFail() throws Exception {
118 sdcArtifact = new SDCArtifact();
119 sdcArtifact.setResourceVersion("RESOURCE VERSION");
120 sdcArtifact.setArtifactUUID("123-456-789");
121 sdcArtifact.setResourceName("Resource Name");
122 when(dependencyModelGenerator.getDependencyModel(anyString(), anyString()))
123 .thenThrow(new APPCException());
124 toscaCsarArtifactProcessor.processArtifact(sdcArtifact);
128 * This method tests the process Artifacts method success scenario.
130 * @throws APPCException if the there are any exception in sdc artifacts
133 public void testProcessArtifactDistributionClient() throws APPCException {
134 when(distributionClientDownloadResult.getArtifactPayload()).thenReturn(new byte[1]);
135 ToscaCsarArtifactProcessor toscaCsarArtifactProcessorSpy =
136 Mockito.spy(toscaCsarArtifactProcessor);
137 toscaCsarArtifactProcessorSpy.processArtifact(distributionClientDownloadResult);
138 verify(toscaCsarArtifactProcessorSpy, times(1))
139 .processArtifact(distributionClientDownloadResult);