Search in sources :

Example 6 with Payload

use of org.openstack4j.model.common.Payload in project camel by apache.

the class ObjectProducerTest method createTest.

@Test
public void createTest() throws Exception {
    when(objectService.put(anyString(), anyString(), any(Payload.class))).thenReturn(ETAG);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.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));
}
Also used : Payload(org.openstack4j.model.common.Payload) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 7 with Payload

use of org.openstack4j.model.common.Payload 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 8 with Payload

use of org.openstack4j.model.common.Payload 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)

Aggregations

Payload (org.openstack4j.model.common.Payload)8 Image (org.openstack4j.model.image.Image)5 Test (org.junit.Test)4 File (java.io.File)3 Message (org.apache.camel.Message)3 Matchers.anyString (org.mockito.Matchers.anyString)3 GlanceImage (org.openstack4j.openstack.image.domain.GlanceImage)3 InputStream (java.io.InputStream)2 FileInputStream (java.io.FileInputStream)1 URL (java.net.URL)1