use of org.openstack4j.model.common.Payload in project camel by apache.
the class GlanceProducerTest method uploadWithUpdatingTest.
@Test
public void uploadWithUpdatingTest() throws Exception {
final String newName = "newName";
dummyImage.setName(newName);
when(osImage.getName()).thenReturn(newName);
msg.setHeader(OpenstackConstants.OPERATION, GlanceConstants.UPLOAD);
final String id = "id";
msg.setHeader(OpenstackConstants.ID, id);
msg.setHeader(OpenstackConstants.NAME, dummyImage.getName());
msg.setHeader(GlanceConstants.OWNER, dummyImage.getOwner());
msg.setHeader(GlanceConstants.MIN_DISK, dummyImage.getMinDisk());
msg.setHeader(GlanceConstants.MIN_RAM, dummyImage.getMinRam());
msg.setHeader(GlanceConstants.CHECKSUM, dummyImage.getChecksum());
msg.setHeader(GlanceConstants.DISK_FORMAT, dummyImage.getDiskFormat());
msg.setHeader(GlanceConstants.CONTAINER_FORMAT, dummyImage.getContainerFormat());
final File file = File.createTempFile("image", ".iso");
msg.setBody(file);
producer.process(exchange);
ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
ArgumentCaptor<String> imageIdCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<org.openstack4j.model.image.Image> imageCaptor = ArgumentCaptor.forClass(org.openstack4j.model.image.Image.class);
verify(imageService).upload(imageIdCaptor.capture(), payloadCaptor.capture(), imageCaptor.capture());
assertEquals(id, imageIdCaptor.getValue());
assertEquals(file, payloadCaptor.getValue().getRaw());
assertEquals(newName, imageCaptor.getValue().getName());
final Image result = msg.getBody(Image.class);
assertNotNull(result.getId());
assertEqualsImages(dummyImage, result);
}
use of org.openstack4j.model.common.Payload in project camel by apache.
the class GlanceProducer method doUpload.
private void doUpload(Exchange exchange) {
final Message msg = exchange.getIn();
final String imageId = msg.getHeader(OpenstackConstants.ID, String.class);
ObjectHelper.notEmpty(imageId, "Image ID");
final Image in = messageHeadersToImage(msg, false);
final Payload payload = createPayload(msg);
final Image out = os.images().upload(imageId, payload, in);
msg.setBody(out);
}
use of org.openstack4j.model.common.Payload in project camel by apache.
the class GlanceProducer method doCreate.
private void doCreate(Exchange exchange) {
final Message msg = exchange.getIn();
final Image in = messageHeadersToImage(msg, true);
final Payload payload = createPayload(msg);
final Image out = os.images().create(in, payload);
msg.setBody(out);
}
use of org.openstack4j.model.common.Payload in project camel by apache.
the class AbstractOpenstackProducer method createPayload.
protected Payload createPayload(Message msg) {
//if payload object is send directly
Payload payload = msg.getBody(Payload.class);
if (ObjectHelper.isNotEmpty(payload)) {
return payload;
}
Object messageBody = msg.getBody();
if (messageBody instanceof URL) {
payload = Payloads.create((URL) messageBody);
}
if (messageBody instanceof File) {
payload = Payloads.create((File) messageBody);
}
if (messageBody instanceof InputStream) {
payload = Payloads.create((InputStream) messageBody);
}
if (payload == null) {
throw new IllegalArgumentException("You have to set payload. It can be InputStream, File or URL class");
}
return payload;
}
use of org.openstack4j.model.common.Payload in project camel by apache.
the class ObjectProducer method doCreate.
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);
}
Aggregations