@Test public void testUpdateAttachmentContent_fail() throws FileNotFoundException { handler.addRequest("PUT", "/qcbin/rest/domains/domain/projects/project/defects/1/attachments/logfile.txt", 500) .responseBody("Failed"); boolean updated = attachmentService.updateAttachmentContent("logfile.txt", new EntityRef("defect", 1), new IndicatingInputStream(file, null), file.length(), false); Assert.assertFalse(updated); checkError("Failed"); }
public boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent) { Map<String,String> headers = Collections.singletonMap("Content-Type", "application/octet-stream"); MyResultInfo result = new MyResultInfo(); if(restService.put(new MyInputData(is, length, headers), result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return false; } else { EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { entityService.fireEntityLoaded(list.get(0), EntityListener.Event.GET); } return true; } }
AttachmentService { public boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent) { Map<String,String> headers = Collections.singletonMap("Content-Type", "application/octet-stream"); MyResultInfo result = new MyResultInfo(); if(restService.put(new MyInputData(is, length, headers), result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return false; } else { EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { entityService.fireEntityLoaded(list.get(0), EntityListener.Event.GET); } return true; } } }
AttachmentService { public boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent) { Map<String,String> headers = Collections.singletonMap("Content-Type", "application/octet-stream"); MyResultInfo result = new MyResultInfo(); if(restService.put(new MyInputData(is, length, headers), result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return false; } else { EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { entityService.fireEntityLoaded(list.get(0), EntityListener.Event.GET); } return true; } } AttachmentService(RestService restService, EntityService entityService, ErrorService errorService); }
AttachmentService { public boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent) { Map<String,String> headers = Collections.singletonMap("Content-Type", "application/octet-stream"); MyResultInfo result = new MyResultInfo(); if(restService.put(new MyInputData(is, length, headers), result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return false; } else { EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { entityService.fireEntityLoaded(list.get(0), EntityListener.Event.GET); } return true; } } AttachmentService(RestService restService, EntityService entityService, ErrorService errorService); Entity getAttachmentEntity(Entity entity); Entity getAttachmentEntity(String name, EntityRef parent); String createAttachment(String filename, IndicatingInputStream is, long length, EntityRef parent); boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent); Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent); void deleteAttachment(String name, EntityRef parent); }
AttachmentService { public boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent) { Map<String,String> headers = Collections.singletonMap("Content-Type", "application/octet-stream"); MyResultInfo result = new MyResultInfo(); if(restService.put(new MyInputData(is, length, headers), result, "{0}s/{1}/attachments/{2}", parent.type, parent.id, EntityQuery.encode(name)) != HttpStatus.SC_OK) { if(!silent) { errorService.showException(new RestException(result)); } return false; } else { EntityList list = EntityList.create(result.getBodyAsStream(), true); if(!list.isEmpty()) { entityService.fireEntityLoaded(list.get(0), EntityListener.Event.GET); } return true; } } AttachmentService(RestService restService, EntityService entityService, ErrorService errorService); Entity getAttachmentEntity(Entity entity); Entity getAttachmentEntity(String name, EntityRef parent); String createAttachment(String filename, IndicatingInputStream is, long length, EntityRef parent); boolean updateAttachmentContent(String name, EntityRef parent, IndicatingInputStream is, long length, boolean silent); Entity updateAttachmentProperty(String name, EntityRef parent, String propertyName, String propertyValue, boolean silent); void deleteAttachment(String name, EntityRef parent);  }