2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.ecomp;
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;
35 import java.util.HashSet;
39 public class PortalRestAPICentralServiceImplTest {
41 PortalRestAPICentralServiceImpl testSubject;
42 UserBusinessLogic ubl;
45 public void setUp() throws Exception {
46 ubl = Mockito.mock(UserBusinessLogic.class);
47 testSubject = new PortalRestAPICentralServiceImpl(ubl);
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"));
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();
67 role.setName("Designer");
69 user.setRoles(roleSet);
71 testSubject.pushUser(user);
72 }catch (PortalAPIException e) {
73 System.out.println(e);
74 Assert.assertTrue(e.getMessage().startsWith("Failed to create user {}"));
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();
88 role.setName("Designer");
90 user.setRoles(roleSet);
91 testSubject.pushUser(user);
95 public void testPushUserNullRoles() throws Exception {
96 EcompUser user = new EcompUser();
98 testSubject.pushUser(user);
99 } catch (PortalAPIException e){
100 Assert.assertTrue(e.getMessage().equals("Received null roles for user" + user));
106 public void testPushUserUserNull() throws Exception {
108 testSubject.pushUser(null);
109 } catch (PortalAPIException e) {
110 Assert.assertTrue(e.getMessage().equals("Received null for argument user"));
117 * Method: editUser(String loginId, EcompUser user)
121 public void testEditUser() throws Exception {
122 //TODO: Test goes here...
127 * Method: getUserId(HttpServletRequest request)
131 public void testGetUserId() throws Exception {
132 //TODO: Test goes here...
141 public void testValue() throws Exception {
142 //TODO: Test goes here...