GroupDelegator extends BaseDelegator implements IGroupDelegator { @Override public String deleteUserGroup(@Nonnull IUserGroup group, @Nullable UpdateUserGroupOptions opts) throws P4JavaException { Validate.notNull(group); Validate.notBlank(group.getName(), "Group name shouldn't a null or empty."); List<Map<String, Object>> resultMaps = execMapCmdList(GROUP, Parameters .processParameters(opts, null, new String[] { "-d", group.getName() }, server), null); return ResultMapParser.parseCommandResultMapAsString(resultMaps); } GroupDelegator(IOptionsServer server); @Override IUserGroup getUserGroup(@Nonnull final String name); @Override String deleteUserGroup(@Nonnull IUserGroup group, @Nullable UpdateUserGroupOptions opts); @Override String createUserGroup(@Nonnull final IUserGroup group,
            @Nullable final UpdateUserGroupOptions opts); @Override String updateUserGroup(@Nonnull final IUserGroup group,
            @Nullable final UpdateUserGroupOptions opts); String createUserGroup(@Nonnull final IUserGroup group); String updateUserGroup(@Nonnull final IUserGroup group, final boolean updateIfOwner); String deleteUserGroup(@Nonnull final IUserGroup group);  }
@Test public void testDeleteUserGroupWithOptions() throws P4JavaException { when(group.getName()).thenReturn(groupName); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", groupName })), eq(null))).thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); assertThrows(NullPointerException.class, () -> groupDelegator.deleteUserGroup(null, null)); assertThrows(IllegalArgumentException.class, () -> { UserGroup emptyName = new UserGroup(); emptyName.setName(EMPTY); groupDelegator.deleteUserGroup(emptyName, null); }); String userGroup = groupDelegator.deleteUserGroup(group, new UpdateUserGroupOptions()); assertEquals(groupName, userGroup); }
@Test public void testDeleteUserGroup() throws P4JavaException { when(group.getName()).thenReturn(groupName); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", groupName })), eq((Map<String, Object>) null))).thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); String userGroup = groupDelegator.deleteUserGroup(group); assertEquals(groupName, userGroup); }
@Test public void testDeleteUserGroupWithOptions() throws P4JavaException { when(group.getName()).thenReturn(groupName); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", groupName })), eq((Map<String, Object>) null))).thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); try { groupDelegator.deleteUserGroup(null, null); fail("Expected exception"); } catch (Throwable e) { assertEquals(NullPointerException.class, e.getClass()); } try { UserGroup emptyName = new UserGroup(); emptyName.setName(EMPTY); groupDelegator.deleteUserGroup(emptyName, null); fail("Expected exception"); } catch (Throwable e) { assertEquals(IllegalArgumentException.class, e.getClass()); } String userGroup = groupDelegator.deleteUserGroup(group, new UpdateUserGroupOptions()); assertEquals(groupName, userGroup); }
@Test public void testDeleteUserGroup() throws P4JavaException { when(group.getName()).thenReturn(groupName); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", groupName })), eq(null))).thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); String userGroup = groupDelegator.deleteUserGroup(group); assertEquals(groupName, userGroup); }
@Test public void testDeleteUserGroupWithOptions() throws P4JavaException { when(group.getName()).thenReturn(groupName); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-d", groupName })), eq(null))).thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); expectThrows(NullPointerException.class, () -> groupDelegator.deleteUserGroup(null, null)); expectThrows(IllegalArgumentException.class, () -> { UserGroup emptyName = new UserGroup(); emptyName.setName(EMPTY); groupDelegator.deleteUserGroup(emptyName, null); }); String userGroup = groupDelegator.deleteUserGroup(group, new UpdateUserGroupOptions()); assertEquals(groupName, userGroup); }