mirror of https://github.com/apache/jclouds.git
merged cdmi changes and fixed classpath issues
This commit is contained in:
parent
180265fe49
commit
929a9ce044
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.snia.cdmi.v1;
|
package org.jclouds.snia.cdmi.v1;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object Types used in CDMI.
|
* Object Types used in CDMI.
|
||||||
*
|
*
|
||||||
|
@ -27,5 +26,6 @@ package org.jclouds.snia.cdmi.v1;
|
||||||
public interface ObjectTypes {
|
public interface ObjectTypes {
|
||||||
|
|
||||||
public static final String CONTAINER = "application/cdmi-container";
|
public static final String CONTAINER = "application/cdmi-container";
|
||||||
|
public static final String DATAOBJECT = "application/cdmi-object";
|
||||||
|
public static final String CDMIOBJECT = "application/cdmi-object";
|
||||||
}
|
}
|
|
@ -21,10 +21,19 @@ package org.jclouds.snia.cdmi.v1.domain;
|
||||||
import static com.google.common.base.Objects.equal;
|
import static com.google.common.base.Objects.equal;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.jclouds.domain.JsonBall;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Objects.ToStringHelper;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base type for all objects in the CDMI model.
|
* The base type for all objects in the CDMI model.
|
||||||
|
@ -48,6 +57,18 @@ public class CDMIObject {
|
||||||
private String objectID;
|
private String objectID;
|
||||||
private String objectType;
|
private String objectType;
|
||||||
private String objectName;
|
private String objectName;
|
||||||
|
private String parentURI;
|
||||||
|
|
||||||
|
private Map<String, JsonBall> metadata = Maps.newHashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DataObject#getMetadata()
|
||||||
|
*/
|
||||||
|
public B metadata(Map<String, JsonBall> metadata) {
|
||||||
|
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata,
|
||||||
|
"metadata"));
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected B self() {
|
protected B self() {
|
||||||
|
@ -78,24 +99,41 @@ public class CDMIObject {
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see CDMIObject#getParentURI()
|
||||||
|
*/
|
||||||
|
public B parentURI(String parentURI) {
|
||||||
|
this.parentURI = parentURI;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
public CDMIObject build() {
|
public CDMIObject build() {
|
||||||
return new CDMIObject(this);
|
return new CDMIObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected B fromCDMIObject(CDMIObject in) {
|
protected B fromCDMIObject(CDMIObject in) {
|
||||||
return objectID(in.getObjectID()).objectType(in.getObjectType())
|
return objectID(in.getObjectID()).objectType(in.getObjectType())
|
||||||
.objectName(in.getObjectName());
|
.objectName(in.getObjectName())
|
||||||
|
.parentURI(in.getParentURI()).metadata(in.getMetadata());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String objectID;
|
private final String objectID;
|
||||||
private final String objectType;
|
private final String objectType;
|
||||||
private final String objectName;
|
private final String objectName;
|
||||||
|
private String parentURI;
|
||||||
|
private final Map<String, JsonBall> metadata;
|
||||||
|
private Map<String, String> userMetaDataIn;
|
||||||
|
private Map<String, String> systemMetaDataIn;
|
||||||
|
private List<Map<String, String>> aclMetaDataIn;
|
||||||
|
|
||||||
protected CDMIObject(Builder<?> builder) {
|
protected CDMIObject(Builder<?> builder) {
|
||||||
this.objectID = checkNotNull(builder.objectID, "objectID");
|
this.objectID = checkNotNull(builder.objectID, "objectID");
|
||||||
this.objectType = checkNotNull(builder.objectType, "objectType");
|
this.objectType = checkNotNull(builder.objectType, "objectType");
|
||||||
this.objectName = builder.objectName;
|
this.objectName = builder.objectName;
|
||||||
|
this.parentURI = checkNotNull(builder.parentURI, "parentURI");
|
||||||
|
this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata,
|
||||||
|
"metadata"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,6 +172,102 @@ public class CDMIObject {
|
||||||
return (objectName == null) ? "" : objectName;
|
return (objectName == null) ? "" : objectName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* parent URI
|
||||||
|
*/
|
||||||
|
public String getParentURI() {
|
||||||
|
return parentURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metadata for the CDMI object. This field includes any user and system
|
||||||
|
* metadata specified in the request body metadata field, along with storage
|
||||||
|
* system metadata generated by the cloud storage system.
|
||||||
|
*/
|
||||||
|
public Map<String, JsonBall> getMetadata() {
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse Metadata for the container object from the original JsonBall.
|
||||||
|
* System metadata data is prefixed with cdmi. System ACL metadata data is
|
||||||
|
* prefixed with cdmi_acl
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void parseMetadata() {
|
||||||
|
userMetaDataIn = new HashMap<String, String>();
|
||||||
|
systemMetaDataIn = new HashMap<String, String>();
|
||||||
|
aclMetaDataIn = new ArrayList<Map<String, String>>();
|
||||||
|
Iterator<String> keys = metadata.keySet().iterator();
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
String key = keys.next();
|
||||||
|
JsonBall value = metadata.get(key);
|
||||||
|
if (key.startsWith("cdmi")) {
|
||||||
|
if (key.matches("cdmi_acl")) {
|
||||||
|
String[] cdmi_acl_array = value.toString().split("[{}]");
|
||||||
|
for (int i = 0; i < cdmi_acl_array.length; i++) {
|
||||||
|
if (!(cdmi_acl_array[i].startsWith("[")
|
||||||
|
|| cdmi_acl_array[i].startsWith("]") || cdmi_acl_array[i]
|
||||||
|
.startsWith(","))) {
|
||||||
|
HashMap<String, String> aclMap = new HashMap<String, String>();
|
||||||
|
String[] cdmi_acl_member = cdmi_acl_array[i]
|
||||||
|
.split(",");
|
||||||
|
for (String s : cdmi_acl_member) {
|
||||||
|
String cdmi_acl_key = s.substring(0,
|
||||||
|
s.indexOf(":"));
|
||||||
|
String cdmi_acl_value = s.substring(s
|
||||||
|
.indexOf(":") + 1);
|
||||||
|
cdmi_acl_value.replace('"', ' ').trim();
|
||||||
|
aclMap.put(cdmi_acl_key, cdmi_acl_value);
|
||||||
|
}
|
||||||
|
aclMetaDataIn.add(aclMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
systemMetaDataIn.put(key, value.toString()
|
||||||
|
.replace('"', ' ').trim());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userMetaDataIn.put(key, value.toString().replace('"', ' ')
|
||||||
|
.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get User Metadata for the container object. This field includes any user
|
||||||
|
* metadata
|
||||||
|
*/
|
||||||
|
public Map<String, String> getUserMetadata() {
|
||||||
|
if (userMetaDataIn == null) {
|
||||||
|
parseMetadata();
|
||||||
|
}
|
||||||
|
return userMetaDataIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get System Metadata for the container object excluding ACL related
|
||||||
|
* metadata
|
||||||
|
*/
|
||||||
|
public Map<String, String> getSystemMetadata() {
|
||||||
|
if (systemMetaDataIn == null) {
|
||||||
|
parseMetadata();
|
||||||
|
}
|
||||||
|
return systemMetaDataIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get System Metadata for the container object excluding ACL related
|
||||||
|
* metadata
|
||||||
|
*/
|
||||||
|
public List<Map<String, String>> getACLMetadata() {
|
||||||
|
if (aclMetaDataIn == null) {
|
||||||
|
parseMetadata();
|
||||||
|
}
|
||||||
|
return aclMetaDataIn;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o)
|
if (this == o)
|
||||||
|
@ -143,7 +277,9 @@ public class CDMIObject {
|
||||||
CDMIObject that = CDMIObject.class.cast(o);
|
CDMIObject that = CDMIObject.class.cast(o);
|
||||||
return equal(this.objectID, that.objectID)
|
return equal(this.objectID, that.objectID)
|
||||||
&& equal(this.objectName, that.objectName)
|
&& equal(this.objectName, that.objectName)
|
||||||
&& equal(this.objectType, that.objectType);
|
&& equal(this.objectType, that.objectType)
|
||||||
|
&& equal(this.parentURI, that.parentURI)
|
||||||
|
&& equal(this.metadata, that.metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean clone(Object o) {
|
public boolean clone(Object o) {
|
||||||
|
@ -157,7 +293,8 @@ public class CDMIObject {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(objectID, objectName, objectType);
|
return Objects.hashCode(objectID, objectName, objectType, parentURI,
|
||||||
|
metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -167,6 +304,7 @@ public class CDMIObject {
|
||||||
|
|
||||||
protected ToStringHelper string() {
|
protected ToStringHelper string() {
|
||||||
return Objects.toStringHelper("").add("objectID", objectID)
|
return Objects.toStringHelper("").add("objectID", objectID)
|
||||||
.add("objectName", objectName).add("objectType", objectType);
|
.add("objectName", objectName).add("objectType", objectType)
|
||||||
|
.add("parentURI", parentURI).add("metadata", metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,20 +21,11 @@ package org.jclouds.snia.cdmi.v1.domain;
|
||||||
import static com.google.common.base.Objects.equal;
|
import static com.google.common.base.Objects.equal;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.domain.JsonBall;
|
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.google.common.base.Objects.ToStringHelper;
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -55,7 +46,6 @@ public class Container extends CDMIObject {
|
||||||
CDMIObject.Builder<B> {
|
CDMIObject.Builder<B> {
|
||||||
|
|
||||||
private Set<String> children = ImmutableSet.of();
|
private Set<String> children = ImmutableSet.of();
|
||||||
private Map<String, JsonBall> metadata = Maps.newHashMap();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Container#getChildren()
|
* @see Container#getChildren()
|
||||||
|
@ -74,14 +64,6 @@ public class Container extends CDMIObject {
|
||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see Container#getMetadata()
|
|
||||||
*/
|
|
||||||
public B metadata(Map<String, JsonBall> metadata) {
|
|
||||||
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata,
|
|
||||||
"metadata"));
|
|
||||||
return self();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Container build() {
|
public Container build() {
|
||||||
|
@ -89,8 +71,8 @@ public class Container extends CDMIObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public B fromContainer(Container in) {
|
public B fromContainer(Container in) {
|
||||||
return fromCDMIObject(in).children(in.getChildren()).metadata(
|
return fromCDMIObject(in).children(in.getChildren());
|
||||||
in.getMetadata());
|
// .metadata(in.getMetadata());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,18 +80,11 @@ public class Container extends CDMIObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Set<String> children;
|
private final Set<String> children;
|
||||||
private final Map<String, JsonBall> metadata;
|
|
||||||
|
|
||||||
private Map<String, String> userMetaDataIn;
|
|
||||||
private Map<String, String> systemMetaDataIn;
|
|
||||||
private List<Map<String, String>> aclMetaDataIn;
|
|
||||||
|
|
||||||
protected Container(Builder<?> builder) {
|
protected Container(Builder<?> builder) {
|
||||||
super(builder);
|
super(builder);
|
||||||
this.children = ImmutableSet.copyOf(checkNotNull(builder.children,
|
this.children = ImmutableSet.copyOf(checkNotNull(builder.children,
|
||||||
"children"));
|
"children"));
|
||||||
this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata,
|
|
||||||
"metadata"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,93 +95,6 @@ public class Container extends CDMIObject {
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Metadata for the container object. This field includes any user and
|
|
||||||
* system metadata specified in the request body metadata field, along with
|
|
||||||
* storage system metadata generated by the cloud storage system.
|
|
||||||
*/
|
|
||||||
public Map<String, JsonBall> getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse Metadata for the container object from the original JsonBall.
|
|
||||||
* System metadata data is prefixed with cdmi. System ACL metadata data is
|
|
||||||
* prefixed with cdmi_acl
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private void parseMetadata() {
|
|
||||||
userMetaDataIn = new HashMap<String, String>();
|
|
||||||
systemMetaDataIn = new HashMap<String, String>();
|
|
||||||
aclMetaDataIn = new ArrayList<Map<String, String>>();
|
|
||||||
Iterator<String> keys = metadata.keySet().iterator();
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
String key = keys.next();
|
|
||||||
JsonBall value = metadata.get(key);
|
|
||||||
if (key.startsWith("cdmi")) {
|
|
||||||
if (key.matches("cdmi_acl")) {
|
|
||||||
String[] cdmi_acl_array = value.toString().split("[{}]");
|
|
||||||
for (int i = 0; i < cdmi_acl_array.length; i++) {
|
|
||||||
if (!(cdmi_acl_array[i].startsWith("[")
|
|
||||||
|| cdmi_acl_array[i].startsWith("]") || cdmi_acl_array[i]
|
|
||||||
.startsWith(","))) {
|
|
||||||
HashMap<String, String> aclMap = new HashMap<String, String>();
|
|
||||||
String[] cdmi_acl_member = cdmi_acl_array[i]
|
|
||||||
.split(",");
|
|
||||||
for (String s : cdmi_acl_member) {
|
|
||||||
String cdmi_acl_key = s.substring(0,
|
|
||||||
s.indexOf(":"));
|
|
||||||
String cdmi_acl_value = s.substring(s
|
|
||||||
.indexOf(":") + 1);
|
|
||||||
cdmi_acl_value.replace('"', ' ').trim();
|
|
||||||
aclMap.put(cdmi_acl_key, cdmi_acl_value);
|
|
||||||
}
|
|
||||||
aclMetaDataIn.add(aclMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
systemMetaDataIn.put(key, value.toString()
|
|
||||||
.replace('"', ' ').trim());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
userMetaDataIn.put(key, value.toString().replace('"', ' ')
|
|
||||||
.trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get User Metadata for the container object. This field includes any user
|
|
||||||
* metadata
|
|
||||||
*/
|
|
||||||
public Map<String, String> getUserMetadata() {
|
|
||||||
if (userMetaDataIn == null) {
|
|
||||||
parseMetadata();
|
|
||||||
}
|
|
||||||
return userMetaDataIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get System Metadata for the container object excluding ACL related
|
|
||||||
* metadata
|
|
||||||
*/
|
|
||||||
public Map<String, String> getSystemMetadata() {
|
|
||||||
if (systemMetaDataIn == null) {
|
|
||||||
parseMetadata();
|
|
||||||
}
|
|
||||||
return systemMetaDataIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get System Metadata for the container object excluding ACL related
|
|
||||||
* metadata
|
|
||||||
*/
|
|
||||||
public List<Map<String, String>> getACLMetadata() {
|
|
||||||
if (aclMetaDataIn == null) {
|
|
||||||
parseMetadata();
|
|
||||||
}
|
|
||||||
return aclMetaDataIn;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
@ -215,19 +103,17 @@ public class Container extends CDMIObject {
|
||||||
if (o == null || getClass() != o.getClass())
|
if (o == null || getClass() != o.getClass())
|
||||||
return false;
|
return false;
|
||||||
Container that = Container.class.cast(o);
|
Container that = Container.class.cast(o);
|
||||||
return super.equals(that) && equal(this.children, that.children)
|
return super.equals(that) && equal(this.children, that.children);
|
||||||
&& equal(this.metadata, that.metadata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(super.hashCode(), children, metadata);
|
return Objects.hashCode(super.hashCode(), children);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ToStringHelper string() {
|
public ToStringHelper string() {
|
||||||
return super.string().add("children", children)
|
return super.string().add("children", children);
|
||||||
.add("metadata", metadata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,198 @@
|
||||||
|
/**
|
||||||
|
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. jclouds licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.snia.cdmi.v1.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Objects.equal;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.base.Objects.ToStringHelper;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
import com.google.common.io.InputSupplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Kenneth Nagin
|
||||||
|
*/
|
||||||
|
public class DataObject extends CDMIObject {
|
||||||
|
|
||||||
|
public static Builder<?> builder() {
|
||||||
|
return new ConcreteBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Builder<?> toBuilder() {
|
||||||
|
return builder().fromDataObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder<B extends Builder<B>> extends
|
||||||
|
CDMIObject.Builder<B> {
|
||||||
|
private String mimetype = new String();
|
||||||
|
private String value = new String();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DataObject#getMimetype()
|
||||||
|
*/
|
||||||
|
public B mimetype(String mimetype) {
|
||||||
|
this.mimetype = mimetype;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DataObject#getValueAsString()
|
||||||
|
*/
|
||||||
|
public B value(String value) {
|
||||||
|
this.value = value;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataObject build() {
|
||||||
|
return new DataObject(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public B fromDataObject(DataObject in) {
|
||||||
|
return fromCDMIObject(in).mimetype(in.getMimetype());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String mimetype;
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
protected DataObject(Builder<?> builder) {
|
||||||
|
super(builder);
|
||||||
|
this.mimetype = checkNotNull(builder.mimetype, "mimetype");
|
||||||
|
this.value = checkNotNull(builder.value, "value");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's mimetype.
|
||||||
|
*/
|
||||||
|
public String getMimetype() {
|
||||||
|
return mimetype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a String
|
||||||
|
*/
|
||||||
|
public String getValueAsString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a InputStream value character set is
|
||||||
|
* Charsets.UTF_8
|
||||||
|
*
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public InputSupplier<ByteArrayInputStream> getValueAsInputSupplier() {
|
||||||
|
return ByteStreams.newInputStreamSupplier(value.getBytes(Charsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a InputStream
|
||||||
|
*
|
||||||
|
* @param charset
|
||||||
|
* value character set
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public InputSupplier<ByteArrayInputStream> getValueAsInputSupplier(Charset charset) {
|
||||||
|
return ByteStreams.newInputStreamSupplier(value.getBytes(charset));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a ByteArray value character set is
|
||||||
|
* Charsets.UTF_8
|
||||||
|
*
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public byte[] getValueAsByteArray() {
|
||||||
|
return value.getBytes(Charsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a InputStream
|
||||||
|
*
|
||||||
|
* @param charset
|
||||||
|
* value character set
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public byte[] getValueAsByteArray(Charset charset) {
|
||||||
|
return value.getBytes(charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a File value character set is Charsets.UTF_8
|
||||||
|
*
|
||||||
|
* @param destDir
|
||||||
|
* destination directory
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public File getValueAsFile(File destDir) throws IOException {
|
||||||
|
File fileOut = new File(destDir, this.getObjectName());
|
||||||
|
Files.copy(getValueAsInputSupplier(), fileOut);
|
||||||
|
return fileOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get dataObject's value as a File
|
||||||
|
*
|
||||||
|
* @param charset
|
||||||
|
* value character set
|
||||||
|
* @return value
|
||||||
|
*/
|
||||||
|
public File getValueAsFile(File destDir, Charset charset)
|
||||||
|
throws IOException {
|
||||||
|
File fileOut = new File(destDir, this.getObjectName());
|
||||||
|
Files.copy(getValueAsInputSupplier(charset), fileOut);
|
||||||
|
return fileOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
DataObject that = DataObject.class.cast(o);
|
||||||
|
return super.equals(that) && equal(this.mimetype, that.mimetype)
|
||||||
|
&& equal(this.value, that.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(super.hashCode(), mimetype, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ToStringHelper string() {
|
||||||
|
return super.string().add("mimetype", mimetype);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -27,6 +27,8 @@ import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.Headers;
|
import org.jclouds.rest.annotations.Headers;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
@ -36,6 +38,7 @@ import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
||||||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||||
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
||||||
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -68,13 +71,13 @@ public interface ContainerAsyncClient {
|
||||||
@Produces( { ObjectTypes.CONTAINER})
|
@Produces( { ObjectTypes.CONTAINER})
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
@Path("/{containerName}/")
|
@Path("/{containerName}/")
|
||||||
ListenableFuture<Container> createContainer(@PathParam("containerName") String containerName);
|
ListenableFuture<Container> createContainer(@PathParam("containerName") String containerName,
|
||||||
|
CreateContainerOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ContainerClient#createContainer()
|
* @see ContainerClient#createContainer()
|
||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
// @Consumes( { ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON })
|
|
||||||
@Consumes( MediaType.APPLICATION_JSON )
|
@Consumes( MediaType.APPLICATION_JSON )
|
||||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
@Path("/{containerName}/")
|
@Path("/{containerName}/")
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container Object Resource Operations
|
* Container Object Resource Operations
|
||||||
|
@ -32,7 +33,8 @@ import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface ContainerClient {
|
public interface ContainerClient {
|
||||||
Container createContainer(String containerName);
|
Container createContainer(String containerName,
|
||||||
|
CreateContainerOptions... options);
|
||||||
|
|
||||||
Container getContainer(String containerName);
|
Container getContainer(String containerName);
|
||||||
|
|
||||||
|
|
|
@ -18,22 +18,91 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.snia.cdmi.v1.features;
|
package org.jclouds.snia.cdmi.v1.features;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.rest.annotations.ExceptionParser;
|
||||||
import org.jclouds.rest.annotations.Headers;
|
import org.jclouds.rest.annotations.Headers;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.SkipEncoding;
|
import org.jclouds.rest.annotations.SkipEncoding;
|
||||||
|
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||||
|
import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
||||||
|
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||||
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId;
|
||||||
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectNonCDMIOptions;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data Object Resource Operations
|
* Data Object Resource Operations
|
||||||
*
|
*
|
||||||
* @see DataClient
|
* @see DataClient
|
||||||
* @author Adrian Cole
|
* @author Kenneth Nagin
|
||||||
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
||||||
*/
|
*/
|
||||||
@SkipEncoding( { '/', '=' })
|
@SkipEncoding({ '/', '=' })
|
||||||
@RequestFilters( { BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class })
|
@RequestFilters({ BasicAuthenticationAndTenantId.class,
|
||||||
@Headers(keys="X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
StripExtraAcceptHeader.class })
|
||||||
public interface DataAsyncClient {
|
public interface DataAsyncClient {
|
||||||
|
/**
|
||||||
|
* @see DataClient#getDataObject()
|
||||||
|
*/
|
||||||
|
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||||
|
@GET
|
||||||
|
@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
@Path("/{containerName}/{dataObjectName}")
|
||||||
|
ListenableFuture<DataObject> getDataObject(
|
||||||
|
@PathParam("containerName") String containerName,
|
||||||
|
@PathParam("dataObjectName") String dataObjectName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DataClient#createDataObject
|
||||||
|
*/
|
||||||
|
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||||
|
@PUT
|
||||||
|
@Consumes({ ObjectTypes.DATAOBJECT, MediaType.APPLICATION_JSON })
|
||||||
|
@Produces({ ObjectTypes.DATAOBJECT })
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
@Path("/{containerName}/{dataObjectName}")
|
||||||
|
ListenableFuture<DataObject> createDataObject(
|
||||||
|
@PathParam("containerName") String containerName,
|
||||||
|
@PathParam("dataObjectName") String dataObjectName,
|
||||||
|
CreateDataObjectOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DataClient#createDataObjectNonCDMI
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Consumes({ "text/plain" })
|
||||||
|
@Produces({ "text/plain;charset=utf-8" })
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
@Path("/{containerName}/{dataObjectName}")
|
||||||
|
ListenableFuture<Void> createDataObjectNonCDMI(
|
||||||
|
@PathParam("containerName") String containerName,
|
||||||
|
@PathParam("dataObjectName") String dataObjectName,
|
||||||
|
CreateDataObjectNonCDMIOptions... options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see DataClient#deleteDataObject()
|
||||||
|
*/
|
||||||
|
@Headers(keys = "X-CDMI-Specification-Version", values = "{jclouds.api-version}")
|
||||||
|
@DELETE
|
||||||
|
@Consumes(MediaType.TEXT_PLAIN)
|
||||||
|
// note: MediaType.APPLICATION_JSON work also, however without consumes
|
||||||
|
// jclouds throws null exception
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
@Path("/{containerName}/{dataObjectName}")
|
||||||
|
ListenableFuture<Void> deleteDataObject(
|
||||||
|
@PathParam("containerName") String containerName,
|
||||||
|
@PathParam("dataObjectName") String dataObjectName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,29 @@
|
||||||
package org.jclouds.snia.cdmi.v1.features;
|
package org.jclouds.snia.cdmi.v1.features;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
|
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectNonCDMIOptions;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data Object Resource Operations
|
* Data Object Resource Operations
|
||||||
*
|
*
|
||||||
* @see DataAsyncClient
|
* @see DataAsyncClient
|
||||||
* @author Adrian Cole
|
* @author Kenneth Nagin
|
||||||
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
* @see <a href="http://www.snia.org/cdmi">api doc</a>
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface DataClient {
|
public interface DataClient {
|
||||||
|
DataObject createDataObject(String containerName, String dataObjectName,
|
||||||
|
CreateDataObjectOptions... options);
|
||||||
|
|
||||||
|
void createDataObjectNonCDMI(String containerName, String dataObjectName,
|
||||||
|
CreateDataObjectNonCDMIOptions... options );
|
||||||
|
|
||||||
|
DataObject getDataObject(String containerName, String dataObjectName);
|
||||||
|
|
||||||
|
void deleteDataObject(String containerName, String dataObjectName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package org.jclouds.snia.cdmi.v1.options;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains options supported in the REST API for the CREATE container
|
||||||
|
* operation. <h2>
|
||||||
|
*
|
||||||
|
* @author Kenneth Nagin
|
||||||
|
*/
|
||||||
|
public class CreateContainerOptions extends BaseHttpRequestOptions {
|
||||||
|
/**
|
||||||
|
* A name-value pair to associate with the container as metadata.
|
||||||
|
*/
|
||||||
|
public CreateContainerOptions withMetadata(Map<String, String> metadata) {
|
||||||
|
String s = "{ \"metadata\" : {\"key1\" : \"value1\",\"key2\" : \"value2\"} }";
|
||||||
|
this.payload = s;
|
||||||
|
String payload = "{ \"metadata\" : {";
|
||||||
|
String separator = " ";
|
||||||
|
for (Entry<String, String> entry : metadata.entrySet()) {
|
||||||
|
payload = payload + separator + "\"" + entry.getKey() + "\" : \""
|
||||||
|
+ entry.getValue() + "\"";
|
||||||
|
separator = ",";
|
||||||
|
}
|
||||||
|
this.payload = payload + "} }";
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
public static CreateContainerOptions withMetadata(
|
||||||
|
Map<String, String> metadata) {
|
||||||
|
CreateContainerOptions options = new CreateContainerOptions();
|
||||||
|
return (CreateContainerOptions) options.withMetadata(metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.jclouds.snia.cdmi.v1.options;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains options supported in the REST API for the CREATE container
|
||||||
|
* operation. <h2>
|
||||||
|
*
|
||||||
|
* @author Kenneth Nagin
|
||||||
|
*/
|
||||||
|
public class CreateDataObjectNonCDMIOptions extends BaseHttpRequestOptions {
|
||||||
|
/**
|
||||||
|
* A name-value pair to associate with the container as metadata.
|
||||||
|
*/
|
||||||
|
public CreateDataObjectNonCDMIOptions withStringPayload(String value) {
|
||||||
|
this.payload = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
public static CreateDataObjectNonCDMIOptions withStringPayload(
|
||||||
|
String value) {
|
||||||
|
CreateDataObjectNonCDMIOptions options = new CreateDataObjectNonCDMIOptions();
|
||||||
|
return (CreateDataObjectNonCDMIOptions) options.withStringPayload(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,223 @@
|
||||||
|
package org.jclouds.snia.cdmi.v1.options;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.common.io.CharStreams;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CreateDataObjectOptions options supported in the REST API for the CREATE CDMI
|
||||||
|
* Data Object operation. <h2>
|
||||||
|
*
|
||||||
|
* @author Kenneth Nagin
|
||||||
|
*/
|
||||||
|
public class CreateDataObjectOptions extends BaseHttpRequestOptions {
|
||||||
|
private JsonObject jsonObjectBody = new JsonObject();
|
||||||
|
|
||||||
|
public CreateDataObjectOptions() {
|
||||||
|
jsonObjectBody.addProperty("value", new String());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with metadata
|
||||||
|
*
|
||||||
|
* @param metadata
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions metadata(Map<String, String> metadata) {
|
||||||
|
JsonObject jsonObjectMetadata = new JsonObject();
|
||||||
|
if (metadata != null) {
|
||||||
|
for (Entry<String, String> entry : metadata.entrySet()) {
|
||||||
|
jsonObjectMetadata
|
||||||
|
.addProperty(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonObjectBody.add("metadata", jsonObjectMetadata);
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with mimetype
|
||||||
|
*
|
||||||
|
* @param mimetype
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions mimetype(String mimetype) {
|
||||||
|
jsonObjectBody.addProperty("mimetype", mimetype);
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with value equal to empty string
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value() {
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with String value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* String value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value(String value) {
|
||||||
|
jsonObjectBody.addProperty("value", (value == null) ? new String()
|
||||||
|
: value);
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with byte array value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* byte array value byte array is converted to a String value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value(byte[] value) throws IOException {
|
||||||
|
jsonObjectBody.addProperty("value",
|
||||||
|
(value == null) ? new String() : new DataInputStream(
|
||||||
|
new ByteArrayInputStream(value)).readUTF());
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with file value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* File File is converted to a String value with charset UTF_8
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value(File value) throws IOException {
|
||||||
|
jsonObjectBody.addProperty("value", (value == null) ? new String()
|
||||||
|
: Files.toString(value, Charsets.UTF_8));
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with file value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* File
|
||||||
|
* @param charset
|
||||||
|
* character set of file File is converted to a String value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value(File value, Charset charset)
|
||||||
|
throws IOException {
|
||||||
|
jsonObjectBody.addProperty("value", (value == null) ? new String()
|
||||||
|
: Files.toString(value, charset));
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with InputStream value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* InputSteam InputSteam is converted to a String value with
|
||||||
|
* charset UTF_8
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value(InputStream value) throws IOException {
|
||||||
|
jsonObjectBody
|
||||||
|
.addProperty(
|
||||||
|
"value",
|
||||||
|
(value == null) ? new String() : CharStreams
|
||||||
|
.toString(new InputStreamReader(value,
|
||||||
|
Charsets.UTF_8)));
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create CDMI data object with InputStream value
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* InputSteam
|
||||||
|
* @param charset
|
||||||
|
* character set of input stream InputSteam is converted to a
|
||||||
|
* String value with charset UTF_8
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public CreateDataObjectOptions value(InputStream value, Charset charset)
|
||||||
|
throws IOException {
|
||||||
|
jsonObjectBody.addProperty("value", (value == null) ? new String()
|
||||||
|
: CharStreams.toString(new InputStreamReader(value, charset)));
|
||||||
|
this.payload = jsonObjectBody.toString();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
public static CreateDataObjectOptions metadata(
|
||||||
|
Map<String, String> metadata) {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.metadata(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions mimetype(String mimetype) {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.mimetype(mimetype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value() {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value(String value) {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value(byte[] value)
|
||||||
|
throws IOException {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value(File value)
|
||||||
|
throws IOException {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value(File value, Charset charset)
|
||||||
|
throws IOException {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value(value, charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value(InputStream value)
|
||||||
|
throws IOException {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CreateDataObjectOptions value(InputStream value,
|
||||||
|
Charset charset) throws IOException {
|
||||||
|
CreateDataObjectOptions options = new CreateDataObjectOptions();
|
||||||
|
return (CreateDataObjectOptions) options.value(value, charset);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,27 +21,41 @@ package org.jclouds.snia.cdmi.v1.features;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.jclouds.domain.JsonBall;
|
||||||
import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
import org.jclouds.snia.cdmi.v1.ObjectTypes;
|
||||||
import org.jclouds.snia.cdmi.v1.domain.Container;
|
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||||
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest;
|
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Kenneth Nagin
|
* @author Kenneth Nagin
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Test(groups = "live", testName = "ContainerClientLiveTest")
|
@Test(groups = "live", testName = "ContainerClientLiveTest")
|
||||||
public class ContainerClientLiveTest extends BaseCDMIClientLiveTest {
|
public class ContainerClientLiveTest extends BaseCDMIClientLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateContainer() throws Exception {
|
public void testCreateContainer() throws Exception {
|
||||||
String pContainerName = "MyContainer" + System.currentTimeMillis();
|
String pContainerName = "MyContainer" + System.currentTimeMillis();
|
||||||
|
Map<String, String> pContainerMetaDataIn = new HashMap<String, String>();
|
||||||
|
Iterator<String> keys;
|
||||||
|
pContainerMetaDataIn.put("containerkey1", "value1");
|
||||||
|
pContainerMetaDataIn.put("containerkey2", "value2");
|
||||||
|
pContainerMetaDataIn.put("containerkey3", "value3");
|
||||||
|
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||||
|
.withMetadata(pContainerMetaDataIn);
|
||||||
ContainerClient client = cdmiContext.getApi().getContainerClient();
|
ContainerClient client = cdmiContext.getApi().getContainerClient();
|
||||||
Logger.getAnonymousLogger().info("createContainer: " + pContainerName);
|
Logger.getAnonymousLogger().info("createContainer: " + pContainerName);
|
||||||
Container container = client.createContainer(pContainerName);
|
Container container = client.createContainer(pContainerName,
|
||||||
|
pCreateContainerOptions);
|
||||||
assertNotNull(container);
|
assertNotNull(container);
|
||||||
System.out.println(container);
|
System.out.println(container);
|
||||||
Logger.getAnonymousLogger().info("getContainer: " + pContainerName);
|
Logger.getAnonymousLogger().info("getContainer: " + pContainerName);
|
||||||
|
@ -52,11 +66,27 @@ public class ContainerClientLiveTest extends BaseCDMIClientLiveTest {
|
||||||
assertNotNull(container.getObjectID());
|
assertNotNull(container.getObjectID());
|
||||||
assertNotNull(container.getObjectName());
|
assertNotNull(container.getObjectName());
|
||||||
assertEquals(container.getObjectName(), pContainerName + "/");
|
assertEquals(container.getObjectName(), pContainerName + "/");
|
||||||
|
assertEquals(container.getParentURI(), "/");
|
||||||
assertNotNull(container.getChildren());
|
assertNotNull(container.getChildren());
|
||||||
assertEquals(container.getChildren().isEmpty(), true);
|
assertEquals(container.getChildren().isEmpty(), true);
|
||||||
System.out.println("Children: " + container.getChildren());
|
System.out.println("Children: " + container.getChildren());
|
||||||
assertNotNull(container.getMetadata());
|
assertNotNull(container.getMetadata());
|
||||||
|
System.out.println("Raw metadata: " + container.getMetadata());
|
||||||
|
keys = container.getMetadata().keySet().iterator();
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
String key = keys.next();
|
||||||
|
JsonBall value = container.getMetadata().get(key);
|
||||||
|
System.out.println(key + ":" + value);
|
||||||
|
}
|
||||||
assertNotNull(container.getUserMetadata());
|
assertNotNull(container.getUserMetadata());
|
||||||
|
Map<String, String> pContainerMetaDataOut = container.getUserMetadata();
|
||||||
|
keys = pContainerMetaDataIn.keySet().iterator();
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
String key = keys.next();
|
||||||
|
assertEquals(pContainerMetaDataOut.containsKey(key), true);
|
||||||
|
assertEquals(pContainerMetaDataOut.get(key),
|
||||||
|
pContainerMetaDataIn.get(key));
|
||||||
|
}
|
||||||
System.out.println("UserMetaData: " + container.getUserMetadata());
|
System.out.println("UserMetaData: " + container.getUserMetadata());
|
||||||
assertNotNull(container.getSystemMetadata());
|
assertNotNull(container.getSystemMetadata());
|
||||||
System.out.println("SystemMetaData: " + container.getSystemMetadata());
|
System.out.println("SystemMetaData: " + container.getSystemMetadata());
|
||||||
|
@ -68,12 +98,14 @@ public class ContainerClientLiveTest extends BaseCDMIClientLiveTest {
|
||||||
}
|
}
|
||||||
container = client.getContainer("/");
|
container = client.getContainer("/");
|
||||||
System.out.println("root container: " + container);
|
System.out.println("root container: " + container);
|
||||||
assertEquals(container.getChildren().contains(pContainerName + "/"), true);
|
assertEquals(container.getChildren().contains(pContainerName + "/"),
|
||||||
|
true);
|
||||||
Logger.getAnonymousLogger().info("deleteContainer: " + pContainerName);
|
Logger.getAnonymousLogger().info("deleteContainer: " + pContainerName);
|
||||||
client.deleteContainer(pContainerName);
|
client.deleteContainer(pContainerName);
|
||||||
container = client.getContainer("/");
|
container = client.getContainer("/");
|
||||||
System.out.println("root container: " + container);
|
System.out.println("root container: " + container);
|
||||||
assertEquals(container.getChildren().contains(pContainerName + "/"), false);
|
assertEquals(container.getChildren().contains(pContainerName + "/"),
|
||||||
|
false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,592 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.snia.cdmi.v1.features;
|
package org.jclouds.snia.cdmi.v1.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.jclouds.snia.cdmi.v1.domain.Container;
|
||||||
|
import org.jclouds.snia.cdmi.v1.domain.DataObject;
|
||||||
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest;
|
import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateContainerOptions;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectNonCDMIOptions;
|
||||||
|
import org.jclouds.snia.cdmi.v1.options.CreateDataObjectOptions;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.io.CharStreams;
|
||||||
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Kenneth Nagin
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", testName = "DataClientLiveTest")
|
@Test(groups = "live", testName = "DataClientLiveTest")
|
||||||
public class DataClientLiveTest extends BaseCDMIClientLiveTest {
|
public class DataClientLiveTest extends BaseCDMIClientLiveTest {
|
||||||
|
@Test
|
||||||
|
public void testCreateDataObjects() throws Exception {
|
||||||
|
|
||||||
|
String containerName = "MyContainer" + System.currentTimeMillis();
|
||||||
|
String dataObjectNameIn = "dataobject1.txt";
|
||||||
|
File tmpFileIn = new File("temp.txt");
|
||||||
|
String value;
|
||||||
|
InputStream is;
|
||||||
|
File tmpFileOut;
|
||||||
|
Files.touch(tmpFileIn);
|
||||||
|
CreateDataObjectOptions pCreateDataObjectOptions;
|
||||||
|
DataObject dataObject;
|
||||||
|
Iterator<String> keys;
|
||||||
|
Map<String, String> dataObjectMetaDataOut;
|
||||||
|
Map<String, String> pContainerMetaDataIn = new HashMap<String, String>();
|
||||||
|
Map<String, String> pDataObjectMetaDataIn = new LinkedHashMap<String, String>();
|
||||||
|
pDataObjectMetaDataIn.put("dataObjectkey1", "value1");
|
||||||
|
pDataObjectMetaDataIn.put("dataObjectkey2", "value2");
|
||||||
|
pDataObjectMetaDataIn.put("dataObjectkey3", "value3");
|
||||||
|
|
||||||
|
CreateContainerOptions pCreateContainerOptions = CreateContainerOptions.Builder
|
||||||
|
.withMetadata(pContainerMetaDataIn);
|
||||||
|
ContainerClient containerClient = cdmiContext.getApi()
|
||||||
|
.getContainerClient();
|
||||||
|
DataClient dataClient = cdmiContext.getApi().getDataClient();
|
||||||
|
Logger.getAnonymousLogger().info("createContainer: " + containerName);
|
||||||
|
Container container = containerClient.createContainer(containerName,
|
||||||
|
pCreateContainerOptions);
|
||||||
|
try {
|
||||||
|
assertNotNull(container);
|
||||||
|
System.out.println(container);
|
||||||
|
container = containerClient.getContainer(containerName);
|
||||||
|
assertNotNull(container);
|
||||||
|
assertNotNull(container.getChildren());
|
||||||
|
assertEquals(container.getChildren().isEmpty(), true);
|
||||||
|
|
||||||
|
// exercise create data object with none cdmi put
|
||||||
|
value = "Hello CDMI World1";
|
||||||
|
CreateDataObjectNonCDMIOptions pCreateDataObjectNoneCDMIOptions = CreateDataObjectNonCDMIOptions.Builder
|
||||||
|
.withStringPayload(value);
|
||||||
|
dataClient.createDataObjectNonCDMI(containerName, dataObjectNameIn,
|
||||||
|
pCreateDataObjectNoneCDMIOptions);
|
||||||
|
System.out.println(containerClient.getContainer(containerName));
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
dataObjectNameIn);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
System.out.println(dataObject);
|
||||||
|
System.out.println("value: " + dataObject.getValueAsString());
|
||||||
|
assertEquals(dataObject.getValueAsString(), 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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
// exercise create data object with value mimetype and metadata
|
||||||
|
value = "Hello CDMI World2";
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||||
|
.value(value).mimetype("text/plain")
|
||||||
|
.metadata(pDataObjectMetaDataIn);
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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);
|
||||||
|
keys = pDataObjectMetaDataIn.keySet().iterator();
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
String key = keys.next();
|
||||||
|
assertEquals(dataObjectMetaDataOut.containsKey(key), true);
|
||||||
|
assertEquals(dataObjectMetaDataOut.get(key),
|
||||||
|
pDataObjectMetaDataIn.get(key));
|
||||||
|
}
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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);
|
||||||
|
keys = pDataObjectMetaDataIn.keySet().iterator();
|
||||||
|
while (keys.hasNext()) {
|
||||||
|
String key = keys.next();
|
||||||
|
assertEquals(dataObjectMetaDataOut.containsKey(key), true);
|
||||||
|
assertEquals(dataObjectMetaDataOut.get(key),
|
||||||
|
pDataObjectMetaDataIn.get(key));
|
||||||
|
}
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
// exercise create data object with only value
|
||||||
|
value = "Hello CDMI World6";
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||||
|
.value(value);
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
dataObjectNameIn);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
System.out.println(dataObject);
|
||||||
|
System.out.println("value: " + dataObject.getValueAsString());
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
// exercise create data object with empty mimetype only
|
||||||
|
value = "";
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||||
|
.mimetype(new String());
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(true, dataObjectMetaDataOut.isEmpty());
|
||||||
|
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
|
||||||
|
// exercise create data object with no value
|
||||||
|
value = "";
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder.value();
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
dataObjectNameIn);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
System.out.println(dataObject);
|
||||||
|
System.out.println("value: " + dataObject.getValueAsString());
|
||||||
|
assertEquals(dataObject.getValueAsString(), "");
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
// exercise create data object with byte array
|
||||||
|
value = "Hello CDMI World 7";
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream out = new DataOutputStream(bos);
|
||||||
|
out.writeUTF(value);
|
||||||
|
out.close();
|
||||||
|
byte[] bytes = bos.toByteArray();
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||||
|
.value(bytes);
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
// exercise create data object with an existing file
|
||||||
|
File inFile = new File(System.getProperty("user.dir")
|
||||||
|
+ "/src/test/resources/container.json");
|
||||||
|
assertEquals(true, inFile.isFile());
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||||
|
.value(inFile);
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(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 = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
// exercise create data object with an inputstream
|
||||||
|
is = new ByteArrayInputStream(value.getBytes());
|
||||||
|
pCreateDataObjectOptions = CreateDataObjectOptions.Builder
|
||||||
|
.value(is);
|
||||||
|
dataObject = dataClient.createDataObject(containerName,
|
||||||
|
dataObjectNameIn, pCreateDataObjectOptions);
|
||||||
|
assertNotNull(dataObject);
|
||||||
|
dataObject = dataClient.getDataObject(containerName,
|
||||||
|
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(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), true);
|
||||||
|
dataClient.deleteDataObject(containerName, dataObjectNameIn);
|
||||||
|
assertEquals(containerClient.getContainer(containerName)
|
||||||
|
.getChildren().contains(dataObjectNameIn), false);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
tmpFileIn.delete();
|
||||||
|
containerClient.deleteContainer(containerName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class ParseContainerTest extends BaseItemParserTest<Container> {
|
||||||
.objectType("application/cdmi-container")
|
.objectType("application/cdmi-container")
|
||||||
.objectID("00007E7F00102E230ED82694DAA975D2")
|
.objectID("00007E7F00102E230ED82694DAA975D2")
|
||||||
.objectName("MyContainer/")
|
.objectName("MyContainer/")
|
||||||
|
.parentURI("/")
|
||||||
.metadata(ImmutableMap.<String, JsonBall>builder()
|
.metadata(ImmutableMap.<String, JsonBall>builder()
|
||||||
.put("cdmi_size", new JsonBall("\"83\""))
|
.put("cdmi_size", new JsonBall("\"83\""))
|
||||||
.build())
|
.build())
|
||||||
|
|
Loading…
Reference in New Issue