JobSpecDelegator extends BaseDelegator implements IJobSpecDelegator { @SuppressWarnings("unchecked") @Override public IJobSpec getJobSpec() throws ConnectionException, RequestException, AccessException { List<Map<String, Object>> resultMaps = execMapCmdList(JOBSPEC, new String[] { "-o" }, null); return ResultListBuilder.buildNullableObjectFromNonInfoMessageCommandResultMaps( resultMaps, new Function<Map<String, Object>, IJobSpec>() { @Override public IJobSpec apply(Map<String, Object> map) { return new JobSpec(map, server); } } ); } JobSpecDelegator(final IOptionsServer server); @SuppressWarnings("unchecked") @Override IJobSpec getJobSpec();  }
@Test(expected = ConnectionException.class) public void testJobSpecConnectionException() throws P4JavaException { when(server.execMapCmdList(eq(JOBSPEC.toString()), argThat(SIMPLE_MATCHER), eq(null))) .thenThrow(ConnectionException.class); jobSpecDelegator.getJobSpec(); }
@Test(expected = AccessException.class) public void testJobSpecAccessException() throws P4JavaException { when(server.execMapCmdList(eq(JOBSPEC.toString()), argThat(SIMPLE_MATCHER), eq(null))) .thenThrow(AccessException.AccessExceptionForTests.class); jobSpecDelegator.getJobSpec(); }
@Test(expected = RequestException.class) public void testJobSpecRequestException() throws P4JavaException { when(server.execMapCmdList(eq(JOBSPEC.toString()), argThat(SIMPLE_MATCHER), eq(null))) .thenThrow(RequestException.class); jobSpecDelegator.getJobSpec(); }
@Test(expected = P4JavaException.class) public void testJobSpecP4JavaException() throws P4JavaException { when(server.execMapCmdList(eq(JOBSPEC.toString()), argThat(SIMPLE_MATCHER), eq(null))) .thenThrow(P4JavaException.class); jobSpecDelegator.getJobSpec(); }
@Test public void testJobSpec() throws P4JavaException { when(server.execMapCmdList(eq(JOBSPEC.toString()), argThat(SIMPLE_MATCHER), eq(null))) .thenReturn(buildValidGetResultMap()); IJobSpec jobSpec = jobSpecDelegator.getJobSpec(); verify(server).execMapCmdList(eq(JOBSPEC.toString()), argThat(SIMPLE_MATCHER), eq(null)); List<IJobSpecField> jsfList = jobSpec.getFields(); assertNotNull(jsfList); assertEquals(2, jsfList.size()); assertField0(jsfList.get(0)); assertField1(jsfList.get(1)); Map<String, String> presets = jobSpec.getPresets(); assertEquals("open,fix/fixed", presets.get("Status")); List<String> expectedValues = Arrays .asList(new String[] { "open", "triaged", "inprogress", "review", "fixed", "closed", "punted", "suspended", "duplicate", "obsolete", "reopened" }); Map<String, List<String>> values = jobSpec.getValues(); assertNotNull(values.get("Status")); assertEquals(expectedValues, values.get("Status")); }