Merge pull request #894 from akka/wip-2724-streamcache-patriknw

Reset StreamCache in getBodyAs to be able to re-read it, see #2724
This commit is contained in:
Patrik Nordwall 2012-11-26 07:12:36 -08:00
commit e5fce9ee2a
3 changed files with 32 additions and 4 deletions

View file

@ -8,6 +8,7 @@ import akka.actor.ActorSystem;
import akka.dispatch.Mapper;
import akka.japi.Function;
import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.converter.stream.InputStreamCache;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -100,6 +101,14 @@ public class MessageJavaTestBase {
message("test1" , createMap("A", "1")).withHeaders(createMap("C", "3")));
}
@Test
public void shouldBeAbleToReReadStreamCacheBody() throws Exception {
CamelMessage msg = new CamelMessage(new InputStreamCache("test1".getBytes("utf-8")), empty);
assertEquals("test1", msg.getBodyAs(String.class, camel.context()));
// re-read
assertEquals("test1", msg.getBodyAs(String.class, camel.context()));
}
private static Set<String> createSet(String... entries) {
HashSet<String> set = new HashSet<String>();
set.addAll(Arrays.asList(entries));