DataFileServiceV1 implements DataFileService { private DataFile descriptorToDataFile(DataFileDao dao, DataFileDescriptor dfd) { DataFile dataFile; if (dfd.getId() != null && dfd.getId() != 0) { dataFile = dao.findById(dfd.getId()); dataFile.setComments(dfd.getComments()); dataFile.setPath(dfd.getName()); dataFile.setCreator(dfd.getCreator()); } else { dataFile = DataFileServiceUtil.descriptorToDataFile(dfd); } return dataFile; }  @Override String ping(); @Override StreamingOutput getDataFileData(Integer id); @Override StreamingOutput getDataFileDataOffset(Integer id, int offset, int numLines); @Override StreamingOutput getDataFileVersion(Integer id, Integer version, final int offset, final int numLines); @Override Response saveOrUpdateDataFile(FormDataMultiPart formData); @Override Response deleteDataFile(Integer id); @Override Response getDataFiles(); @Override Response getDataFile(Integer id); @Override Response setDataFile(Integer id, FormDataMultiPart formData); @Override Response downloadDataFileData(Integer id);  }
@Test @Tag(TestGroups.MANUAL) public void testPostDataFile() { WebTarget webTarget = client.target(SERVICE_BASE_URL + "/data-file"); webTarget.property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE); File f = new File("src/test/resources/users.csv"); MultiPart multiPart = new MultiPart(); FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file", f); multiPart.bodyPart(fileDataBodyPart); DataFileDescriptor df = new DataFileDescriptor(); df.setName(f.getName()); df.setCreator("Denis"); df.setComments("comments"); multiPart.bodyPart(new FormDataBodyPart("dataFile", df, MediaType.APPLICATION_XML_TYPE)); webTarget.request(MediaType.APPLICATION_XML_TYPE); Response response = webTarget.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE)); DataFileDescriptor entity = response.readEntity(DataFileDescriptor.class); assertNotNull(entity); assertNotNull(entity.getId()); assertNotNull(entity.getCreated()); assertNotNull(entity.getModified()); assertEquals(df.getComments(), entity.getComments()); assertEquals(df.getCreator(), entity.getCreator()); assertEquals(df.getName(), entity.getName()); df = DataFileServiceUtil.dataFileToDescriptor(DataFileServiceUtil.descriptorToDataFile(entity)); entity.setComments("New Comments"); entity.setName("new_name.csv"); multiPart = new MultiPart(); multiPart.bodyPart(new FormDataBodyPart("dataFile", df, MediaType.APPLICATION_XML_TYPE)); webTarget.request(MediaType.APPLICATION_XML_TYPE); response = webTarget.request().post(Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE)); entity = response.readEntity(DataFileDescriptor.class); assertNotNull(entity); assertNotNull(entity.getId()); assertNotNull(entity.getCreated()); assertNotNull(entity.getModified()); assertEquals(df.getComments(), entity.getComments()); assertEquals(df.getCreator(), entity.getCreator()); assertEquals(df.getName(), entity.getName()); webTarget = client.target(SERVICE_BASE_URL + "/data-file/" + entity.getId()); response = webTarget.request().get(); entity = response.readEntity(DataFileDescriptor.class); assertNotNull(entity); assertNotNull(entity.getId()); assertNotNull(entity.getCreated()); assertNotNull(entity.getModified()); assertEquals(df.getComments(), entity.getComments()); assertEquals(df.getCreator(), entity.getCreator()); assertEquals(df.getName(), entity.getName()); response = webTarget.request().delete(); assertEquals(Status.OK.getStatusCode(), response.getStatus()); }