497abe0f79a7d6ea74cdd2845f19e13f909c77a5
[clamp.git] / src / test / java / org / onap / clamp / clds / client / req / SdcReqTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
22  */
23
24 package org.onap.clamp.clds.client.req;
25
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
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;
40
41 public class SdcReqTest {
42
43     String baseUrl              = "AYBABTU";
44     String serviceInvariantUuid = "serviceInvariantUUID";
45
46     @Test
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);
56
57         Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
58
59         Global global = mock(Global.class);
60         when(prop.getGlobal()).thenReturn(global);
61         Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
62
63         when(global.getService()).thenReturn(serviceInvariantUuid);
64         Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
65
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());
70
71         when(cldsSdcServiceDetail.getResources()).thenReturn(cldsSdcResources);
72         Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
73
74         when(cldsSdcResource.getResoucreType()).thenReturn("VF");
75         Assert.assertTrue(SdcReq.getSdcReqUrlsList(prop, baseUrl, sdcCatalogServices, delegateExecution).isEmpty());
76
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));
83     }
84 }