1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.openehealth.ipf.commons.ihe.fhir.support.translation;
18
19 import ca.uhn.fhir.context.FhirContext;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.openehealth.ipf.commons.ihe.fhir.support.DefaultNamingSystemServiceImpl;
23 import org.openehealth.ipf.commons.ihe.fhir.translation.UriMapper;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27
28
29
30
31 abstract class AbstractSystemUriMapperTest {
32
33 private UriMapper uriMapper;
34
35 @Before
36 public void setup() {
37 this.uriMapper = initMapper(new DefaultNamingSystemServiceImpl(FhirContext.forDstu3()));
38 }
39
40 protected abstract UriMapper initMapper(DefaultNamingSystemServiceImpl namingSystemService);
41
42 @Test
43 public void testTranslateOidUrn() throws Exception {
44 String oid = "1.2.3.4.5.6.7.8.9";
45 assertEquals(oid, uriMapper.uriToOid("urn:oid:" + oid).get());
46 }
47
48 @Test
49 public void testTranslateUriToOid() throws Exception {
50 String uri = "http://org.openehealth/ipf/commons/ihe/fhir/1";
51 assertEquals("1.2.3.4", uriMapper.uriToOid(uri).get());
52 }
53
54 @Test
55 public void testTranslateUriToOidFails() throws Exception {
56 String uri = "http://org.openehealth/ipf/commons/ihe/fhir/9";
57 assertFalse(uriMapper.uriToOid(uri).isPresent());
58 }
59
60 @Test
61 public void testTranslatePinUrn() throws Exception {
62 String namespace = "namespace";
63 assertEquals(namespace, uriMapper.uriToNamespace("urn:pin:" + namespace).get());
64 }
65
66 @Test
67 public void testTranslateUriToNamespace() throws Exception {
68 String uri = "http://org.openehealth/ipf/commons/ihe/fhir/1";
69 assertEquals("fhir1", uriMapper.uriToNamespace(uri).get());
70 uri = "http://org.openehealth/ipf/commons/ihe/fhir/9";
71 assertFalse(uriMapper.uriToNamespace(uri).isPresent());
72 }
73
74 @Test
75 public void testTranslateNamespaceToUri() throws Exception {
76 String namespace = "fhir1";
77 assertEquals("http://org.openehealth/ipf/commons/ihe/fhir/1", uriMapper.namespaceToUri(namespace));
78 }
79 }