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.it;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.security.GeneralSecurityException;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.apache.commons.codec.DecoderException;
34 import org.camunda.bpm.engine.delegate.DelegateExecution;
35 import org.junit.Assert;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
39 import org.onap.clamp.clds.client.req.sdc.SdcReq;
40 import org.onap.clamp.clds.model.CldsSdcResource;
41 import org.onap.clamp.clds.model.CldsSdcServiceDetail;
42 import org.onap.clamp.clds.model.prop.Global;
43 import org.onap.clamp.clds.model.prop.ModelProperties;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.boot.test.context.SpringBootTest;
46 import org.springframework.test.context.TestPropertySource;
47 import org.springframework.test.context.junit4.SpringRunner;
49 @RunWith(SpringRunner.class)
51 @TestPropertySource(locations = "classpath:application-no-camunda.properties")
52 public class SdcReqItCase {
53 String baseUrl = "AYBABTU";
54 String serviceInvariantUuid = "serviceInvariantUUID";
56 private SdcReq sdcReq;
59 public void getSdcReqUrlsListNoGlobalPropTest() throws GeneralSecurityException, DecoderException {
60 ModelProperties prop = mock(ModelProperties.class);
61 SdcCatalogServices sdcCatalogServices = mock(SdcCatalogServices.class);
62 DelegateExecution delegateExecution = mock(DelegateExecution.class);
63 CldsSdcResource cldsSdcResource = mock(CldsSdcResource.class);
64 List<CldsSdcResource> cldsSdcResources = new ArrayList<>();
65 cldsSdcResources.add(cldsSdcResource);
66 List<String> resourceVf = new ArrayList<>();
67 resourceVf.add(serviceInvariantUuid);
68 Assert.assertTrue(sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
69 Global global = mock(Global.class);
70 when(prop.getGlobal()).thenReturn(global);
71 Assert.assertTrue(sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
72 when(global.getService()).thenReturn(serviceInvariantUuid);
73 Assert.assertTrue(sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
74 CldsSdcServiceDetail cldsSdcServiceDetail = mock(CldsSdcServiceDetail.class);
75 when(sdcCatalogServices.getCldsSdcServiceDetailFromJson(null)).thenReturn(cldsSdcServiceDetail);
76 when(global.getResourceVf()).thenReturn(new ArrayList<>());
77 Assert.assertTrue(sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
78 when(cldsSdcServiceDetail.getResources()).thenReturn(cldsSdcResources);
79 Assert.assertTrue(sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
80 when(cldsSdcResource.getResoucreType()).thenReturn("VF");
81 Assert.assertTrue(sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
82 when(global.getResourceVf()).thenReturn(resourceVf);
83 when(cldsSdcResource.getResourceInvariantUUID()).thenReturn(serviceInvariantUuid);
84 when(cldsSdcResource.getResourceInstanceName()).thenReturn("Resource instance name");
85 List<String> expected = new ArrayList<>();
86 expected.add("AYBABTU/null/resourceInstances/resourceinstancename/artifacts");
87 Assert.assertEquals(expected, sdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution));