View Javadoc
1   /*
2    * Copyright 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.EbXMLFactory;
22  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRetrieveImagingDocumentSetRequest;
23  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
24  import org.openehealth.ipf.commons.ihe.xds.core.requests.DocumentReference;
25  import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveImagingDocumentSet;
26  import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveSeries;
27  import org.openehealth.ipf.commons.ihe.xds.core.requests.RetrieveStudy;
28  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.RetrieveImagingDocumentSetRequestTransformer;
29  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage;
30  import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
31  
32  import java.util.ArrayList;
33  import java.util.List;
34  
35  import static org.junit.Assert.assertEquals;
36  import static org.junit.Assert.fail;
37  import static org.openehealth.ipf.commons.ihe.xds.RAD.Interactions.RAD_69;
38  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.DOC_ID_MUST_BE_SPECIFIED;
39  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.REPO_ID_MUST_BE_SPECIFIED;
40  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.SERIES_INSTANCE_UID_MUST_BE_SPECIFIED;
41  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.STUDY_INSTANCE_UID_MUST_BE_SPECIFIED;
42  
43  /**
44   * Validates {@link org.openehealth.ipf.commons.ihe.xds.core.validate.requests.RetrieveImagingDocumentSetRequestValidator}.
45   * @author Clay Sebourn
46   */
47  public class RetrieveImagingDocumentSetRequestValidatorTest
48  {
49      private RetrieveImagingDocumentSetRequestValidator validator;
50      private RetrieveImagingDocumentSet request;
51      private RetrieveImagingDocumentSetRequestTransformer transformer;
52  
53      @Before
54      public void setUp() {
55          validator = new RetrieveImagingDocumentSetRequestValidator();
56          EbXMLFactory factory = new EbXMLFactory30();
57          transformer = new RetrieveImagingDocumentSetRequestTransformer(factory);
58          request = SampleData.createRetrieveImagingDocumentSet();
59      }
60      
61      @Test
62      public void testGoodCase() throws XDSMetaDataException {
63          validator.validate(transformer.toEbXML(request), RAD_69);
64      }
65      
66      @Test
67      public void testStudyInstanceIdMustBeSpecified() {
68          List<DocumentReference> documentReferences = new ArrayList<>();
69          DocumentReference documentReference = new DocumentReference("repo1", "doc1", "urn:oid:1.2.5");
70          documentReferences.add(documentReference);
71  
72          RetrieveSeries retrieveSeries = new RetrieveSeries("urn:oid:1.2.3", documentReferences);
73          List<RetrieveSeries> retrieveSerieses = new ArrayList<>();
74          retrieveSerieses.add(retrieveSeries);
75  
76          request.getRetrieveStudies().add(new RetrieveStudy(null, retrieveSerieses));
77          EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(request);
78          expectFailure(STUDY_INSTANCE_UID_MUST_BE_SPECIFIED, ebXML);
79      }
80  
81      @Test
82      public void testSteriesInstanceIdMustBeSpecified() {
83          List<DocumentReference> documentReferences = new ArrayList<>();
84          DocumentReference documentReference = new DocumentReference("repo1", "doc1", "urn:oid:1.2.6");
85          documentReferences.add(documentReference);
86  
87          RetrieveSeries retrieveSeries = new RetrieveSeries(null, documentReferences);
88          List<RetrieveSeries> retrieveSerieses = new ArrayList<>();
89          retrieveSerieses.add(retrieveSeries);
90  
91          request.getRetrieveStudies().add(new RetrieveStudy("urn:oid:1.1.3", retrieveSerieses));
92          EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(request);
93          expectFailure(SERIES_INSTANCE_UID_MUST_BE_SPECIFIED, ebXML);
94      }
95  
96      @Test
97      public void testRepoIdMustBeSpecified() {
98          request.getRetrieveStudies().get(0).getRetrieveSerieses().get(0).getDocuments().add(new DocumentReference(null, "doc3", "home3"));
99          EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(request);
100         expectFailure(REPO_ID_MUST_BE_SPECIFIED, ebXML);
101     }
102 
103     @Test
104     public void testDocIdMustBeSpecified() {
105         request.getRetrieveStudies().get(0).getRetrieveSerieses().get(0).getDocuments().add(new DocumentReference("repo3", "", "home3"));
106         EbXMLRetrieveImagingDocumentSetRequest ebXML = transformer.toEbXML(request);
107         expectFailure(DOC_ID_MUST_BE_SPECIFIED, ebXML);
108     }
109         
110     private void expectFailure(ValidationMessage expectedMessage, EbXMLRetrieveImagingDocumentSetRequest ebXML) {
111         try {
112             validator.validate(ebXML, RAD_69);
113             fail("Expected exception: " + XDSMetaDataException.class);
114         }
115         catch (XDSMetaDataException e) {
116             assertEquals(expectedMessage, e.getValidationMessage());
117         }
118     }
119 }