1 | package eu.clarin.cmdi.virtualcollectionregistry.pid; |
---|
2 | |
---|
3 | import de.uni_leipzig.asv.clarin.webservices.pidservices2.Configuration; |
---|
4 | import de.uni_leipzig.asv.clarin.webservices.pidservices2.HandleField; |
---|
5 | import de.uni_leipzig.asv.clarin.webservices.pidservices2.interfaces.PidWriter; |
---|
6 | import eu.clarin.cmdi.virtualcollectionregistry.model.Creator; |
---|
7 | import eu.clarin.cmdi.virtualcollectionregistry.model.VirtualCollection; |
---|
8 | import eu.clarin.cmdi.virtualcollectionregistry.pid.PersistentIdentifier.Type; |
---|
9 | import static org.hamcrest.Matchers.*; |
---|
10 | import org.jmock.Expectations; |
---|
11 | import org.jmock.Mockery; |
---|
12 | import org.jmock.integration.junit4.JUnit4Mockery; |
---|
13 | import static org.junit.Assert.*; |
---|
14 | import org.junit.Before; |
---|
15 | import org.junit.Test; |
---|
16 | |
---|
17 | /** |
---|
18 | * |
---|
19 | * @author twagoo |
---|
20 | */ |
---|
21 | public class EPICPersistentIdentifierProviderTest { |
---|
22 | |
---|
23 | private final Mockery context = new JUnit4Mockery(); |
---|
24 | private final Configuration pidConfig = new Configuration("http://epic/server", "9999", "user", "password"); |
---|
25 | private EPICPersistentIdentifierProvider instance; |
---|
26 | private PidWriter pidWriter; |
---|
27 | |
---|
28 | @Before |
---|
29 | public void setUp() { |
---|
30 | pidWriter = context.mock(PidWriter.class); |
---|
31 | instance = new EPICPersistentIdentifierProvider(pidWriter, pidConfig); |
---|
32 | instance.setBaseUri("http://vcr/"); |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * Test of createIdentifier method, of class |
---|
37 | * EPIC2PersistentIdentifierProvider. |
---|
38 | */ |
---|
39 | @Test |
---|
40 | public void testCreateIdentifier() throws Exception { |
---|
41 | VirtualCollection vc = new VirtualCollection(); |
---|
42 | vc.setName("VC Name"); |
---|
43 | vc.setId(123L); |
---|
44 | vc.getCreators().add(new Creator("Joe Unit")); |
---|
45 | vc.getCreators().add(new Creator("Joe Mock")); |
---|
46 | |
---|
47 | context.checking(new Expectations() { |
---|
48 | { |
---|
49 | // should call pidwriter |
---|
50 | exactly(1).of(equal(pidWriter)).method("registerNewPID").with( |
---|
51 | equal(pidConfig), |
---|
52 | allOf( |
---|
53 | hasEntry(HandleField.URL, "http://vcr/service/virtualcollections/123"), |
---|
54 | hasEntry(HandleField.TITLE, "VC Name"), |
---|
55 | hasEntry(HandleField.CREATOR, "Joe Unit") |
---|
56 | ), |
---|
57 | equalTo("VCR-123") |
---|
58 | ); |
---|
59 | will(returnValue("9999/VCR-123")); |
---|
60 | } |
---|
61 | }); |
---|
62 | |
---|
63 | PersistentIdentifier result = instance.createIdentifier(vc); |
---|
64 | assertEquals("9999/VCR-123", result.getIdentifier()); |
---|
65 | assertEquals(Type.HANDLE, result.getType()); |
---|
66 | } |
---|
67 | |
---|
68 | } |
---|