View Javadoc
1   /*
2    * Copyright 2009 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.EbXMLNonconstructiveDocumentSetRequest;
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.RetrieveDocumentSet;
26  import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.RetrieveDocumentSetRequestTransformer;
27  import org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage;
28  import org.openehealth.ipf.commons.ihe.xds.core.validate.XDSMetaDataException;
29  
30  import static org.junit.Assert.assertEquals;
31  import static org.junit.Assert.fail;
32  import static org.openehealth.ipf.commons.ihe.xds.XDS.Interactions.ITI_43;
33  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.DOC_ID_MUST_BE_SPECIFIED;
34  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.REPO_ID_MUST_BE_SPECIFIED;
35  
36  /**
37   * Validates {@link NonconstructiveDocumentSetRequestValidator}.
38   * @author Jens Riemschneider
39   */
40  public class NonconstructiveDocumentSetRequestValidatorTest {
41      private NonconstructiveDocumentSetRequestValidator validator;
42      private RetrieveDocumentSet request;
43      private RetrieveDocumentSetRequestTransformer transformer;
44  
45      @Before
46      public void setUp() {
47          validator = new NonconstructiveDocumentSetRequestValidator();
48          EbXMLFactory factory = new EbXMLFactory30();
49          transformer = new RetrieveDocumentSetRequestTransformer(factory);
50          request = SampleData.createRetrieveDocumentSet();
51      }
52      
53      @Test
54      public void testGoodCase() throws XDSMetaDataException {
55          validator.validate(transformer.toEbXML(request), ITI_43);
56      }
57      
58      @Test
59      public void testRepoIdMustBeSpecified() {
60          request.getDocuments().add(new DocumentReference(null, "doc3", "home3"));
61          EbXMLNonconstructiveDocumentSetRequest ebXML = transformer.toEbXML(request);
62          expectFailure(REPO_ID_MUST_BE_SPECIFIED, ebXML);
63      }
64      
65      @Test
66      public void testDocIdMustBeSpecified() {
67          request.getDocuments().add(new DocumentReference("repo3", "", "home3"));
68          EbXMLNonconstructiveDocumentSetRequest ebXML = transformer.toEbXML(request);
69          expectFailure(DOC_ID_MUST_BE_SPECIFIED, ebXML);
70      }
71          
72      private void expectFailure(ValidationMessage expectedMessage, EbXMLNonconstructiveDocumentSetRequest ebXML) {
73          try {
74              validator.validate(ebXML, ITI_43);
75              fail("Expected exception: " + XDSMetaDataException.class);
76          }
77          catch (XDSMetaDataException e) {
78              assertEquals(expectedMessage, e.getValidationMessage());
79          }
80      }
81  }