Author: iocanel Date: Thu Jan 12 03:49:59 2012 New Revision: 1230389 URL: http://svn.apache.org/viewvc?rev=1230389&view=rev Log: [CAMEL-4889] KratiProducer now accepts non-string keys. Added a unit test to test producer with non-string keys.
Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KeyObject.java camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/ValueObject.java Modified: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerTest.java Modified: camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java?rev=1230389&r1=1230388&r2=1230389&view=diff ============================================================================== --- camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java (original) +++ camel/trunk/components/camel-krati/src/main/java/org/apache/camel/component/krati/KratiProducer.java Thu Jan 12 03:49:59 2012 @@ -39,7 +39,7 @@ public class KratiProducer extends Defau public void process(Exchange exchange) throws Exception { String operation = getOperation(exchange); - String key = getKey(exchange); + Object key = getKey(exchange); LOG.trace("Processing {} operation on '[{}]'", operation, exchange); if (KratiConstants.KRATI_OPERATION_GET.equals(operation) && key != null) { @@ -94,11 +94,11 @@ public class KratiProducer extends Defau * @param exchange * @return */ - public String getKey(Exchange exchange) { - String key = ((KratiEndpoint) getEndpoint()).getKey(); + public Object getKey(Exchange exchange) { + Object key = ((KratiEndpoint) getEndpoint()).getKey(); if (exchange.getIn().getHeader(KratiConstants.KEY) != null) { - key = (String) exchange.getIn().getHeader(KratiConstants.KEY); + key = exchange.getIn().getHeader(KratiConstants.KEY); } return key; } Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KeyObject.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KeyObject.java?rev=1230389&view=auto ============================================================================== --- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KeyObject.java (added) +++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KeyObject.java Thu Jan 12 03:49:59 2012 @@ -0,0 +1,46 @@ +/** + * 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 org.apache.camel.component.krati; + +import java.io.Serializable; + +public class KeyObject implements Serializable { + + private String id; + + public KeyObject(String id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + KeyObject keyObject = (KeyObject) o; + + if (id != null ? !id.equals(keyObject.id) : keyObject.id != null) return false; + + return true; + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } +} Modified: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerTest.java?rev=1230389&r1=1230388&r2=1230389&view=diff ============================================================================== --- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerTest.java (original) +++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/KratiProducerTest.java Thu Jan 12 03:49:59 2012 @@ -28,9 +28,9 @@ public class KratiProducerTest extends C @Test public void testPut() throws InterruptedException { ProducerTemplate template = context.createProducerTemplate(); - template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1"); - template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2"); - template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3"); + template.sendBodyAndHeader("direct:put", new ValueObject("TEST1"), KratiConstants.KEY, new KeyObject("1")); + template.sendBodyAndHeader("direct:put", new ValueObject("TEST2"), KratiConstants.KEY, new KeyObject("2")); + template.sendBodyAndHeader("direct:put", new ValueObject("TEST3"), KratiConstants.KEY, new KeyObject("3")); MockEndpoint endpoint = context.getEndpoint("mock:results", MockEndpoint.class); endpoint.expectedMessageCount(3); endpoint.assertIsSatisfied(); @@ -40,11 +40,11 @@ public class KratiProducerTest extends C @Test public void testPutAndGet() throws InterruptedException { ProducerTemplate template = context.createProducerTemplate(); - template.sendBodyAndHeader("direct:put", "TEST1", KratiConstants.KEY, "1"); - template.sendBodyAndHeader("direct:put", "TEST2", KratiConstants.KEY, "2"); - template.sendBodyAndHeader("direct:put", "TEST3", KratiConstants.KEY, "3"); - Object result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, "3"); - assertEquals("TEST3", result); + template.sendBodyAndHeader("direct:put", new ValueObject("TEST1"), KratiConstants.KEY, new KeyObject("1")); + template.sendBodyAndHeader("direct:put", new ValueObject("TEST2"), KratiConstants.KEY, new KeyObject("2")); + template.sendBodyAndHeader("direct:put", new ValueObject("TEST3"), KratiConstants.KEY, new KeyObject("3")); + Object result = template.requestBodyAndHeader("direct:get", null, KratiConstants.KEY, new KeyObject("3")); + assertEquals(new ValueObject("TEST3"), result); } @Test Added: camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/ValueObject.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/ValueObject.java?rev=1230389&view=auto ============================================================================== --- camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/ValueObject.java (added) +++ camel/trunk/components/camel-krati/src/test/java/org/apache/camel/component/krati/ValueObject.java Thu Jan 12 03:49:59 2012 @@ -0,0 +1,46 @@ +/** + * 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 org.apache.camel.component.krati; + +import java.io.Serializable; + +public class ValueObject implements Serializable { + + Object value; + + public ValueObject(Object value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ValueObject that = (ValueObject) o; + + if (value != null ? !value.equals(that.value) : that.value != null) return false; + + return true; + } + + @Override + public int hashCode() { + return value != null ? value.hashCode() : 0; + } +}