/** * Converts the given UserNamespaceAuthorizationEntity to NamespaceAuthorization. * * @param userNamespaceAuthorizationEntity The UserNamespaceAuthorizationEntity * * @return The NamespaceAuthorization */ private NamespaceAuthorization toNamespaceAuthorization(UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity) { NamespaceAuthorization namespaceAuthorization = new NamespaceAuthorization(); namespaceAuthorization.setNamespace(userNamespaceAuthorizationEntity.getNamespace().getCode()); namespaceAuthorization.setNamespacePermissions(getNamespacePermissions(userNamespaceAuthorizationEntity)); return namespaceAuthorization; }
/** * Converts the given UserNamespaceAuthorizationEntity to NamespaceAuthorization. * * @param userNamespaceAuthorizationEntity The UserNamespaceAuthorizationEntity * * @return The NamespaceAuthorization */ private NamespaceAuthorization toNamespaceAuthorization(UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity) { NamespaceAuthorization namespaceAuthorization = new NamespaceAuthorization(); namespaceAuthorization.setNamespace(userNamespaceAuthorizationEntity.getNamespace().getCode()); namespaceAuthorization.setNamespacePermissions(getNamespacePermissions(userNamespaceAuthorizationEntity)); return namespaceAuthorization; }
@Test public void testCreateUserNamespaceAuthorizationHappyPath() { when(alternateKeyHelper.validateStringParameter("namespace", NAMESPACE_VALUE)).thenReturn(NAMESPACE_VALUE); when(alternateKeyHelper.validateStringParameter("user id", USER_ID_VALUE)).thenReturn(USER_ID_VALUE); when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(USER_NAMESPACE_AUTHORIZATION_KEY)).thenReturn(null); when(namespaceDaoHelper.getNamespaceEntity(NAMESPACE_VALUE)).thenReturn(NAMESPACE_ENTITY); when(userNamespaceAuthorizationDao.saveAndRefresh(any())).thenReturn(USER_NAMESPACE_AUTHORIZATION_ENTITY); when(userNamespaceAuthorizationHelper.getNamespacePermissions(USER_NAMESPACE_AUTHORIZATION_ENTITY)).thenReturn(NAMESPACE_PERMISSIONS); UserNamespaceAuthorization userNamespaceAuthorization = userNamespaceAuthorizationService.createUserNamespaceAuthorization(USER_NAMESPACE_AUTHORIZATION_CREATE_REQUEST); assertEquals(USER_NAMESPACE_AUTHORIZATION_ID, userNamespaceAuthorization.getId()); assertEquals(USER_NAMESPACE_AUTHORIZATION_KEY, userNamespaceAuthorization.getUserNamespaceAuthorizationKey()); assertEquals(NAMESPACE_PERMISSIONS, userNamespaceAuthorization.getNamespacePermissions()); verify(alternateKeyHelper).validateStringParameter("namespace", NAMESPACE_VALUE); verify(alternateKeyHelper).validateStringParameter("user id", USER_ID_VALUE); verify(namespaceDaoHelper).getNamespaceEntity(NAMESPACE_VALUE); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationByKey(USER_NAMESPACE_AUTHORIZATION_KEY); verify(userNamespaceAuthorizationDao).saveAndRefresh(any(UserNamespaceAuthorizationEntity.class)); verify(messageNotificationEventService).processUserNamespaceAuthorizationChangeNotificationEvent(USER_NAMESPACE_AUTHORIZATION_KEY); verify(userNamespaceAuthorizationHelper).getNamespacePermissions(USER_NAMESPACE_AUTHORIZATION_ENTITY); verifyNoMoreInteractionsHelper(); }
@Test public void testDeleteUserNamespaceAuthorizationHappyPath() { when(alternateKeyHelper.validateStringParameter("namespace", NAMESPACE_VALUE)).thenReturn(NAMESPACE_VALUE); when(alternateKeyHelper.validateStringParameter("user id", USER_ID_VALUE)).thenReturn(USER_ID_VALUE); when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(USER_NAMESPACE_AUTHORIZATION_KEY)) .thenReturn(USER_NAMESPACE_AUTHORIZATION_ENTITY); when(userNamespaceAuthorizationHelper.getNamespacePermissions(USER_NAMESPACE_AUTHORIZATION_ENTITY)).thenReturn(NAMESPACE_PERMISSIONS); UserNamespaceAuthorization userNamespaceAuthorization = userNamespaceAuthorizationService.deleteUserNamespaceAuthorization(USER_NAMESPACE_AUTHORIZATION_KEY); assertEquals(USER_NAMESPACE_AUTHORIZATION_ID, userNamespaceAuthorization.getId()); assertEquals(USER_NAMESPACE_AUTHORIZATION_KEY, userNamespaceAuthorization.getUserNamespaceAuthorizationKey()); assertEquals(NAMESPACE_PERMISSIONS, userNamespaceAuthorization.getNamespacePermissions()); verify(alternateKeyHelper).validateStringParameter("namespace", NAMESPACE_VALUE); verify(alternateKeyHelper).validateStringParameter("user id", USER_ID_VALUE); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationByKey(USER_NAMESPACE_AUTHORIZATION_KEY); verify(userNamespaceAuthorizationDao).delete(any(UserNamespaceAuthorizationEntity.class)); verify(messageNotificationEventService).processUserNamespaceAuthorizationChangeNotificationEvent(USER_NAMESPACE_AUTHORIZATION_KEY); verify(userNamespaceAuthorizationHelper).getNamespacePermissions(USER_NAMESPACE_AUTHORIZATION_ENTITY); verifyNoMoreInteractionsHelper(); }
@Test public void testUpdateUserNamespaceAuthorizationHappyPath() { when(alternateKeyHelper.validateStringParameter("namespace", NAMESPACE_VALUE)).thenReturn(NAMESPACE_VALUE); when(alternateKeyHelper.validateStringParameter("user id", USER_ID_VALUE)).thenReturn(USER_ID_VALUE); when(currentUserService.getCurrentUser()).thenReturn(USER_AUTHORIZATIONS); when(userNamespaceAuthorizationDao.getUserNamespaceAuthorizationByKey(USER_NAMESPACE_AUTHORIZATION_KEY)) .thenReturn(USER_NAMESPACE_AUTHORIZATION_ENTITY); when(userNamespaceAuthorizationHelper.getNamespacePermissions(USER_NAMESPACE_AUTHORIZATION_ENTITY)).thenReturn(NAMESPACE_PERMISSIONS); UserNamespaceAuthorization userNamespaceAuthorization = userNamespaceAuthorizationService.updateUserNamespaceAuthorization(USER_NAMESPACE_AUTHORIZATION_KEY, USER_NAMESPACE_AUTHORIZATION_UPDATE_REQUEST); assertEquals(USER_NAMESPACE_AUTHORIZATION_ID, userNamespaceAuthorization.getId()); assertEquals(USER_NAMESPACE_AUTHORIZATION_KEY, userNamespaceAuthorization.getUserNamespaceAuthorizationKey()); assertEquals(NAMESPACE_PERMISSIONS, userNamespaceAuthorization.getNamespacePermissions()); verify(alternateKeyHelper).validateStringParameter("namespace", NAMESPACE_VALUE); verify(alternateKeyHelper).validateStringParameter("user id", USER_ID_VALUE); verify(currentUserService).getCurrentUser(); verify(userNamespaceAuthorizationDao).getUserNamespaceAuthorizationByKey(USER_NAMESPACE_AUTHORIZATION_KEY); verify(userNamespaceAuthorizationDao).saveAndRefresh(any(UserNamespaceAuthorizationEntity.class)); verify(messageNotificationEventService).processUserNamespaceAuthorizationChangeNotificationEvent(USER_NAMESPACE_AUTHORIZATION_KEY); verify(userNamespaceAuthorizationHelper).getNamespacePermissions(USER_NAMESPACE_AUTHORIZATION_ENTITY); verifyNoMoreInteractionsHelper(); }
/** * Creates the user namespace authorization from the persisted entity. * * @param userNamespaceAuthorizationEntity the user namespace authorization entity * * @return the user namespace authorization */ private UserNamespaceAuthorization createUserNamespaceAuthorizationFromEntity(UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity) { UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization(); userNamespaceAuthorization.setId(userNamespaceAuthorizationEntity.getId()); UserNamespaceAuthorizationKey userNamespaceAuthorizationKey = new UserNamespaceAuthorizationKey(); userNamespaceAuthorization.setUserNamespaceAuthorizationKey(userNamespaceAuthorizationKey); userNamespaceAuthorizationKey.setUserId(userNamespaceAuthorizationEntity.getUserId()); userNamespaceAuthorizationKey.setNamespace(userNamespaceAuthorizationEntity.getNamespace().getCode()); userNamespaceAuthorization.setNamespacePermissions(userNamespaceAuthorizationHelper.getNamespacePermissions(userNamespaceAuthorizationEntity)); return userNamespaceAuthorization; }
/** * Creates the user namespace authorization from the persisted entity. * * @param userNamespaceAuthorizationEntity the user namespace authorization entity * * @return the user namespace authorization */ private UserNamespaceAuthorization createUserNamespaceAuthorizationFromEntity(UserNamespaceAuthorizationEntity userNamespaceAuthorizationEntity) { UserNamespaceAuthorization userNamespaceAuthorization = new UserNamespaceAuthorization(); userNamespaceAuthorization.setId(userNamespaceAuthorizationEntity.getId()); UserNamespaceAuthorizationKey userNamespaceAuthorizationKey = new UserNamespaceAuthorizationKey(); userNamespaceAuthorization.setUserNamespaceAuthorizationKey(userNamespaceAuthorizationKey); userNamespaceAuthorizationKey.setUserId(userNamespaceAuthorizationEntity.getUserId()); userNamespaceAuthorizationKey.setNamespace(userNamespaceAuthorizationEntity.getNamespace().getCode()); userNamespaceAuthorization.setNamespacePermissions(userNamespaceAuthorizationHelper.getNamespacePermissions(userNamespaceAuthorizationEntity)); return userNamespaceAuthorization; }