2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.client.req;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.util.ArrayList;
30 import java.util.List;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.onap.clamp.clds.client.SdcCatalogServices;
36 import org.onap.clamp.clds.model.CldsSdcResource;
37 import org.onap.clamp.clds.model.CldsSdcServiceDetail;
38 import org.onap.clamp.clds.model.prop.Global;
39 import org.onap.clamp.clds.model.prop.ModelProperties;
41 public class SdcReqTest {
43 String baseUrl = "AYBABTU";
44 String serviceInvariantUuid = "serviceInvariantUUID";
47 public void getSdcReqUrlsListNoGlobalPropTest() {
48 ModelProperties prop = mock(ModelProperties.class);
49 SdcCatalogServices sdcCatalogServices = mock(SdcCatalogServices.class);
50 DelegateExecution delegateExecution = mock(DelegateExecution.class);
51 CldsSdcResource cldsSdcResource = mock(CldsSdcResource.class);
52 List<CldsSdcResource> cldsSdcResources = new ArrayList<>();
53 cldsSdcResources.add(cldsSdcResource);
54 List<String> resourceVf = new ArrayList<>();
55 resourceVf.add(serviceInvariantUuid);
57 Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
59 Global global = mock(Global.class);
60 when(prop.getGlobal()).thenReturn(global);
61 Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
63 when(global.getService()).thenReturn(serviceInvariantUuid);
64 Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
66 CldsSdcServiceDetail cldsSdcServiceDetail = mock(CldsSdcServiceDetail.class);
67 when(sdcCatalogServices.getCldsSdcServiceDetailFromJson(null)).thenReturn(cldsSdcServiceDetail);
68 when(global.getResourceVf()).thenReturn(new ArrayList<>());
69 Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
71 when(cldsSdcServiceDetail.getResources()).thenReturn(cldsSdcResources);
72 Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
74 when(cldsSdcResource.getResoucreType()).thenReturn("VF");
75 Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
77 when(global.getResourceVf()).thenReturn(resourceVf);
78 when(cldsSdcResource.getResourceInvariantUUID()).thenReturn(serviceInvariantUuid);
79 when(cldsSdcResource.getResourceInstanceName()).thenReturn("Resource instance name");
80 List<String> expected = new ArrayList<>();
81 expected.add("AYBABTU/null/resourceInstances/resourceinstancename/artifacts");
82 Assert.assertEquals(expected, SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution));