7
7
import edu .unc .lib .boxc .auth .api .exceptions .AccessRestrictionException ;
8
8
import edu .unc .lib .boxc .auth .api .services .AccessControlService ;
9
9
import edu .unc .lib .boxc .auth .fcrepo .models .AccessGroupSetImpl ;
10
+ import edu .unc .lib .boxc .model .api .DatastreamType ;
10
11
import edu .unc .lib .boxc .model .api .ids .PID ;
11
12
import edu .unc .lib .boxc .search .api .models .Datastream ;
12
13
import edu .unc .lib .boxc .search .api .requests .SimpleIdRequest ;
@@ -66,10 +67,14 @@ public void testGetImageAtFullSize() throws Exception {
66
67
var formattedPid = idToPath (pidString , 4 , 2 ) + pidString + ".jp2" ;
67
68
var filename = "bunny.jpg" ;
68
69
ContentObjectSolrRecord contentObjectSolrRecord = mock (ContentObjectSolrRecord .class );
69
- Datastream datastream = mock (Datastream .class );
70
+ Datastream originalDatastream = mock (Datastream .class );
71
+ Datastream jp2Datastream = mock (Datastream .class );
72
+
70
73
when (solrSearchService .getObjectById (any (SimpleIdRequest .class ))).thenReturn (contentObjectSolrRecord );
71
- when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (datastream );
72
- when (datastream .getFilename ()).thenReturn (filename );
74
+ when (contentObjectSolrRecord .getDatastreamObject (DatastreamType .ORIGINAL_FILE .getId ())).thenReturn (originalDatastream );
75
+ when (originalDatastream .getFilename ()).thenReturn (filename );
76
+ when (contentObjectSolrRecord .getDatastreamObject (DatastreamType .JP2_ACCESS_COPY .getId ())).thenReturn (jp2Datastream );
77
+
73
78
when (contentObjectSolrRecord .getPid ()).thenReturn (pid );
74
79
75
80
stubFor (WireMock .get (urlMatching ("/" + formattedPid + "/full/full/0/default.jpg" ))
@@ -93,7 +98,8 @@ public void testGetImageAtPixelSizeSmallerThanFull() throws Exception {
93
98
var formattedPid = idToPath (pidString , 4 , 2 ) + pidString + ".jp2" ;
94
99
var filename = "bunny.jpg" ;
95
100
ContentObjectSolrRecord contentObjectSolrRecord = mock (ContentObjectSolrRecord .class );
96
- Datastream datastream = mock (Datastream .class );
101
+ Datastream originalDatastream = mock (Datastream .class );
102
+ Datastream jp2Datastream = mock (Datastream .class );
97
103
98
104
stubFor (WireMock .get (urlMatching ("/" + formattedPid + "/full/!800,800/0/default.jpg" ))
99
105
.willReturn (aResponse ()
@@ -102,9 +108,10 @@ public void testGetImageAtPixelSizeSmallerThanFull() throws Exception {
102
108
.withHeader ("Content-Type" , "image/jpeg" )));
103
109
104
110
when (solrSearchService .getObjectById (any (SimpleIdRequest .class ))).thenReturn (contentObjectSolrRecord );
105
- when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (datastream );
106
- when (datastream .getExtent ()).thenReturn ("1200x1200" );
107
- when (datastream .getFilename ()).thenReturn (filename );
111
+ when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (originalDatastream );
112
+ when (originalDatastream .getExtent ()).thenReturn ("1200x1200" );
113
+ when (originalDatastream .getFilename ()).thenReturn (filename );
114
+ when (contentObjectSolrRecord .getDatastreamObject (DatastreamType .JP2_ACCESS_COPY .getId ())).thenReturn (jp2Datastream );
108
115
when (contentObjectSolrRecord .getPid ()).thenReturn (pid );
109
116
110
117
MvcResult result = mvc .perform (get ("/downloadImage/" + pidString + "/800" ))
@@ -124,7 +131,8 @@ public void testGetImageAtPixelSizeBiggerThanFull() throws Exception {
124
131
var formattedPid = idToPath (pidString , 4 , 2 ) + pidString + ".jp2" ;
125
132
var filename = "bunny.jpg" ;
126
133
ContentObjectSolrRecord contentObjectSolrRecord = mock (ContentObjectSolrRecord .class );
127
- Datastream datastream = mock (Datastream .class );
134
+ Datastream originalDatastream = mock (Datastream .class );
135
+ Datastream jp2Datastream = mock (Datastream .class );
128
136
129
137
stubFor (WireMock .get (urlMatching ("/" + formattedPid + "/full/full/0/default.jpg" ))
130
138
.willReturn (aResponse ()
@@ -133,9 +141,10 @@ public void testGetImageAtPixelSizeBiggerThanFull() throws Exception {
133
141
.withHeader ("Content-Type" , "image/jpeg" )));
134
142
135
143
when (solrSearchService .getObjectById (any (SimpleIdRequest .class ))).thenReturn (contentObjectSolrRecord );
136
- when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (datastream );
137
- when (datastream .getExtent ()).thenReturn ("1200x1200" );
138
- when (datastream .getFilename ()).thenReturn (filename );
144
+ when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (originalDatastream );
145
+ when (originalDatastream .getExtent ()).thenReturn ("1200x1200" );
146
+ when (originalDatastream .getFilename ()).thenReturn (filename );
147
+ when (contentObjectSolrRecord .getDatastreamObject (DatastreamType .JP2_ACCESS_COPY .getId ())).thenReturn (jp2Datastream );
139
148
when (contentObjectSolrRecord .getPid ()).thenReturn (pid );
140
149
141
150
MvcResult result = mvc .perform (get ("/downloadImage/" + pidString + "/2500" ))
@@ -168,13 +177,16 @@ public void testFullSizeAccessImageNoFullSizePermissions() throws Exception {
168
177
public void testGetImageAtPixelSizeBiggerThanFullNoPermission () throws Exception {
169
178
PID filePid = makePid ();
170
179
ContentObjectSolrRecord contentObjectSolrRecord = mock (ContentObjectSolrRecord .class );
171
- Datastream datastream = mock (Datastream .class );
180
+ Datastream originalDatastream = mock (Datastream .class );
181
+ Datastream jp2Datastream = mock (Datastream .class );
172
182
when (solrSearchService .getObjectById (any (SimpleIdRequest .class ))).thenReturn (contentObjectSolrRecord );
173
183
doThrow (new AccessRestrictionException ()).when (accessControlService )
174
184
.assertHasAccess (anyString (), eq (filePid ), any (AccessGroupSetImpl .class ), eq (viewOriginal ));
175
185
176
- when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (datastream );
177
- when (datastream .getExtent ()).thenReturn ("1200x1200" );
186
+ when (contentObjectSolrRecord .getDatastreamObject ("original_file" )).thenReturn (originalDatastream );
187
+ when (originalDatastream .getExtent ()).thenReturn ("1200x1200" );
188
+ when (contentObjectSolrRecord .getDatastreamObject (DatastreamType .JP2_ACCESS_COPY .getId ())).thenReturn (jp2Datastream );
189
+
178
190
179
191
MvcResult result = mvc .perform (get ("/downloadImage/" + filePid .getId () + "/2500" ))
180
192
.andExpect (status ().isForbidden ())
@@ -258,6 +270,17 @@ public void testGetAccessImageNoOriginalFile() throws Exception {
258
270
assertEquals (message , DownloadImageService .INVALID_SIZE_MESSAGE );
259
271
}
260
272
273
+ @ Test
274
+ public void testGetImageNoJP2 () throws Exception {
275
+ PID filePid = makePid ();
276
+ ContentObjectSolrRecord contentObjectSolrRecord = mock (ContentObjectSolrRecord .class );
277
+ when (solrSearchService .getObjectById (any (SimpleIdRequest .class ))).thenReturn (contentObjectSolrRecord );
278
+
279
+ mvc .perform (get ("/downloadImage/" + filePid .getId () + "/full" ))
280
+ .andExpect (status ().is4xxClientError ())
281
+ .andReturn ();
282
+ }
283
+
261
284
private void assertCorrectImageReturned (MockHttpServletResponse response ) throws IOException {
262
285
assertEquals ("image/jpeg" , response .getContentType ());
263
286
0 commit comments