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