Merge "UserController up"
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / EPRoleServiceImplTest.java
index 4c97b6d..32bd649 100644 (file)
@@ -33,7 +33,7 @@
  *
  * ============LICENSE_END============================================
  *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * 
  */
 package org.onap.portalapp.portal.service;
 
@@ -49,6 +49,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InjectMocks;
+import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
@@ -56,6 +57,7 @@ import org.onap.portalapp.portal.core.MockEPUser;
 import org.onap.portalapp.portal.domain.EPRole;
 import org.onap.portalapp.portal.framework.MockitoTestSuite;
 import org.onap.portalapp.portal.service.EPRoleServiceImpl;
+import org.onap.portalapp.portal.utils.PortalConstants;
 import org.onap.portalsdk.core.domain.RoleFunction;
 import org.onap.portalsdk.core.service.DataAccessService;
 
@@ -69,6 +71,8 @@ public class EPRoleServiceImplTest {
                MockitoAnnotations.initMocks(this);
        }
 
+       @Mock
+       ExternalAccessRolesService externalAccessRolesService;
        @InjectMocks
        EPRoleServiceImpl ePRoleServiceImpl = new EPRoleServiceImpl();
 
@@ -89,35 +93,34 @@ public class EPRoleServiceImplTest {
 
        @Test
        public void getAvailableChildRolesIfRoleIdIsNullTest() {
+               Long roleId = (long)123;
                List<EPRole> roleList = new ArrayList<>();
+               EPRole epRole = new EPRole();
                EPRole role = new EPRole();
                EPRole role1 = new EPRole();
                role.addChildRole(role1);
                roleList.add(role);
                Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList);
+               Mockito.when(dataAccessService.getDomainObject(EPRole.class, roleId, null)).thenReturn(epRole);
                List<EPRole> expectedRoleList = ePRoleServiceImpl.getAvailableChildRoles(null);
                assertEquals(roleList, expectedRoleList);
        }
 
-       // @Test
-       // public void getAvailableChildRolesIfRoleIdNotNullTest()
-       // {
-       // List<EPRole> roleList = new ArrayList<>();
-       // EPRole role = new EPRole();
-       // EPRole role1= new EPRole();
-       // role.addChildRole(role1);
-       // roleList.add(role);
-       // Mockito.when(dataAccessService.getDomainObject(EPRole.class, 1,
-       // null)).thenReturn(role);
-       // Mockito.when(dataAccessService.getList(EPRole.class,
-       // null)).thenReturn(roleList);
-       //
-       // List<EPRole> expectedRoleList =
-       // ePRoleServiceImpl.getAvailableChildRoles((long) 1);
-       // System.out.println(expectedRoleList);
-       // assertEquals(roleList,expectedRoleList);
-       // }
-       //
+       @Test
+       public void getAvailableChildRolesIfRoleIdTest() {
+               Long roleId = (long)123;
+               List<EPRole> roleList = new ArrayList<>();
+               EPRole epRole = new EPRole();
+               EPRole role = new EPRole();
+               EPRole role1 = new EPRole();
+               role.addChildRole(role1);
+               roleList.add(role);
+               Mockito.when(dataAccessService.getList(EPRole.class, null)).thenReturn(roleList);
+               Mockito.when(dataAccessService.getDomainObject(EPRole.class, roleId, null)).thenReturn(epRole);
+               List<EPRole> expectedRoleList = ePRoleServiceImpl.getAvailableChildRoles(roleId);
+               assertEquals(roleList, expectedRoleList);
+       }
+       
        @Test
        public void getRoleFunctionTest() {
                RoleFunction roleFunction = new RoleFunction();
@@ -216,6 +219,7 @@ public class EPRoleServiceImplTest {
                final Map<String, String> portalParams = null;
                List<EPRole> roleList = new ArrayList<>();
                Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoles", portalParams, null)).thenReturn(roleList);
+               Mockito.when(externalAccessRolesService.getPortalAppRoleInfo(Matchers.anyLong())).thenReturn(roleList);
                assertNull(ePRoleServiceImpl.getAppRole("test", (long) 1));
 
        }
@@ -232,8 +236,6 @@ public class EPRoleServiceImplTest {
                Mockito.when((List<EPRole>) dataAccessService.executeNamedQuery("getAppRoles", params, null))
                                .thenReturn(roleList);
                List<EPRole> expectedRoleList = (List<EPRole>) ePRoleServiceImpl.getAppRole("test", (long) 10);
-               System.out.println(expectedRoleList);
-
        }
 
        @Test