2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
22 * ============LICENSE_END=========================================================
24 package org.onap.appc.sdc.artifacts.impl;
26 import static org.mockito.Matchers.anyObject;
27 import static org.mockito.Matchers.anyString;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Matchers;
34 import org.mockito.Mockito;
35 import org.onap.appc.adapter.message.EventSender;
36 import org.onap.appc.exceptions.APPCException;
37 import org.onap.appc.sdc.artifacts.helper.ArtifactStorageService;
38 import org.onap.appc.sdc.artifacts.object.SDCArtifact;
39 import org.onap.sdc.api.IDistributionClient;
40 import org.onap.sdc.api.notification.IArtifactInfo;
41 import org.onap.sdc.api.notification.INotificationData;
42 import org.onap.sdc.api.notification.IResourceInstance;
43 import org.powermock.api.mockito.PowerMockito;
44 import org.powermock.modules.junit4.PowerMockRunner;
45 import org.powermock.reflect.Whitebox;
47 @RunWith(PowerMockRunner.class)
48 public class TestLicenseArtifactProcessor {
50 private LicenseArtifactProcessor artifactProcessor;
52 private ArtifactStorageService storageService;
54 private INotificationData notificationData;
56 private IResourceInstance resourceInstance;
58 private IArtifactInfo artifactInfo;
61 public void setup() throws Exception {
62 IDistributionClient client = PowerMockito.mock(IDistributionClient.class);
63 EventSender eventSender = PowerMockito.mock(EventSender.class);
64 storageService = PowerMockito.mock(ArtifactStorageService.class);
65 artifactProcessor = Mockito.spy(new LicenseArtifactProcessor(client, eventSender, notificationData,
66 resourceInstance, artifactInfo, null));
67 Whitebox.setInternalState(artifactProcessor, "artifactStorageService", storageService);
68 PowerMockito.doCallRealMethod().when(artifactProcessor)
69 .processArtifact((SDCArtifact) Matchers.anyObject());
70 PowerMockito.doNothing().when(storageService).storeSDCArtifact(Matchers.anyObject());
73 @Test(expected = org.onap.appc.exceptions.APPCException.class)
74 public void testProcessArtifactWithMissingData() throws APPCException {
75 SDCArtifact artifact = new SDCArtifact();
76 artifact.setResourceVersion("RESOURCE VERSION");
77 artifact.setArtifactUUID("123-456-789");
78 artifactProcessor.processArtifact(artifact);
82 public void testProcessArtifact() throws APPCException {
83 PowerMockito.when(storageService.retrieveSDCArtifact(anyString(), anyString(), anyString()))
85 SDCArtifact artifact = new SDCArtifact();
86 artifact.setResourceVersion("RESOURCE VERSION");
87 artifact.setArtifactUUID("123-456-789");
88 artifact.setResourceName("Resource Name");
89 artifactProcessor.processArtifact(artifact);
90 verify(storageService, Mockito.times(1)).storeSDCArtifact(anyObject());
94 public void testProcessArtifactWithDuplicateArtifact() throws APPCException {
95 SDCArtifact artifact = new SDCArtifact();
96 artifact.setResourceVersion("RESOURCE VERSION");
97 artifact.setArtifactUUID("123-456-789");
98 artifact.setResourceName("Resource Name");
99 PowerMockito.when(storageService.retrieveSDCArtifact(anyString(), anyString(), anyString()))
100 .thenReturn(artifact);
101 artifactProcessor.processArtifact(artifact);
102 verify(storageService, Mockito.times(0)).storeSDCArtifact(anyObject());
106 * This method tests the process Artifacts method failure scenario.
108 * @throws APPCException if the there are any exception in sdc artifacts
110 @Test(expected = APPCException.class)
111 public void testProcessArtifactNullSDCArtifact() throws APPCException {
112 SDCArtifact artifact = new SDCArtifact();
113 artifact.setResourceVersion("RESOURCE VERSION");
114 artifact.setArtifactUUID("123-456-789");
115 artifact.setResourceName("Resource Name");
116 when(storageService.retrieveSDCArtifact(anyString(), anyString(), anyString()))
117 .thenThrow(new APPCException());
118 artifactProcessor.processArtifact(artifact);