-
Notifications
You must be signed in to change notification settings - Fork 129
/
FedoraFixityTest.java
184 lines (147 loc) · 4.93 KB
/
FedoraFixityTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
* Copyright 2014 DuraSpace, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.fcrepo.http.api;
import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl;
import static org.fcrepo.http.commons.test.util.TestHelpers.mockSession;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.springframework.test.util.ReflectionTestUtils.setField;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.TimeoutHandler;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import org.fcrepo.kernel.models.FedoraBinary;
import org.fcrepo.kernel.identifiers.IdentifierConverter;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* <p>FedoraFixityTest class.</p>
*
* @author awoods
*/
public class FedoraFixityTest {
FedoraFixity testObj;
private Session mockSession;
private UriInfo uriInfo;
@Mock
private Request mockRequest;
@Mock
private Node mockNode;
@Mock
private FedoraBinary mockBinary;
private String externalPath = "objects/FedoraDatastreamsTest1/testDS";
@Before
public void setUp() throws RepositoryException {
initMocks(this);
testObj = spy(new FedoraFixity(externalPath));
this.uriInfo = getUriInfoImpl();
setField(testObj, "uriInfo", uriInfo);
mockSession = mockSession(testObj);
setField(testObj, "session", mockSession);
when(mockNode.getSession()).thenReturn(mockSession);
when(mockBinary.getPath()).thenReturn(externalPath);
doReturn(mockBinary).when(testObj).getResourceFromPath(externalPath);
}
@Test
public void testGetDatastreamFixity() throws RepositoryException, InterruptedException {
final RdfStream expected = new RdfStream();
when(mockBinary.getFixity(any(IdentifierConverter.class))).thenReturn(expected);
final TestAsyncResponse asyncResponse = new TestAsyncResponse();
synchronized (asyncResponse) {
testObj.getDatastreamFixity(asyncResponse);
asyncResponse.wait(1000);
}
assertEquals(expected, asyncResponse.getResponse());
}
private class TestAsyncResponse implements AsyncResponse {
private Object response;
public Object getResponse() {
return response;
}
@Override
public boolean resume(final Object o) {
synchronized (this) {
this.response = o;
notify();
}
return true;
}
@Override
public boolean resume(final Throwable throwable) {
return false;
}
@Override
public boolean cancel() {
return false;
}
@Override
public boolean cancel(final int i) {
return false;
}
@Override
public boolean cancel(final Date date) {
return false;
}
@Override
public boolean isSuspended() {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return false;
}
@Override
public boolean setTimeout(final long l, final TimeUnit timeUnit) {
return false;
}
@Override
public void setTimeoutHandler(final TimeoutHandler timeoutHandler) {
}
@Override
public Collection<Class<?>> register(final Class<?> aClass) {
return null;
}
@Override
public Map<Class<?>, Collection<Class<?>>> register(final Class<?> aClass, final Class<?>... classes) {
return null;
}
@Override
public Collection<Class<?>> register(final Object o) {
return null;
}
@Override
public Map<Class<?>, Collection<Class<?>>> register(final Object o, final Object... objects) {
return null;
}
}
}