GroupDelegator extends BaseDelegator implements IGroupDelegator { @Override public String createUserGroup(@Nonnull final IUserGroup group, @Nullable final UpdateUserGroupOptions opts) throws P4JavaException { return updateUserGroup(group, opts); } 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 testCreateUserGroup() throws P4JavaException { when(group.getName()).thenReturn(groupName); Map<String, Object> inMap = InputMapper.map(group); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-i" })), eq(inMap))) .thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); assertThrows(NullPointerException.class, () -> groupDelegator.createUserGroup(null)); String userGroup = groupDelegator.createUserGroup(group); assertEquals(groupName, userGroup); }
@Test public void testCreatUserGroupWithOptions() throws P4JavaException { when(group.getName()).thenReturn(groupName); Map<String, Object> inMap = InputMapper.map(group); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-A", "-i" })), eq(inMap))) .thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); assertThrows(NullPointerException.class, () -> groupDelegator.createUserGroup(null, null)); String userGroup = groupDelegator.createUserGroup(group, new UpdateUserGroupOptions().setAddIfAdmin(true)); assertEquals(groupName, userGroup); }
@Test(expected = NullPointerException.class) public void testCreateUserGroup() throws P4JavaException { when(group.getName()).thenReturn(groupName); Map<String, Object> inMap = InputMapper.map(group); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-i" })), eq(inMap))) .thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); String userGroup = groupDelegator.createUserGroup(group); assertEquals(groupName, userGroup); groupDelegator.createUserGroup(null); }
@Test public void testCreatUserGroupWithOptions() throws P4JavaException { when(group.getName()).thenReturn(groupName); Map<String, Object> inMap = InputMapper.map(group); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-A", "-i" })), eq(inMap))) .thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); try { groupDelegator.createUserGroup(null, null); fail("Expected exception"); } catch (Throwable e) { assertEquals(NullPointerException.class, e.getClass()); } String userGroup = groupDelegator.createUserGroup(group, new UpdateUserGroupOptions().setAddIfAdmin(true)); assertEquals(groupName, userGroup); }
@Test public void testCreateUserGroup() throws P4JavaException { when(group.getName()).thenReturn(groupName); Map<String, Object> inMap = InputMapper.map(group); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-i" })), eq(inMap))) .thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); expectThrows(NullPointerException.class, () -> groupDelegator.createUserGroup(null)); String userGroup = groupDelegator.createUserGroup(group); assertEquals(groupName, userGroup); }
@Test public void testCreatUserGroupWithOptions() throws P4JavaException { when(group.getName()).thenReturn(groupName); Map<String, Object> inMap = InputMapper.map(group); when(server.execMapCmdList(eq(CmdSpec.GROUP.toString()), argThat(new CommandLineArgumentMatcher(new String[] { "-A", "-i" })), eq(inMap))) .thenReturn(resultMaps); when(resultMap.get(RpcFunctionMapKey.CODE0)).thenReturn("268435456"); when(resultMap.get(RpcFunctionMapKey.FMT0)).thenReturn(groupName); expectThrows(NullPointerException.class, () -> groupDelegator.createUserGroup(null, null)); String userGroup = groupDelegator.createUserGroup(group, new UpdateUserGroupOptions().setAddIfAdmin(true)); assertEquals(groupName, userGroup); }