@AfterClass
 public static void tearDownClass() throws Exception {
   if (ctx != null) {
     ctx.getBlobStore().deleteContainer(DEFAULT_CONTAINER);
     ctx.close();
   }
 }
 @Override
 public BlobStoreContext call() throws Exception {
   BlobStoreContext context =
       new BlobStoreContextFactory()
           .createContext("filesystem", "", "", ImmutableSet.<Module>of(), overrides);
   context.getBlobStore().createContainerInLocation(null, CREDENTIALS_STORE);
   return context;
 }
Пример #3
0
 public ListContainers(String username, String apiKey) {
   BlobStoreContext context =
       ContextBuilder.newBuilder(PROVIDER)
           .credentials(username, apiKey)
           .buildView(BlobStoreContext.class);
   blobStore = context.getBlobStore();
   swift = context.unwrap();
 }
 private BlobStore getBlobStore() {
   BlobStoreContext context =
       ContextBuilder.newBuilder("transient")
           .name("test-transient")
           .credentials("user", "pass")
           .build(BlobStoreContext.class);
   return context.getBlobStore();
 }
 @BeforeMethod
 protected void setUp() throws Exception {
   // create context for filesystem container
   Properties prop = new Properties();
   prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR);
   context = ContextBuilder.newBuilder(PROVIDER).overrides(prop).build(BlobStoreContext.class);
   // create a container in the default location
   blobStore = context.getBlobStore();
   new File(TestUtils.TARGET_BASE_DIR).mkdir();
   TestUtils.createResources();
 }
public class JcloudsBlobStoreProducerTest extends CamelTestSupport {

  private static final String TEST_CONTAINER = "testContainer";
  private static final String TEST_BLOB_IN_DIR = "/dir/testBlob";
  private static final String MESSAGE = "<test>This is a test</test>";

  BlobStoreContext blobStoreContext =
      ContextBuilder.newBuilder("transient")
          .credentials("identity", "credential")
          .build(BlobStoreContext.class);
  BlobStore blobStore = blobStoreContext.getBlobStore();

  @Test
  public void testBlobStorePut() throws InterruptedException {
    MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
    mockEndpoint.expectedMessageCount(1);
    template.sendBody("direct:put", "Some message");
    mockEndpoint.assertIsSatisfied();
  }

  @Test
  public void testBlobStorePutAndGet() throws InterruptedException {
    String message = "Some message";
    template.sendBody("direct:put-and-get", message);
    Object result =
        template.requestBodyAndHeader(
            "direct:put-and-get",
            null,
            JcloudsConstants.OPERATION,
            JcloudsConstants.GET,
            String.class);
    assertEquals(message, result);
  }

  @Test
  public void testBlobStorePutWithStreamAndGet() throws InterruptedException, TransformerException {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(MESSAGE.getBytes());
    Exchange exchange = new DefaultExchange(context);
    StreamCache streamCache =
        StreamCacheConverter.convertToStreamCache(
            new SAXSource(new InputSource(inputStream)), exchange);
    template.sendBody("direct:put-and-get", streamCache);
    Object result =
        template.requestBodyAndHeader(
            "direct:put-and-get",
            null,
            JcloudsConstants.OPERATION,
            JcloudsConstants.GET,
            String.class);
    assertEquals(MESSAGE, result);
  }

  @Override
  protected RouteBuilder createRouteBuilder() throws Exception {
    blobStore.createContainerInLocation(null, TEST_CONTAINER);
    ((JcloudsComponent) context.getComponent("jclouds"))
        .setBlobStores(Lists.newArrayList(blobStore));

    return new RouteBuilder() {
      public void configure() {
        from("direct:put")
            .setHeader(JcloudsConstants.BLOB_NAME, constant(TEST_BLOB_IN_DIR))
            .setHeader(JcloudsConstants.CONTAINER_NAME, constant(TEST_CONTAINER))
            .to("jclouds:blobstore:transient")
            .to("mock:results");

        from("direct:put-and-get")
            .setHeader(JcloudsConstants.BLOB_NAME, constant(TEST_BLOB_IN_DIR))
            .setHeader(JcloudsConstants.CONTAINER_NAME, constant(TEST_CONTAINER))
            .to("jclouds:blobstore:transient");
      }
    };
  }
}
 @BeforeClass
 public static void setUpClass() {
   ctx = ContextBuilder.newBuilder("transient").buildView(BlobStoreContext.class);
   System.setProperty("com.netflix.config.blobstore.containerName", DEFAULT_CONTAINER);
   ctx.getBlobStore().createContainerInLocation(null, DEFAULT_CONTAINER);
 }