Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / ecomp / PortalRestAPICentralServiceImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.ecomp;
22
23 import fj.data.Either;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
29 import org.onap.portalsdk.core.restful.domain.EcompRole;
30 import org.onap.portalsdk.core.restful.domain.EcompUser;
31 import org.openecomp.sdc.be.model.User;
32 import org.openecomp.sdc.be.user.UserBusinessLogic;
33 import org.openecomp.sdc.exception.ResponseFormat;
34
35 import java.util.HashSet;
36 import java.util.Map;
37 import java.util.Set;
38
39 public class PortalRestAPICentralServiceImplTest {
40
41     PortalRestAPICentralServiceImpl testSubject;
42     UserBusinessLogic ubl;
43
44     @Before
45     public void setUp() throws Exception {
46         ubl = Mockito.mock(UserBusinessLogic.class);
47         testSubject = new PortalRestAPICentralServiceImpl(ubl);
48     }
49
50     @Test
51     public void testGetAppCredentials() throws Exception {
52         Map<String, String> appCredentials = testSubject.getAppCredentials();
53         Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_APP_NAME.value()).equals("sdc"));
54         Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_USER.value()).equals("sdc"));
55         Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_PASS.value()).equals("asdc"));
56     }
57
58     @Test
59     public void testPushUserGeneralError() throws Exception {
60         ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
61         Mockito.when(responseFormat.getMessageId()).thenReturn("mock");
62         Mockito.when(ubl.createUser(Mockito.any(), Mockito.any())).thenReturn(Either.right(responseFormat));
63         EcompUser user = new EcompUser();
64         Set<EcompRole> roleSet = new HashSet<>();
65         EcompRole role = new EcompRole();
66         role.setId(1L);
67         role.setName("Designer");
68         roleSet.add(role);
69         user.setRoles(roleSet);
70         try{
71             testSubject.pushUser(user);
72         }catch (PortalAPIException e) {
73             System.out.println(e);
74             Assert.assertTrue(e.getMessage().startsWith("Failed to create user {}"));
75         }
76
77     }
78
79     @Test
80     public void testPushUserSuccess() throws Exception {
81         ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
82         Mockito.when(responseFormat.getMessageId()).thenReturn("SVC4006");
83         Mockito.when(ubl.createUser(Mockito.any(), Mockito.any())).thenReturn(Either.left(new User()));
84         EcompUser user = new EcompUser();
85         Set<EcompRole> roleSet = new HashSet<>();
86         EcompRole role = new EcompRole();
87         role.setId(1L);
88         role.setName("Designer");
89         roleSet.add(role);
90         user.setRoles(roleSet);
91         testSubject.pushUser(user);
92     }
93
94     @Test
95     public void testPushUserNullRoles() throws Exception {
96         EcompUser user = new EcompUser();
97         try{
98             testSubject.pushUser(user);
99         } catch (PortalAPIException e){
100             Assert.assertTrue(e.getMessage().equals("Received null roles for user" + user));
101         }
102
103     }
104
105     @Test
106     public void testPushUserUserNull() throws Exception {
107         try {
108             testSubject.pushUser(null);
109         } catch (PortalAPIException e) {
110             Assert.assertTrue(e.getMessage().equals("Received null for argument user"));
111         }
112
113     }
114
115     /**
116     *
117     * Method: editUser(String loginId, EcompUser user)
118     *
119     */
120     @Test
121     public void testEditUser() throws Exception {
122     //TODO: Test goes here...
123     }
124
125     /**
126     *
127     * Method: getUserId(HttpServletRequest request)
128     *
129     */
130     @Test
131     public void testGetUserId() throws Exception {
132     //TODO: Test goes here...
133     }
134
135     /**
136     *
137     * Method: value()
138     *
139     */
140     @Test
141     public void testValue() throws Exception {
142     //TODO: Test goes here...
143     }
144
145 }