2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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============================================
20 * ===================================================================
24 package org.onap.clamp.clds.it.sdc.controller;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.assertj.core.api.Assertions;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mockito;
34 import org.onap.clamp.clds.config.ClampProperties;
35 import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfigurationTest;
36 import org.onap.clamp.clds.sdc.controller.SdcSingleController;
37 import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
38 import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
39 import org.onap.sdc.api.notification.IArtifactInfo;
40 import org.onap.sdc.api.notification.INotificationData;
41 import org.onap.sdc.api.notification.IResourceInstance;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.boot.test.context.SpringBootTest;
44 import org.springframework.test.context.junit4.SpringRunner;
46 @RunWith(SpringRunner.class)
48 public class SdcSingleControllerItCase {
50 private static final String SDC_FOLDER = "/tmp/csar-handler-tests";
51 private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar";
52 private static final String SERVICE_UUID = "serviceUUID";
53 private static final String RESOURCE1_UUID = "resource1UUID";
54 private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0";
55 private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020";
56 private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml";
59 private ClampProperties clampProp;
61 private SdcSingleController sdcSingleController;
63 private INotificationData buildFakeSdcNotification() {
64 // BUild what is needed for CSAR
65 IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class);
66 Mockito.when(serviceArtifact.getArtifactType()).thenReturn(CsarHandler.CSAR_TYPE);
67 Mockito.when(serviceArtifact.getArtifactName()).thenReturn(CSAR_ARTIFACT_NAME);
68 List<IArtifactInfo> servicesList = new ArrayList<>();
69 servicesList.add(serviceArtifact);
70 INotificationData notifData = Mockito.mock(INotificationData.class);
71 Mockito.when(notifData.getServiceArtifacts()).thenReturn(servicesList);
72 // Build what is needed for UUID
73 Mockito.when(notifData.getServiceInvariantUUID()).thenReturn(SERVICE_UUID);
74 // Build fake resource with one artifact BLUEPRINT
75 IResourceInstance resource1 = Mockito.mock(IResourceInstance.class);
76 Mockito.when(resource1.getResourceType()).thenReturn("VF");
77 Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID);
78 Mockito.when(resource1.getResourceInstanceName()).thenReturn(RESOURCE1_INSTANCE_NAME);
79 // Create a fake artifact for resource
80 IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class);
81 Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE);
82 List<IArtifactInfo> artifactsListForResource = new ArrayList<>();
83 artifactsListForResource.add(blueprintArtifact);
84 Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource);
85 List<IResourceInstance> resourcesList = new ArrayList<>();
86 resourcesList.add(resource1);
87 Mockito.when(notifData.getResources()).thenReturn(resourcesList);
92 * Initialization method.
96 sdcSingleController = new SdcSingleController(clampProp, Mockito.mock(CsarInstaller.class),
97 SdcSingleControllerConfigurationTest.loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
104 public void testTreatNotification() {
105 sdcSingleController.treatNotification(buildFakeSdcNotification());
106 Assertions.assertThat(sdcSingleController.getNbOfNotificationsOngoing()).isEqualTo(0);