Author: davsclaus
Date: Sat Dec 17 10:22:18 2011
New Revision: 1215448
URL: http://svn.apache.org/viewvc?rev=1215448&view=rev
Log:
CAMEL-4764: Added SimpleDB component to AWS. Fixed CS. Thanks to Bilgin for the
patch.
Added:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java
(with props)
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java
(with props)
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java
(with props)
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java
(with props)
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java
(with props)
camel/trunk/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-sdb
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java
(with props)
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java
(with props)
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java
(with props)
Added:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java
(added)
+++
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,51 @@
+/**
+ * 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.aws.sdb;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+public class SdbComponent extends DefaultComponent {
+
+ public SdbComponent() {
+ super();
+ }
+
+ public SdbComponent(CamelContext context) {
+ super(context);
+ }
+
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
+ SdbConfiguration configuration = new SdbConfiguration();
+ setProperties(configuration, parameters);
+
+ if (remaining == null || remaining.trim().length() == 0) {
+ throw new IllegalArgumentException("Domain name must be
specified.");
+ }
+ configuration.setDomainName(remaining);
+
+ if (configuration.getAmazonSdbClient() == null &&
(configuration.getAccessKey() == null || configuration.getSecretKey() == null))
{
+ throw new IllegalArgumentException("amazonSdbClient or accessKey
and secretKey must be specified");
+ }
+
+ SdbEndpoint endpoint = new SdbEndpoint(uri, getCamelContext(),
configuration);
+ return endpoint;
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java
(added)
+++
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,76 @@
+/**
+ * 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.aws.sdb;
+
+import com.amazonaws.services.simpledb.AmazonSimpleDB;
+
+public class SdbConfiguration {
+ private String accessKey;
+ private String secretKey;
+ private AmazonSimpleDB amazonSdbClient;
+ private String amazonSdbEndpoint;
+ private String domainName;
+ private String operation;
+
+ public void setAmazonSdbEndpoint(String amazonSdbEndpoint) {
+ this.amazonSdbEndpoint = amazonSdbEndpoint;
+ }
+
+ public String getAmazonSdbEndpoint() {
+ return amazonSdbEndpoint;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public AmazonSimpleDB getAmazonSdbClient() {
+ return amazonSdbClient;
+ }
+
+ public void setAmazonSdbClient(AmazonSimpleDB amazonSdbClient) {
+ this.amazonSdbClient = amazonSdbClient;
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java
(added)
+++
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,28 @@
+/**
+ * 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.aws.sdb;
+
+public interface SdbConstants {
+ String MESSAGE_ID = "CamelAwsSdbMessageId";
+ String DOMAIN_NAME = "CamelAwsSdbDomainName";
+ String ITEM_KEY = "CamelAwsSdbItemKey";
+ String ATTRIBUTE_PREFIX = "CamelAwsSdbAttributePrefix";
+ String OPERATION = "CamelAwsSdbOperation";
+ String OPERATION_PUT = "CamelAwsSdbPut";
+ String OPERATION_GET = "CamelAwsSdbGet";
+ String OPERATION_DELETE = "CamelAwsSdbDelete";
+}
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbConstants.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java
(added)
+++
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,91 @@
+/**
+ * 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.aws.sdb;
+
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.simpledb.AmazonSimpleDB;
+import com.amazonaws.services.simpledb.AmazonSimpleDBClient;
+import com.amazonaws.services.simpledb.model.CreateDomainRequest;
+import com.amazonaws.services.simpledb.model.DomainMetadataRequest;
+import com.amazonaws.services.simpledb.model.NoSuchDomainException;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.aws.s3.S3Endpoint;
+import org.apache.camel.impl.ScheduledPollEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SdbEndpoint extends ScheduledPollEndpoint {
+ private static final Logger LOG =
LoggerFactory.getLogger(S3Endpoint.class);
+ private SdbConfiguration configuration;
+
+ public SdbEndpoint(String uri, CamelContext context, SdbConfiguration
configuration) {
+ super(uri, context);
+ this.configuration = configuration;
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("You cannot receive messages
from this endpoint");
+ }
+
+ public Producer createProducer() throws Exception {
+ return new SdbProducer(this);
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ @Override
+ public void doStart() throws Exception {
+ super.doStart();
+ AmazonSimpleDB sdbClient = getSdbClient();
+ String domainName = getConfiguration().getDomainName();
+ LOG.trace("Querying whether domain [{}] already exists...",
domainName);
+
+ try {
+ sdbClient.domainMetadata(new DomainMetadataRequest(domainName));
+ LOG.trace("Domain [{}] already exists", domainName);
+ return;
+ } catch (NoSuchDomainException ase) {
+ LOG.trace("Domain [{}] doesn't exist yet", domainName);
+ sdbClient.createDomain(new CreateDomainRequest(domainName));
+ LOG.trace("Domain created:" + domainName);
+ }
+ }
+
+ public SdbConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public AmazonSimpleDB getSdbClient() {
+ return configuration.getAmazonSdbClient() != null ?
configuration.getAmazonSdbClient() : createSdbClient();
+ }
+
+ AmazonSimpleDBClient createSdbClient() {
+ AWSCredentials credentials = new
BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
+ AmazonSimpleDBClient client = new AmazonSimpleDBClient(credentials);
+ if (configuration.getAmazonSdbEndpoint() != null) {
+ client.setEndpoint(configuration.getAmazonSdbEndpoint());
+ }
+ configuration.setAmazonSdbClient(client);
+ return client;
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java
(added)
+++
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,130 @@
+/**
+ * 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.aws.sdb;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import com.amazonaws.services.simpledb.model.Attribute;
+import com.amazonaws.services.simpledb.model.DeleteAttributesRequest;
+import com.amazonaws.services.simpledb.model.GetAttributesRequest;
+import com.amazonaws.services.simpledb.model.GetAttributesResult;
+import com.amazonaws.services.simpledb.model.PutAttributesRequest;
+import com.amazonaws.services.simpledb.model.ReplaceableAttribute;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.URISupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SdbProducer extends DefaultProducer {
+ private static final Logger LOG =
LoggerFactory.getLogger(SdbProducer.class);
+
+ public SdbProducer(Endpoint endpoint) {
+ super(endpoint);
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ String domainName = determineDomainName(exchange);
+ String itemName = determineItemName(exchange);
+ String operation = determineOperation(exchange);
+
+ if (SdbConstants.OPERATION_PUT.equals(operation)) {
+ executePut(exchange, domainName, itemName);
+ } else if (SdbConstants.OPERATION_GET.equals(operation)) {
+ executeGet(exchange, domainName, itemName);
+ } else if (SdbConstants.OPERATION_DELETE.equals(operation)) {
+ executeDelete(domainName, itemName);
+ } else {
+ throw new UnsupportedOperationException("Not supported operation:
" + operation);
+ }
+ }
+
+ private void executeDelete(String domainName, String itemName) {
+ LOG.trace("Deleting item [{}] from domain [{}]...", itemName,
domainName);
+ getEndpoint().getSdbClient().deleteAttributes(new
DeleteAttributesRequest(domainName, itemName));
+ }
+
+ private void executeGet(Exchange exchange, String domainName, String
itemName) {
+ LOG.trace("Getting item [{}] from domain [{}]...", itemName,
domainName);
+ GetAttributesRequest getAttributesRequest = new
GetAttributesRequest(domainName, itemName);
+ GetAttributesResult result =
getEndpoint().getSdbClient().getAttributes(getAttributesRequest);
+ populateExchangeWithResult(exchange, result);
+ }
+
+ private void populateExchangeWithResult(Exchange exchange,
GetAttributesResult attributesResult) {
+ for (Attribute attribute : attributesResult.getAttributes()) {
+ exchange.getIn().setHeader(attribute.getName(),
attribute.getValue());
+ }
+ }
+
+ private void executePut(Exchange exchange, String domainName, String
itemName) {
+ List<ReplaceableAttribute> attributes =
extractAttributesFrom(exchange);
+ PutAttributesRequest request = new PutAttributesRequest(domainName,
itemName, attributes);
+
+ LOG.trace("Put object [{}] from exchange [{}]...", request, exchange);
+ getEndpoint().getSdbClient().putAttributes(request);
+ }
+
+ private List<ReplaceableAttribute> extractAttributesFrom(Exchange
exchange) {
+ List<ReplaceableAttribute> attributes = new
ArrayList<ReplaceableAttribute>();
+ for (Map.Entry<String, Object> entry :
exchange.getIn().getHeaders().entrySet()) {
+ if (entry.getKey().startsWith(SdbConstants.ATTRIBUTE_PREFIX)) {
+ String fieldName =
entry.getKey().substring(SdbConstants.ATTRIBUTE_PREFIX.length());
+ attributes.add(new ReplaceableAttribute(fieldName, (String)
entry.getValue(), true));
+ }
+ }
+ return attributes;
+ }
+
+ private String determineDomainName(Exchange exchange) {
+ String domainName =
exchange.getIn().getHeader(SdbConstants.DOMAIN_NAME, String.class);
+ return domainName != null ? domainName :
getConfiguration().getDomainName();
+ }
+
+ private String determineOperation(Exchange exchange) {
+ String operation = exchange.getIn().getHeader(SdbConstants.OPERATION,
String.class);
+ if (operation == null) {
+ operation = getConfiguration().getOperation();
+ }
+ return operation != null ? operation : SdbConstants.OPERATION_PUT;
+ }
+
+ private String determineItemName(Exchange exchange) {
+ String key = exchange.getIn().getHeader(SdbConstants.ITEM_KEY,
String.class);
+ if (key == null) {
+ throw new IllegalArgumentException("AWS SDB Item Key header is
missing.");
+ }
+ return key;
+ }
+
+ protected SdbConfiguration getConfiguration() {
+ return getEndpoint().getConfiguration();
+ }
+
+ @Override
+ public String toString() {
+ return "SdbProducer[" +
URISupport.sanitizeUri(getEndpoint().getEndpointUri()) + "]";
+ }
+
+ @Override
+ public SdbEndpoint getEndpoint() {
+ return (SdbEndpoint) super.getEndpoint();
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/main/java/org/apache/camel/component/aws/sdb/SdbProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-sdb
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-sdb?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-sdb
(added)
+++
camel/trunk/components/camel-aws/src/main/resources/META-INF/services/org/apache/camel/component/aws-sdb
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,18 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+class=org.apache.camel.component.aws.sdb.SdbComponent
Added:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java
(added)
+++
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,84 @@
+/**
+ * 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.aws.sdb;
+
+import com.amazonaws.AmazonClientException;
+import com.amazonaws.AmazonServiceException;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.simpledb.AmazonSimpleDBClient;
+import com.amazonaws.services.simpledb.model.Attribute;
+import com.amazonaws.services.simpledb.model.CreateDomainRequest;
+import com.amazonaws.services.simpledb.model.DeleteAttributesRequest;
+import com.amazonaws.services.simpledb.model.DomainMetadataRequest;
+import com.amazonaws.services.simpledb.model.DomainMetadataResult;
+import com.amazonaws.services.simpledb.model.GetAttributesRequest;
+import com.amazonaws.services.simpledb.model.GetAttributesResult;
+import com.amazonaws.services.simpledb.model.NoSuchDomainException;
+import com.amazonaws.services.simpledb.model.PutAttributesRequest;
+
+public class AmazonSDBClientMock extends AmazonSimpleDBClient {
+ private String domainNameToCreate;
+ private String itemNameToDelete;
+ private PutAttributesRequest putAttributesRequest;
+
+ public AmazonSDBClientMock() {
+ super(new BasicAWSCredentials("user", "secret"));
+ }
+
+ @Override
+ public DomainMetadataResult domainMetadata(DomainMetadataRequest
domainMetadataRequest) throws AmazonServiceException, AmazonClientException {
+ throw new NoSuchDomainException(domainNameToCreate + " doesn't exist");
+ }
+
+ @Override
+ public void createDomain(CreateDomainRequest createDomainRequest) throws
AmazonServiceException, AmazonClientException {
+ this.domainNameToCreate = createDomainRequest.getDomainName();
+ }
+
+ @Override
+ public void putAttributes(PutAttributesRequest putAttributesRequest)
throws AmazonServiceException, AmazonClientException {
+ this.putAttributesRequest = putAttributesRequest;
+ }
+
+ @Override
+ public void deleteAttributes(DeleteAttributesRequest
deleteAttributesRequest) throws AmazonServiceException, AmazonClientException {
+ String domainName = deleteAttributesRequest.getDomainName();
+ if ("MissingDomain".equals(domainName)) {
+ throw new NoSuchDomainException(domainName);
+ }
+ this.itemNameToDelete = deleteAttributesRequest.getItemName();
+ }
+
+ @Override
+ public GetAttributesResult getAttributes(GetAttributesRequest
getAttributesRequest) throws AmazonServiceException, AmazonClientException {
+ return new GetAttributesResult()
+ .withAttributes(new Attribute("AttributeOne", "Value One"))
+ .withAttributes(new Attribute("AttributeTwo", "Value Two"));
+ }
+
+ public PutAttributesRequest getPutAttributesRequest() {
+ return putAttributesRequest;
+ }
+
+ public String getDomainNameToCreate() {
+ return domainNameToCreate;
+ }
+
+ public String getItemNameToDelete() {
+ return itemNameToDelete;
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/AmazonSDBClientMock.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java
(added)
+++
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,151 @@
+/**
+ * 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.aws.sdb;
+
+import java.util.List;
+
+import com.amazonaws.services.simpledb.model.NoSuchDomainException;
+import com.amazonaws.services.simpledb.model.ReplaceableAttribute;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class SdbComponentTest extends CamelTestSupport {
+ private AmazonSDBClientMock amazonSdbClient;
+
+ @Test
+ public void domainCreatedOnStart() throws Exception {
+ assertEquals("TestDomain", amazonSdbClient.getDomainNameToCreate());
+ }
+
+ @Test
+ public void putItemFromMessageHeaders() throws Exception {
+ template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_PUT);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_PREFIX +
"AttributeOne", "Value One");
+ exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_PREFIX +
"AttributeTwo", "Value Two");
+ }
+ });
+
+ assertEquals("TestDomain", domainNameToBeCreated());
+ assertEquals("ItemOne", itemNameToBeCreated());
+ assertEquals("Value One", getAttributeValueFor("AttributeOne"));
+ assertEquals("Value Two", getAttributeValueFor("AttributeTwo"));
+ assertEquals(2, getAttributesSize());
+ }
+
+ @Test
+ public void deleteItemByKey() throws Exception {
+ template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_DELETE);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ }
+ });
+
+ assertEquals("ItemOne", amazonSdbClient.getItemNameToDelete());
+ }
+
+ @Test
+ public void getItemByKey() throws Exception {
+ Exchange exchange = template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_GET);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ }
+ });
+
+ assertEquals("Value One", exchange.getIn().getHeader("AttributeOne"));
+ assertEquals("Value Two", exchange.getIn().getHeader("AttributeTwo"));
+ }
+
+ @Test
+ public void deletingItemOnNonExistingDomainCauseException() throws
Exception {
+ Exchange exchange = template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.DOMAIN_NAME,
"MissingDomain");
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_DELETE);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ }
+ });
+
+ Exception exception = exchange.getException();
+ assertNotNull("NoSuchDomainException is missing", exception);
+ assertTrue(exception instanceof NoSuchDomainException);
+ }
+
+
+ @Test
+ public void itemKeyHeaderIsAlwaysRequired() throws Exception {
+ Exchange exchange = template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_PUT);
+ exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_PREFIX +
"AttributeOne", "Value One");
+ }
+ });
+
+ Exception exception = exchange.getException();
+ assertNotNull("IllegalArgumentException is missing", exception);
+ assertTrue(exception instanceof IllegalArgumentException);
+ }
+
+ private int getAttributesSize() {
+ return
amazonSdbClient.getPutAttributesRequest().getAttributes().size();
+ }
+
+ private String getAttributeValueFor(String attributeName) {
+ List<ReplaceableAttribute> attributes =
amazonSdbClient.getPutAttributesRequest().getAttributes();
+ for (ReplaceableAttribute attribute : attributes) {
+ if (attribute.getName().equals(attributeName)) {
+ return attribute.getValue();
+ }
+ }
+ return "Attribute Not Found" + attributeName;
+ }
+
+ private String itemNameToBeCreated() {
+ return amazonSdbClient.getPutAttributesRequest().getItemName();
+ }
+
+ private String domainNameToBeCreated() {
+ return amazonSdbClient.getPutAttributesRequest().getDomainName();
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ amazonSdbClient = new AmazonSDBClientMock();
+ registry.bind("amazonSdbClient", amazonSdbClient);
+ return registry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+
.to("aws-sdb://TestDomain?amazonSdbClient=#amazonSdbClient&operation=CamelAwsSdbGet");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java?rev=1215448&view=auto
==============================================================================
---
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java
(added)
+++
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java
Sat Dec 17 10:22:18 2011
@@ -0,0 +1,73 @@
+/**
+ * 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.aws.sdb.integration;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.aws.sdb.SdbConstants;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore("Must be manually tested. Provide your own accessKey and secretKey!")
+public class SdbComponentIntegrationTest extends CamelTestSupport {
+
+ @Test
+ public void putItemFromMessageHeaders() throws Exception {
+ Exchange exchange = template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_PUT);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_PREFIX +
"AttributeOne", "Value One");
+ exchange.getIn().setHeader(SdbConstants.ATTRIBUTE_PREFIX +
"AttributeTwo", "Value Two");
+ }
+ });
+
+ assertNull("No exceptions during PUT operation",
exchange.getException());
+
+ exchange = template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_GET);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ }
+ });
+
+ assertNull("No exceptions during GET operation",
exchange.getException());
+ assertEquals("Value One", exchange.getIn().getHeader("AttributeOne"));
+ assertEquals("Value Two", exchange.getIn().getHeader("AttributeTwo"));
+
+ exchange = template.send("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setHeader(SdbConstants.OPERATION,
SdbConstants.OPERATION_DELETE);
+ exchange.getIn().setHeader(SdbConstants.ITEM_KEY, "ItemOne");
+ }
+ });
+
+ assertNull("No exceptions during DELETE operation",
exchange.getException());
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+
.to("aws-sdb://TestDomain?accessKey=xxx&secretKey=yyy");
+ }
+ };
+ }
+}
Propchange:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/integration/SdbComponentIntegrationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date