1
|
package eu.etaxonomy.cdm.remote.service;
|
2
|
|
3
|
|
4
|
import static org.junit.Assert.assertTrue;
|
5
|
|
6
|
import org.easymock.EasyMock;
|
7
|
import org.junit.Before;
|
8
|
import org.junit.Test;
|
9
|
import org.springframework.test.web.ModelAndViewAssert;
|
10
|
import org.springframework.web.servlet.ModelAndView;
|
11
|
import org.unitils.UnitilsJUnit4;
|
12
|
import org.unitils.easymock.annotation.Mock;
|
13
|
import org.unitils.inject.annotation.InjectInto;
|
14
|
import org.unitils.inject.annotation.TestedObject;
|
15
|
|
16
|
import com.ibm.lsid.LSIDException;
|
17
|
import com.ibm.lsid.MalformedLSIDException;
|
18
|
import com.ibm.lsid.MetadataResponse;
|
19
|
import com.ibm.lsid.server.LSIDServerException;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.lsid.LSIDMetadataService;
|
22
|
import eu.etaxonomy.cdm.model.common.LSID;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
24
|
import eu.etaxonomy.cdm.test.util.LSIDMatchers;
|
25
|
|
26
|
public class MetadataControllerTest extends UnitilsJUnit4 {
|
27
|
|
28
|
@Mock
|
29
|
@InjectInto(property = "lsidMetadataService")
|
30
|
private LSIDMetadataService metadataService;
|
31
|
|
32
|
@TestedObject
|
33
|
private MetadataController metadataController;
|
34
|
|
35
|
private LSID lsid;
|
36
|
private String[] acceptedFormats;
|
37
|
|
38
|
@Before
|
39
|
public void setUp() {
|
40
|
metadataController = new MetadataController();
|
41
|
metadataService = EasyMock.createMock(LSIDMetadataService.class);
|
42
|
try {
|
43
|
lsid = new LSID("urn:lsid:fred.org:dagg:1");
|
44
|
} catch (MalformedLSIDException e) { }
|
45
|
acceptedFormats = new String[]{MetadataResponse.RDF_FORMAT};
|
46
|
}
|
47
|
|
48
|
@Test
|
49
|
public void testGetMetadata() throws Exception {
|
50
|
Taxon taxon = Taxon.NewInstance(null,null);
|
51
|
EasyMock.expect(metadataService.getMetadata(LSIDMatchers.eqLSID(lsid))).andReturn(taxon);
|
52
|
EasyMock.replay(metadataService);
|
53
|
|
54
|
|
55
|
ModelAndView modelAndView = metadataController.getMetadata(lsid, "application/xml+rdf");
|
56
|
|
57
|
EasyMock.verify(metadataService);
|
58
|
ModelAndViewAssert.assertViewName(modelAndView, "Metadata.rdf");
|
59
|
assertTrue(modelAndView.getModel().containsValue(taxon));
|
60
|
}
|
61
|
|
62
|
@Test(expected = LSIDServerException.class)
|
63
|
public void testGetMetadataWithoutAcceptedFormat() throws Exception {
|
64
|
acceptedFormats = new String[]{MetadataResponse.N3_FORMAT,MetadataResponse.XMI_FORMAT};
|
65
|
EasyMock.replay(metadataService);
|
66
|
|
67
|
metadataController.getMetadata(lsid, "application/n3,application/xml+xmi");
|
68
|
}
|
69
|
|
70
|
@Test(expected = LSIDServerException.class)
|
71
|
public void testGetMetadataWithUnknownLSID() throws Exception {
|
72
|
|
73
|
LSIDServerException lse = new LSIDServerException(LSIDException.UNKNOWN_LSID, "Unknown LSID");
|
74
|
EasyMock.expect(metadataService.getMetadata(LSIDMatchers.eqLSID(lsid))).andThrow(lse);
|
75
|
EasyMock.replay(metadataService);
|
76
|
|
77
|
metadataController.getMetadata(lsid, "application/xml+rdf");
|
78
|
}
|
79
|
}
|