Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceOffTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceOffTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceOffTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceOffTest.java Wed May 13 13:49:36 2015 @@ -1,150 +1,150 @@ -package org.apache.tika.server; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.server.resource.DetectorResource; -import org.apache.tika.server.resource.MetadataResource; -import org.apache.tika.server.resource.RecursiveMetadataResource; -import org.apache.tika.server.resource.TikaResource; -import org.apache.tika.server.resource.UnpackerResource; -import org.apache.tika.server.writer.CSVMessageBodyWriter; -import org.apache.tika.server.writer.JSONMessageBodyWriter; -import org.apache.tika.server.writer.TextMessageBodyWriter; -import org.apache.tika.server.writer.XMPMessageBodyWriter; -import org.junit.Assert; -import org.junit.Test; - - -/** - * Test to make sure that no stack traces are returned - * when the stack trace param is set to false. - */ -public class StackTraceOffTest extends CXFTestBase { - public static final String TEST_NULL = "mock/null_pointer.xml"; - public static final String TEST_PASSWORD_PROTECTED = "password.xls"; - - private static final String[] PATHS = new String[]{ - "/tika", - "/rmeta", - "/unpack", - "/meta", - }; - private static final int UNPROCESSEABLE = 422; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - List<ResourceProvider> rCoreProviders = new ArrayList<ResourceProvider>(); - rCoreProviders.add(new SingletonResourceProvider(new MetadataResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new DetectorResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new TikaResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource(tika))); - sf.setResourceProviders(rCoreProviders); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - List<Object> providers = new ArrayList<Object>(); - providers.add(new TikaServerParseExceptionMapper(false)); - providers.add(new JSONMessageBodyWriter()); - providers.add(new CSVMessageBodyWriter()); - providers.add(new XMPMessageBodyWriter()); - providers.add(new TextMessageBodyWriter()); - sf.setProviders(providers); - } - - @Test - public void testEncrypted() throws Exception { - for (String path : PATHS) { - Response response = WebClient - .create(endPoint + path) - .accept("*/*") - .header("Content-Disposition", - "attachment; filename=" + TEST_PASSWORD_PROTECTED) - .put(ClassLoader.getSystemResourceAsStream(TEST_PASSWORD_PROTECTED)); - assertNotNull("null response: " + path, response); - assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); - String msg = getStringFromInputStream((InputStream) response - .getEntity()); - assertEquals("should be empty: " + path, "", msg); - } - } - - @Test - public void testNullPointerOnTika() throws Exception { - for (String path : PATHS) { - Response response = WebClient - .create(endPoint + path) - .accept("*/*") - .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); - assertNotNull("null response: " + path, response); - assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); - String msg = getStringFromInputStream((InputStream) response - .getEntity()); - assertEquals("should be empty: " + path, "", msg); - } - } - - @Test - public void test415() throws Exception { - //no stack traces for 415 - for (String path : PATHS) { - Response response = WebClient - .create(endPoint + path) - .type("blechdeblah/deblechdeblah") - .accept("*/*") - .header("Content-Disposition", - "attachment; filename=null_pointer.evil") - .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); - assertNotNull("null response: " + path, response); - assertEquals("bad type: " + path, 415, response.getStatus()); - String msg = getStringFromInputStream((InputStream) response - .getEntity()); - assertEquals("should be empty: " + path, "", msg); - } - } - - //For now, make sure that non-complete document - //still returns BAD_REQUEST. We may want to - //make MetadataResource return the same types of parse - //exceptions as the others... - @Test - public void testMeta() throws Exception { - InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC); - - Response response = WebClient.create(endPoint + "/meta" + "/Author").type("application/msword") - .accept(MediaType.TEXT_PLAIN).put(copy(stream, 8000)); - Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - String msg = getStringFromInputStream((InputStream) response.getEntity()); - assertEquals("Failed to get metadata field Author", msg); - } -} +package org.apache.tika.server; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.server.resource.DetectorResource; +import org.apache.tika.server.resource.MetadataResource; +import org.apache.tika.server.resource.RecursiveMetadataResource; +import org.apache.tika.server.resource.TikaResource; +import org.apache.tika.server.resource.UnpackerResource; +import org.apache.tika.server.writer.CSVMessageBodyWriter; +import org.apache.tika.server.writer.JSONMessageBodyWriter; +import org.apache.tika.server.writer.TextMessageBodyWriter; +import org.apache.tika.server.writer.XMPMessageBodyWriter; +import org.junit.Assert; +import org.junit.Test; + + +/** + * Test to make sure that no stack traces are returned + * when the stack trace param is set to false. + */ +public class StackTraceOffTest extends CXFTestBase { + public static final String TEST_NULL = "mock/null_pointer.xml"; + public static final String TEST_PASSWORD_PROTECTED = "password.xls"; + + private static final String[] PATHS = new String[]{ + "/tika", + "/rmeta", + "/unpack", + "/meta", + }; + private static final int UNPROCESSEABLE = 422; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + List<ResourceProvider> rCoreProviders = new ArrayList<ResourceProvider>(); + rCoreProviders.add(new SingletonResourceProvider(new MetadataResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new DetectorResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new TikaResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource(tika))); + sf.setResourceProviders(rCoreProviders); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + List<Object> providers = new ArrayList<Object>(); + providers.add(new TikaServerParseExceptionMapper(false)); + providers.add(new JSONMessageBodyWriter()); + providers.add(new CSVMessageBodyWriter()); + providers.add(new XMPMessageBodyWriter()); + providers.add(new TextMessageBodyWriter()); + sf.setProviders(providers); + } + + @Test + public void testEncrypted() throws Exception { + for (String path : PATHS) { + Response response = WebClient + .create(endPoint + path) + .accept("*/*") + .header("Content-Disposition", + "attachment; filename=" + TEST_PASSWORD_PROTECTED) + .put(ClassLoader.getSystemResourceAsStream(TEST_PASSWORD_PROTECTED)); + assertNotNull("null response: " + path, response); + assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); + String msg = getStringFromInputStream((InputStream) response + .getEntity()); + assertEquals("should be empty: " + path, "", msg); + } + } + + @Test + public void testNullPointerOnTika() throws Exception { + for (String path : PATHS) { + Response response = WebClient + .create(endPoint + path) + .accept("*/*") + .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); + assertNotNull("null response: " + path, response); + assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); + String msg = getStringFromInputStream((InputStream) response + .getEntity()); + assertEquals("should be empty: " + path, "", msg); + } + } + + @Test + public void test415() throws Exception { + //no stack traces for 415 + for (String path : PATHS) { + Response response = WebClient + .create(endPoint + path) + .type("blechdeblah/deblechdeblah") + .accept("*/*") + .header("Content-Disposition", + "attachment; filename=null_pointer.evil") + .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); + assertNotNull("null response: " + path, response); + assertEquals("bad type: " + path, 415, response.getStatus()); + String msg = getStringFromInputStream((InputStream) response + .getEntity()); + assertEquals("should be empty: " + path, "", msg); + } + } + + //For now, make sure that non-complete document + //still returns BAD_REQUEST. We may want to + //make MetadataResource return the same types of parse + //exceptions as the others... + @Test + public void testMeta() throws Exception { + InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC); + + Response response = WebClient.create(endPoint + "/meta" + "/Author").type("application/msword") + .accept(MediaType.TEXT_PLAIN).put(copy(stream, 8000)); + Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + String msg = getStringFromInputStream((InputStream) response.getEntity()); + assertEquals("Failed to get metadata field Author", msg); + } +}
Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/StackTraceTest.java Wed May 13 13:49:36 2015 @@ -1,146 +1,146 @@ -package org.apache.tika.server; -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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. - */ - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.server.resource.DetectorResource; -import org.apache.tika.server.resource.MetadataResource; -import org.apache.tika.server.resource.RecursiveMetadataResource; -import org.apache.tika.server.resource.TikaResource; -import org.apache.tika.server.resource.UnpackerResource; -import org.apache.tika.server.writer.CSVMessageBodyWriter; -import org.apache.tika.server.writer.JSONMessageBodyWriter; -import org.apache.tika.server.writer.TextMessageBodyWriter; -import org.apache.tika.server.writer.XMPMessageBodyWriter; -import org.junit.Assert; -import org.junit.Test; - -public class StackTraceTest extends CXFTestBase { - public static final String TEST_NULL = "mock/null_pointer.xml"; - public static final String TEST_PASSWORD_PROTECTED = "password.xls"; - - private static final String[] PATHS = new String[]{ - "/tika", - "/rmeta", - "/unpack", - "/meta", - }; - private static final int UNPROCESSEABLE = 422; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - List<ResourceProvider> rCoreProviders = new ArrayList<ResourceProvider>(); - rCoreProviders.add(new SingletonResourceProvider(new MetadataResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new DetectorResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new TikaResource(tika))); - rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource(tika))); - sf.setResourceProviders(rCoreProviders); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - List<Object> providers = new ArrayList<Object>(); - providers.add(new TikaServerParseExceptionMapper(true)); - providers.add(new JSONMessageBodyWriter()); - providers.add(new CSVMessageBodyWriter()); - providers.add(new XMPMessageBodyWriter()); - providers.add(new TextMessageBodyWriter()); - sf.setProviders(providers); - } - - @Test - public void testEncrypted() throws Exception { - for (String path : PATHS) { - Response response = WebClient - .create(endPoint + path) - .accept("*/*") - .header("Content-Disposition", - "attachment; filename=" + TEST_PASSWORD_PROTECTED) - .put(ClassLoader.getSystemResourceAsStream(TEST_PASSWORD_PROTECTED)); - assertNotNull("null response: " + path, response); - assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); - String msg = getStringFromInputStream((InputStream) response - .getEntity()); - assertContains("org.apache.tika.exception.EncryptedDocumentException", - msg); - } - } - - @Test - public void testNullPointerOnTika() throws Exception { - for (String path : PATHS) { - Response response = WebClient - .create(endPoint + path) - .accept("*/*") - .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); - assertNotNull("null response: " + path, response); - assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); - String msg = getStringFromInputStream((InputStream) response - .getEntity()); - assertContains("Caused by: java.lang.NullPointerException: null pointer message", - msg); - } - } - - @Test - public void test415() throws Exception { - //no stack traces for 415 - for (String path : PATHS) { - Response response = WebClient - .create(endPoint + path) - .type("blechdeblah/deblechdeblah") - .accept("*/*") - .header("Content-Disposition", - "attachment; filename=null_pointer.evil") - .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); - assertNotNull("null response: " + path, response); - assertEquals("bad type: " + path, 415, response.getStatus()); - String msg = getStringFromInputStream((InputStream) response - .getEntity()); - assertEquals("should be empty: " + path, "", msg); - } - } - - //For now, make sure that non-complete document - //still returns BAD_REQUEST. We may want to - //make MetadataResource return the same types of parse - //exceptions as the others... - @Test - public void testMeta() throws Exception { - InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC); - - Response response = WebClient.create(endPoint + "/meta" + "/Author").type("application/msword") - .accept(MediaType.TEXT_PLAIN).put(copy(stream, 8000)); - Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); - String msg = getStringFromInputStream((InputStream) response.getEntity()); - assertEquals("Failed to get metadata field Author", msg); - } -} +package org.apache.tika.server; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * 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. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.server.resource.DetectorResource; +import org.apache.tika.server.resource.MetadataResource; +import org.apache.tika.server.resource.RecursiveMetadataResource; +import org.apache.tika.server.resource.TikaResource; +import org.apache.tika.server.resource.UnpackerResource; +import org.apache.tika.server.writer.CSVMessageBodyWriter; +import org.apache.tika.server.writer.JSONMessageBodyWriter; +import org.apache.tika.server.writer.TextMessageBodyWriter; +import org.apache.tika.server.writer.XMPMessageBodyWriter; +import org.junit.Assert; +import org.junit.Test; + +public class StackTraceTest extends CXFTestBase { + public static final String TEST_NULL = "mock/null_pointer.xml"; + public static final String TEST_PASSWORD_PROTECTED = "password.xls"; + + private static final String[] PATHS = new String[]{ + "/tika", + "/rmeta", + "/unpack", + "/meta", + }; + private static final int UNPROCESSEABLE = 422; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + List<ResourceProvider> rCoreProviders = new ArrayList<ResourceProvider>(); + rCoreProviders.add(new SingletonResourceProvider(new MetadataResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new DetectorResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new TikaResource(tika))); + rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource(tika))); + sf.setResourceProviders(rCoreProviders); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + List<Object> providers = new ArrayList<Object>(); + providers.add(new TikaServerParseExceptionMapper(true)); + providers.add(new JSONMessageBodyWriter()); + providers.add(new CSVMessageBodyWriter()); + providers.add(new XMPMessageBodyWriter()); + providers.add(new TextMessageBodyWriter()); + sf.setProviders(providers); + } + + @Test + public void testEncrypted() throws Exception { + for (String path : PATHS) { + Response response = WebClient + .create(endPoint + path) + .accept("*/*") + .header("Content-Disposition", + "attachment; filename=" + TEST_PASSWORD_PROTECTED) + .put(ClassLoader.getSystemResourceAsStream(TEST_PASSWORD_PROTECTED)); + assertNotNull("null response: " + path, response); + assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); + String msg = getStringFromInputStream((InputStream) response + .getEntity()); + assertContains("org.apache.tika.exception.EncryptedDocumentException", + msg); + } + } + + @Test + public void testNullPointerOnTika() throws Exception { + for (String path : PATHS) { + Response response = WebClient + .create(endPoint + path) + .accept("*/*") + .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); + assertNotNull("null response: " + path, response); + assertEquals("unprocessable: " + path, UNPROCESSEABLE, response.getStatus()); + String msg = getStringFromInputStream((InputStream) response + .getEntity()); + assertContains("Caused by: java.lang.NullPointerException: null pointer message", + msg); + } + } + + @Test + public void test415() throws Exception { + //no stack traces for 415 + for (String path : PATHS) { + Response response = WebClient + .create(endPoint + path) + .type("blechdeblah/deblechdeblah") + .accept("*/*") + .header("Content-Disposition", + "attachment; filename=null_pointer.evil") + .put(ClassLoader.getSystemResourceAsStream(TEST_NULL)); + assertNotNull("null response: " + path, response); + assertEquals("bad type: " + path, 415, response.getStatus()); + String msg = getStringFromInputStream((InputStream) response + .getEntity()); + assertEquals("should be empty: " + path, "", msg); + } + } + + //For now, make sure that non-complete document + //still returns BAD_REQUEST. We may want to + //make MetadataResource return the same types of parse + //exceptions as the others... + @Test + public void testMeta() throws Exception { + InputStream stream = ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC); + + Response response = WebClient.create(endPoint + "/meta" + "/Author").type("application/msword") + .accept(MediaType.TEXT_PLAIN).put(copy(stream, 8000)); + Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + String msg = getStringFromInputStream((InputStream) response.getEntity()); + assertEquals("Failed to get metadata field Author", msg); + } +} Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaDetectorsTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaDetectorsTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaDetectorsTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaDetectorsTest.java Wed May 13 13:49:36 2015 @@ -1,142 +1,142 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tika.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.Map; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.mime.MimeTypes; -import org.apache.tika.parser.microsoft.POIFSContainerDetector; -import org.apache.tika.parser.pkg.ZipContainerDetector; -import org.apache.tika.server.resource.TikaDetectors; -import org.eclipse.jetty.util.ajax.JSON; -import org.gagravarr.tika.OggDetector; -import org.junit.Test; - -public class TikaDetectorsTest extends CXFTestBase { - private static final String DETECTORS_PATH = "/detectors"; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - sf.setResourceClasses(TikaDetectors.class); - sf.setResourceProvider( - TikaDetectors.class, - new SingletonResourceProvider(new TikaDetectors(tika)) - ); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - } - - @Test - public void testGetPlainText() throws Exception { - Response response = WebClient - .create(endPoint + DETECTORS_PATH) - .type("text/plain") - .accept("text/plain") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains("org.apache.tika.detect.DefaultDetector (Composite Detector)", text); - assertContains(OggDetector.class.getName(), text); - assertContains(POIFSContainerDetector.class.getName(), text); - assertContains(ZipContainerDetector.class.getName(), text); - assertContains(MimeTypes.class.getName(), text); - } - - @Test - public void testGetHTML() throws Exception { - Response response = WebClient - .create(endPoint + DETECTORS_PATH) - .type("text/html") - .accept("text/html") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains("<h2>DefaultDetector</h2>", text); - assertContains("Composite", text); - - assertContains("<h3>OggDetector", text); - assertContains("<h3>POIFSContainerDetector", text); - assertContains("<h3>MimeTypes", text); - - assertContains(OggDetector.class.getName(), text); - assertContains(POIFSContainerDetector.class.getName(), text); - assertContains(ZipContainerDetector.class.getName(), text); - assertContains(MimeTypes.class.getName(), text); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetJSON() throws Exception { - Response response = WebClient - .create(endPoint + DETECTORS_PATH) - .type(javax.ws.rs.core.MediaType.APPLICATION_JSON) - .accept(javax.ws.rs.core.MediaType.APPLICATION_JSON) - .get(); - - String jsonStr = getStringFromInputStream((InputStream) response.getEntity()); - Map<String, Map<String, Object>> json = (Map<String, Map<String, Object>>) JSON.parse(jsonStr); - - // Should have a nested structure - assertTrue(json.containsKey("name")); - assertTrue(json.containsKey("composite")); - assertTrue(json.containsKey("children")); - assertEquals("org.apache.tika.detect.DefaultDetector", json.get("name")); - assertEquals(Boolean.TRUE, json.get("composite")); - - // At least 4 child detectors, none of them composite - Object[] children = (Object[]) (Object) json.get("children"); - assertTrue(children.length >= 4); - boolean hasOgg = false, hasPOIFS = false, hasZIP = false, hasMime = false; - for (Object o : children) { - Map<String, Object> d = (Map<String, Object>) o; - assertTrue(d.containsKey("name")); - assertTrue(d.containsKey("composite")); - assertEquals(Boolean.FALSE, d.get("composite")); - assertEquals(false, d.containsKey("children")); - - String name = (String) d.get("name"); - if (OggDetector.class.getName().equals(name)) { - hasOgg = true; - } - if (POIFSContainerDetector.class.getName().equals(name)) { - hasPOIFS = true; - } - if (ZipContainerDetector.class.getName().equals(name)) { - hasZIP = true; - } - if (MimeTypes.class.getName().equals(name)) { - hasMime = true; - } - } - assertTrue(hasOgg); - assertTrue(hasPOIFS); - assertTrue(hasZIP); - assertTrue(hasMime); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tika.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.Map; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.mime.MimeTypes; +import org.apache.tika.parser.microsoft.POIFSContainerDetector; +import org.apache.tika.parser.pkg.ZipContainerDetector; +import org.apache.tika.server.resource.TikaDetectors; +import org.eclipse.jetty.util.ajax.JSON; +import org.gagravarr.tika.OggDetector; +import org.junit.Test; + +public class TikaDetectorsTest extends CXFTestBase { + private static final String DETECTORS_PATH = "/detectors"; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + sf.setResourceClasses(TikaDetectors.class); + sf.setResourceProvider( + TikaDetectors.class, + new SingletonResourceProvider(new TikaDetectors(tika)) + ); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + } + + @Test + public void testGetPlainText() throws Exception { + Response response = WebClient + .create(endPoint + DETECTORS_PATH) + .type("text/plain") + .accept("text/plain") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains("org.apache.tika.detect.DefaultDetector (Composite Detector)", text); + assertContains(OggDetector.class.getName(), text); + assertContains(POIFSContainerDetector.class.getName(), text); + assertContains(ZipContainerDetector.class.getName(), text); + assertContains(MimeTypes.class.getName(), text); + } + + @Test + public void testGetHTML() throws Exception { + Response response = WebClient + .create(endPoint + DETECTORS_PATH) + .type("text/html") + .accept("text/html") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains("<h2>DefaultDetector</h2>", text); + assertContains("Composite", text); + + assertContains("<h3>OggDetector", text); + assertContains("<h3>POIFSContainerDetector", text); + assertContains("<h3>MimeTypes", text); + + assertContains(OggDetector.class.getName(), text); + assertContains(POIFSContainerDetector.class.getName(), text); + assertContains(ZipContainerDetector.class.getName(), text); + assertContains(MimeTypes.class.getName(), text); + } + + @Test + @SuppressWarnings("unchecked") + public void testGetJSON() throws Exception { + Response response = WebClient + .create(endPoint + DETECTORS_PATH) + .type(javax.ws.rs.core.MediaType.APPLICATION_JSON) + .accept(javax.ws.rs.core.MediaType.APPLICATION_JSON) + .get(); + + String jsonStr = getStringFromInputStream((InputStream) response.getEntity()); + Map<String, Map<String, Object>> json = (Map<String, Map<String, Object>>) JSON.parse(jsonStr); + + // Should have a nested structure + assertTrue(json.containsKey("name")); + assertTrue(json.containsKey("composite")); + assertTrue(json.containsKey("children")); + assertEquals("org.apache.tika.detect.DefaultDetector", json.get("name")); + assertEquals(Boolean.TRUE, json.get("composite")); + + // At least 4 child detectors, none of them composite + Object[] children = (Object[]) (Object) json.get("children"); + assertTrue(children.length >= 4); + boolean hasOgg = false, hasPOIFS = false, hasZIP = false, hasMime = false; + for (Object o : children) { + Map<String, Object> d = (Map<String, Object>) o; + assertTrue(d.containsKey("name")); + assertTrue(d.containsKey("composite")); + assertEquals(Boolean.FALSE, d.get("composite")); + assertEquals(false, d.containsKey("children")); + + String name = (String) d.get("name"); + if (OggDetector.class.getName().equals(name)) { + hasOgg = true; + } + if (POIFSContainerDetector.class.getName().equals(name)) { + hasPOIFS = true; + } + if (ZipContainerDetector.class.getName().equals(name)) { + hasZIP = true; + } + if (MimeTypes.class.getName().equals(name)) { + hasMime = true; + } + } + assertTrue(hasOgg); + assertTrue(hasPOIFS); + assertTrue(hasZIP); + assertTrue(hasMime); + } +} Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaMimeTypesTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaMimeTypesTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaMimeTypesTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaMimeTypesTest.java Wed May 13 13:49:36 2015 @@ -1,121 +1,121 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tika.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.Map; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.server.resource.TikaMimeTypes; -import org.eclipse.jetty.util.ajax.JSON; -import org.junit.Test; - -public class TikaMimeTypesTest extends CXFTestBase { - private static final String MIMETYPES_PATH = "/mime-types"; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - sf.setResourceClasses(TikaMimeTypes.class); - sf.setResourceProvider( - TikaMimeTypes.class, - new SingletonResourceProvider(new TikaMimeTypes(tika)) - ); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - } - - @Test - public void testGetPlainText() throws Exception { - Response response = WebClient - .create(endPoint + MIMETYPES_PATH) - .type("text/plain") - .accept("text/plain") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains("text/plain", text); - assertContains("application/xml", text); - assertContains("video/x-ogm", text); - - assertContains("supertype: video/ogg", text); - - assertContains("alias: image/bmp", text); - } - - @Test - public void testGetHTML() throws Exception { - Response response = WebClient - .create(endPoint + MIMETYPES_PATH) - .type("text/html") - .accept("text/html") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains("text/plain", text); - assertContains("application/xml", text); - assertContains("video/x-ogm", text); - - assertContains("<h2>text/plain", text); - assertContains("name=\"text/plain", text); - - assertContains("Super Type: <a href=\"#video/ogg\">video/ogg", text); - - assertContains("Alias: image/bmp", text); - } - - @Test - @SuppressWarnings("unchecked") - public void testGetJSON() throws Exception { - Response response = WebClient - .create(endPoint + MIMETYPES_PATH) - .type(javax.ws.rs.core.MediaType.APPLICATION_JSON) - .accept(javax.ws.rs.core.MediaType.APPLICATION_JSON) - .get(); - - String jsonStr = getStringFromInputStream((InputStream) response.getEntity()); - Map<String, Map<String, Object>> json = (Map<String, Map<String, Object>>) JSON.parse(jsonStr); - - assertEquals(true, json.containsKey("text/plain")); - assertEquals(true, json.containsKey("application/xml")); - assertEquals(true, json.containsKey("video/x-ogm")); - assertEquals(true, json.containsKey("image/x-ms-bmp")); - - Map<String, Object> bmp = json.get("image/x-ms-bmp"); - assertEquals(true, bmp.containsKey("alias")); - Object[] aliases = (Object[]) bmp.get("alias"); - assertEquals(1, aliases.length); - assertEquals("image/bmp", aliases[0]); - - String whichParser = bmp.get("parser").toString(); - assertTrue("Which parser", whichParser.equals("org.apache.tika.parser.ocr.TesseractOCRParser") || - whichParser.equals("org.apache.tika.parser.image.ImageParser")); - - Map<String, Object> ogm = json.get("video/x-ogm"); - assertEquals("video/ogg", ogm.get("supertype")); - assertEquals("org.gagravarr.tika.OggParser", ogm.get("parser")); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tika.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.Map; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.server.resource.TikaMimeTypes; +import org.eclipse.jetty.util.ajax.JSON; +import org.junit.Test; + +public class TikaMimeTypesTest extends CXFTestBase { + private static final String MIMETYPES_PATH = "/mime-types"; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + sf.setResourceClasses(TikaMimeTypes.class); + sf.setResourceProvider( + TikaMimeTypes.class, + new SingletonResourceProvider(new TikaMimeTypes(tika)) + ); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + } + + @Test + public void testGetPlainText() throws Exception { + Response response = WebClient + .create(endPoint + MIMETYPES_PATH) + .type("text/plain") + .accept("text/plain") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains("text/plain", text); + assertContains("application/xml", text); + assertContains("video/x-ogm", text); + + assertContains("supertype: video/ogg", text); + + assertContains("alias: image/bmp", text); + } + + @Test + public void testGetHTML() throws Exception { + Response response = WebClient + .create(endPoint + MIMETYPES_PATH) + .type("text/html") + .accept("text/html") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains("text/plain", text); + assertContains("application/xml", text); + assertContains("video/x-ogm", text); + + assertContains("<h2>text/plain", text); + assertContains("name=\"text/plain", text); + + assertContains("Super Type: <a href=\"#video/ogg\">video/ogg", text); + + assertContains("Alias: image/bmp", text); + } + + @Test + @SuppressWarnings("unchecked") + public void testGetJSON() throws Exception { + Response response = WebClient + .create(endPoint + MIMETYPES_PATH) + .type(javax.ws.rs.core.MediaType.APPLICATION_JSON) + .accept(javax.ws.rs.core.MediaType.APPLICATION_JSON) + .get(); + + String jsonStr = getStringFromInputStream((InputStream) response.getEntity()); + Map<String, Map<String, Object>> json = (Map<String, Map<String, Object>>) JSON.parse(jsonStr); + + assertEquals(true, json.containsKey("text/plain")); + assertEquals(true, json.containsKey("application/xml")); + assertEquals(true, json.containsKey("video/x-ogm")); + assertEquals(true, json.containsKey("image/x-ms-bmp")); + + Map<String, Object> bmp = json.get("image/x-ms-bmp"); + assertEquals(true, bmp.containsKey("alias")); + Object[] aliases = (Object[]) bmp.get("alias"); + assertEquals(1, aliases.length); + assertEquals("image/bmp", aliases[0]); + + String whichParser = bmp.get("parser").toString(); + assertTrue("Which parser", whichParser.equals("org.apache.tika.parser.ocr.TesseractOCRParser") || + whichParser.equals("org.apache.tika.parser.image.ImageParser")); + + Map<String, Object> ogm = json.get("video/x-ogm"); + assertEquals("video/ogg", ogm.get("supertype")); + assertEquals("org.gagravarr.tika.OggParser", ogm.get("parser")); + } +} Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaParsersTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaParsersTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaParsersTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaParsersTest.java Wed May 13 13:49:36 2015 @@ -1,182 +1,182 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tika.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.Map; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.parser.microsoft.ooxml.OOXMLParser; -import org.apache.tika.parser.pdf.PDFParser; -import org.apache.tika.parser.pkg.PackageParser; -import org.apache.tika.server.resource.TikaParsers; -import org.eclipse.jetty.util.ajax.JSON; -import org.gagravarr.tika.OpusParser; -import org.junit.Test; - -public class TikaParsersTest extends CXFTestBase { - private static final String PARSERS_SUMMARY_PATH = "/parsers"; - private static final String PARSERS_DETAILS_PATH = "/parsers/details"; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - sf.setResourceClasses(TikaParsers.class); - sf.setResourceProvider( - TikaParsers.class, - new SingletonResourceProvider(new TikaParsers(tika)) - ); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - } - - protected String getPath(boolean withDetails) { - return withDetails ? PARSERS_DETAILS_PATH : PARSERS_SUMMARY_PATH; - } - - @Test - public void testGetPlainText() throws Exception { - for (boolean details : new boolean[]{false, true}) { - Response response = WebClient - .create(endPoint + getPath(details)) - .type("text/plain") - .accept("text/plain") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains("org.apache.tika.parser.DefaultParser (Composite Parser)", text); - assertContains(OpusParser.class.getName(), text); - assertContains(PackageParser.class.getName(), text); - assertContains(OOXMLParser.class.getName(), text); - - if (details) { - // Should have the mimetypes they handle - assertContains("text/plain", text); - assertContains("application/pdf", text); - assertContains("audio/ogg", text); - } else { - // Shouldn't do - assertNotFound("text/plain", text); - assertNotFound("application/pdf", text); - assertNotFound("audio/ogg", text); - } - } - } - - @Test - public void testGetHTML() throws Exception { - for (boolean details : new boolean[]{false, true}) { - Response response = WebClient - .create(endPoint + getPath(details)) - .type("text/html") - .accept("text/html") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains("<h2>DefaultParser</h2>", text); - assertContains("Composite", text); - - assertContains("<h3>OpusParser", text); - assertContains("<h3>PackageParser", text); - assertContains("<h3>OOXMLParser", text); - - assertContains(OpusParser.class.getName(), text); - assertContains(PackageParser.class.getName(), text); - assertContains(OOXMLParser.class.getName(), text); - - if (details) { - // Should have the mimetypes they handle - assertContains("<li>text/plain", text); - assertContains("<li>application/pdf", text); - assertContains("<li>audio/ogg", text); - } else { - // Shouldn't do - assertNotFound("text/plain", text); - assertNotFound("application/pdf", text); - assertNotFound("audio/ogg", text); - } - } - } - - @Test - @SuppressWarnings("unchecked") - public void testGetJSON() throws Exception { - for (boolean details : new boolean[]{false, true}) { - Response response = WebClient - .create(endPoint + getPath(details)) - .type(javax.ws.rs.core.MediaType.APPLICATION_JSON) - .accept(javax.ws.rs.core.MediaType.APPLICATION_JSON) - .get(); - - String jsonStr = getStringFromInputStream((InputStream) response.getEntity()); - Map<String, Map<String, Object>> json = (Map<String, Map<String, Object>>) JSON.parse(jsonStr); - - // Should have a nested structure - assertEquals(true, json.containsKey("name")); - assertEquals(true, json.containsKey("composite")); - assertEquals(true, json.containsKey("children")); - assertEquals("org.apache.tika.parser.DefaultParser", json.get("name")); - assertEquals(Boolean.TRUE, json.get("composite")); - - // At least 20 child parsers which aren't composite - Object[] children = (Object[]) (Object) json.get("children"); - assertTrue(children.length >= 20); - boolean hasOpus = false, hasOOXML = false, hasPDF = false, hasZip = false; - int nonComposite = 0; - for (Object o : children) { - Map<String, Object> d = (Map<String, Object>) o; - assertEquals(true, d.containsKey("name")); - assertEquals(true, d.containsKey("composite")); - assertEquals(Boolean.FALSE, d.get("composite")); - assertEquals(false, d.containsKey("children")); - - if (d.get("composite") == Boolean.FALSE) nonComposite++; - - // Will only have mime types if requested - assertEquals(details, d.containsKey("supportedTypes")); - - String name = (String) d.get("name"); - if (OpusParser.class.getName().equals(name)) { - hasOpus = true; - } - if (OOXMLParser.class.getName().equals(name)) { - hasOOXML = true; - } - if (PDFParser.class.getName().equals(name)) { - hasPDF = true; - } - if (PackageParser.class.getName().equals(name)) { - hasZip = true; - } - } - assertEquals(true, hasOpus); - assertEquals(true, hasOOXML); - assertEquals(true, hasPDF); - assertEquals(true, hasZip); - assertTrue(nonComposite > 20); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tika.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.Map; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.parser.microsoft.ooxml.OOXMLParser; +import org.apache.tika.parser.pdf.PDFParser; +import org.apache.tika.parser.pkg.PackageParser; +import org.apache.tika.server.resource.TikaParsers; +import org.eclipse.jetty.util.ajax.JSON; +import org.gagravarr.tika.OpusParser; +import org.junit.Test; + +public class TikaParsersTest extends CXFTestBase { + private static final String PARSERS_SUMMARY_PATH = "/parsers"; + private static final String PARSERS_DETAILS_PATH = "/parsers/details"; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + sf.setResourceClasses(TikaParsers.class); + sf.setResourceProvider( + TikaParsers.class, + new SingletonResourceProvider(new TikaParsers(tika)) + ); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + } + + protected String getPath(boolean withDetails) { + return withDetails ? PARSERS_DETAILS_PATH : PARSERS_SUMMARY_PATH; + } + + @Test + public void testGetPlainText() throws Exception { + for (boolean details : new boolean[]{false, true}) { + Response response = WebClient + .create(endPoint + getPath(details)) + .type("text/plain") + .accept("text/plain") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains("org.apache.tika.parser.DefaultParser (Composite Parser)", text); + assertContains(OpusParser.class.getName(), text); + assertContains(PackageParser.class.getName(), text); + assertContains(OOXMLParser.class.getName(), text); + + if (details) { + // Should have the mimetypes they handle + assertContains("text/plain", text); + assertContains("application/pdf", text); + assertContains("audio/ogg", text); + } else { + // Shouldn't do + assertNotFound("text/plain", text); + assertNotFound("application/pdf", text); + assertNotFound("audio/ogg", text); + } + } + } + + @Test + public void testGetHTML() throws Exception { + for (boolean details : new boolean[]{false, true}) { + Response response = WebClient + .create(endPoint + getPath(details)) + .type("text/html") + .accept("text/html") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains("<h2>DefaultParser</h2>", text); + assertContains("Composite", text); + + assertContains("<h3>OpusParser", text); + assertContains("<h3>PackageParser", text); + assertContains("<h3>OOXMLParser", text); + + assertContains(OpusParser.class.getName(), text); + assertContains(PackageParser.class.getName(), text); + assertContains(OOXMLParser.class.getName(), text); + + if (details) { + // Should have the mimetypes they handle + assertContains("<li>text/plain", text); + assertContains("<li>application/pdf", text); + assertContains("<li>audio/ogg", text); + } else { + // Shouldn't do + assertNotFound("text/plain", text); + assertNotFound("application/pdf", text); + assertNotFound("audio/ogg", text); + } + } + } + + @Test + @SuppressWarnings("unchecked") + public void testGetJSON() throws Exception { + for (boolean details : new boolean[]{false, true}) { + Response response = WebClient + .create(endPoint + getPath(details)) + .type(javax.ws.rs.core.MediaType.APPLICATION_JSON) + .accept(javax.ws.rs.core.MediaType.APPLICATION_JSON) + .get(); + + String jsonStr = getStringFromInputStream((InputStream) response.getEntity()); + Map<String, Map<String, Object>> json = (Map<String, Map<String, Object>>) JSON.parse(jsonStr); + + // Should have a nested structure + assertEquals(true, json.containsKey("name")); + assertEquals(true, json.containsKey("composite")); + assertEquals(true, json.containsKey("children")); + assertEquals("org.apache.tika.parser.DefaultParser", json.get("name")); + assertEquals(Boolean.TRUE, json.get("composite")); + + // At least 20 child parsers which aren't composite + Object[] children = (Object[]) (Object) json.get("children"); + assertTrue(children.length >= 20); + boolean hasOpus = false, hasOOXML = false, hasPDF = false, hasZip = false; + int nonComposite = 0; + for (Object o : children) { + Map<String, Object> d = (Map<String, Object>) o; + assertEquals(true, d.containsKey("name")); + assertEquals(true, d.containsKey("composite")); + assertEquals(Boolean.FALSE, d.get("composite")); + assertEquals(false, d.containsKey("children")); + + if (d.get("composite") == Boolean.FALSE) nonComposite++; + + // Will only have mime types if requested + assertEquals(details, d.containsKey("supportedTypes")); + + String name = (String) d.get("name"); + if (OpusParser.class.getName().equals(name)) { + hasOpus = true; + } + if (OOXMLParser.class.getName().equals(name)) { + hasOOXML = true; + } + if (PDFParser.class.getName().equals(name)) { + hasPDF = true; + } + if (PackageParser.class.getName().equals(name)) { + hasZip = true; + } + } + assertEquals(true, hasOpus); + assertEquals(true, hasOOXML); + assertEquals(true, hasPDF); + assertEquals(true, hasZip); + assertTrue(nonComposite > 20); + } + } +} Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaVersionTest.java Wed May 13 13:49:36 2015 @@ -1,60 +1,60 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tika.server; - -import static org.junit.Assert.assertEquals; - -import javax.ws.rs.core.Response; - -import java.io.InputStream; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.Tika; -import org.apache.tika.server.resource.TikaVersion; -import org.junit.Test; - -public class TikaVersionTest extends CXFTestBase { - protected static final String VERSION_PATH = "/version"; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - sf.setResourceClasses(TikaVersion.class); - sf.setResourceProvider( - TikaVersion.class, - new SingletonResourceProvider(new TikaVersion(tika)) - ); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - } - - @Test - public void testGetVersion() throws Exception { - Response response = WebClient - .create(endPoint + VERSION_PATH) - .type("text/plain") - .accept("text/plain") - .get(); - - assertEquals(new Tika().toString(), - getStringFromInputStream((InputStream) response.getEntity())); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tika.server; + +import static org.junit.Assert.assertEquals; + +import javax.ws.rs.core.Response; + +import java.io.InputStream; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.Tika; +import org.apache.tika.server.resource.TikaVersion; +import org.junit.Test; + +public class TikaVersionTest extends CXFTestBase { + protected static final String VERSION_PATH = "/version"; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + sf.setResourceClasses(TikaVersion.class); + sf.setResourceProvider( + TikaVersion.class, + new SingletonResourceProvider(new TikaVersion(tika)) + ); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + } + + @Test + public void testGetVersion() throws Exception { + Response response = WebClient + .create(endPoint + VERSION_PATH) + .type("text/plain") + .accept("text/plain") + .get(); + + assertEquals(new Tika().toString(), + getStringFromInputStream((InputStream) response.getEntity())); + } +} Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaWelcomeTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaWelcomeTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaWelcomeTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TikaWelcomeTest.java Wed May 13 13:49:36 2015 @@ -1,112 +1,112 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tika.server; - -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.Tika; -import org.apache.tika.server.resource.DetectorResource; -import org.apache.tika.server.resource.MetadataResource; -import org.apache.tika.server.resource.TikaVersion; -import org.apache.tika.server.resource.TikaWelcome; -import org.junit.Test; - -public class TikaWelcomeTest extends CXFTestBase { - protected static final String WELCOME_PATH = "/"; - private static final String VERSION_PATH = TikaVersionTest.VERSION_PATH; - protected static final String PATH_RESOURCE = "/detect/stream"; // TIKA-1567 - protected static final String PATH_RESOURCE_2 = "/meta/form"; //TIKA-1567 - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - List<ResourceProvider> rpsCore = - new ArrayList<ResourceProvider>(); - rpsCore.add(new SingletonResourceProvider(new TikaVersion(tika))); - rpsCore.add(new SingletonResourceProvider(new DetectorResource(tika))); - rpsCore.add(new SingletonResourceProvider(new MetadataResource(tika))); - List<ResourceProvider> all = new ArrayList<ResourceProvider>(rpsCore); - all.add(new SingletonResourceProvider(new TikaWelcome(tika, rpsCore))); - sf.setResourceProviders(all); - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - } - - @Test - public void testGetHTMLWelcome() throws Exception { - String html = WebClient - .create(endPoint + WELCOME_PATH) - .type("text/html") - .accept("text/html") - .get(String.class); - - - assertContains(new Tika().toString(), html); - assertContains("href=\"http", html); - - // Check our details were found - assertContains("GET", html); - assertContains(WELCOME_PATH, html); - assertContains("text/plain", html); - - // Check that the Tika Version details come through too - assertContains(VERSION_PATH, html); - } - - @Test - public void testGetTextWelcome() throws Exception { - Response response = WebClient - .create(endPoint + WELCOME_PATH) - .type("text/plain") - .accept("text/plain") - .get(); - - String text = getStringFromInputStream((InputStream) response.getEntity()); - assertContains(new Tika().toString(), text); - - // Check our details were found - assertContains("GET " + WELCOME_PATH, text); - assertContains("=> text/plain", text); - - // Check that the Tika Version details come through too - assertContains("GET " + VERSION_PATH, text); - } - - - @Test - public void testProperPathWelcome() throws Exception{ - Response response = WebClient - .create(endPoint + WELCOME_PATH) - .type("text/html") - .accept("text/html") - .get(); - - String html = getStringFromInputStream((InputStream) response.getEntity()); - assertContains(PATH_RESOURCE, html); - assertContains(PATH_RESOURCE_2, html); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tika.server; + +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.ResourceProvider; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.Tika; +import org.apache.tika.server.resource.DetectorResource; +import org.apache.tika.server.resource.MetadataResource; +import org.apache.tika.server.resource.TikaVersion; +import org.apache.tika.server.resource.TikaWelcome; +import org.junit.Test; + +public class TikaWelcomeTest extends CXFTestBase { + protected static final String WELCOME_PATH = "/"; + private static final String VERSION_PATH = TikaVersionTest.VERSION_PATH; + protected static final String PATH_RESOURCE = "/detect/stream"; // TIKA-1567 + protected static final String PATH_RESOURCE_2 = "/meta/form"; //TIKA-1567 + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + List<ResourceProvider> rpsCore = + new ArrayList<ResourceProvider>(); + rpsCore.add(new SingletonResourceProvider(new TikaVersion(tika))); + rpsCore.add(new SingletonResourceProvider(new DetectorResource(tika))); + rpsCore.add(new SingletonResourceProvider(new MetadataResource(tika))); + List<ResourceProvider> all = new ArrayList<ResourceProvider>(rpsCore); + all.add(new SingletonResourceProvider(new TikaWelcome(tika, rpsCore))); + sf.setResourceProviders(all); + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + } + + @Test + public void testGetHTMLWelcome() throws Exception { + String html = WebClient + .create(endPoint + WELCOME_PATH) + .type("text/html") + .accept("text/html") + .get(String.class); + + + assertContains(new Tika().toString(), html); + assertContains("href=\"http", html); + + // Check our details were found + assertContains("GET", html); + assertContains(WELCOME_PATH, html); + assertContains("text/plain", html); + + // Check that the Tika Version details come through too + assertContains(VERSION_PATH, html); + } + + @Test + public void testGetTextWelcome() throws Exception { + Response response = WebClient + .create(endPoint + WELCOME_PATH) + .type("text/plain") + .accept("text/plain") + .get(); + + String text = getStringFromInputStream((InputStream) response.getEntity()); + assertContains(new Tika().toString(), text); + + // Check our details were found + assertContains("GET " + WELCOME_PATH, text); + assertContains("=> text/plain", text); + + // Check that the Tika Version details come through too + assertContains("GET " + VERSION_PATH, text); + } + + + @Test + public void testProperPathWelcome() throws Exception{ + Response response = WebClient + .create(endPoint + WELCOME_PATH) + .type("text/html") + .accept("text/html") + .get(); + + String html = getStringFromInputStream((InputStream) response.getEntity()); + assertContains(PATH_RESOURCE, html); + assertContains(PATH_RESOURCE_2, html); + } +} Modified: tika/trunk/tika-server/src/test/java/org/apache/tika/server/TranslateResourceTest.java URL: http://svn.apache.org/viewvc/tika/trunk/tika-server/src/test/java/org/apache/tika/server/TranslateResourceTest.java?rev=1679211&r1=1679210&r2=1679211&view=diff ============================================================================== --- tika/trunk/tika-server/src/test/java/org/apache/tika/server/TranslateResourceTest.java (original) +++ tika/trunk/tika-server/src/test/java/org/apache/tika/server/TranslateResourceTest.java Wed May 13 13:49:36 2015 @@ -1,86 +1,86 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.tika.server; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import javax.ws.rs.core.Response; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; -import org.apache.tika.server.resource.TranslateResource; -import org.apache.tika.server.writer.TarWriter; -import org.apache.tika.server.writer.ZipWriter; -import org.junit.Test; - -public class TranslateResourceTest extends CXFTestBase { - - private static final String TRANSLATE_PATH = "/translate"; - private static final String TRANSLATE_ALL_PATH = TRANSLATE_PATH + "/all"; - private static final String TRANSLATE_TXT = "This won't translate"; - private static final String LINGO_PATH = "/org.apache.tika.language.translate.Lingo24Translator"; - private static final String SRCDEST = "/es/en"; - private static final String DEST = "/en"; - - @Override - protected void setUpResources(JAXRSServerFactoryBean sf) { - sf.setResourceClasses(TranslateResource.class); - sf.setResourceProvider(TranslateResource.class, - new SingletonResourceProvider(new TranslateResource(tika))); - - } - - @Override - protected void setUpProviders(JAXRSServerFactoryBean sf) { - List<Object> providers = new ArrayList<Object>(); - providers.add(new TarWriter()); - providers.add(new ZipWriter()); - providers.add(new TikaServerParseExceptionMapper(false)); - sf.setProviders(providers); - - } - - @Test - public void testTranslateFull() throws Exception { - String url = endPoint + TRANSLATE_ALL_PATH + LINGO_PATH + SRCDEST; - Response response = WebClient.create(url).type("text/plain") - .accept("*/*").put(TRANSLATE_TXT); - assertNotNull(response); - String translated = getStringFromInputStream((InputStream) response - .getEntity()); - assertEquals(TRANSLATE_TXT, translated); - } - - @Test - public void testTranslateAutoLang() throws Exception{ - String url = endPoint + TRANSLATE_ALL_PATH + LINGO_PATH + DEST; - Response response = WebClient.create(url).type("text/plain") - .accept("*/*").put(TRANSLATE_TXT); - assertNotNull(response); - String translated = getStringFromInputStream((InputStream) response - .getEntity()); - assertEquals(TRANSLATE_TXT, translated); - } - -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.tika.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; +import org.apache.tika.server.resource.TranslateResource; +import org.apache.tika.server.writer.TarWriter; +import org.apache.tika.server.writer.ZipWriter; +import org.junit.Test; + +public class TranslateResourceTest extends CXFTestBase { + + private static final String TRANSLATE_PATH = "/translate"; + private static final String TRANSLATE_ALL_PATH = TRANSLATE_PATH + "/all"; + private static final String TRANSLATE_TXT = "This won't translate"; + private static final String LINGO_PATH = "/org.apache.tika.language.translate.Lingo24Translator"; + private static final String SRCDEST = "/es/en"; + private static final String DEST = "/en"; + + @Override + protected void setUpResources(JAXRSServerFactoryBean sf) { + sf.setResourceClasses(TranslateResource.class); + sf.setResourceProvider(TranslateResource.class, + new SingletonResourceProvider(new TranslateResource(tika))); + + } + + @Override + protected void setUpProviders(JAXRSServerFactoryBean sf) { + List<Object> providers = new ArrayList<Object>(); + providers.add(new TarWriter()); + providers.add(new ZipWriter()); + providers.add(new TikaServerParseExceptionMapper(false)); + sf.setProviders(providers); + + } + + @Test + public void testTranslateFull() throws Exception { + String url = endPoint + TRANSLATE_ALL_PATH + LINGO_PATH + SRCDEST; + Response response = WebClient.create(url).type("text/plain") + .accept("*/*").put(TRANSLATE_TXT); + assertNotNull(response); + String translated = getStringFromInputStream((InputStream) response + .getEntity()); + assertEquals(TRANSLATE_TXT, translated); + } + + @Test + public void testTranslateAutoLang() throws Exception{ + String url = endPoint + TRANSLATE_ALL_PATH + LINGO_PATH + DEST; + Response response = WebClient.create(url).type("text/plain") + .accept("*/*").put(TRANSLATE_TXT); + assertNotNull(response); + String translated = getStringFromInputStream((InputStream) response + .getEntity()); + assertEquals(TRANSLATE_TXT, translated); + } + +}
