@Test public void testCreateRecord() throws Exception { String recordId = "recordIdSample"; String datasetId = "datasetIdSample"; Document document = DocumentHelper.createDocument(); Element root = document.addElement("root"); Element node = root.addElement("author") .addAttribute("name", "exampleName") .addText("Some Text"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XmlUtil.writePrettyPrint(baos, node); baos.toString(); when(dataManager.saveRecord(anyString(), anyString(), anyString())).thenThrow(new IOException()).thenThrow(new ObjectNotFoundException("Not found!")).thenReturn(MessageType.OK); WebTarget target = target("/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", "").queryParam("recordId", recordId); Response response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(baos.toString(), MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); target = target("/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", ""); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(baos.toString(), MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); target = target("/" + RecordOptionListContainer.RECORDS).queryParam("datasetId", datasetId).queryParam("recordId", recordId); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity("", MediaType.APPLICATION_XML), Response.class); assertEquals(406, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(baos.toString(), MediaType.APPLICATION_XML), Response.class); assertEquals(500, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(baos.toString(), MediaType.APPLICATION_XML), Response.class); assertEquals(404, response.getStatus()); response = target.request(MediaType.APPLICATION_XML).post(Entity.entity(baos.toString(), MediaType.APPLICATION_XML), Response.class); assertEquals(201, response.getStatus()); }
@POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId, @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString) throws DoesNotExistException, MissingArgumentsException { if (datasetId == null || datasetId.equals("")) throw new MissingArgumentsException("Missing value: " + "datasetId type missing!"); if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (recordString == null || recordString.equals("")) throw new MissingArgumentsException("Missing value: " + "Record information is empty!"); try { dataManager.saveRecord(recordId, datasetId, recordString); } catch (IOException | DocumentException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(201).entity(new Result("Record with id: " + recordId + " created!")).build(); }
RecordsResource { @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId, @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString) throws DoesNotExistException, MissingArgumentsException { if (datasetId == null || datasetId.equals("")) throw new MissingArgumentsException("Missing value: " + "datasetId type missing!"); if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (recordString == null || recordString.equals("")) throw new MissingArgumentsException("Missing value: " + "Record information is empty!"); try { dataManager.saveRecord(recordId, datasetId, recordString); } catch (IOException | DocumentException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(201).entity(new Result("Record with id: " + recordId + " created!")).build(); } }
RecordsResource { @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId, @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString) throws DoesNotExistException, MissingArgumentsException { if (datasetId == null || datasetId.equals("")) throw new MissingArgumentsException("Missing value: " + "datasetId type missing!"); if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (recordString == null || recordString.equals("")) throw new MissingArgumentsException("Missing value: " + "Record information is empty!"); try { dataManager.saveRecord(recordId, datasetId, recordString); } catch (IOException | DocumentException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(201).entity(new Result("Record with id: " + recordId + " created!")).build(); } RecordsResource();  RecordsResource(DefaultDataManager dataManager, Urn urn); }
RecordsResource { @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId, @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString) throws DoesNotExistException, MissingArgumentsException { if (datasetId == null || datasetId.equals("")) throw new MissingArgumentsException("Missing value: " + "datasetId type missing!"); if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (recordString == null || recordString.equals("")) throw new MissingArgumentsException("Missing value: " + "Record information is empty!"); try { dataManager.saveRecord(recordId, datasetId, recordString); } catch (IOException | DocumentException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(201).entity(new Result("Record with id: " + recordId + " created!")).build(); } RecordsResource();  RecordsResource(DefaultDataManager dataManager, Urn urn); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "OPTIONS", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getOptions(); @GET @Path("/" + RecordOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "GET", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getGETOptions(); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific record.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a Record)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getRecord(@ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId); @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response removeRecord(
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId,
            @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type); @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), // @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId,
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString); }
RecordsResource { @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) public Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId, @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString) throws DoesNotExistException, MissingArgumentsException { if (datasetId == null || datasetId.equals("")) throw new MissingArgumentsException("Missing value: " + "datasetId type missing!"); if (recordId == null || recordId.equals("")) throw new MissingArgumentsException("Missing value: " + "recordId type missing!"); if (recordString == null || recordString.equals("")) throw new MissingArgumentsException("Missing value: " + "Record information is empty!"); try { dataManager.saveRecord(recordId, datasetId, recordString); } catch (IOException | DocumentException e) { throw new InternalServerErrorException("Internal Server Error : " + e.getMessage()); } catch (ObjectNotFoundException e) { throw new DoesNotExistException("Does NOT exist: " + e.getMessage()); } return Response.status(201).entity(new Result("Record with id: " + recordId + " created!")).build(); } RecordsResource();  RecordsResource(DefaultDataManager dataManager, Urn urn); @OPTIONS @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "OPTIONS", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getOptions(); @GET @Path("/" + RecordOptionListContainer.OPTIONS) @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get options over record conext.", httpMethod = "GET", response = RecordOptionListContainer.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a list of all available options)") }) RecordOptionListContainer getGETOptions(); @GET @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Get specific record.", httpMethod = "GET", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a Record)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response getRecord(@ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId); @DELETE @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Deletes (mark) or permanently erase a record.", httpMethod = "DELETE", response = String.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK (Response containing a String message)"), @ApiResponse(code = 400, message = "InvalidArgumentsException"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response removeRecord(
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId,
            @ApiParam(value = "Delete(mark) or erase(permanent)", defaultValue = RecordOptionListContainer.DELETE, allowableValues = RecordOptionListContainer.DELETE + " , " + RecordOptionListContainer.ERASE) @DefaultValue(RecordOptionListContainer.DELETE) @QueryParam("type") String type); @POST @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes(MediaType.APPLICATION_XML) @ApiOperation(value = "Create a new record.", httpMethod = "POST", response = String.class) @ApiResponses(value = { @ApiResponse(code = 201, message = "OK (Response containing a String message)"), @ApiResponse(code = 404, message = "DoesNotExistException"), @ApiResponse(code = 406, message = "MissingArgumentsException"), // @ApiResponse(code = 409, message = "AlreadyExistsException"), @ApiResponse(code = 500, message = "InternalServerErrorException") }) Response createRecord(@ApiParam(value = "Id of dataset", required = true) @QueryParam("datasetId") String datasetId,
            @ApiParam(value = "Id of record", required = true) @QueryParam("recordId") String recordId, @ApiParam(value = "Record data", required = true) String recordString); public DefaultDataManager dataManager; public Urn urn; }