You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@nutch.apache.org by José Ignacio Ortiz de Galisteo <jo...@salir.com> on 2012/01/19 15:28:54 UTC

java.net.MalformedURLException creating new Content in unit test

Hi.

I'm trying to make a unit test of a custom parse plugin. When I load a
fixture I have to create a new Content object in order to mock the
behaviour of Nutch. Doing this

new Content(url, url, bytes, "text/html", new Metadata(),
NutchConfiguration.create());

the following exception is thrown:

java.lang.RuntimeException: java.net.MalformedURLException
    at org.apache.nutch.util.MimeUtil.<init>(MimeUtil.java:68)
    at org.apache.nutch.protocol.Content.<init>(Content.java:87)
    at
com.salir.nutch.parse.routing.RoutingParserTest.pageTest(RoutingParserTest.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

It seems to be a problem with the Configuration object in MimeUtil, but I
don't what's going on and how to fix it. Someone with the same problem?

Thanks in advance.
Regards.

Re: java.net.MalformedURLException creating new Content in unit test

Posted by José Ignacio Ortiz de Galisteo <jo...@salir.com>.
Hi all.
Well, I have just found was the problem was, in case somebody has the same
problem: In our case the configuration mime.types.file was
tika.mimetype.xml (this is the default type). To solve it just include the
tika-mimetype.xml file in the classpath of the project. Instead of this we
create a copy, test-tika-mimetype.xml and set to the Configuration object:
Configuration conf = NutchConfiguration.create();
conf.set("mime.types.file", "path/to/test-tika-mimetypes.xml");

That's it. Hope this helps someone.
Regards.

El 19 de enero de 2012 15:28, José Ignacio Ortiz de Galisteo <
joseignacio@salir.com> escribió:

> Hi.
>
> I'm trying to make a unit test of a custom parse plugin. When I load a
> fixture I have to create a new Content object in order to mock the
> behaviour of Nutch. Doing this
>
> new Content(url, url, bytes, "text/html", new Metadata(),
> NutchConfiguration.create());
>
> the following exception is thrown:
>
> java.lang.RuntimeException: java.net.MalformedURLException
>      at org.apache.nutch.util.MimeUtil.<init>(MimeUtil.java:68)
>     at org.apache.nutch.protocol.Content.<init>(Content.java:87)
>     at
> com.salir.nutch.parse.routing.RoutingParserTest.pageTest(RoutingParserTest.java:129)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>     at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>     at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>     at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>     at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>     at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
>     at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
>     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
>     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
>     at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
>     at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
>     at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
>     at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
>     at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>     at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>
> It seems to be a problem with the Configuration object in MimeUtil, but I
> don't what's going on and how to fix it. Someone with the same problem?
>
> Thanks in advance.
> Regards.
>