@Test(expected = MissingArgumentsException.class) public void testCreateRecordMissingArguments() throws InternalServerErrorException, DoesNotExistException, MissingArgumentsException { Mockito.when(response.getStatus()).thenReturn(406); Mockito.when(response.readEntity(Result.class)).thenReturn(new Result("Missing argument!")); ra.createRecord("ds0", "rd0", "<root>example</root>"); }
public void createRecord(String datasetId, String recordId, String record) throws DoesNotExistException, MissingArgumentsException, InternalServerErrorException { WebTarget target = client.target(restUrl + "/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", recordId); Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(record, MediaType.APPLICATION_XML), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } Result result = response.readEntity(Result.class); LOGGER.info("createRecord(..) success! : " + result.getResult()); }
RecordsAccessor { public void createRecord(String datasetId, String recordId, String record) throws DoesNotExistException, MissingArgumentsException, InternalServerErrorException { WebTarget target = client.target(restUrl + "/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", recordId); Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(record, MediaType.APPLICATION_XML), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } Result result = response.readEntity(Result.class); LOGGER.info("createRecord(..) success! : " + result.getResult()); } }
RecordsAccessor { public void createRecord(String datasetId, String recordId, String record) throws DoesNotExistException, MissingArgumentsException, InternalServerErrorException { WebTarget target = client.target(restUrl + "/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", recordId); Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(record, MediaType.APPLICATION_XML), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } Result result = response.readEntity(Result.class); LOGGER.info("createRecord(..) success! : " + result.getResult()); } RecordsAccessor(URL restUrl, String username, String password);   RecordsAccessor(URL restUrl, String username, String password, Client client); }
RecordsAccessor { public void createRecord(String datasetId, String recordId, String record) throws DoesNotExistException, MissingArgumentsException, InternalServerErrorException { WebTarget target = client.target(restUrl + "/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", recordId); Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(record, MediaType.APPLICATION_XML), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } Result result = response.readEntity(Result.class); LOGGER.info("createRecord(..) success! : " + result.getResult()); } RecordsAccessor(URL restUrl, String username, String password);   RecordsAccessor(URL restUrl, String username, String password, Client client); String getRecord(String id); void removeRecord(String id, String type); void createRecord(String datasetId, String recordId, String record); }
RecordsAccessor { public void createRecord(String datasetId, String recordId, String record) throws DoesNotExistException, MissingArgumentsException, InternalServerErrorException { WebTarget target = client.target(restUrl + "/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", recordId); Response response = target.request(MediaType.APPLICATION_JSON).post(Entity.entity(record, MediaType.APPLICATION_XML), Response.class); switch (response.getStatus()) { case 404: Result errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new DoesNotExistException(errorMessage.getResult()); case 406: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new MissingArgumentsException(errorMessage.getResult()); case 500: errorMessage = response.readEntity(Result.class); LOGGER.warn("createRecord(..) failure! : " + errorMessage.getResult()); throw new InternalServerErrorException(errorMessage.getResult()); } Result result = response.readEntity(Result.class); LOGGER.info("createRecord(..) success! : " + result.getResult()); } RecordsAccessor(URL restUrl, String username, String password);   RecordsAccessor(URL restUrl, String username, String password, Client client); String getRecord(String id); void removeRecord(String id, String type); void createRecord(String datasetId, String recordId, String record);  }