1 | /* |
---|
2 | * Copyright (C) 2014 CLARIN |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation, either version 3 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | */ |
---|
17 | package eu.clarin.cmdi.vlo.service.impl; |
---|
18 | |
---|
19 | import java.net.URI; |
---|
20 | import nl.mpi.archiving.corpusstructure.core.handle.HandleResolver; |
---|
21 | import nl.mpi.archiving.corpusstructure.core.handle.InvalidHandleException; |
---|
22 | import org.jmock.Expectations; |
---|
23 | import static org.jmock.Expectations.returnValue; |
---|
24 | import org.jmock.Mockery; |
---|
25 | import org.jmock.integration.junit4.JUnit4Mockery; |
---|
26 | import static org.junit.Assert.assertEquals; |
---|
27 | import org.junit.Before; |
---|
28 | import org.junit.Test; |
---|
29 | |
---|
30 | /** |
---|
31 | * |
---|
32 | * @author twagoo |
---|
33 | */ |
---|
34 | public class UriResolverImplTest { |
---|
35 | |
---|
36 | private final Mockery context = new JUnit4Mockery(); |
---|
37 | private UriResolverImpl instance; |
---|
38 | private HandleResolver handleClient; |
---|
39 | |
---|
40 | @Before |
---|
41 | public void setUp() { |
---|
42 | handleClient = context.mock(HandleResolver.class); |
---|
43 | instance = new UriResolverImpl(handleClient); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * Test of resolve method, of class HandleClientUriResolverImpl. |
---|
48 | */ |
---|
49 | @Test |
---|
50 | public void testResolveNonHandle() { |
---|
51 | String result = instance.resolve("http://www.clarin.eu"); |
---|
52 | assertEquals("http://www.clarin.eu", result); |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Test of resolve method, of class HandleClientUriResolverImpl. |
---|
57 | */ |
---|
58 | @Test |
---|
59 | public void testResolveHandleScheme() throws InvalidHandleException { |
---|
60 | context.checking(new Expectations() { |
---|
61 | { |
---|
62 | oneOf(handleClient).resolve(URI.create("hdl:1234/5678")); |
---|
63 | will(returnValue(URI.create("http://www.clarin.eu"))); |
---|
64 | } |
---|
65 | }); |
---|
66 | String result = instance.resolve("hdl:1234/5678"); |
---|
67 | assertEquals("http://www.clarin.eu", result); |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Test of resolve method, of class HandleClientUriResolverImpl. |
---|
72 | */ |
---|
73 | @Test |
---|
74 | public void testResolveHandleProxy() throws InvalidHandleException { |
---|
75 | context.checking(new Expectations() { |
---|
76 | { |
---|
77 | oneOf(handleClient).resolve(URI.create("hdl:1234/5678")); |
---|
78 | will(returnValue(URI.create("http://www.clarin.eu"))); |
---|
79 | } |
---|
80 | }); |
---|
81 | String result = instance.resolve("http://hdl.handle.net/1234/5678"); |
---|
82 | assertEquals("http://www.clarin.eu", result); |
---|
83 | } |
---|
84 | |
---|
85 | } |
---|