Package org.jclouds.snia.cdmi.v1.handlers

Examples of org.jclouds.snia.cdmi.v1.handlers.CDMIErrorHandler


      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      DataNonCDMIContentTypeApi dataNonCDMIContentTypeApi = cdmiContext.getApi()
               .getDataNonCDMIContentTypeApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {

         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with none cdmi put with payload string.
         value = "Hello CDMI World non-cdmi String";
         dataNonCDMIContentTypeApi.create(dataObjectNameIn, value);
         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
View Full Code Here


      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi api = cdmiContext.getApi().getApi();

      Logger.getAnonymousLogger().info("create: " + pContainerName);

      Container container = api.create(pContainerName, pCreateContainerOptions);
      assertNotNull(container);
      try {
         System.out.println(container);
         Logger.getAnonymousLogger().info("get: " + pContainerName);
         container = api.get(pContainerName);
         assertNotNull(container);
         System.out.println(container);
         assertEquals(container.getObjectType(), ObjectTypes.CONTAINER);
         assertNotNull(container.getObjectID());
         assertNotNull(container.getObjectName());
         assertEquals(container.getObjectName(), pContainerName);
         assertEquals(container.getParentURI(), "/");
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);
         System.out.println("Children: " + container.getChildren());
         assertNotNull(container.getMetadata());
         System.out.println("Raw metadata: " + container.getMetadata());
         for (Map.Entry<String, JsonBall> entry : container.getMetadata().entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
         }
         assertNotNull(container.getUserMetadata());
         Map<String, String> pContainerMetaDataOut = container.getUserMetadata();
         for (Map.Entry<String, String> entry : pContainerMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(pContainerMetaDataOut.containsKey(key), true);
            assertEquals(pContainerMetaDataOut.get(key), entry.getValue());
         }
         System.out.println("UserMetaData: " + container.getUserMetadata());
         assertNotNull(container.getSystemMetadata());
         System.out.println("SystemMetaData: " + container.getSystemMetadata());
         assertNotNull(container.getACLMetadata());
         assertEquals(container.getACLMetadata().size(), 3);
         List<Map<String, String>> aclMetadataOut = container.getACLMetadata();
         System.out.println("ACLMetaData: ");
         for (Map<String, String> aclMap : aclMetadataOut) {
            System.out.println(aclMap);
         }
         container = api.get("/");
         System.out.println("root container: " + container);
         assertEquals(container.getChildren().contains(pContainerName), true);
         System.out.println("adding containers to container");
         String firstParentURI = api.get(pContainerName).getObjectName();
         for (int i = 0; i < 10; i++) {
            // container = api.create(firstParentURI+"childcontainer"+i+"/");
            container = api.create(pContainerName + "childcontainer" + i + "/");
            assertNotNull(container);
            System.out.println(container);
            assertEquals(container.getParentURI(), pContainerName);
            assertEquals(container.getObjectName(), "childcontainer" + i + "/");
            container = api.create(container.getParentURI() + container.getObjectName() + "grandchild/");
            assertEquals(container.getParentURI(), pContainerName + "childcontainer" + i + "/");
            assertEquals(container.getObjectName(), "grandchild/");
            System.out.println(container);
         }
         container = api.get(pContainerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().size(), 10);

      } finally {
         Logger.getAnonymousLogger().info("delete: " + pContainerName);
         api.delete(pContainerName);
         container = api.get("/");
         System.out.println("root container: " + container);
         assertEquals(container.getChildren().contains(pContainerName), false);
      }

   }
