JobDelegator extends BaseDelegator implements IJobDelegator { @Override public IJob createJob(@Nonnull final Map<String, Object> fieldMap) throws ConnectionException, RequestException, AccessException { Validate.notNull(fieldMap); final int wordLength = 3; List<Map<String, Object>> resultMaps = execMapCmdList(JOB, new String[] { "-i" }, fieldMap); if (nonNull(resultMaps)) { for (Map<String, Object> map : resultMaps) { ResultMapParser.handleErrorStr(map); String infoStr = ResultMapParser.getInfoStr(map); if (contains(infoStr, "Job ") && contains(infoStr, " saved")) { String[] words = split(infoStr, SPACE); if (words.length == wordLength) { String potentialJobId = words[1]; if (isNotBlank(potentialJobId)) { return getJob(potentialJobId); } } } } } return null; } JobDelegator(final IOptionsServer server); @Override IJob createJob(@Nonnull final Map<String, Object> fieldMap); @Override String deleteJob(final String jobId); @SuppressWarnings("unchecked") @Override IJob getJob(final String jobId); @Override String updateJob(@Nonnull final IJob job);  }
@Test(expected = AccessException.class) public void testJobCreateAccessException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenThrow(AccessException.AccessExceptionForTests.class); jobDelegator.createJob(CREATE_FIELD_MAP); }
@Test public void testJobCreate() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenReturn(buildValidCreateResultMap()); when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq((Map<String, Object>)null))) .thenReturn(buildValidGetResultMap()); IJob job = jobDelegator.createJob(CREATE_FIELD_MAP); verify(server).execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP)); verify(server).execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq((Map<String, Object>)null)); assertJob(job); }
@Test(expected = NullPointerException.class) public void testJobCreateNull() throws P4JavaException { jobDelegator.createJob(null); }
@Test(expected = ConnectionException.class) public void testJobCreateConnectionException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenThrow(ConnectionException.class); jobDelegator.createJob(CREATE_FIELD_MAP); }
@Test(expected = AccessException.class) public void testJobCreateAccessException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenThrow(AccessException.class); jobDelegator.createJob(CREATE_FIELD_MAP); }
@Test(expected = RequestException.class) public void testJobCreateRequestException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenThrow(RequestException.class); jobDelegator.createJob(CREATE_FIELD_MAP); }
@Test(expected = P4JavaException.class) public void testJobCreateP4JavaException() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenThrow(P4JavaException.class); jobDelegator.createJob(CREATE_FIELD_MAP); }
@Test public void testJobCreate() throws P4JavaException { when(server.execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP))).thenReturn(buildValidCreateResultMap()); when(server.execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null))) .thenReturn(buildValidGetResultMap()); IJob job = jobDelegator.createJob(CREATE_FIELD_MAP); verify(server).execMapCmdList(eq(JOB.toString()), argThat(CREATE_MATCHER), eq(CREATE_FIELD_MAP)); verify(server).execMapCmdList(eq(JOB.toString()), argThat(GET_MATCHER), eq(null)); assertJob(job); }