You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/06/12 17:47:31 UTC
svn commit: r954023 - in /camel/trunk/components/camel-bindy/src:
main/java/org/apache/camel/dataformat/bindy/
test/java/org/apache/camel/dataformat/bindy/fix/
test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/
Author: davsclaus
Date: Sat Jun 12 15:47:30 2010
New Revision: 954023
URL: http://svn.apache.org/viewvc?rev=954023&view=rev
Log:
Polished test and fixed CS.
Modified:
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java
Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java?rev=954023&r1=954022&r2=954023&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java Sat Jun 12 15:47:30 2010
@@ -18,7 +18,6 @@ package org.apache.camel.dataformat.bind
import java.lang.reflect.Field;
import java.text.NumberFormat;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -32,14 +31,13 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * The BindyAbstractFactory implements what its common to all the formats
+ * The {@link BindyAbstractFactory} implements what its common to all the formats
* supported by camel bindy
*/
public abstract class BindyAbstractFactory implements BindyFactory {
private static final transient Log LOG = LogFactory.getLog(BindyAbstractFactory.class);
protected Set<Class<?>> models;
protected Map<String, List<Field>> annotedLinkFields = new LinkedHashMap<String, List<Field>>();
- protected List<Field> linkFields = new ArrayList<Field>();
protected String crlf;
private AnnotationModelLoader modelsLoader;
@@ -62,7 +60,7 @@ public abstract class BindyAbstractFacto
* method uses to initialize the model representing the classes who will
* bind the data. This process will scan for classes according to the
* package name provided, check the annotated classes and fields.
- *
+ *
* @throws Exception
*/
public void initModel() throws Exception {
@@ -78,7 +76,7 @@ public abstract class BindyAbstractFacto
}
/**
- * Find fields annoted in each class of the model
+ * Find fields annotated in each class of the model
*/
public abstract void initAnnotedFields() throws Exception;
@@ -107,7 +105,6 @@ public abstract class BindyAbstractFacto
ObjectHelper.notNull(to, "No @link annotation has been defined for the oject to link");
field.set(model.get(field.getDeclaringClass().getName()), to);
-
}
}
}
@@ -115,7 +112,7 @@ public abstract class BindyAbstractFacto
/**
* Factory method generating new instances of the model and adding them to a
* HashMap
- *
+ *
* @return Map is a collection of the objects used to bind data from
* records, messages
* @throws Exception can be thrown
@@ -135,31 +132,26 @@ public abstract class BindyAbstractFacto
/**
* Generate a unique key
- *
+ *
* @param key1 The key of the section number
* @param key2 The key of the position of the field
* @return the key generated
*/
protected static Integer generateKey(Integer key1, Integer key2) {
-
String key2Formated;
String keyGenerated;
-
+
// Test added for ticket - camel-2773
-
if ((key1 != null) && (key2 != null)) {
- key2Formated = getNumberFormat().format((long)key2);
- keyGenerated = String.valueOf(key1) + key2Formated;
+ key2Formated = getNumberFormat().format((long) key2);
+ keyGenerated = String.valueOf(key1) + key2Formated;
} else {
- throw new IllegalArgumentException("@Section and/or @KeyValuePairDataField have not been defined !");
+ throw new IllegalArgumentException("@Section and/or @KeyValuePairDataField have not been defined !");
}
return Integer.valueOf(keyGenerated);
}
- /**
- * @return NumberFormat
- */
private static NumberFormat getNumberFormat() {
// Get instance of NumberFormat
NumberFormat nf = NumberFormat.getInstance();
@@ -171,15 +163,7 @@ public abstract class BindyAbstractFacto
return nf;
}
- /**
- * Return Default value for primitive type
- *
- * @param clazz
- * @return
- * @throws Exception
- */
- public static Object getDefaultValueforPrimitive(Class<?> clazz) throws Exception {
-
+ public static Object getDefaultValueForPrimitive(Class<?> clazz) throws Exception {
if (clazz == byte.class) {
return Byte.MIN_VALUE;
} else if (clazz == short.class) {
Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=954023&r1=954022&r2=954023&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java Sat Jun 12 15:47:30 2010
@@ -200,7 +200,7 @@ public class BindyCsvFactory extends Bin
throw new IllegalArgumentException("Parsing error detected for field defined at the position : " + pos + ", line : " + line, e);
}
} else {
- value = getDefaultValueforPrimitive(field.getType());
+ value = getDefaultValueForPrimitive(field.getType());
}
field.set(modelField, value);
Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java?rev=954023&r1=954022&r2=954023&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java Sat Jun 12 15:47:30 2010
@@ -26,13 +26,11 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import org.apache.camel.dataformat.bindy.annotation.DataField;
import org.apache.camel.dataformat.bindy.annotation.KeyValuePairField;
import org.apache.camel.dataformat.bindy.annotation.Link;
import org.apache.camel.dataformat.bindy.annotation.Message;
import org.apache.camel.dataformat.bindy.annotation.OneToMany;
import org.apache.camel.dataformat.bindy.annotation.Section;
-import org.apache.camel.dataformat.bindy.format.FormatException;
import org.apache.camel.dataformat.bindy.util.Converter;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.util.ObjectHelper;
@@ -220,7 +218,7 @@ public class BindyKeyValuePairFactory ex
throw new IllegalArgumentException("The mandatory key/tag : " + key + " has not been defined !");
}
- Object result = getDefaultValueforPrimitive(field.getType());
+ Object result = getDefaultValueForPrimitive(field.getType());
try {
field.set(obj, result);
@@ -248,7 +246,7 @@ public class BindyKeyValuePairFactory ex
obj = clazz.newInstance();
}
- Object result = getDefaultValueforPrimitive(field.getType());
+ Object result = getDefaultValueForPrimitive(field.getType());
try {
field.set(obj, result);
} catch (Exception e) {
@@ -301,7 +299,7 @@ public class BindyKeyValuePairFactory ex
}
} else {
- result = getDefaultValueforPrimitive(field.getType());
+ result = getDefaultValueForPrimitive(field.getType());
}
try {
field.set(obj, result);
@@ -346,7 +344,7 @@ public class BindyKeyValuePairFactory ex
if (value != null) {
field.set(obj, result);
} else {
- field.set(obj, getDefaultValueforPrimitive(field.getType()));
+ field.set(obj, getDefaultValueForPrimitive(field.getType()));
}
} catch (Exception e) {
throw new IllegalArgumentException("Setting of field " + field + " failed for object : " + obj + " and result : " + result);
@@ -374,7 +372,7 @@ public class BindyKeyValuePairFactory ex
} else {
// No values found from message
- Object result = getDefaultValueforPrimitive(field.getType());
+ Object result = getDefaultValueForPrimitive(field.getType());
try {
field.set(obj, result);
Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java?rev=954023&r1=954022&r2=954023&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java Sat Jun 12 15:47:30 2010
@@ -16,8 +16,6 @@
*/
package org.apache.camel.dataformat.bindy.fix;
-import static org.junit.Assert.assertEquals;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -30,13 +28,9 @@ import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
-import org.apache.camel.dataformat.bindy.csv.BindySimpleCsvUnmarshallBadIntegerTest;
import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat;
import org.apache.camel.dataformat.bindy.model.fix.withoutsection.Order;
-import org.apache.camel.model.dataformat.BindyType;
import org.apache.camel.processor.interceptor.Tracer;
-import org.apache.camel.test.junit4.TestSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
@@ -44,12 +38,13 @@ import org.springframework.test.context.
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
@ContextConfiguration
public class BindySimpleKeyValuePairWithoutSectionMarshallDslTest extends AbstractJUnit4SpringContextTests {
-
+
private static final transient Log LOG = LogFactory.getLog(BindySimpleKeyValuePairWithoutSectionMarshallDslTest.class);
-
+
private static final String URI_MOCK_RESULT = "mock:result";
private static final String URI_MOCK_ERROR = "mock:error";
private static final String URI_DIRECT_START = "direct:start";
@@ -61,7 +56,7 @@ public class BindySimpleKeyValuePairWith
@EndpointInject(uri = URI_MOCK_RESULT)
private MockEndpoint result;
-
+
@EndpointInject(uri = URI_MOCK_ERROR)
private MockEndpoint error;
@@ -78,15 +73,12 @@ public class BindySimpleKeyValuePairWith
result.assertIsSatisfied();
error.assertIsSatisfied();
-
+
// and check that we have the caused exception stored
Exchange exch = error.getReceivedExchanges().get(0);
- /**
Exception cause = exch.getProperty(Exchange.EXCEPTION_CAUGHT, IllegalArgumentException.class);
- TestSupport.assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
-
+ assertNotNull(cause);
assertEquals("@Section and/or @KeyValuePairDataField have not been defined !", cause.getMessage());
- **/
}
public List<Map<String, Object>> generateModel() {
@@ -107,11 +99,11 @@ public class BindySimpleKeyValuePairWith
}
public static class ContextConfig extends RouteBuilder {
-
- BindyKeyValuePairDataFormat orderBindyDataFormat = new BindyKeyValuePairDataFormat("org.apache.camel.dataformat.bindy.model.fix.withoutsection");
-
+
+ BindyKeyValuePairDataFormat orderBindyDataFormat = new BindyKeyValuePairDataFormat("org.apache.camel.dataformat.bindy.model.fix.withoutsection");
+
public void configure() {
-
+
Tracer tracer = new Tracer();
tracer.setLogLevel(LoggingLevel.FATAL);
tracer.setLogName("org.apache.camel.bindy");
@@ -119,12 +111,12 @@ public class BindySimpleKeyValuePairWith
tracer.setTraceExceptions(true);
getContext().addInterceptStrategy(tracer);
-
+
// default should errors go to mock:error
errorHandler(deadLetterChannel(URI_MOCK_ERROR));
onException(IllegalArgumentException.class).maximumRedeliveries(0).handled(true);
-
+
from(URI_DIRECT_START).marshal(orderBindyDataFormat).to(URI_MOCK_RESULT);
}
Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java?rev=954023&r1=954022&r2=954023&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java Sat Jun 12 15:47:30 2010
@@ -21,7 +21,7 @@ import org.apache.camel.dataformat.bindy
import org.apache.camel.dataformat.bindy.annotation.Message;
// No section has been defined
-@Message(keyValuePairSeparator = "=", pairSeparator = "\\u0001", type = "FIX", version = "4.1", isOrdered=true)
+@Message(keyValuePairSeparator = "=", pairSeparator = "\\u0001", type = "FIX", version = "4.1", isOrdered = true)
public class Order {
@KeyValuePairField(tag = 1)
@@ -98,10 +98,8 @@ public class Order {
@Override
public String toString() {
-
- return Order.class.getName() + " --> 1: " + this.account + ", 11: " + this.clOrdId + ", 22: " + this.iDSource + ", 48: " + this.securityId + ", 54: " + this.side
- + ", 58: " + this.text;
-
+ return Order.class.getName() + " --> 1: " + this.account + ", 11: " + this.clOrdId + ", 22: " + this.iDSource
+ + ", 48: " + this.securityId + ", 54: " + this.side + ", 58: " + this.text;
}
}