View Full Code Here

      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      DataNonCDMIContentTypeApi dataNonCDMIContentTypeApi = cdmiContext.getApi()
               .getDataNonCDMIContentTypeApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {

         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with none cdmi put with payload string.
         value = "Hello CDMI World non-cdmi String";
         dataNonCDMIContentTypeApi.create(dataObjectNameIn, value);
         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
View Full Code Here

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {
         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with value mimetype and metadata
         value = "Hello CDMI data object with value mimetype and metadata";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain")
                  .metadata(pDataObjectMetaDataIn);
View Full Code Here

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {
         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with value mimetype and metadata
         value = "Hello CDMI data object with value mimetype and metadata";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain")
                  .metadata(pDataObjectMetaDataIn);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         for (Map.Entry<String, String> entry : pDataObjectMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(dataObjectMetaDataOut.containsKey(key), true);
            assertEquals(dataObjectMetaDataOut.get(key), entry.getValue());
         }
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")
                  .field("objectName"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")
                  .field("objectName").field("mimetype"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getMimetype(), "text/plain");

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")
                  .field("objectName").field("mimetype").metadata());
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getMimetype(), "text/plain");
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         for (Map.Entry<String, String> entry : pDataObjectMetaDataIn.entrySet()) {
View Full Code Here

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi api = cdmiContext.getApi().getApi();

      Logger.getAnonymousLogger().info("create: " + pContainerName);

      Container container = api.create(pContainerName, pCreateContainerOptions);
      assertNotNull(container);
      try {
         System.out.println(container);
         Logger.getAnonymousLogger().info("get: " + pContainerName);
         container = api.get(pContainerName);
         assertNotNull(container);
         System.out.println(container);
         assertEquals(container.getObjectType(), ObjectTypes.CONTAINER);
         assertNotNull(container.getObjectID());
         assertNotNull(container.getObjectName());
         assertEquals(container.getObjectName(), pContainerName);
         assertEquals(container.getParentURI(), "/");
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);
         System.out.println("Children: " + container.getChildren());
         assertNotNull(container.getMetadata());
         System.out.println("Raw metadata: " + container.getMetadata());
         for (Map.Entry<String, JsonBall> entry : container.getMetadata().entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
         }
         assertNotNull(container.getUserMetadata());
         Map<String, String> pContainerMetaDataOut = container.getUserMetadata();
         for (Map.Entry<String, String> entry : pContainerMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(pContainerMetaDataOut.containsKey(key), true);
            assertEquals(pContainerMetaDataOut.get(key), entry.getValue());
         }
         System.out.println("UserMetaData: " + container.getUserMetadata());
         assertNotNull(container.getSystemMetadata());
         System.out.println("SystemMetaData: " + container.getSystemMetadata());
         assertNotNull(container.getACLMetadata());
         assertEquals(container.getACLMetadata().size(), 3);
         List<Map<String, String>> aclMetadataOut = container.getACLMetadata();
         System.out.println("ACLMetaData: ");
         for (Map<String, String> aclMap : aclMetadataOut) {
            System.out.println(aclMap);
         }
         container = api.get("/");
         System.out.println("root container: " + container);
         assertEquals(container.getChildren().contains(pContainerName), true);
         System.out.println("adding containers to container");
         String firstParentURI = api.get(pContainerName).getObjectName();
         for (int i = 0; i < 10; i++) {
            // container = api.create(firstParentURI+"childcontainer"+i+"/");
            container = api.create(pContainerName + "childcontainer" + i + "/");
            assertNotNull(container);
            System.out.println(container);
            assertEquals(container.getParentURI(), pContainerName);
            assertEquals(container.getObjectName(), "childcontainer" + i + "/");
            container = api.create(container.getParentURI() + container.getObjectName() + "grandchild/");
            assertEquals(container.getParentURI(), pContainerName + "childcontainer" + i + "/");
            assertEquals(container.getObjectName(), "grandchild/");
            System.out.println(container);
         }
         container = api.get(pContainerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().size(), 10);

      } finally {
         Logger.getAnonymousLogger().info("delete: " + pContainerName);
         api.delete(pContainerName);
         container = api.get("/");
         System.out.println("root container: " + container);
         assertEquals(container.getChildren().contains(pContainerName), false);
      }

   }
View Full Code Here

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi api = cdmiContext.getApi().getApi();

      Logger.getAnonymousLogger().info("create: " + pContainerName);

      Container container = api.create(pContainerName, pCreateContainerOptions);
      assertNotNull(container);
      try {
         System.out.println(container);
         Logger.getAnonymousLogger().info("get: " + pContainerName);
         container = api.get(pContainerName);
         assertNotNull(container);
         System.out.println(container);
         assertEquals(container.getObjectType(), ObjectTypes.CONTAINER);
         assertNotNull(container.getObjectID());
         assertNotNull(container.getObjectName());
         assertEquals(container.getObjectName(), pContainerName);
         assertEquals(container.getParentURI(), "/");
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);
         System.out.println("Children: " + container.getChildren());
         assertNotNull(container.getMetadata());
         System.out.println("Raw metadata: " + container.getMetadata());
         for (Map.Entry<String, JsonBall> entry : container.getMetadata().entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
         }
         assertNotNull(container.getUserMetadata());
         Map<String, String> pContainerMetaDataOut = container.getUserMetadata();
         for (Map.Entry<String, String> entry : pContainerMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(pContainerMetaDataOut.containsKey(key), true);
            assertEquals(pContainerMetaDataOut.get(key), entry.getValue());
         }
         System.out.println("UserMetaData: " + container.getUserMetadata());
         assertNotNull(container.getSystemMetadata());
         System.out.println("SystemMetaData: " + container.getSystemMetadata());
         assertNotNull(container.getACLMetadata());
         List<Map<String, String>> aclMetadataOut = container.getACLMetadata();
         System.out.println("ACLMetaData: ");
         for (Map<String, String> aclMap : aclMetadataOut) {
            System.out.println(aclMap);
         }
         container = api.get("/");
         System.out.println("root container: " + container);
         assertEquals(container.getChildren().contains(pContainerName), true);
         container = api.get(pContainerName, ContainerQueryParams.Builder.field("parentURI"));
         assertNotNull(container);
         assertEquals(container.getParentURI(), "/");
         System.out.println(container);

         container = api.get(pContainerName, ContainerQueryParams.Builder.field("parentURI").field("objectName"));
         assertNotNull(container);
         assertEquals(container.getParentURI(), "/");
         assertEquals(container.getObjectName(), pContainerName);

         container = api.get(pContainerName, ContainerQueryParams.Builder.metadata());
         assertNotNull(container);
         pContainerMetaDataOut = container.getUserMetadata();
         for (Map.Entry<String, String> entry : pContainerMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(pContainerMetaDataOut.containsKey(key), true);
            assertEquals(pContainerMetaDataOut.get(key), entry.getValue());
         }
         System.out.println(container);

         System.out.println("GetContainerOptions.Builder.metadata(cdmi_acl)");
         container = api.get(pContainerName, ContainerQueryParams.Builder.metadata("cdmi_acl"));
         assertNotNull(container);
         System.out.println(container);
         assertNotNull(container.getACLMetadata());
         assertEquals(container.getACLMetadata().size(), 3);

         System.out.println("adding containers to container");
         String firstParentURI = api.get(pContainerName).getObjectName();
         for (int i = 0; i < 10; i++) {
            container = api.create(firstParentURI + "childcontainer" + i + "/");
            assertNotNull(container);
            assertEquals(container.getParentURI(), pContainerName);
            assertEquals(container.getObjectName(), "childcontainer" + i + "/");
            container = api.create(container.getParentURI() + container.getObjectName() + "grandchild/",
                     pCreateContainerOptions);
            assertEquals(container.getParentURI(), pContainerName + "childcontainer" + i + "/");
            assertEquals(container.getObjectName(), "grandchild" + "/");
            container = api.get(container.getParentURI(), ContainerQueryParams.Builder.children());
            assertEquals(container.getChildren().contains("grandchild" + "/"), true);
         }
         container = api.get(pContainerName, ContainerQueryParams.Builder.children());
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().size(), 10);
         container = api.get(pContainerName, ContainerQueryParams.Builder.children(0, 3));
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().size(), 4);

         container = api.get(pContainerName, ContainerQueryParams.Builder.field("parentURI").field("objectName")
                  .children().metadata());
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().size(), 10);
         assertEquals(container.getParentURI(), "/");
         assertEquals(container.getObjectName(), pContainerName);
         assertEquals(container.getParentURI(), "/");
         assertEquals(container.getACLMetadata().size(), 3);
         for (String childName : container.getChildren()) {
            api.delete(container.getObjectName() + childName);
         }
         assertEquals(api.get(pContainerName, ContainerQueryParams.Builder.children()).getChildren().isEmpty(), true);

      } finally {
         Logger.getAnonymousLogger().info("delete: " + pContainerName);
         api.delete(pContainerName);
         container = api.get("/");
         System.out.println("root container: " + container);
         assertEquals(container.getChildren().contains(pContainerName), false);
      }

   }
