You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/12/17 11:53:44 UTC
[05/17] camel git commit: CAMEL-9748: camel-openstack swift
CAMEL-9748: camel-openstack swift
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8780c099
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8780c099
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8780c099
Branch: refs/heads/master
Commit: 8780c099b0d4c917eaba9fbc3797f345c86a8c70
Parents: fd9e822
Author: Jan Bouska <jb...@redhat.com>
Authored: Fri Nov 18 19:15:01 2016 +0100
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Sat Dec 17 12:25:13 2016 +0100
----------------------------------------------------------------------
.../SwiftComponentAutoConfiguration.java | 80 ++++++++
.../openstack/swift/SwiftComponent.java | 32 +++
.../openstack/swift/SwiftConstants.java | 42 ++++
.../openstack/swift/SwiftEndpoint.java | 158 +++++++++++++++
.../swift/producer/ContainerProducer.java | 194 +++++++++++++++++++
.../swift/producer/ObjectProducer.java | 131 +++++++++++++
.../org/apache/camel/component/openstack-swift | 1 +
.../openstack/swift/ContainerProducerTest.java | 193 ++++++++++++++++++
.../openstack/swift/ObjectProducerTest.java | 191 ++++++++++++++++++
.../swift/SwiftProducerTestSupport.java | 52 +++++
10 files changed, 1074 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components-starter/camel-openstack-starter/src/main/java/org/apache/camel/component/openstack/swift/springboot/SwiftComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components-starter/camel-openstack-starter/src/main/java/org/apache/camel/component/openstack/swift/springboot/SwiftComponentAutoConfiguration.java b/components-starter/camel-openstack-starter/src/main/java/org/apache/camel/component/openstack/swift/springboot/SwiftComponentAutoConfiguration.java
new file mode 100644
index 0000000..2a21ed9
--- /dev/null
+++ b/components-starter/camel-openstack-starter/src/main/java/org/apache/camel/component/openstack/swift/springboot/SwiftComponentAutoConfiguration.java
@@ -0,0 +1,80 @@
+/**
+ * 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.openstack.swift.springboot;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.openstack.swift.SwiftComponent;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionMessage;
+import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
+import org.springframework.boot.bind.RelaxedPropertyResolver;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Configuration
+@ConditionalOnBean(type = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+@Conditional(SwiftComponentAutoConfiguration.Condition.class)
+@AutoConfigureAfter(name = "org.apache.camel.spring.boot.CamelAutoConfiguration")
+public class SwiftComponentAutoConfiguration {
+
+ @Lazy
+ @Bean(name = "openstack-swift-component")
+ @ConditionalOnClass(CamelContext.class)
+ @ConditionalOnMissingBean(SwiftComponent.class)
+ public SwiftComponent configureSwiftComponent(CamelContext camelContext)
+ throws Exception {
+ SwiftComponent component = new SwiftComponent();
+ component.setCamelContext(camelContext);
+ return component;
+ }
+
+ public static class Condition extends SpringBootCondition {
+ @Override
+ public ConditionOutcome getMatchOutcome(
+ ConditionContext conditionContext,
+ AnnotatedTypeMetadata annotatedTypeMetadata) {
+ boolean groupEnabled = isEnabled(conditionContext,
+ "camel.component.", true);
+ ConditionMessage.Builder message = ConditionMessage
+ .forCondition("camel.component.openstack-swift");
+ if (isEnabled(conditionContext, "camel.component.openstack-swift.",
+ groupEnabled)) {
+ return ConditionOutcome.match(message.because("enabled"));
+ }
+ return ConditionOutcome.noMatch(message.because("not enabled"));
+ }
+
+ private boolean isEnabled(
+ org.springframework.context.annotation.ConditionContext context,
+ java.lang.String prefix, boolean defaultValue) {
+ RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(
+ context.getEnvironment(), prefix);
+ return resolver.getProperty("enabled", Boolean.class, defaultValue);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftComponent.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftComponent.java
new file mode 100644
index 0000000..70e1042
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftComponent.java
@@ -0,0 +1,32 @@
+/**
+ * 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.openstack.swift;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+import java.util.Map;
+
+public class SwiftComponent extends DefaultComponent {
+
+ @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ SwiftEndpoint endpoint = new SwiftEndpoint(uri, this);
+ setProperties(endpoint, parameters);
+ endpoint.setHost(remaining);
+ return endpoint;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftConstants.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftConstants.java
new file mode 100644
index 0000000..ed7a856
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftConstants.java
@@ -0,0 +1,42 @@
+/**
+ * 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.openstack.swift;
+
+import org.apache.camel.component.openstack.common.OpenstackConstants;
+
+public final class SwiftConstants extends OpenstackConstants{
+
+ public static final String SWIFT_SUBSYSTEM_OBJECTS = "objects";
+ public static final String SWIFT_SUBSYSTEM_CONTAINERS = "containers";
+
+ public static final String CONTAINER_NAME = "containerName";
+ public static final String OBJECT_NAME = "objectName";
+
+ public static final String LIMIT = "limit";
+ public static final String MARKER = "marker";
+ public static final String END_MARKER = "end_marker";
+ public static final String DELIMITER = "delimiter";
+ public static final String PATH = "path";
+
+ public static final String GET_METADATA = "getMetadata";
+ public static final String CREATE_UPDATE_METADATA = "createUpdateMetadata";
+ public static final String DELETE_METADATA = "deleteMetadata";
+
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftEndpoint.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftEndpoint.java
new file mode 100644
index 0000000..19627a8
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/SwiftEndpoint.java
@@ -0,0 +1,158 @@
+/**
+ * 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.openstack.swift;
+
+import org.apache.camel.Producer;
+import org.apache.camel.component.openstack.common.AbstractOpenstackEndpoint;
+import org.apache.camel.component.openstack.swift.producer.ContainerProducer;
+import org.apache.camel.component.openstack.swift.producer.ObjectProducer;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+
+@UriEndpoint(scheme = "openstack-swift", title = "OpenStack-Swift", syntax = "openstack-swift:host", label = "cloud")
+public class SwiftEndpoint extends AbstractOpenstackEndpoint {
+
+ @UriPath
+ @Metadata(required = "true")
+ private String host;
+
+ @UriParam(defaultValue = "default")
+ private String domain = "default";
+
+ @UriParam(enums = "objects, containers")
+ @Metadata(required = "true")
+ String subsystem;
+
+ @UriParam
+ @Metadata(required = "true")
+ private String project;
+
+ @UriParam
+ private String operation;
+
+ @UriParam
+ @Metadata(required = "true")
+ private String username;
+
+ @UriParam
+ @Metadata(required = "true")
+ private String password;
+
+ public SwiftEndpoint(String uri, SwiftComponent component) {
+ super(uri, component);
+
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ switch (subsystem) {
+ case SwiftConstants.SWIFT_SUBSYSTEM_OBJECTS:
+ return new ObjectProducer(this, createClient());
+ case SwiftConstants.SWIFT_SUBSYSTEM_CONTAINERS:
+ return new ContainerProducer(this, createClient());
+ default:
+ throw new IllegalArgumentException("Can't create producer with subsystem " + subsystem);
+ }
+ }
+
+ public String getSubsystem() {
+ return subsystem;
+ }
+
+ /**
+ * OpenStack Nova subsystem
+ */
+ public void setSubsystem(String subsystem) {
+ this.subsystem = subsystem;
+ }
+
+ @Override
+ public String getDomain() {
+ return domain;
+ }
+
+ /**
+ * Authentication domain
+ */
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ @Override
+ public String getProject() {
+ return project;
+ }
+
+ /**
+ * The project ID
+ */
+ public void setProject(String project) {
+ this.project = project;
+ }
+
+ @Override
+ public String getOperation() {
+ return operation;
+ }
+
+ /**
+ * The operation to do
+ */
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ @Override
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * OpenStack username
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ @Override
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * OpenStack password
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ @Override
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * OpenStack host url
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ContainerProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ContainerProducer.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ContainerProducer.java
new file mode 100644
index 0000000..16ca6b9
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ContainerProducer.java
@@ -0,0 +1,194 @@
+/**
+ * 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.openstack.swift.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.openstack.common.AbstractOpenstackProducer;
+import org.apache.camel.component.openstack.swift.SwiftConstants;
+import org.apache.camel.component.openstack.swift.SwiftEndpoint;
+import org.apache.camel.util.ObjectHelper;
+
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.storage.object.SwiftContainer;
+import org.openstack4j.model.storage.object.SwiftHeaders;
+import org.openstack4j.model.storage.object.options.ContainerListOptions;
+import org.openstack4j.model.storage.object.options.CreateUpdateContainerOptions;
+
+import java.util.List;
+import java.util.Map;
+
+public class ContainerProducer extends AbstractOpenstackProducer {
+
+ public ContainerProducer(SwiftEndpoint endpoint, OSClient client) {
+ super(endpoint, client);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String operation = getOperation(exchange);
+
+ switch (operation) {
+ case SwiftConstants.CREATE:
+ doCreate(exchange);
+ break;
+ case SwiftConstants.GET:
+ doGet(exchange);
+ break;
+ case SwiftConstants.GET_ALL:
+ doGetAll(exchange);
+ break;
+ case SwiftConstants.UPDATE:
+ doUpdate(exchange);
+ break;
+ case SwiftConstants.DELETE:
+ doDelete(exchange);
+ break;
+ case SwiftConstants.GET_METADATA:
+ doGetMetadata(exchange);
+ break;
+ case SwiftConstants.CREATE_UPDATE_METADATA:
+ doUpdateMetadata(exchange);
+ break;
+ case SwiftConstants.DELETE_METADATA:
+ doDeleteMetadata(exchange);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported operation " + operation);
+ }
+ }
+
+ private void doCreate(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.NAME, msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+
+ final CreateUpdateContainerOptions options = messageToCreateUpdateOptions(msg);
+ final ActionResponse out = os.objectStorage().containers().create(name, options);
+ checkFailure(out, msg, "Create container " + name);
+ }
+
+ private void doGet(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final ContainerListOptions options = messageToListOptions(msg);
+ final List<? extends SwiftContainer> out = os.objectStorage().containers().list(options);
+ msg.setBody(out);
+ }
+
+ private void doGetAll(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final List<? extends SwiftContainer> out = os.objectStorage().containers().list();
+ msg.setBody(out);
+ }
+
+ private void doUpdate(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.NAME, msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+ final CreateUpdateContainerOptions options = messageToCreateUpdateOptions(msg);
+ final ActionResponse out = os.objectStorage().containers().update(name, options);
+ checkFailure(out, msg, "Update container " + name);
+ }
+
+ private void doDelete(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.NAME, msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+ final ActionResponse out = os.objectStorage().containers().delete(name);
+ checkFailure(out, msg, "Delete container " + name);
+ }
+
+ private void doGetMetadata(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.NAME, msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+ msg.setBody(os.objectStorage().containers().getMetadata(name));
+ }
+
+ private void doDeleteMetadata(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.NAME, msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+ boolean success = os.objectStorage().containers().deleteMetadata(name, msg.getBody(Map.class));
+ msg.setFault(!success);
+ if (!success) {
+ msg.setBody("Removing metadata was not successful");
+ }
+ }
+
+ private void doUpdateMetadata(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.NAME, msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+ boolean success = os.objectStorage().containers().updateMetadata(name, msg.getBody(Map.class));
+ msg.setFault(!success);
+ if (!success) {
+ msg.setBody("Updating metadata was not successful");
+ }
+ }
+
+ private CreateUpdateContainerOptions messageToCreateUpdateOptions(Message message) {
+ CreateUpdateContainerOptions options = message.getBody(CreateUpdateContainerOptions.class);
+ if (options == null) {
+ Map headers = message.getHeaders();
+ if (headers.containsKey(SwiftHeaders.CONTAINER_METADATA_PREFIX))
+ options = getCreateUpdateOptions(options).metadata(message.getHeader(SwiftHeaders.CONTAINER_METADATA_PREFIX, Map.class));
+
+ if (headers.containsKey(SwiftHeaders.VERSIONS_LOCATION))
+ options = getCreateUpdateOptions(options).versionsLocation(message.getHeader(SwiftHeaders.VERSIONS_LOCATION, String.class));
+
+ if (headers.containsKey(SwiftHeaders.CONTAINER_READ))
+ options = getCreateUpdateOptions(options).accessRead(message.getHeader(SwiftHeaders.CONTAINER_READ, String.class));
+
+ if (headers.containsKey(SwiftHeaders.CONTAINER_WRITE))
+ options = getCreateUpdateOptions(options).accessWrite(message.getHeader(SwiftHeaders.CONTAINER_WRITE, String.class));
+ }
+ return options;
+ }
+
+ private CreateUpdateContainerOptions getCreateUpdateOptions(CreateUpdateContainerOptions options) {
+ return options == null ? CreateUpdateContainerOptions.create() : options;
+ }
+
+ private ContainerListOptions messageToListOptions(Message message) {
+ ContainerListOptions options = message.getBody(ContainerListOptions.class);
+ if (options == null) {
+ Map headers = message.getHeaders();
+
+ if (headers.containsKey(SwiftConstants.LIMIT))
+ options = getListOptions(options).limit(message.getHeader(SwiftConstants.LIMIT, Integer.class));
+
+ if (headers.containsKey(SwiftConstants.MARKER))
+ options = getListOptions(options).marker(message.getHeader(SwiftConstants.MARKER, String.class));
+
+ if (headers.containsKey(SwiftConstants.END_MARKER))
+ options = getListOptions(options).endMarker(message.getHeader(SwiftConstants.END_MARKER, String.class));
+
+ if (headers.containsKey(SwiftConstants.DELIMITER))
+ options = getListOptions(options).delimiter(message.getHeader(SwiftConstants.DELIMITER, Character.class));
+
+ if (headers.containsKey(SwiftConstants.PATH))
+ options = getListOptions(options).path(message.getHeader(SwiftConstants.PATH, String.class));
+ }
+ return options;
+ }
+
+ private ContainerListOptions getListOptions(ContainerListOptions options) {
+ return options == null ? ContainerListOptions.create() : options;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ObjectProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ObjectProducer.java b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ObjectProducer.java
new file mode 100644
index 0000000..40a079d
--- /dev/null
+++ b/components/camel-openstack/src/main/java/org/apache/camel/component/openstack/swift/producer/ObjectProducer.java
@@ -0,0 +1,131 @@
+/**
+ * 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.openstack.swift.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.component.openstack.common.AbstractOpenstackProducer;
+import org.apache.camel.component.openstack.swift.SwiftConstants;
+import org.apache.camel.component.openstack.swift.SwiftEndpoint;
+import org.apache.camel.util.ObjectHelper;
+
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.common.Payload;
+import org.openstack4j.model.storage.object.SwiftObject;
+import org.openstack4j.model.storage.object.options.ObjectLocation;
+
+import java.util.List;
+import java.util.Map;
+
+public class ObjectProducer extends AbstractOpenstackProducer {
+
+ public ObjectProducer(SwiftEndpoint endpoint, OSClient client) {
+ super(endpoint, client);
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String operation = getOperation(exchange);
+
+ switch (operation) {
+ case SwiftConstants.CREATE:
+ doCreate(exchange);
+ break;
+ case SwiftConstants.GET:
+ doGet(exchange);
+ break;
+ case SwiftConstants.GET_ALL:
+ doGetAll(exchange);
+ break;
+ case SwiftConstants.DELETE:
+ doDelete(exchange);
+ break;
+ case SwiftConstants.GET_METADATA:
+ doGetMetadata(exchange);
+ break;
+ case SwiftConstants.CREATE_UPDATE_METADATA:
+ doUpdateMetadata(exchange);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported operation " + operation);
+ }
+ }
+
+ private void doCreate(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final Payload payload = createPayload(msg);
+ final String containerName = msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class);
+ final String objectName = msg.getHeader(SwiftConstants.OBJECT_NAME, String.class);
+ ObjectHelper.notEmpty(containerName, "Container name");
+ ObjectHelper.notEmpty(objectName, "Object name");
+ final String etag = os.objectStorage().objects().put(containerName, objectName, payload);
+ msg.setBody(etag);
+ }
+
+ private void doGet(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String containerName = msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class);
+ final String objectName = msg.getHeader(SwiftConstants.OBJECT_NAME, String.class);
+ ObjectHelper.notEmpty(containerName, "Container name");
+ ObjectHelper.notEmpty(objectName, "Object name");
+ final SwiftObject out = os.objectStorage().objects().get(containerName, objectName);
+ msg.setBody(out);
+ }
+
+ private void doGetAll(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String name = msg.getHeader(SwiftConstants.CONTAINER_NAME, msg.getHeader(SwiftConstants.NAME, String.class), String.class);
+ ObjectHelper.notEmpty(name, "Container name");
+ final List<? extends SwiftObject> out = os.objectStorage().objects().list(name);
+ exchange.getIn().setBody(out);
+ }
+
+ private void doDelete(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String containerName = msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class);
+ final String objectName = msg.getHeader(SwiftConstants.OBJECT_NAME, String.class);
+ ObjectHelper.notEmpty(containerName, "Container name");
+ ObjectHelper.notEmpty(objectName, "Object name");
+ final ActionResponse out = os.objectStorage().objects().delete(containerName, objectName);
+ msg.setBody(out.getFault());
+ msg.setFault(!out.isSuccess());
+ }
+
+ private void doGetMetadata(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String containerName = msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class);
+ final String objectName = msg.getHeader(SwiftConstants.OBJECT_NAME, String.class);
+ ObjectHelper.notEmpty(containerName, "Container name");
+ ObjectHelper.notEmpty(objectName, "Object name");
+
+ msg.setBody(os.objectStorage().objects().getMetadata(containerName, objectName));
+ }
+
+ private void doUpdateMetadata(Exchange exchange) {
+ final Message msg = exchange.getIn();
+ final String containerName = msg.getHeader(SwiftConstants.CONTAINER_NAME, String.class);
+ final String objectName = msg.getHeader(SwiftConstants.OBJECT_NAME, String.class);
+ ObjectHelper.notEmpty(containerName, "Container name");
+ ObjectHelper.notEmpty(objectName, "Object name");
+ final boolean success = os.objectStorage().objects().updateMetadata(ObjectLocation.create(containerName, objectName), msg.getBody(Map.class));
+ msg.setFault(!success);
+ if (!success) {
+ msg.setBody("Updating metadata was not successful");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-swift
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-swift b/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-swift
new file mode 100644
index 0000000..161ab0a
--- /dev/null
+++ b/components/camel-openstack/src/main/resources/META-INF/services/org/apache/camel/component/openstack-swift
@@ -0,0 +1 @@
+class=org.apache.camel.component.openstack
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ContainerProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ContainerProducerTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ContainerProducerTest.java
new file mode 100644
index 0000000..980047e
--- /dev/null
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ContainerProducerTest.java
@@ -0,0 +1,193 @@
+/**
+ * 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.openstack.swift;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.component.openstack.swift.producer.ContainerProducer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.common.Payload;
+import org.openstack4j.model.common.Payloads;
+import org.openstack4j.model.storage.object.SwiftContainer;
+import org.openstack4j.model.storage.object.options.ContainerListOptions;
+import org.openstack4j.model.storage.object.options.CreateUpdateContainerOptions;
+import org.openstack4j.model.storage.object.options.ObjectLocation;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ContainerProducerTest extends SwiftProducerTestSupport {
+
+ private static final String CONTAINER_NAME = "containerName";
+
+ @Mock
+ private SwiftContainer mockOsContainer;
+
+ @Before
+ public void setUp() {
+ producer = new ContainerProducer(endpoint, client);
+ }
+
+ @Test
+ public void createTestWithoutOptions() throws Exception {
+ when(containerService.create(anyString(), any(CreateUpdateContainerOptions.class))).thenReturn(ActionResponse.actionSuccess());
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.CREATE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+
+ producer.process(exchange);
+
+ ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<CreateUpdateContainerOptions> optionsCaptor = ArgumentCaptor.forClass(CreateUpdateContainerOptions.class);
+
+ verify(containerService).create(containerNameCaptor.capture(), optionsCaptor.capture());
+ assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
+ assertNull(optionsCaptor.getValue());
+
+ assertFalse(msg.isFault());
+ }
+
+ @Test
+ public void createTestWithOptions() throws Exception {
+ when(containerService.create(anyString(), any(CreateUpdateContainerOptions.class))).thenReturn(ActionResponse.actionSuccess());
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.CREATE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ final CreateUpdateContainerOptions options = CreateUpdateContainerOptions.create().accessAnybodyRead();
+ msg.setBody(options);
+ producer.process(exchange);
+
+ ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<CreateUpdateContainerOptions> optionsCaptor = ArgumentCaptor.forClass(CreateUpdateContainerOptions.class);
+
+ verify(containerService).create(containerNameCaptor.capture(), optionsCaptor.capture());
+ assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
+ assertEquals(options, optionsCaptor.getValue());
+ assertFalse(msg.isFault());
+ }
+
+ @Test
+ public void getTest() throws Exception {
+ List<SwiftContainer> list = new ArrayList<>();
+ list.add(mockOsContainer);
+ doReturn(list).when(containerService).list(any(ContainerListOptions.class));
+ when(endpoint.getOperation()).thenReturn(SwiftConstants.GET);
+
+ msg.setHeader(SwiftConstants.LIMIT, 10);
+ msg.setHeader(SwiftConstants.DELIMITER, 'x');
+
+ producer.process(exchange);
+ ArgumentCaptor<ContainerListOptions> optionsCaptor = ArgumentCaptor.forClass(ContainerListOptions.class);
+ verify(containerService).list(optionsCaptor.capture());
+ Map<String, String> options = optionsCaptor.getValue().getOptions();
+ assertEquals(String.valueOf(10), options.get(SwiftConstants.LIMIT));
+ assertEquals("x", options.get(SwiftConstants.DELIMITER));
+ assertEquals(list, msg.getBody(List.class));
+ }
+
+ @Test
+ public void getAllFromContainerTest() throws Exception {
+ List<SwiftContainer> list = new ArrayList<>();
+ list.add(mockOsContainer);
+ doReturn(list).when(containerService).list();
+
+ when(endpoint.getOperation()).thenReturn(SwiftConstants.GET_ALL);
+
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+
+ producer.process(exchange);
+ assertEquals(mockOsContainer, msg.getBody(List.class).get(0));
+ }
+
+ @Test
+ public void deleteObjectTest() throws Exception {
+ when(containerService.delete(anyString())).thenReturn(ActionResponse.actionSuccess());
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.DELETE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+
+ producer.process(exchange);
+
+ ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
+ verify(containerService).delete(containerNameCaptor.capture());
+ assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
+
+ assertFalse(msg.isFault());
+ }
+
+ @Test
+ public void deleteObjectFailTest() throws Exception {
+ final String failMessage = "fail";
+ when(containerService.delete(anyString())).thenReturn(ActionResponse.actionFailed(failMessage, 401));
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.DELETE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+
+ producer.process(exchange);
+
+ assertTrue(msg.isFault());
+ assertTrue(msg.getBody(String.class).contains(failMessage));
+ }
+
+ @Test
+ public void createUpdateMetadataTest() throws Exception {
+ final Map<String, String> md = new HashMap<>();
+ md.put("key", "val");
+
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.CREATE_UPDATE_METADATA);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setBody(md);
+
+ producer.process(exchange);
+
+ ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<Map> dataCaptor = ArgumentCaptor.forClass(Map.class);
+ verify(containerService).updateMetadata(nameCaptor.capture(), dataCaptor.capture());
+
+ assertEquals(CONTAINER_NAME, nameCaptor.getValue());
+ assertEquals(md, dataCaptor.getValue());
+ }
+
+ @Test
+ public void getMetadataTest() throws Exception {
+ final Map<String, String> md = new HashMap<>();
+ md.put("key", "val");
+
+ when(containerService.getMetadata(CONTAINER_NAME)).thenReturn(md);
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.GET_METADATA);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+
+ producer.process(exchange);
+
+ assertEquals(md, msg.getBody(Map.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ObjectProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ObjectProducerTest.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ObjectProducerTest.java
new file mode 100644
index 0000000..1dd6a2d
--- /dev/null
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/ObjectProducerTest.java
@@ -0,0 +1,191 @@
+/**
+ * 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.openstack.swift;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.component.openstack.swift.producer.ObjectProducer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.openstack4j.model.common.ActionResponse;
+import org.openstack4j.model.common.Payload;
+import org.openstack4j.model.common.Payloads;
+import org.openstack4j.model.storage.object.SwiftObject;
+import org.openstack4j.model.storage.object.options.ObjectLocation;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+public class ObjectProducerTest extends SwiftProducerTestSupport {
+
+ private static final String CONTAINER_NAME = "containerName";
+ private static final String OBJECT_NAME = "objectName";
+ private static final String ETAG = UUID.randomUUID().toString();
+
+ @Mock
+ private SwiftObject mockOsObject;
+
+ @Before
+ public void setUp() {
+ producer = new ObjectProducer(endpoint, client);
+
+ when(mockOsObject.getETag()).thenReturn(ETAG);
+ }
+
+ @Test
+ public void createTest() throws Exception {
+ when(objectService.put(anyString(), anyString(), any(Payload.class))).thenReturn(ETAG);
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.CREATE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setHeader(SwiftConstants.OBJECT_NAME, OBJECT_NAME);
+ final Payload payload = getTmpPayload();
+ msg.setBody(payload);
+
+ producer.process(exchange);
+
+ ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<String> objectNameCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<Payload> payloadArgumentCaptor = ArgumentCaptor.forClass(Payload.class);
+ verify(objectService).put(containerNameCaptor.capture(), objectNameCaptor.capture(), payloadArgumentCaptor.capture());
+ assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
+ assertEquals(OBJECT_NAME, objectNameCaptor.getValue());
+ assertEquals(payload, payloadArgumentCaptor.getValue());
+
+ assertEquals(ETAG, msg.getBody(String.class));
+ }
+
+ @Test
+ public void getTest() throws Exception {
+ when(objectService.get(CONTAINER_NAME, OBJECT_NAME)).thenReturn(mockOsObject);
+ when(endpoint.getOperation()).thenReturn(SwiftConstants.GET);
+
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setHeader(SwiftConstants.OBJECT_NAME, OBJECT_NAME);
+
+ producer.process(exchange);
+
+ assertEquals(ETAG, msg.getBody(SwiftObject.class).getETag());
+ }
+
+ @Test
+ public void getAllFromContainerTest() throws Exception {
+ List<SwiftObject> objectsList = new ArrayList<>();
+ objectsList.add(mockOsObject);
+ doReturn(objectsList).when(objectService).list(CONTAINER_NAME);
+
+ when(endpoint.getOperation()).thenReturn(SwiftConstants.GET_ALL);
+
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+
+ producer.process(exchange);
+ assertEquals(mockOsObject, msg.getBody(List.class).get(0));
+ }
+
+
+ @Test
+ public void deleteObjectTest() throws Exception {
+ final String failMessage = "fail";
+ when(objectService.delete(anyString(), anyString())).thenReturn(ActionResponse.actionSuccess());
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.DELETE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setHeader(SwiftConstants.OBJECT_NAME, OBJECT_NAME);
+
+ producer.process(exchange);
+
+ ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
+ ArgumentCaptor<String> objectNameCaptor = ArgumentCaptor.forClass(String.class);
+ verify(objectService).delete(containerNameCaptor.capture(), objectNameCaptor.capture());
+ assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
+ assertEquals(OBJECT_NAME, objectNameCaptor.getValue());
+
+ assertFalse(msg.isFault());
+ }
+
+
+ @Test
+ public void deleteObjectFailTest() throws Exception {
+ final String failMessage = "fail";
+ when(objectService.delete(anyString(), anyString())).thenReturn(ActionResponse.actionFailed(failMessage, 401));
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.DELETE);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setHeader(SwiftConstants.OBJECT_NAME, OBJECT_NAME);
+
+ producer.process(exchange);
+
+ assertTrue(msg.isFault());
+ assertTrue(msg.getBody(String.class).contains(failMessage));
+ }
+
+ @Test
+ public void updateMetadataTest() throws Exception {
+ final Map<String, String> md = new HashMap<>();
+ md.put("key", "val");
+
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.CREATE_UPDATE_METADATA);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setHeader(SwiftConstants.OBJECT_NAME, OBJECT_NAME);
+ msg.setBody(md);
+
+ producer.process(exchange);
+
+ ArgumentCaptor<ObjectLocation> locationCaptor = ArgumentCaptor.forClass(ObjectLocation.class);
+ ArgumentCaptor<Map> dataCaptor = ArgumentCaptor.forClass(Map.class);
+ verify(objectService).updateMetadata(locationCaptor.capture(), dataCaptor.capture());
+ ObjectLocation location = locationCaptor.getValue();
+ assertEquals(CONTAINER_NAME, location.getContainerName());
+ assertEquals(OBJECT_NAME, location.getObjectName());
+ assertEquals(md, dataCaptor.getValue());
+ }
+
+ @Test
+ public void getMetadataTest() throws Exception {
+ final Map<String, String> md = new HashMap<>();
+ md.put("key", "val");
+
+ when(objectService.getMetadata(CONTAINER_NAME, OBJECT_NAME)).thenReturn(md);
+ msg.setHeader(SwiftConstants.OPERATION, SwiftConstants.GET_METADATA);
+ msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
+ msg.setHeader(SwiftConstants.OBJECT_NAME, OBJECT_NAME);
+
+ producer.process(exchange);
+
+ assertEquals(md, msg.getBody(Map.class));
+ }
+
+
+ private Payload getTmpPayload() throws IOException {
+ return Payloads.create(File.createTempFile("payloadPreffix", ".txt"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8780c099/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/SwiftProducerTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/SwiftProducerTestSupport.java b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/SwiftProducerTestSupport.java
new file mode 100644
index 0000000..53ea867
--- /dev/null
+++ b/components/camel-openstack/src/test/java/org/apache/camel/component/openstack/swift/SwiftProducerTestSupport.java
@@ -0,0 +1,52 @@
+/**
+ * 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.openstack.swift;
+
+import static org.mockito.Mockito.when;
+
+import org.apache.camel.component.openstack.AbstractProducerTestSupport;
+
+import org.junit.Before;
+
+import org.mockito.Mock;
+import org.openstack4j.api.storage.ObjectStorageContainerService;
+import org.openstack4j.api.storage.ObjectStorageObjectService;
+import org.openstack4j.api.storage.ObjectStorageService;
+
+public class SwiftProducerTestSupport extends AbstractProducerTestSupport {
+
+ @Mock
+ protected SwiftEndpoint endpoint;
+
+ @Mock
+ protected ObjectStorageService objectStorageService;
+
+ @Mock
+ protected ObjectStorageContainerService containerService;
+
+ @Mock
+ protected ObjectStorageObjectService objectService;
+
+ @Before
+ public void setUpComputeService(){
+ when(client.objectStorage()).thenReturn(objectStorageService);
+ when(objectStorageService.containers()).thenReturn(containerService);
+ when(objectStorageService.objects()).thenReturn(objectService);
+ }
+
+
+}