Search in sources :

Example 6 with Image

use of org.openstack4j.model.image.Image in project camel by apache.

the class GlanceProducerTest method reserveWithHeadersTest.

@Test
public void reserveWithHeadersTest() throws Exception {
    when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE);
    msg.setHeader(OpenstackConstants.NAME, dummyImage.getName());
    msg.setHeader(GlanceConstants.CONTAINER_FORMAT, dummyImage.getContainerFormat());
    msg.setHeader(GlanceConstants.DISK_FORMAT, dummyImage.getDiskFormat());
    msg.setHeader(GlanceConstants.CHECKSUM, dummyImage.getChecksum());
    msg.setHeader(GlanceConstants.MIN_DISK, dummyImage.getMinDisk());
    msg.setHeader(GlanceConstants.MIN_RAM, dummyImage.getMinRam());
    msg.setHeader(GlanceConstants.OWNER, dummyImage.getOwner());
    producer.process(exchange);
    final ArgumentCaptor<Image> captor = ArgumentCaptor.forClass(Image.class);
    verify(imageService).reserve(captor.capture());
    assertEqualsImages(dummyImage, captor.getValue());
    final Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
Also used : GlanceImage(org.openstack4j.openstack.image.domain.GlanceImage) Image(org.openstack4j.model.image.Image) Test(org.junit.Test)

Example 7 with Image

use of org.openstack4j.model.image.Image in project camel by apache.

the class GlanceProducer method doReserve.

private void doReserve(Exchange exchange) {
    final Image in = messageToImage(exchange.getIn());
    final Image out = os.images().reserve(in);
    exchange.getIn().setBody(out);
}
Also used : Image(org.openstack4j.model.image.Image)

Example 8 with Image

use of org.openstack4j.model.image.Image in project camel by apache.

the class GlanceProducerTest method createTest.

@Test
public void createTest() throws Exception {
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    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 InputStream is = new FileInputStream(File.createTempFile("image", ".iso"));
    msg.setBody(is);
    producer.process(exchange);
    final ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
    final ArgumentCaptor<org.openstack4j.model.image.Image> imageCaptor = ArgumentCaptor.forClass(org.openstack4j.model.image.Image.class);
    verify(imageService).create(imageCaptor.capture(), payloadCaptor.capture());
    assertEquals(is, payloadCaptor.getValue().open());
    final Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Payload(org.openstack4j.model.common.Payload) GlanceImage(org.openstack4j.openstack.image.domain.GlanceImage) Image(org.openstack4j.model.image.Image) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with Image

use of org.openstack4j.model.image.Image in project camel by apache.

the class GlanceProducerTest method uploadWithoutUpdatingTest.

@Test
public void uploadWithoutUpdatingTest() throws Exception {
    msg.setHeader(OpenstackConstants.OPERATION, GlanceConstants.UPLOAD);
    final String id = "id";
    msg.setHeader(OpenstackConstants.ID, id);
    final File file = File.createTempFile("image", ".iso");
    msg.setBody(file);
    producer.process(exchange);
    final ArgumentCaptor<Payload> payloadCaptor = ArgumentCaptor.forClass(Payload.class);
    final ArgumentCaptor<String> imageIdCaptor = ArgumentCaptor.forClass(String.class);
    final 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(file, payloadCaptor.getValue().getRaw());
    assertEquals(id, imageIdCaptor.getValue());
    assertNull(imageCaptor.getValue());
    final Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
Also used : Payload(org.openstack4j.model.common.Payload) Matchers.anyString(org.mockito.Matchers.anyString) GlanceImage(org.openstack4j.openstack.image.domain.GlanceImage) Image(org.openstack4j.model.image.Image) File(java.io.File) Test(org.junit.Test)

Example 10 with Image

use of org.openstack4j.model.image.Image in project camel by apache.

the class GlanceProducerTest method reserveTest.

@Test
public void reserveTest() throws Exception {
    when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE);
    msg.setBody(dummyImage);
    producer.process(exchange);
    ArgumentCaptor<Image> captor = ArgumentCaptor.forClass(Image.class);
    verify(imageService).reserve(captor.capture());
    assertEquals(dummyImage, captor.getValue());
    Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
Also used : GlanceImage(org.openstack4j.openstack.image.domain.GlanceImage) Image(org.openstack4j.model.image.Image) Test(org.junit.Test)

Aggregations

Image (org.openstack4j.model.image.Image)11 Test (org.junit.Test)6 GlanceImage (org.openstack4j.openstack.image.domain.GlanceImage)6 Message (org.apache.camel.Message)5 Payload (org.openstack4j.model.common.Payload)5 File (java.io.File)2 Matchers.anyString (org.mockito.Matchers.anyString)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 CamelContext (org.apache.camel.CamelContext)1 Exchange (org.apache.camel.Exchange)1 Producer (org.apache.camel.Producer)1 VolumeProducer (org.apache.camel.component.openstack.cinder.producer.VolumeProducer)1 GlanceEndpoint (org.apache.camel.component.openstack.glance.GlanceEndpoint)1 GlanceProducer (org.apache.camel.component.openstack.glance.GlanceProducer)1 ProjectProducer (org.apache.camel.component.openstack.keystone.producer.ProjectProducer)1 NetworkProducer (org.apache.camel.component.openstack.neutron.producer.NetworkProducer)1 KeypairProducer (org.apache.camel.component.openstack.nova.producer.KeypairProducer)1 ContainerProducer (org.apache.camel.component.openstack.swift.producer.ContainerProducer)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1