1 | /* |
---|
2 | * To change this license header, choose License Headers in Project Properties. |
---|
3 | * To change this template file, choose Tools | Templates |
---|
4 | * and open the template in the editor. |
---|
5 | */ |
---|
6 | package eu.clarin.cmdi.virtualcollectionregistry.service.impl; |
---|
7 | |
---|
8 | import eu.clarin.cmdi.virtualcollectionregistry.model.Creator; |
---|
9 | import eu.clarin.cmdi.virtualcollectionregistry.service.CreatorProvider; |
---|
10 | import java.security.Principal; |
---|
11 | import java.util.Arrays; |
---|
12 | import org.jmock.Expectations; |
---|
13 | import org.jmock.Mockery; |
---|
14 | import org.jmock.integration.junit4.JUnit4Mockery; |
---|
15 | import static org.junit.Assert.*; |
---|
16 | import org.junit.Test; |
---|
17 | |
---|
18 | /** |
---|
19 | * |
---|
20 | * @author twagoo |
---|
21 | */ |
---|
22 | public class ChaningCreatorProviderTest { |
---|
23 | |
---|
24 | private final Mockery context = new JUnit4Mockery(); |
---|
25 | |
---|
26 | /** |
---|
27 | * Test of getCreator method, of class ChaningCreatorProvider. |
---|
28 | */ |
---|
29 | @Test |
---|
30 | public void testGetCreator() { |
---|
31 | final CreatorProvider provider1 = context.mock(CreatorProvider.class, "p1"); |
---|
32 | final Creator creator1 = new Creator(); |
---|
33 | creator1.setAddress("addr1"); |
---|
34 | creator1.setEMail("email1"); |
---|
35 | creator1.setOrganisation("org1"); |
---|
36 | |
---|
37 | final CreatorProvider provider2 = context.mock(CreatorProvider.class, "p2"); |
---|
38 | final Creator creator2 = new Creator(); |
---|
39 | creator2.setPerson("pers2"); |
---|
40 | creator2.setRole("role2"); |
---|
41 | creator2.setTelephone("tel2"); |
---|
42 | creator2.setWebsite("web2"); |
---|
43 | |
---|
44 | Creator expResult = new Creator(); |
---|
45 | expResult.setAddress("addr1"); |
---|
46 | expResult.setEMail("email1"); |
---|
47 | expResult.setOrganisation("org1"); |
---|
48 | expResult.setPerson("pers2"); |
---|
49 | expResult.setRole("role2"); |
---|
50 | expResult.setTelephone("tel2"); |
---|
51 | expResult.setWebsite("web2"); |
---|
52 | |
---|
53 | final Principal principal = new Principal() { |
---|
54 | |
---|
55 | @Override |
---|
56 | public String getName() { |
---|
57 | return "name"; |
---|
58 | } |
---|
59 | }; |
---|
60 | |
---|
61 | context.checking(new Expectations(){{ |
---|
62 | oneOf(provider1).getCreator(principal); |
---|
63 | will(returnValue(creator1)); |
---|
64 | oneOf(provider2).getCreator(principal); |
---|
65 | will(returnValue(creator2)); |
---|
66 | }}); |
---|
67 | final ChaningCreatorProvider instance = new ChaningCreatorProvider(Arrays.asList(provider1, provider2)); |
---|
68 | final Creator result = instance.getCreator(principal); |
---|
69 | |
---|
70 | assertEquals(expResult, result); |
---|
71 | } |
---|
72 | |
---|
73 | } |
---|