Project

General

Profile

« Previous | Next » 

Revision 896e7ef8

Added by Andreas Kohlbecker almost 4 years ago

ref #9134 fixing calculation of croped thumbnail images and adding tests

View differences:

cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/media/MediaUriTransformationProcessorTest.java
173 173
        assertEquals(Integer.valueOf(300), image.getHeight());
174 174
    }
175 175

  
176
    @Test
177
    public void testMakeMediaCropLandcape() throws URISyntaxException {
178

  
179
        MediaUriTransformation transformation1 = new MediaUriTransformation();
180
        transformation1.setPathQueryFragment(new SearchReplace(PATTERN_1, "digilib/Scaler/?fn=$1/$2&mo=crop&dw=200&dh=147&uvfix=1"));
181
        transformation1.setMimeType("image/jpeg");
182
        transformation1.setWidth(200);
183
        transformation1.setHeight(147);
184
        MediaUriTransformationProcessor processor = new MediaUriTransformationProcessor();
185
        processor.add(transformation1);
186

  
187
        MediaRepresentation repr = makeImageMediaRepresentation(2000, 1500); // aspect ratio = 4/3
188

  
189
        List<MediaRepresentation> representations = processor.makeNewMediaRepresentationsFor(repr.getParts().get(0));
190

  
191
        assertEquals("https://pictures.bgbm.org/digilib/Scaler/?fn=Cyprus/Salvia_aethiopis_A1.jpg&mo=crop&dw=200&dh=147&uvfix=1", representations.get(0).getParts().get(0).getUri().toString());
192
        assertEquals(ImageFile.class, representations.get(0).getParts().get(0).getClass());
193
        ImageFile image = (ImageFile)representations.get(0).getParts().get(0);
194
        assertEquals(Integer.valueOf(200), image.getWidth());
195
        assertEquals(Integer.valueOf(147), image.getHeight());
196

  
197
        // aspect ratio = 3/4
198
        MediaRepresentation repr2 = makeImageMediaRepresentation(1500, 2000);
199

  
200
        representations = processor.makeNewMediaRepresentationsFor(repr2.getParts().get(0));
201

  
202
        assertEquals("https://pictures.bgbm.org/digilib/Scaler/?fn=Cyprus/Salvia_aethiopis_A1.jpg&mo=crop&dw=200&dh=147&uvfix=1", representations.get(0).getParts().get(0).getUri().toString());
203
        assertEquals(ImageFile.class, representations.get(0).getParts().get(0).getClass());
204
        image = (ImageFile)representations.get(0).getParts().get(0);
205
        assertEquals(Integer.valueOf(200), image.getWidth());
206
        assertEquals(Integer.valueOf(147), image.getHeight());
207
    }
208

  
209
    @Test
210
    public void testMakeMediaCropPortrait() throws URISyntaxException {
211

  
212
        MediaUriTransformation transformation1 = new MediaUriTransformation();
213
        transformation1.setPathQueryFragment(new SearchReplace(PATTERN_1, "digilib/Scaler/?fn=$1/$2&mo=crop&dw=147&dh=200&uvfix=1"));
214
        transformation1.setMimeType("image/jpeg");
215
        transformation1.setWidth(147);
216
        transformation1.setHeight(200);
217
        MediaUriTransformationProcessor processor = new MediaUriTransformationProcessor();
218
        processor.add(transformation1);
219

  
220
        MediaRepresentation repr = makeImageMediaRepresentation(2000, 1500); // aspect ratio = 4/3
221

  
222
        List<MediaRepresentation> representations = processor.makeNewMediaRepresentationsFor(repr.getParts().get(0));
223

  
224
        assertEquals("https://pictures.bgbm.org/digilib/Scaler/?fn=Cyprus/Salvia_aethiopis_A1.jpg&mo=crop&dw=147&dh=200&uvfix=1", representations.get(0).getParts().get(0).getUri().toString());
225
        assertEquals(ImageFile.class, representations.get(0).getParts().get(0).getClass());
226
        ImageFile image = (ImageFile)representations.get(0).getParts().get(0);
227
        assertEquals(Integer.valueOf(147), image.getWidth());
228
        assertEquals(Integer.valueOf(200), image.getHeight());
229

  
230
        // aspect ratio = 3/4
231
        MediaRepresentation repr2 = makeImageMediaRepresentation(1500, 2000);
232

  
233
        representations = processor.makeNewMediaRepresentationsFor(repr2.getParts().get(0));
234

  
235
        assertEquals("https://pictures.bgbm.org/digilib/Scaler/?fn=Cyprus/Salvia_aethiopis_A1.jpg&mo=crop&dw=147&dh=200&uvfix=1", representations.get(0).getParts().get(0).getUri().toString());
236
        assertEquals(ImageFile.class, representations.get(0).getParts().get(0).getClass());
237
        image = (ImageFile)representations.get(0).getParts().get(0);
238
        assertEquals(Integer.valueOf(147), image.getWidth());
239
        assertEquals(Integer.valueOf(200), image.getHeight());
240
    }
241

  
176 242
    @Test
177 243
    public void testMakeMediaCalculateExtend() throws URISyntaxException {
178 244

  
......
195 261
        assertEquals(Integer.valueOf(400), image.getWidth());
196 262
        assertEquals(Integer.valueOf(300), image.getHeight());
197 263

  
198
        //height = 250
199
        transformation1.setHeight(250);
200
        representations = processor.makeNewMediaRepresentationsFor(repr1.getParts().get(0));
201
        image = (ImageFile)representations.get(0).getParts().get(0);
202
        assertEquals(Integer.valueOf(333), image.getWidth());
203
        assertEquals(Integer.valueOf(250), image.getHeight());
204
        transformation1.setHeight(400);  //reset
205

  
206 264
        // aspect ratio = 3/4
207 265
        MediaRepresentation repr2 = makeImageMediaRepresentation(1500, 2000);
208 266

  
......
213 271
        image = (ImageFile)representations.get(0).getParts().get(0);
214 272
        assertEquals(Integer.valueOf(300), image.getWidth());
215 273
        assertEquals(Integer.valueOf(400), image.getHeight());
216

  
217
        //width = 250
218
        transformation1.setWidth(250);
219
        representations = processor.makeNewMediaRepresentationsFor(repr2.getParts().get(0));
220
        image = (ImageFile)representations.get(0).getParts().get(0);
221
        assertEquals(Integer.valueOf(250), image.getWidth());
222
        assertEquals(Integer.valueOf(333), image.getHeight());
223
        transformation1.setWidth(250);  //reset
224 274
    }
225 275
}

Also available in: Unified diff