GroupCreationWorkflow implements IsWidget { protected void checkCreate() { final String identifier = createEntity.getEntityIdentifier(); if (identifier != null) { loadingBox.show(); final Collection<String> constrainedGroups = userSystemManager.getConstrainedGroups(); if (null != constrainedGroups && constrainedGroups.contains(identifier)) { loadingBox.hide(); showErrorMessage(UsersManagementClientConstants.INSTANCE.roleAlreadyExists()); createEntity.setErrorState(); } else { userSystemManager.groups(o -> { loadingBox.hide(); showErrorMessage(UsersManagementClientConstants.INSTANCE.groupAlreadyExists()); createEntity.setErrorState(); }, new ErrorCallback<Message>() { @Override public boolean error(final Message o, final Throwable throwable) { loadingBox.hide(); Throwable error = throwable; if (throwable instanceof GroupNotFoundException) { createGroup(identifier); error = null; } else if (throwable instanceof InvalidEntityIdentifierException) { error = new SecurityManagementException(getGroupIdentifierNotValidMessage((InvalidEntityIdentifierException) throwable), throwable); } if (null != error) { showError(throwable); create(); } return false; } }).get(identifier); } } } @Inject  GroupCreationWorkflow(final ClientUserSystemManager userSystemManager,
                                 final Caller<AuthorizationService> authorizationService,
                                 final PermissionManager permissionManager,
                                 final Event<OnErrorEvent> errorEvent,
                                 final ConfirmBox confirmBox,
                                 final LoadingBox loadingBox,
                                 final Event<NotificationEvent> workbenchNotification,
                                 final CreateEntity createEntity,
                                 final GroupUsersAssignment groupUsersAssignment,
                                 final Event<CreateGroupEvent> onCreateGroupEvent,
                                 final EntityWorkflowView view); @PostConstruct void init(); void create(); void clear(); @Override Widget asWidget();  }
@Test public void testCheckCreateExisting() { when(groupsManagerService.get(anyString())).thenReturn(group); when(createEntity.getEntityIdentifier()).thenReturn("group1"); tested.checkCreate(); verify(loadingBox, times(1)).show(); verify(loadingBox, times(1)).hide(); verify(errorEvent, times(1)).fire(any(OnErrorEvent.class)); verify(createEntity, times(1)).setErrorState(); }
@Test public void testCheckCreateConstrainedGroup() { Collection<String> cGroups = new ArrayList<String>(1); cGroups.add("admin"); when(userSystemManager.getConstrainedGroups()).thenReturn(cGroups); when(createEntity.getEntityIdentifier()).thenReturn("admin"); tested.checkCreate(); verify(loadingBox, times(1)).show(); verify(loadingBox, times(1)).hide(); verify(errorEvent, times(1)).fire(any(OnErrorEvent.class)); verify(createEntity, times(1)).setErrorState(); }