View Full Code Here

      InputStream is;
      File tmpFileOut;
      File inFile;
      Files.touch(tmpFileIn);
      byte[] bytes;
      DataObject dataObject;
      Map<String, String> pContainerMetaDataIn = Maps.newHashMap();
      Map<String, String> pDataObjectMetaDataIn = Maps.newLinkedHashMap();
      pDataObjectMetaDataIn.put("dataObjectkey1", "value1");
      pDataObjectMetaDataIn.put("dataObjectkey2", "value2");
      pDataObjectMetaDataIn.put("dataObjectkey3", "value3");

      Payload payloadIn;
      Payload payloadOut;

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      DataNonCDMIContentTypeApi dataNonCDMIContentTypeApi = cdmiContext.getApi()
               .getDataNonCDMIContentTypeApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {

         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with none cdmi put with payload string.
         value = "Hello CDMI World non-cdmi String";
         dataNonCDMIContentTypeApi.create(dataObjectNameIn, value);
         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
         assertNotNull(payloadOut);
         assertEquals(Strings2.toString(payloadOut), value);

         payloadIn = new StringPayload(value);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build()));
         dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn);

         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
         assertNotNull(payloadOut);
         assertEquals(Strings2.toString(payloadOut), value);

         dataObject = dataNonCDMIContentTypeApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         dataObject = dataNonCDMIContentTypeApi.get(dataObjectNameIn,
                  DataObjectQueryParams.Builder.metadata().field("parentURI").field("objectName").field("objectType")
                           .field("mimetype"));
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(dataObject.getMimetype(), MediaType.PLAIN_TEXT_UTF_8.toString());

         dataNonCDMIContentTypeApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with payload byte array.
         value = "Hello CDMI World non-cdmi byte array";
         bytes = value.getBytes(Charsets.UTF_8);
         payloadIn = new ByteArrayPayload(bytes);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build()));
         dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn);
         System.out.println(containerApi.get(containerName));
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         assertEquals(new String(dataObject.getValueAsByteArray()), value);
         assertEquals(dataObject.getUserMetadata().isEmpty(), true);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
         assertNotNull(payloadOut);
         assertEquals(Strings2.toString(payloadOut), value);

         dataNonCDMIContentTypeApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with payload file.
         value = "Hello CDMI World non-cdmi File";
         Files.write(value, tmpFileIn, Charsets.UTF_8);
         payloadIn = new FilePayload(tmpFileIn);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString()).build()));

         dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn);
         System.out.println(containerApi.get(containerName));
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(dataObject.getUserMetadata().isEmpty(), true);
         System.out.println("My Metadata: " + dataObject.getUserMetadata());
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);

         payloadOut = dataNonCDMIContentTypeApi.getValue(dataObjectNameIn);
         assertNotNull(payloadOut);
         // assertEquals(Strings2.toString(payloadOut), value);
         // byte[] _bytes = ByteStreams.toByteArray(payloadOut);
         tmpFileOut = new File(Files.createTempDir(), "temp.txt");
         Files.copy(payloadOut, tmpFileOut);
         assertEquals(Files.equal(tmpFileOut, tmpFileIn), true);
         tmpFileOut.delete();

         dataNonCDMIContentTypeApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with text file payload file.
         inFile = new File(System.getProperty("user.dir") + "/src/test/resources/container.json");
         assertEquals(true, inFile.isFile());
         payloadIn = new FilePayload(inFile);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.JSON_UTF_8.toString()).build()));

         dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn);
         System.out.println(containerApi.get(containerName));
         dataObject = dataApi.get(inFile.getName());
         assertNotNull(dataObject);
         System.out.println(dataObject);
         // System.out.println("value: " + dataObject.getValueAsString());
         // assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, inFile));
         tmpFileOut.delete();
         assertEquals(dataObject.getUserMetadata().isEmpty(), true);
         // System.out.println("My Metadata: "+dataObject.getUserMetadata());
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), inFile.length());
         assertEquals(dataObject.getObjectName(), inFile.getName());
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), true);
         dataApi.delete(inFile.getName());
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with text file payload file.
         // inFile = new File(System.getProperty("user.dir")
         // + "/src/test/resources/Jellyfish.jpg"); // takes too long when working from home
         inFile = new File(System.getProperty("user.dir") + "/src/test/resources/yellow-flowers.jpg");
         assertEquals(true, inFile.isFile());
         payloadIn = new FilePayload(inFile);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.JPEG.toString()).build()));
         dataNonCDMIContentTypeApi.create(inFile.getName(), payloadIn);
         System.out.println(containerApi.get(containerName));
         // note dataApi.get when the data object is not a string
         payloadOut = dataNonCDMIContentTypeApi.getValue(inFile.getName());
         assertNotNull(payloadOut);
         tmpFileOut = new File(Files.createTempDir(), "temp.jpg");
         Files.copy(payloadOut, tmpFileOut);
         assertEquals(Files.equal(tmpFileOut, inFile), true);
         tmpFileOut.delete();

         assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), true);
         dataApi.delete(inFile.getName());
         assertEquals(containerApi.get(containerName).getChildren().contains(inFile.getName()), false);

         // exercise create data object with none cdmi put with payload inputStream riginating from
         // string.
         value = "Hello CDMI World non-cdmi inputStream originating from string";
         is = new ByteArrayInputStream(value.getBytes());
         payloadIn = new InputStreamPayload(is);
         payloadIn.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(payloadIn.getContentMetadata()
                  .toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8.toString())
                  .contentLength(new Long(value.length())).build()));
         dataNonCDMIContentTypeApi.create(dataObjectNameIn, payloadIn);
         System.out.println(containerApi.get(containerName));
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         assertNotNull(dataObject.getValueAsInputSupplier());
         assertEquals(CharStreams.toString(CharStreams.newReaderSupplier(
                  dataObject.getValueAsInputSupplier(Charsets.UTF_8), Charsets.UTF_8)), value);
         assertEquals(dataObject.getUserMetadata().isEmpty(), true);
         System.out.println("My Metadata: " + dataObject.getUserMetadata());
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataNonCDMIContentTypeApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with none cdmi put with payload inputStream originating from
View Full Code Here

      File tmpFileIn = new File("temp.txt");
      String value;
      Files.touch(tmpFileIn);

      CreateDataObjectOptions pCreateDataObjectOptions;
      DataObject dataObject;
      Map<String, String> dataObjectMetaDataOut;
      Map<String, String> pContainerMetaDataIn = Maps.newHashMap();
      Map<String, String> pDataObjectMetaDataIn = Maps.newLinkedHashMap();
      pDataObjectMetaDataIn.put("dataObjectkey1", "value1");
      pDataObjectMetaDataIn.put("dataObjectkey2", "value2");
      pDataObjectMetaDataIn.put("dataObjectkey3", "value3");

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {
         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with value mimetype and metadata
         value = "Hello CDMI data object with value mimetype and metadata";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain")
                  .metadata(pDataObjectMetaDataIn);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         for (Map.Entry<String, String> entry : pDataObjectMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(dataObjectMetaDataOut.containsKey(key), true);
            assertEquals(dataObjectMetaDataOut.get(key), entry.getValue());
         }
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")
                  .field("objectName"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")
                  .field("objectName").field("mimetype"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getMimetype(), "text/plain");

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("parentURI")
                  .field("objectName").field("mimetype").metadata());
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(dataObject.getParentURI(), container.getParentURI() + container.getObjectName());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getMimetype(), "text/plain");
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         for (Map.Entry<String, String> entry : pDataObjectMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(dataObjectMetaDataOut.containsKey(key), true);
            assertEquals(dataObjectMetaDataOut.get(key), entry.getValue());
         }
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.metadata("cdmi_size"));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("mimetype").value());
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println(dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);

         dataObject = dataApi.get(dataObjectNameIn, DataObjectQueryParams.Builder.field("mimetype").value(0, 3));
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println(dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         // value is SGVsbA==. This needs investigating to determine if this
         // is problem with CDMI server or the jclouds client or must understanding of spec

         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);
