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;
17  
18  import org.junit.Test;
19  
20  import java.util.Arrays;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import static org.junit.Assert.fail;
25  
26  /**
27   * Tests for {@link RecipientListValidator}.
28   * @author Jens Riemschneider
29   */
30  public class RecipientListValidatorTest {
31      private static final RecipientListValidator validator = new RecipientListValidator();
32  
33      @Test
34      public void testValidateGoodCases() throws XDSMetaDataException {
35          validator.validate(Collections.singletonList("Some Hospital|^Welby"));
36          validator.validate(Collections.singletonList("|^Welby"));
37          validator.validate(Collections.singletonList("|ID^^^^^^^^&1.2.840.113619.6.197&ISO"));
38          validator.validate(Collections.singletonList("Some Hospital"));
39          validator.validate(Arrays.asList("Some Hospital", "|^Welby"));
40      }
41      
42      @Test 
43      public void testValidateBadCases() throws XDSMetaDataException {
44  //      This check is disabled for compatibility with older versions.
45  //        assertFails(Arrays.<String>asList());
46          assertFails(Collections.singletonList(""));
47          assertFails(Collections.singletonList("^LOL"));
48          assertFails(Collections.singletonList("Some Hospital|^Welby||"));
49          assertFails(Collections.singletonList("|Some Hospital|^Welby|"));
50          assertFails(Arrays.asList("Some Hospital", ""));
51      }
52  
53      private static void assertFails(List<String> value) {
54          try {
55              validator.validate(value);
56              fail("Expected exception: " + XDSMetaDataException.class + " for " + value);
57          } catch (XDSMetaDataException e) {
58              // Expected
59          }
60      }
61  }