/** * 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 camelinaction.bindy; import java.math.BigDecimal; import java.util.Locale; import junit.framework.TestCase; import org.apache.camel.CamelContext; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.model.dataformat.BindyType; import org.junit.Test; /** * @version $Revision$ */ public class PurchaseOrderBindyTest extends TestCase { @Test public void testBindy() throws Exception { final Locale locale = Locale.getDefault(); try { Locale.setDefault(Locale.US); CamelContext context = new DefaultCamelContext(); context.addRoutes(createRoute()); context.start(); MockEndpoint mock = context.getEndpoint("mock:result", MockEndpoint.class); mock.expectedBodiesReceived("Camel in Action,39.95,1\n"); PurchaseOrder order = new PurchaseOrder(); order.setAmount(1); order.setPrice(new BigDecimal("39.95")); order.setName("Camel in Action"); ProducerTemplate template = context.createProducerTemplate(); template.sendBody("direct:toCsv", order); mock.assertIsSatisfied(); } finally { Locale.setDefault(locale); } } public RouteBuilder createRoute() { return new RouteBuilder() { public void configure() throws Exception { from("direct:toCsv") .marshal().bindy(BindyType.Csv, "camelinaction.bindy") .to("mock:result"); } }; } }