View Full Code Here

      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      DataOutputStream out = new DataOutputStream(bos);
      byte[] bytes;

      CreateDataObjectOptions pCreateDataObjectOptions;
      DataObject dataObject;
      Map<String, String> dataObjectMetaDataOut;
      Map<String, String> pContainerMetaDataIn = Maps.newHashMap();
      Map<String, String> pDataObjectMetaDataIn = Maps.newLinkedHashMap();
      pDataObjectMetaDataIn.put("dataObjectkey1", "value1");
      pDataObjectMetaDataIn.put("dataObjectkey2", "value2");
      pDataObjectMetaDataIn.put("dataObjectkey3", "value3");

      CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder.metadata(pContainerMetaDataIn);
      ContainerApi containerApi = cdmiContext.getApi().getApi();
      DataApi dataApi = cdmiContext.getApi().getDataApiForContainer(containerName);
      Logger.getAnonymousLogger().info("create: " + containerName);
      Container container = containerApi.create(containerName, pCreateContainerOptions);
      try {
         assertNotNull(container);
         System.out.println(container);
         container = containerApi.get(containerName);
         assertNotNull(container);
         assertNotNull(container.getChildren());
         assertEquals(container.getChildren().isEmpty(), true);

         // exercise create data object with value mimetype and metadata
         value = "Hello CDMI data object with value mimetype and metadata";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain")
                  .metadata(pDataObjectMetaDataIn);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         for (Map.Entry<String, String> entry : pDataObjectMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(dataObjectMetaDataOut.containsKey(key), true);
            assertEquals(dataObjectMetaDataOut.get(key), entry.getValue());
         }
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);

         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // verify that options order does not matter
         value = "Hello CDMI World3";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.metadata(pDataObjectMetaDataIn)
                  .mimetype("text/plain").value(value);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         for (Map.Entry<String, String> entry : pDataObjectMetaDataIn.entrySet()) {
            String key = entry.getKey();
            assertEquals(dataObjectMetaDataOut.containsKey(key), true);
            assertEquals(dataObjectMetaDataOut.get(key), entry.getValue());
         }
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with empty metadata
         value = "Hello CDMI World4";
         pDataObjectMetaDataIn.clear();
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain")
                  .metadata(pDataObjectMetaDataIn);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         assertEquals(dataObjectMetaDataOut.isEmpty(), true);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with null metadata
         value = "Hello CDMI World5";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value).mimetype("text/plain");
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getMimetype(), "text/plain");
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         assertEquals(true, dataObjectMetaDataOut.isEmpty());
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with only value
         value = "Hello CDMI World6";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(value);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         assertEquals(dataObjectMetaDataOut.isEmpty(), true);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with empty mimetype only
         value = "";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.mimetype(new String());
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         // assertEquals(dataObject.getMimetype(), "");
         assertEquals(dataObject.getValueAsString(), "");
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         // assertEquals(dataObjectMetaDataOut.isEmpty(),true);

         dataApi.delete(dataObjectNameIn);

         // exercise create data object with no value
         value = "";
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value();
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), "");
         dataObjectMetaDataOut = dataObject.getUserMetadata();
         assertNotNull(dataObjectMetaDataOut);
         assertEquals(dataObjectMetaDataOut.isEmpty(), true);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with byte array
         value = "Hello CDMI World 7";
         out.writeUTF(value);
         out.close();
         bytes = bos.toByteArray();
         // String.getBytes causes an exception CreateDataObjectOptions need to investigate byte
         // arrays
         // bytes = value.getBytes(Charsets.UTF_8);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(bytes);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         assertEquals(new String(dataObject.getValueAsByteArray()), value);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with an existing file
         inFile = new File(System.getProperty("user.dir") + "/src/test/resources/container.json");
         assertEquals(true, inFile.isFile());
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(inFile);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, inFile));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")),
                  Files.toString(inFile, Charsets.UTF_8).length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with a temporary file that we create
         // on the fly
         // with default Charset
         value = "Hello CDMI World 10";
         Files.write(value, tmpFileIn, Charsets.UTF_8);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with a temporary file that we create
         // on the fly
         // specify charset UTF_8
         Files.write(value, tmpFileIn, Charsets.UTF_8);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn, Charsets.UTF_8);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with a temporary file that we create
         // on the fly
         // specify charset US_ASCII
         Files.write(value, tmpFileIn, Charsets.US_ASCII);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn, Charsets.US_ASCII);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with a temporary file with multiple
         // lines
         // with default Charset
         Files.write("line1", tmpFileIn, Charsets.UTF_8);
         Files.append("\nline2", tmpFileIn, Charsets.UTF_8);
         Files.append("\nline3", tmpFileIn, Charsets.UTF_8);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(tmpFileIn);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3");
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")),
                  Files.toString(tmpFileIn, Charsets.UTF_8).length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with a temporary file with multiple
         // lines
         // with Charset UTF_8
         Files.write("line1", tmpFileIn, Charsets.UTF_8);
         Files.append("\nline2", tmpFileIn, Charsets.UTF_8);
         Files.append("\nline3", tmpFileIn, Charsets.UTF_8);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(new FileInputStream(tmpFileIn));
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3");
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")),
                  Files.toString(tmpFileIn, Charsets.UTF_8).length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with a temporary file with multiple
         // lines
         // with Charset ISO_8859_1
         Files.write("line1", tmpFileIn, Charsets.ISO_8859_1);
         Files.append("\nline2", tmpFileIn, Charsets.ISO_8859_1);
         Files.append("\nline3", tmpFileIn, Charsets.ISO_8859_1);
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(new FileInputStream(tmpFileIn),
                  Charsets.ISO_8859_1);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), "line1\nline2\nline3");
         tmpFileOut = dataObject.getValueAsFile(Files.createTempDir());
         assertEquals(true, Files.equal(tmpFileOut, tmpFileIn));
         tmpFileOut.delete();
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")),
                  Files.toString(tmpFileIn, Charsets.ISO_8859_1).length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);

         // exercise create data object with an inputstream
         is = new ByteArrayInputStream(value.getBytes());
         pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value(is);
         dataObject = dataApi.create(dataObjectNameIn, pCreateDataObjectOptions);
         assertNotNull(dataObject);
         dataObject = dataApi.get(dataObjectNameIn);
         assertNotNull(dataObject);
         System.out.println(dataObject);
         System.out.println("value: " + dataObject.getValueAsString());
         assertEquals(dataObject.getValueAsString(), value);
         assertNotNull(dataObject.getValueAsInputSupplier());
         assertEquals(CharStreams.toString(CharStreams.newReaderSupplier(
                  dataObject.getValueAsInputSupplier(Charsets.UTF_8), Charsets.UTF_8)), value);
         assertEquals(Integer.parseInt(dataObject.getSystemMetadata().get("cdmi_size")), value.length());
         assertEquals(dataObject.getObjectName(), dataObjectNameIn);
         assertEquals(dataObject.getObjectType(), "application/cdmi-object");
         assertEquals(dataObject.getParentURI(), "/" + containerName);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), true);
         dataApi.delete(dataObjectNameIn);
         assertEquals(containerApi.get(containerName).getChildren().contains(dataObjectNameIn), false);
      } finally {
         tmpFileIn.delete();
View Full Code Here

TOP

Related Classes of org.jclouds.snia.cdmi.v1.handlers.CDMIErrorHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.