source: vlo/branches/vlo-ticket761/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/UriResolverImplTest.java @ 6267

Last change on this file since 6267 was 6267, checked in by Twan Goosen, 9 years ago

made branch up to date with trunk

File size: 2.8 KB
Line 
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 */
17package eu.clarin.cmdi.vlo.service.impl;
18
19import java.net.URI;
20import nl.mpi.archiving.corpusstructure.core.handle.HandleResolver;
21import nl.mpi.archiving.corpusstructure.core.handle.InvalidHandleException;
22import org.jmock.Expectations;
23import static org.jmock.Expectations.returnValue;
24import org.jmock.Mockery;
25import org.jmock.integration.junit4.JUnit4Mockery;
26import static org.junit.Assert.assertEquals;
27import org.junit.Before;
28import org.junit.Test;
29
30/**
31 *
32 * @author twagoo
33 */
34public 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}
Note: See TracBrowser for help on using the repository browser.