Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E324F78A3 for ; Mon, 19 Dec 2011 14:17:13 +0000 (UTC) Received: (qmail 41432 invoked by uid 500); 19 Dec 2011 14:17:13 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 41404 invoked by uid 500); 19 Dec 2011 14:17:13 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 41397 invoked by uid 99); 19 Dec 2011 14:17:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Dec 2011 14:17:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Dec 2011 14:17:11 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5A5682388AA9 for ; Mon, 19 Dec 2011 14:16:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1220758 [3/3] - in /camel/trunk: components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/ components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/ components/camel-aws/src/test/java/org/apache/camel/component/aw... Date: Mon, 19 Dec 2011 14:16:49 -0000 To: commits@camel.apache.org From: cmueller@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111219141651.5A5682388AA9@eris.apache.org> Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/aws/AwsSdbTest.java URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/aws/AwsSdbTest.java?rev=1220758&view=auto ============================================================================== --- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/aws/AwsSdbTest.java (added) +++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/aws/AwsSdbTest.java Mon Dec 19 14:16:47 2011 @@ -0,0 +1,297 @@ +/** + * 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.itest.osgi.aws; + +import java.util.Arrays; +import java.util.List; + +import com.amazonaws.services.simpledb.model.Attribute; +import com.amazonaws.services.simpledb.model.DeletableItem; +import com.amazonaws.services.simpledb.model.Item; +import com.amazonaws.services.simpledb.model.ReplaceableAttribute; +import com.amazonaws.services.simpledb.model.ReplaceableItem; +import com.amazonaws.services.simpledb.model.UpdateCondition; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.component.aws.sdb.SdbConstants; +import org.apache.camel.component.aws.sdb.SdbOperations; +import org.apache.camel.impl.DefaultProducerTemplate; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext; + +@RunWith(JUnit4TestRunner.class) +public class AwsSdbTest extends AwsTestSupport { + + private AmazonSDBClientMock amazonSDBClient; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + + amazonSDBClient = context.getRegistry().lookup("amazonSDBClient", AmazonSDBClientMock.class); + } + + @Override + protected OsgiBundleXmlApplicationContext createApplicationContext() { + return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/aws/CamelContext.xml"}); + } + + @Test + public void doesntCreateDomainOnStartIfExists() throws Exception { + assertNull(amazonSDBClient.createDomainRequest); + } + + @Test + public void createDomainOnStartIfNotExists() throws Exception { + DefaultProducerTemplate.newInstance(context, "aws-sdb://NonExistingDomain?amazonSDBClient=#amazonSDBClient&operation=GetAttributes"); + + assertEquals("NonExistingDomain", amazonSDBClient.createDomainRequest.getDomainName()); + } + + @Test + public void batchDeleteAttributes() { + final List deletableItems = Arrays.asList(new DeletableItem[] { + new DeletableItem("ITEM1", null), + new DeletableItem("ITEM2", null)}); + + template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.BatchDeleteAttributes); + exchange.getIn().setHeader(SdbConstants.DELETABLE_ITEMS, deletableItems); + } + }); + + assertEquals("TestDomain", amazonSDBClient.batchDeleteAttributesRequest.getDomainName()); + assertEquals(deletableItems, amazonSDBClient.batchDeleteAttributesRequest.getItems()); + } + + @Test + public void batchPutAttributes() { + final List replaceableItems = Arrays.asList(new ReplaceableItem[] { + new ReplaceableItem("ITEM1")}); + + template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.BatchPutAttributes); + exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ITEMS, replaceableItems); + } + }); + + assertEquals("TestDomain", amazonSDBClient.batchPutAttributesRequest.getDomainName()); + assertEquals(replaceableItems, amazonSDBClient.batchPutAttributesRequest.getItems()); + } + + @Test + public void deleteAttributes() { + final List attributes = Arrays.asList(new Attribute[] { + new Attribute("NAME1", "VALUE1")}); + final UpdateCondition condition = new UpdateCondition("Key1", "Value1", true); + + template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.DeleteAttributes); + exchange.getIn().setHeader(SdbConstants.ATTRIBUTES, attributes); + exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1"); + exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, condition); + } + }); + + assertEquals("TestDomain", amazonSDBClient.deleteAttributesRequest.getDomainName()); + assertEquals("ITEM1", amazonSDBClient.deleteAttributesRequest.getItemName()); + assertEquals(condition, amazonSDBClient.deleteAttributesRequest.getExpected()); + assertEquals(attributes, amazonSDBClient.deleteAttributesRequest.getAttributes()); + } + + @Test + public void deleteAttributesItemNameIsRequired() { + final List attributes = Arrays.asList(new Attribute[] { + new Attribute("NAME1", "VALUE1")}); + final UpdateCondition condition = new UpdateCondition("Key1", "Value1", true); + + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.DeleteAttributes); + exchange.getIn().setHeader(SdbConstants.ATTRIBUTES, attributes); + exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, condition); + } + }); + + Exception exception = exchange.getException(); + assertTrue(exception instanceof IllegalArgumentException); + } + + @Test + public void deleteDomain() { + template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.DeleteDomain); + } + }); + + assertEquals("TestDomain", amazonSDBClient.deleteDomainRequest.getDomainName()); + } + + @Test + public void domainMetadata() { + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.DomainMetadata); + } + }); + + assertEquals("TestDomain", amazonSDBClient.domainMetadataRequest.getDomainName()); + + assertEquals(new Integer(10), exchange.getIn().getHeader(SdbConstants.TIMESTAMP)); + assertEquals(new Integer(11), exchange.getIn().getHeader(SdbConstants.ITEM_COUNT)); + assertEquals(new Integer(12), exchange.getIn().getHeader(SdbConstants.ATTRIBUTE_NAME_COUNT)); + assertEquals(new Integer(13), exchange.getIn().getHeader(SdbConstants.ATTRIBUTE_VALUE_COUNT)); + assertEquals(new Long(1000000), exchange.getIn().getHeader(SdbConstants.ATTRIBUTE_NAME_SIZE)); + assertEquals(new Long(2000000), exchange.getIn().getHeader(SdbConstants.ATTRIBUTE_VALUE_SIZE)); + assertEquals(new Long(3000000), exchange.getIn().getHeader(SdbConstants.ITEM_NAME_SIZE)); + } + + @SuppressWarnings("unchecked") + @Test + public void getAttributes() { + final List attributeNames = Arrays.asList(new String[] {"ATTRIBUTE1"}); + + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.GetAttributes); + exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1"); + exchange.getIn().setHeader(SdbConstants.CONSISTENT_READ, Boolean.TRUE); + exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_NAMES, attributeNames); + } + }); + + assertEquals("TestDomain", amazonSDBClient.getAttributesRequest.getDomainName()); + assertEquals("ITEM1", amazonSDBClient.getAttributesRequest.getItemName()); + assertEquals(Boolean.TRUE, amazonSDBClient.getAttributesRequest.getConsistentRead()); + assertEquals(attributeNames, amazonSDBClient.getAttributesRequest.getAttributeNames()); + + List attributes = exchange.getIn().getHeader(SdbConstants.ATTRIBUTES, List.class); + assertEquals(2, attributes.size()); + assertEquals("AttributeOne", attributes.get(0).getName()); + assertEquals("Value One", attributes.get(0).getValue()); + assertEquals("AttributeTwo", attributes.get(1).getName()); + assertEquals("Value Two", attributes.get(1).getValue()); + } + + @Test + public void getAttributesItemNameIsRequired() { + final List attributeNames = Arrays.asList(new String[] {"ATTRIBUTE1"}); + + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.GetAttributes); + exchange.getIn().setHeader(SdbConstants.CONSISTENT_READ, Boolean.TRUE); + exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_NAMES, attributeNames); + } + }); + + Exception exception = exchange.getException(); + assertTrue(exception instanceof IllegalArgumentException); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void listDomains() { + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.ListDomains); + exchange.getIn().setHeader(SdbConstants.MAX_NUMBER_OF_DOMAINS, new Integer(5)); + exchange.getIn().setHeader(SdbConstants.NEXT_TOKEN, "TOKEN1"); + } + }); + + assertEquals(new Integer(5), amazonSDBClient.listDomainsRequest.getMaxNumberOfDomains()); + assertEquals("TOKEN1", amazonSDBClient.listDomainsRequest.getNextToken()); + + List domains = exchange.getIn().getHeader(SdbConstants.DOMAIN_NAMES, List.class); + assertEquals("TOKEN2", exchange.getIn().getHeader(SdbConstants.NEXT_TOKEN)); + assertEquals(2, domains.size()); + assertTrue(domains.contains("DOMAIN1")); + assertTrue(domains.contains("DOMAIN2")); + } + + @Test + public void putAttributes() { + final List replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] { + new ReplaceableAttribute("NAME1", "VALUE1", true)}); + final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true); + + template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes); + exchange.getIn().setHeader(SdbConstants.ITEM_NAME, "ITEM1"); + exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, updateCondition); + exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes); + } + }); + + assertEquals("TestDomain", amazonSDBClient.putAttributesRequest.getDomainName()); + assertEquals("ITEM1", amazonSDBClient.putAttributesRequest.getItemName()); + assertEquals(updateCondition, amazonSDBClient.putAttributesRequest.getExpected()); + assertEquals(replaceableAttributes, amazonSDBClient.putAttributesRequest.getAttributes()); + } + + @Test + public void putAttributesItemNameIsRequired() { + final List replaceableAttributes = Arrays.asList(new ReplaceableAttribute[] { + new ReplaceableAttribute("NAME1", "VALUE1", true)}); + final UpdateCondition updateCondition = new UpdateCondition("NAME1", "VALUE1", true); + + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes); + exchange.getIn().setHeader(SdbConstants.UPDATE_CONDITION, updateCondition); + exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, replaceableAttributes); + } + }); + + Exception exception = exchange.getException(); + assertTrue(exception instanceof IllegalArgumentException); + } + + @SuppressWarnings("unchecked") + @Test + public void select() { + Exchange exchange = template.send("direct:start-sdb", new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.Select); + exchange.getIn().setHeader(SdbConstants.NEXT_TOKEN, "TOKEN1"); + exchange.getIn().setHeader(SdbConstants.CONSISTENT_READ, Boolean.TRUE); + exchange.getIn().setHeader(SdbConstants.SELECT_EXPRESSION, "SELECT NAME1 FROM DOMAIN1 WHERE NAME1 LIKE 'VALUE1'"); + } + }); + + assertEquals(Boolean.TRUE, amazonSDBClient.selectRequest.getConsistentRead()); + assertEquals("TOKEN1", amazonSDBClient.selectRequest.getNextToken()); + assertEquals("SELECT NAME1 FROM DOMAIN1 WHERE NAME1 LIKE 'VALUE1'", amazonSDBClient.selectRequest.getSelectExpression()); + + List items = exchange.getIn().getHeader(SdbConstants.ITEMS, List.class); + assertEquals("TOKEN2", exchange.getIn().getHeader(SdbConstants.NEXT_TOKEN)); + assertEquals(2, items.size()); + assertEquals("ITEM1", items.get(0).getName()); + assertEquals("ITEM2", items.get(1).getName()); + } +} \ No newline at end of file Modified: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelContext.xml URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelContext.xml?rev=1220758&r1=1220757&r2=1220758&view=diff ============================================================================== --- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelContext.xml (original) +++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelContext.xml Mon Dec 19 14:16:47 2011 @@ -50,6 +50,11 @@ + + + + + @@ -59,4 +64,6 @@ + + \ No newline at end of file Modified: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelIntegrationContext.xml URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelIntegrationContext.xml?rev=1220758&r1=1220757&r2=1220758&view=diff ============================================================================== --- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelIntegrationContext.xml (original) +++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/aws/CamelIntegrationContext.xml Mon Dec 19 14:16:47 2011 @@ -50,5 +50,10 @@ + + + + + \ No newline at end of file