1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.common;
|
12
|
|
13
|
|
14
|
import java.io.File;
|
15
|
import java.io.IOException;
|
16
|
import java.net.MalformedURLException;
|
17
|
import java.net.URL;
|
18
|
|
19
|
import org.apache.http.HttpException;
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.junit.After;
|
22
|
import org.junit.AfterClass;
|
23
|
import org.junit.Assert;
|
24
|
import org.junit.Before;
|
25
|
import org.junit.BeforeClass;
|
26
|
import org.junit.Ignore;
|
27
|
import org.junit.Test;
|
28
|
|
29
|
import eu.etaxonomy.cdm.common.mediaMetaData.MediaMetaData;
|
30
|
import eu.etaxonomy.cdm.common.mediaMetaData.ImageMetaData;
|
31
|
import eu.etaxonomy.cdm.common.mediaMetaData.MetaDataFactory;
|
32
|
import eu.etaxonomy.cdm.common.mediaMetaData.MimeType;
|
33
|
|
34
|
/**
|
35
|
* @author n.hoffmann
|
36
|
* @created 13.11.2008
|
37
|
* @version 1.0
|
38
|
*/
|
39
|
public class MediaMetaDataTest {
|
40
|
private static final Logger logger = Logger.getLogger(MediaMetaDataTest.class);
|
41
|
|
42
|
/**
|
43
|
* @throws java.lang.Exception
|
44
|
*/
|
45
|
@BeforeClass
|
46
|
public static void setUpBeforeClass() throws Exception {
|
47
|
if (logger.isDebugEnabled()){logger.debug("setUpBeforeClass");}
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* @throws java.lang.Exception
|
52
|
*/
|
53
|
@AfterClass
|
54
|
public static void tearDownAfterClass() throws Exception {
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* @throws java.lang.Exception
|
59
|
*/
|
60
|
@Before
|
61
|
public void setUp() throws Exception {
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* @throws java.lang.Exception
|
66
|
*/
|
67
|
@After
|
68
|
public void tearDown() throws Exception {
|
69
|
}
|
70
|
|
71
|
/********************* TESTS
|
72
|
* @throws IOException
|
73
|
* @throws HttpException ********************/
|
74
|
|
75
|
@Test
|
76
|
public void readImageInfoFromFile() throws IOException, HttpException {
|
77
|
File imageFile = new File("./src/test/resources/images/OregonScientificDS6639-DSC_0307-small.jpg");
|
78
|
MetaDataFactory metaFactory = MetaDataFactory.getInstance();
|
79
|
ImageMetaData imageMetaData = (ImageMetaData) metaFactory.readMediaData(imageFile.toURI(), MimeType.JPEG, 0);
|
80
|
//imageMetaData.readFrom(imageFile);
|
81
|
|
82
|
assertImageInfo(imageMetaData);
|
83
|
imageFile = new File("./src/test/resources/images/OregonScientificDS6639-DSC_0307-small.tif");
|
84
|
|
85
|
imageMetaData = (ImageMetaData) metaFactory.readMediaData(imageFile.toURI(), MimeType.IMAGE, 0);
|
86
|
assertTiffInfo(imageMetaData);
|
87
|
}
|
88
|
|
89
|
@Test
|
90
|
public void readImageInfoFromUrl() throws IOException, HttpException {
|
91
|
try {
|
92
|
|
93
|
//TODO make ready for windows
|
94
|
//URL imageUrl = new URL("file://" + new File("").getAbsolutePath()+ "/src/test/resources/images/OregonScientificDS6639-DSC_0307-small.jpg");
|
95
|
URL imageUrl = new URL("http://wp5.e-taxonomy.eu/media/palmae/photos/palm_tc_100447_6.jpg");
|
96
|
MetaDataFactory metaFactory = MetaDataFactory.getInstance();
|
97
|
ImageMetaData imageMetaData = (ImageMetaData) metaFactory.readMediaData(CdmUtils.string2Uri(imageUrl.toString()), MimeType.JPEG, 30000);
|
98
|
//imageMetaData.readImageMetaData(imageUrl);
|
99
|
|
100
|
Assert.assertNotNull(imageMetaData);
|
101
|
|
102
|
} catch (MalformedURLException e) {
|
103
|
e.printStackTrace();
|
104
|
}
|
105
|
}
|
106
|
|
107
|
private void assertImageInfo (ImageMetaData imageMetaData){
|
108
|
Assert.assertEquals(24, imageMetaData.getBitPerPixel());
|
109
|
Assert.assertEquals("JPEG (Joint Photographic Experts Group) Format", imageMetaData.getFormatName());
|
110
|
Assert.assertEquals(300, imageMetaData.getWidth());
|
111
|
Assert.assertEquals(225, imageMetaData.getHeight());
|
112
|
Assert.assertEquals("image/jpeg", imageMetaData.getMimeType());
|
113
|
|
114
|
}
|
115
|
|
116
|
private void assertTiffInfo (ImageMetaData imageMetaData){
|
117
|
|
118
|
Assert.assertEquals(24, imageMetaData.getBitPerPixel());
|
119
|
Assert.assertEquals("TIFF Tag-based Image File Format", imageMetaData.getFormatName());
|
120
|
Assert.assertEquals(300, imageMetaData.getWidth());
|
121
|
Assert.assertEquals(225, imageMetaData.getHeight());
|
122
|
Assert.assertEquals("image/tiff", imageMetaData.getMimeType());
|
123
|
}
|
124
|
}
|