Package org.jclouds.snia.cdmi.v1.options

Examples of org.jclouds.snia.cdmi.v1.options.ListContainersOptionsTest


      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.getValueAsByteSource());
         assertEquals(dataObject.getValueAsByteSource(Charsets.UTF_8).asCharSource(Charsets.UTF_8).read(), 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


      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

      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.toStringAndClose(payloadOut.openStream()), value);

         payloadIn = newPayload(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.toStringAndClose(payloadOut.openStream()), 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 = Payloads.newByteSourcePayload(ByteSource.wrap(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.toStringAndClose(payloadOut.openStream()), 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");
         is = payloadOut.openStream();
         try {
            Files.asByteSink(tmpFileOut).writeFrom(is);
         } finally {
            Closeables.closeQuietly(is);
         }
         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");
         is = payloadOut.openStream();
         try {
            Files.asByteSink(tmpFileOut).writeFrom(is);
         } finally {
            Closeables.closeQuietly(is);
         }
         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.getValueAsByteSource());
         assertEquals(dataObject.getValueAsByteSource(Charsets.UTF_8).asCharSource(Charsets.UTF_8).read(), 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

      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

      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

      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 jcloud client or must understanding of spec

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

   }

   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
            String content, Class<? extends Exception> expected) {

      CDMIErrorHandler function = new CDMIErrorHandler();

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
      HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
      response.getPayload().getContentMetadata().setContentType(contentType);

      expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
      command.setException(classEq(expected));

      replay(command);

      function.handleError(command, response);

      verify(command);
   }
View Full Code Here

   }

   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
            String content, Class<? extends Exception> expected) {

      CDMIErrorHandler function = new CDMIErrorHandler();

      HttpCommand command = createMock(HttpCommand.class);
      HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
      HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
      response.getPayload().getContentMetadata().setContentType(contentType);

      expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
      command.setException(classEq(expected));

      replay(command);

      function.handleError(command, response);

      verify(command);
   }
View Full Code Here

      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);
View Full Code Here

      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 {
View Full Code Here

TOP

Related Classes of org.jclouds.snia.cdmi.v1.options.ListContainersOptionsTest

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.