String task1ID = nextRandom();
PATask task1 = new PATask(task1ID, new URI("http://localhost/1"), "processID", "urn:completeSOAPAction", Utils.createXMLDocument());
task1.getUserOwners().add("test.system-test");
task1.getUserOwners().add("intalio\\admin");
Attachment attachment1 = new Attachment(new AttachmentMetadata(), new URL("http://localhost/a1"));
task1.addAttachment(attachment1);
Attachment attachment2 = new Attachment(new AttachmentMetadata(), new URL("http://localhost/a2"));
task1.addAttachment(attachment2);
tms.create(task1);
PATask task2 = (PATask) tms.getTask(task1.getID());
Assert.assertEquals(2, task2.getAttachments().size());
tms.removeAttachment(task1.getID(), attachment1.getPayloadURL());
PATask task3 = (PATask) tms.getTask(task1.getID());
Assert.assertEquals(1, task3.getAttachments().size());
Assert.assertEquals(attachment2.getPayloadURL(), task3.getAttachments().iterator().next().getPayloadURL());
Attachment[] attachments = tms.getAttachments(task1.getID());
Assert.assertEquals(1, attachments.length);
Assert.assertEquals(attachment2.getPayloadURL(), attachments[0].getPayloadURL());
tms.removeAttachment(task1.getID(), attachment2.getPayloadURL());
tms.addAttachment(task1.getID(), attachment1);
PATask task4 = (PATask) tms.getTask(task1.getID());
Assert.assertEquals(1, task4.getAttachments().size());
Assert.assertEquals(attachment1.getPayloadURL(), task4.getAttachments().iterator().next().getPayloadURL());