1 | /* |
---|
2 | * Copyright (C) 2013 DASISH |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or |
---|
5 | * modify it under the terms of the GNU General Public License |
---|
6 | * as published by the Free Software Foundation; either version 2 |
---|
7 | * of the License, or (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, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
17 | */ |
---|
18 | package eu.dasish.annotation.backend.rest; |
---|
19 | |
---|
20 | import eu.dasish.annotation.backend.dao.DBDispatcher; |
---|
21 | import org.jmock.Mockery; |
---|
22 | import org.junit.Test; |
---|
23 | import org.junit.runner.RunWith; |
---|
24 | import org.springframework.beans.factory.annotation.Autowired; |
---|
25 | import org.springframework.test.context.ContextConfiguration; |
---|
26 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
---|
27 | |
---|
28 | /** |
---|
29 | * |
---|
30 | * @author Peter Withers <peter.withers@mpi.nl> |
---|
31 | */ |
---|
32 | @RunWith(value = SpringJUnit4ClassRunner.class) |
---|
33 | @ContextConfiguration(locations = {"/spring-test-config/mockeryRest.xml", "/spring-test-config/mockDBDispatcher.xml", "/spring-config/jaxbMarshallerFactory.xml", |
---|
34 | "/spring-config/jaxbUnmarshallerFactory.xml"}) |
---|
35 | public class NotebookResourceTest { |
---|
36 | |
---|
37 | @Autowired |
---|
38 | private Mockery mockeryRest; |
---|
39 | @Autowired |
---|
40 | private DBDispatcher daoDispatcher; |
---|
41 | @Autowired |
---|
42 | private NotebookResource notebookResource; |
---|
43 | |
---|
44 | public NotebookResourceTest() { |
---|
45 | } |
---|
46 | |
---|
47 | @Test |
---|
48 | public void dummy(){ |
---|
49 | |
---|
50 | } |
---|
51 | // |
---|
52 | // /** |
---|
53 | // * Test of getNotebookInfo method, of class NotebookResource. |
---|
54 | // */ |
---|
55 | // @Test |
---|
56 | // public void testGetNotebookInfo() { |
---|
57 | // System.out.println("getNotebookInfo"); |
---|
58 | // final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); |
---|
59 | // httpServletRequest.setRemotePrincipal(TestBackendConstants._TEST_UID_1_); |
---|
60 | // |
---|
61 | // |
---|
62 | // mockery.checking(new Expectations() { |
---|
63 | // { |
---|
64 | // oneOf(notebookDao).getNotebookInfos(UUID.fromString(httpServletRequest.getRemotePrincipal())); |
---|
65 | // will(returnValue(new ArrayList<NotebookInfo>())); |
---|
66 | // } |
---|
67 | // }); |
---|
68 | // JAXBElement<NotebookInfoList> result = notebookResource.getNotebookInfo(httpServletRequest); |
---|
69 | // assertEquals(0, result.getValue().getNotebook().size()); // todo: shoudnt this return 3 infos? |
---|
70 | // } |
---|
71 | // |
---|
72 | // /** |
---|
73 | // * Test of getPrincipalsNotebooks method, of class NotebookResource. |
---|
74 | // */ |
---|
75 | // @Test |
---|
76 | // public void testGetPrincipalsNotebooks() { |
---|
77 | // System.out.println("getPrincipalsNotebooks"); |
---|
78 | // mockery.checking(new Expectations() { |
---|
79 | // { |
---|
80 | // oneOf(notebookDao).getPrincipalsNotebooks(UUID.fromString(TestBackendConstants._TEST_UID_2_)); |
---|
81 | // will(returnValue(new ArrayList<Notebook>())); |
---|
82 | // } |
---|
83 | // }); |
---|
84 | // final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); |
---|
85 | // httpServletRequest.setRemotePrincipal(TestBackendConstants._TEST_UID_2_); |
---|
86 | // List result = notebookResource.getPrincipalsNotebooks(httpServletRequest); |
---|
87 | // assertEquals(0, result.size()); |
---|
88 | // } |
---|
89 | // |
---|
90 | // /** |
---|
91 | // * Test of createNotebook method, of class NotebookResource. |
---|
92 | // */ |
---|
93 | // @Test |
---|
94 | // public void testCreateNotebook() throws Exception { |
---|
95 | // System.out.println("createNotebook"); |
---|
96 | // final MockHttpServletRequest httpServletRequest = new MockHttpServletRequest(); |
---|
97 | // httpServletRequest.setRemotePrincipal(TestBackendConstants._TEST_UID_2_); |
---|
98 | // |
---|
99 | // mockery.checking(new Expectations() { |
---|
100 | // { |
---|
101 | // oneOf(notebookDao).addNotebook(UUID.fromString(httpServletRequest.getRemotePrincipal()), null); |
---|
102 | // will(returnValue(UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_1_EXT_ID))); |
---|
103 | // } |
---|
104 | // }); |
---|
105 | // String expResult = "/api/notebooks/00000000-0000-0000-0000-000000000001"; |
---|
106 | // String result = notebookResource.createNotebook(httpServletRequest); |
---|
107 | // assertEquals(expResult, result.substring(result.length() - expResult.length())); |
---|
108 | // } |
---|
109 | // |
---|
110 | // /** |
---|
111 | // * Test of deleteNotebook method, of class NotebookResource. |
---|
112 | // */ |
---|
113 | // @Test |
---|
114 | // public void testDeleteNotebook() { |
---|
115 | // System.out.println("deleteNotebook"); |
---|
116 | // final UUID externalID = UUID.fromString(TestBackendConstants._TEST_NOTEBOOK_1_EXT_ID); |
---|
117 | // mockery.checking(new Expectations() { |
---|
118 | // { |
---|
119 | // oneOf(notebookDao).deleteNotebook(externalID); |
---|
120 | // will(returnValue(1)); |
---|
121 | // } |
---|
122 | // }); |
---|
123 | // String expResult = "1"; |
---|
124 | // String result = notebookResource.deleteNotebook(externalID); |
---|
125 | // assertEquals(expResult, result); |
---|
126 | // } |
---|
127 | // |
---|
128 | // /** |
---|
129 | // * Test of getMetadata method, of class NotebookResource. Get all metadata |
---|
130 | // * about a specified notebook <nid>, including the information if it is |
---|
131 | // * private or not. GET api/notebooks/<nid>/metadata |
---|
132 | // */ |
---|
133 | // @Test |
---|
134 | // public void testGetMetadata() { |
---|
135 | // System.out.println("test GetMetadata"); |
---|
136 | // |
---|
137 | // final String externalID= TestBackendConstants._TEST_NOTEBOOK_3_EXT; |
---|
138 | // final int notebookID = 3; |
---|
139 | // final NotebookInfo testInfo = new ObjectFactory().createNotebookInfo(); |
---|
140 | // |
---|
141 | // mockery.checking(new Expectations() { |
---|
142 | // { |
---|
143 | // oneOf(notebookDao).getInternalID(UUID.fromString(externalID)); |
---|
144 | // will(returnValue(notebookID)); |
---|
145 | // |
---|
146 | // oneOf(notebookDao).getNotebookInfo(notebookID); |
---|
147 | // will(returnValue(testInfo)); |
---|
148 | // } |
---|
149 | // }); |
---|
150 | // |
---|
151 | // JAXBElement<NotebookInfo> result = notebookResource.getMetadata(externalID); |
---|
152 | // NotebookInfo entity = result.getValue(); |
---|
153 | // assertEquals(testInfo.getRef(), entity.getRef()); |
---|
154 | // assertEquals(testInfo.getTitle(), entity.getTitle()); |
---|
155 | // } |
---|
156 | // |
---|
157 | // |
---|
158 | // @Test |
---|
159 | // public void testGetAllAnnotations() { |
---|
160 | // System.out.println("test getAllAnnotations"); |
---|
161 | // final String externalID= TestBackendConstants._TEST_NOTEBOOK_3_EXT; |
---|
162 | // final UUID aIdOne= UUID.fromString("00000000-0000-0000-0000-000000000021"); |
---|
163 | // final UUID aIdTwo= UUID.fromString("00000000-0000-0000-0000-000000000022"); |
---|
164 | // final List<UUID> annotationIds = new ArrayList<UUID>(); |
---|
165 | // annotationIds.add(aIdOne); |
---|
166 | // annotationIds.add(aIdTwo); |
---|
167 | // |
---|
168 | // mockery.checking(new Expectations() { |
---|
169 | // { |
---|
170 | // oneOf(notebookDao).getAnnotationExternalIDs(UUID.fromString(externalID)); |
---|
171 | // will(returnValue(annotationIds)); |
---|
172 | // |
---|
173 | // } |
---|
174 | // }); |
---|
175 | // |
---|
176 | // List<JAXBElement<UUID>> result= notebookResource.getAllAnnotations(externalID, 0, 0, null, 0); |
---|
177 | // assertFalse(null==result); |
---|
178 | // assertEquals(aIdOne, result.get(0).getValue()); |
---|
179 | // assertEquals(aIdTwo, result.get(1).getValue()); |
---|
180 | // |
---|
181 | // |
---|
182 | // } |
---|
183 | } |
---|