summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java
blob: 1a993824c04835e54936522ec9f058d4ab7c50ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package org.openecomp.sdc.be.ecomp;

import fj.data.Either;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.exception.ResponseFormat;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class PortalRestAPICentralServiceImplTest {

    PortalRestAPICentralServiceImpl testSubject;
    UserBusinessLogic ubl;

    @Before
    public void setUp() throws Exception {
        ubl = Mockito.mock(UserBusinessLogic.class);
        testSubject = new PortalRestAPICentralServiceImpl(ubl);
    }

    @Test
    public void testGetAppCredentials() throws Exception {
        Map<String, String> appCredentials = testSubject.getAppCredentials();
        Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_APP_NAME.value()).equals("sdc"));
        Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_USER.value()).equals("sdc"));
        Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_PASS.value()).equals("asdc"));
    }

    @Test
    public void testPushUserGeneralError() throws Exception {
        ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
        Mockito.when(responseFormat.getMessageId()).thenReturn("mock");
        Mockito.when(ubl.createUser(Mockito.any(), Mockito.any())).thenReturn(Either.right(responseFormat));
        EcompUser user = new EcompUser();
        Set<EcompRole> roleSet = new HashSet<>();
        EcompRole role = new EcompRole();
        role.setId(1L);
        role.setName("Designer");
        roleSet.add(role);
        user.setRoles(roleSet);
        try{
            testSubject.pushUser(user);
        }catch (PortalAPIException e) {
            System.out.println(e);
            Assert.assertTrue(e.getMessage().startsWith("Failed to create user {}"));
        }

    }

    @Test
    public void testPushUserSuccess() throws Exception {
        ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class);
        Mockito.when(responseFormat.getMessageId()).thenReturn("SVC4006");
        Mockito.when(ubl.createUser(Mockito.any(), Mockito.any())).thenReturn(Either.left(new User()));
        EcompUser user = new EcompUser();
        Set<EcompRole> roleSet = new HashSet<>();
        EcompRole role = new EcompRole();
        role.setId(1L);
        role.setName("Designer");
        roleSet.add(role);
        user.setRoles(roleSet);
        testSubject.pushUser(user);
    }

    @Test
    public void testPushUserNullRoles() throws Exception {
        EcompUser user = new EcompUser();
        try{
            testSubject.pushUser(user);
        } catch (PortalAPIException e){
            Assert.assertTrue(e.getMessage().equals("Received null roles for user" + user));
        }

    }

    @Test
    public void testPushUserUserNull() throws Exception {
        try {
            testSubject.pushUser(null);
        } catch (PortalAPIException e) {
            Assert.assertTrue(e.getMessage().equals("Received null for argument user"));
        }

    }

    /**
    *
    * Method: editUser(String loginId, EcompUser user)
    *
    */
    @Test
    public void testEditUser() throws Exception {
    //TODO: Test goes here...
    }

    /**
    *
    * Method: getUserId(HttpServletRequest request)
    *
    */
    @Test
    public void testGetUserId() throws Exception {
    //TODO: Test goes here...
    }

    /**
    *
    * Method: value()
    *
    */
    @Test
    public void testValue() throws Exception {
    //TODO: Test goes here...
    }

}