1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.validate.requests;
17
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
21 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRemoveMetadataRequest;
22 import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLRemoveMetadataRequest30;
23 import org.openehealth.ipf.commons.ihe.xds.core.requests.RemoveMetadata;
24 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.lcm.RemoveObjectsRequest;
25 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ObjectRefListType;
26 import org.openehealth.ipf.commons.ihe.xds.core.stub.ebrs30.rim.ObjectRefType;
27 import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.RemoveMetadataRequestTransformer;
28 import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage;
29 import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationProfile;
30 import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
31
32 import java.util.UUID;
33
34 import static org.junit.Assert.assertEquals;
35 import static org.junit.Assert.fail;
36 import static org.openehealth.ipf.commons.ihe.xds.XDS.Interactions.ITI_62;
37 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.EMPTY_REFERENCE_LIST;
38
39
40
41
42
43 public class RemoveMetadataRequestValidatorTest {
44 private RemoveMetadataRequestValidator validator;
45 private RemoveMetadata request;
46 private RemoveMetadataRequestTransformer transformer;
47
48 @Before
49 public void setUp() {
50 validator = new RemoveMetadataRequestValidator();
51 request = SampleData.createRemoveMetadata();
52 transformer = new RemoveMetadataRequestTransformer();
53 }
54
55 @Test
56 public void testValidateGoodCase() {
57 validator.validate(transformer.toEbXML(request), ITI_62);
58 }
59
60 @Test
61 public void testValidateEmptyReferences() {
62 request.getReferences().clear();
63 expectFailure(EMPTY_REFERENCE_LIST);
64 }
65
66 @Test
67 public void testIssue150() {
68 String[] uuids = {UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()};
69 RemoveObjectsRequest request = new RemoveObjectsRequest();
70 request.setObjectRefList(new ObjectRefListType());
71 for (String uuid : uuids) {
72 ObjectRefType reference = new ObjectRefType();
73 reference.setId(uuid);
74 request.getObjectRefList().getObjectRef().add(reference);
75 }
76 EbXMLRemoveMetadataRequest ebXml = new EbXMLRemoveMetadataRequest30(request);
77 validator.validate(ebXml, ITI_62);
78 }
79
80 private void expectFailure(ValidationMessage expectedMessage) {
81 expectFailure(expectedMessage, transformer.toEbXML(request));
82 }
83
84 private void expectFailure(ValidationMessage expectedMessage, EbXMLRemoveMetadataRequest ebXML) {
85 expectFailure(expectedMessage, ebXML, ITI_62);
86 }
87
88 private void expectFailure(ValidationMessage expectedMessage, EbXMLRemoveMetadataRequest ebXML, ValidationProfile profile) {
89 try {
90 validator.validate(ebXML, profile);
91 fail("Expected exception: " + XDSMetaDataException.class);
92 }
93 catch (XDSMetaDataException e) {
94 assertEquals(expectedMessage, e.getValidationMessage());
95 }
96 }
97 }