Hi,
That is because you are calling the resource method of the resource
class, RevisionResource explicitly and not via an HTTP request/
response. Because RevisionResource class is not managed by Jersey you
will get different behavior.
Paul.
On Apr 22, 2009, at 12:57 PM, Ari Heino wrote:
>
> With a "pure" JUnit test case, if i use that serverside code snippet
> that you
> proposed:
>
> InputStream source =
> multiPart.getBodyParts().get(1).getEntityAs(InputStream.class);
>
> I get an exception:
>
> java.lang.IllegalStateException: The providers property has not been
> set,
> which is done automatically when a MultiPart entity is received
> at com.sun.jersey.multipart.BodyPart.getEntityAs(BodyPart.java:261)
> at
> server
> .communication
> .webservice
> .project.RevisionResource.addRevision(RevisionResource.java:113)
> at
> server
> .communication
> .webservice
> .project.RevisionResourceTest.testPOST(RevisionResourceTest.java:160)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at junit.framework.TestCase.runTest(TestCase.java:168)
> at junit.framework.TestCase.runBare(TestCase.java:134)
> at junit.framework.TestResult$1.protect(TestResult.java:110)
> at junit.framework.TestResult.runProtected(TestResult.java:128)
> at junit.framework.TestResult.run(TestResult.java:113)
> at junit.framework.TestCase.run(TestCase.java:124)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at junit.framework.TestSuite.runTest(TestSuite.java:232)
> at junit.framework.TestSuite.run(TestSuite.java:227)
> at
> org
> .junit
> .internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76)
> at
> org
> .eclipse
> .jdt
> .internal
> .junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
> at
> org
> .eclipse
> .jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org
> .eclipse
> .jdt
> .internal
> .junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> at
> org
> .eclipse
> .jdt
> .internal
> .junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> at
> org
> .eclipse
> .jdt
> .internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> at
> org
> .eclipse
> .jdt
> .internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
> 196)
>
> when I use the old code snippet
>
> // get the second part which is the binary content
> BodyPartEntity bpe = (BodyPartEntity)
> multiPart.getBodyParts().get(1).getEntity();
> InputStream source = null;
>
> try {
> source = bpe.getInputStream();
> }
>
> JUnit test case passes correctly.
>
> Here's my JUnit code:
>
> VersionContentDto dto = new VersionContentDto();
> dto.setName("name");
>
> byte[] byteArray = "test text that does stuph".getBytes();
> ByteArrayInputStream bi = new ByteArrayInputStream(byteArray);
> BodyPartEntity bpe = new BodyPartEntity(bi);
>
> BodyPart dtoPart = new BodyPart(dto,
> MediaType.APPLICATION_XML_TYPE);
> BodyPart bytesPart = new BodyPart(bpe,
> MediaType.APPLICATION_OCTET_STREAM_TYPE);
>
> // Call Service
> // Construct a MultiPart with two body parts
> MultiPart multiPartInput = new
> MultiPart().bodyPart(dtoPart).bodyPart(bytesPart);
>
> Response r = resource.addRevision(multiPartInput);
>
> The previous (12:55pm) client side code snippet was from my
> integration
> (uses runtime server connection) test class.
> --
> View this message in context: http://n2.nabble.com/Multipart-1.0.3-not-finding-message-body-reader-tp2668407p2675399.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>