add common checks

This commit is contained in:
danikov 2012-02-16 00:57:59 +00:00
parent b0168c1b23
commit 76d28a45e5
1 changed files with 40 additions and 1 deletions

View File

@ -27,6 +27,12 @@ import java.net.URI;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -37,6 +43,18 @@ import com.google.common.collect.Iterables;
*/ */
public class Checks { public class Checks {
public static void checkResourceEntityType(ResourceEntityType<?> resourceEntity) {
// Check optional fields
// NOTE status cannot be checked (TODO: doesn't status have a range of valid values?)
FilesList files = resourceEntity.getFiles();
if (files != null && files.getFiles() != null && !files.getFiles().isEmpty()) {
for (File file : files.getFiles()) checkFile(file);
}
// Check parent type
checkEntityType(resourceEntity);
}
public static void checkEntityType(EntityType<?> entity) { public static void checkEntityType(EntityType<?> entity) {
// Check required fields // Check required fields
assertNotNull(entity.getName(), "The Name attribute of an EntityType must be set"); assertNotNull(entity.getName(), "The Name attribute of an EntityType must be set");
@ -146,6 +164,22 @@ public class Checks {
checkEntityType(task); checkEntityType(task);
} }
public static void checkFile(File file) {
// Check optional fields
// NOTE checksum be checked
Long size = file.getSize();
if(size != null) {
assertTrue(file.size >= 0, "File size must be greater than or equal to 0");
}
Long bytesTransferred = file.getBytesTransferred();
if(bytesTransferred != null) {
assertTrue(bytesTransferred >= 0, "Bytes transferred must be greater than or equal to 0");
}
// Check parent type
checkEntityType(file);
}
public static void checkProgress(Integer progress) { public static void checkProgress(Integer progress) {
assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100"); assertTrue(progress >= 0 && progress <= 100, "The Progress attribute must be between 0 and 100");
} }
@ -159,4 +193,9 @@ public class Checks {
// NOTE vendorSpecificErrorCode cannot be checked // NOTE vendorSpecificErrorCode cannot be checked
// NOTE stackTrace cannot be checked // NOTE stackTrace cannot be checked
} }
public static void checkImageType(String imageType) {
assertTrue(Media.ImageType.ALL.contains(imageType),
"The Image type of a Media must be one of the allowed list");
}
} }