use of au.com.bytecode.opencsv.CSVReader in project tika by apache.
the class MetadataResourceTest method testSimpleWord.
@Test
public void testSimpleWord() throws Exception {
Response response = WebClient.create(endPoint + META_PATH).type("application/msword").accept("text/csv").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
Reader reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
CSVReader csvReader = new CSVReader(reader);
Map<String, String> metadata = new HashMap<String, String>();
String[] nextLine;
while ((nextLine = csvReader.readNext()) != null) {
metadata.put(nextLine[0], nextLine[1]);
}
csvReader.close();
assertNotNull(metadata.get("Author"));
assertEquals("Maxim Valyanskiy", metadata.get("Author"));
assertEquals("X-TIKA:digest:MD5", "f8be45c34e8919eedba48cc8d207fbf0", metadata.get("X-TIKA:digest:MD5"));
}
use of au.com.bytecode.opencsv.CSVReader in project tika by apache.
the class MetadataResourceTest method testPasswordProtected.
@Test
public void testPasswordProtected() throws Exception {
Response response = WebClient.create(endPoint + META_PATH).type("application/vnd.ms-excel").accept("text/csv").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_PASSWORD_PROTECTED));
// Won't work, no password given
assertEquals(500, response.getStatus());
// Try again, this time with the wrong password
response = WebClient.create(endPoint + META_PATH).type("application/vnd.ms-excel").accept("text/csv").header("Password", "wrong password").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_PASSWORD_PROTECTED));
assertEquals(500, response.getStatus());
// Try again, this time with the password
response = WebClient.create(endPoint + META_PATH).type("application/vnd.ms-excel").accept("text/csv").header("Password", "password").put(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_PASSWORD_PROTECTED));
// Will work
assertEquals(200, response.getStatus());
// Check results
Reader reader = new InputStreamReader((InputStream) response.getEntity(), UTF_8);
CSVReader csvReader = new CSVReader(reader);
Map<String, String> metadata = new HashMap<String, String>();
String[] nextLine;
while ((nextLine = csvReader.readNext()) != null) {
metadata.put(nextLine[0], nextLine[1]);
}
csvReader.close();
assertNotNull(metadata.get("Author"));
assertEquals("pavel", metadata.get("Author"));
}
Aggregations