// Create a ProductType.
ProductType productType = new ProductType("1", "GenericFile", "test type",
"repository", "versioner");
// Create a ProductResource using Reference, Metadata and Product instances.
Reference reference1 = new Reference("original1", "dataStore1", 500,
new MimeTypes().forName("text/plain"));
List<Reference> references1 = new ArrayList<Reference>();
references1.add(reference1);
Hashtable metadataEntries1 = new Hashtable<String, Object>();
metadataEntries1.put("product1_meta", "test1");
Metadata metadata1 = new Metadata();
metadata1.addMetadata(metadataEntries1);
Product product1 = new Product();
product1.setProductId("123");
product1.setProductName("test.txt");
product1.setProductType(productType);
ProductResource productResource1 = new ProductResource(product1, metadata1,
references1, new File("/tmp"));
// Create another ProductResource using Reference, Metadata and Product
// instances.
Reference reference2 = new Reference("original2", "dataStore2", 1000,
new MimeTypes().forName("application/pdf"));
List<Reference> references2 = new ArrayList<Reference>();
references2.add(reference2);
Hashtable metadataEntries2 = new Hashtable<String, Object>();
metadataEntries2.put("product2_meta", "test2");
Metadata metadata2 = new Metadata();
metadata2.addMetadata(metadataEntries2);
Product product2 = new Product();
product2.setProductId("456");
product2.setProductName("test2.txt");
product2.setProductType(productType);
ProductResource productResource2 = new ProductResource(product2, metadata2,
references2, new File("/tmp"));
// Create a DatasetResource using ProductType, Metadata and ProductResource
// instances.
Hashtable metadataEntries3 = new Hashtable<String, Object>();
metadataEntries3.put("dataset_meta", "test3");
Metadata metadata3 = new Metadata();
metadata3.addMetadata(metadataEntries3);
DatasetResource resource = new DatasetResource(
productType.getProductTypeId(), productType.getName(), metadata3,
new File("/tmp"));
resource.addProductResource(productResource1);
resource.addProductResource(productResource2);
// Generate the expected output.
String expectedXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<dataset>"
+ "<id>" + productType.getProductTypeId() + "</id>"
+ "<name>" + productType.getName() + "</name>"
+ "<metadata>"
+ "<keyval>"
+ "<key>" + metadata3.getAllKeys().get(0) + "</key>"
+ "<val>" + metadata3.getAllValues().get(0) + "</val>"
+ "</keyval>"
+ "</metadata>"
+ "<products>"
+ "<product>"
+ "<id>" + product1.getProductId() + "</id>"
+ "<name>" + product1.getProductName() + "</name>"
+ "<type>" + productType.getName() + "</type>"
+ "<metadata>"
+ "<keyval>"
+ "<key>" + metadata1.getAllKeys().get(0) + "</key>"
+ "<val>" + metadata1.getAllValues().get(0) + "</val>"
+ "</keyval>"
+ "</metadata>"
+ "<references>"
+ "<reference>"
+ "<productId>" + product1.getProductId() + "</productId>"
+ "<refIndex>0</refIndex>"
+ "<dataStoreReference>"
+ reference1.getDataStoreReference()
+ "</dataStoreReference>"
+ "<originalReference>"
+ reference1.getOrigReference()
+ "</originalReference>"
+ "<mimeType>"
+ reference1.getMimeType().getName()
+ "</mimeType>"
+ "<fileSize>" + reference1.getFileSize() + "</fileSize>"
+ "</reference>"
+ "</references>"
+ "</product>"
+ "<product>"
+ "<id>" + product2.getProductId() + "</id>"
+ "<name>" + product2.getProductName() + "</name>"
+ "<type>" + productType.getName() + "</type>"
+ "<metadata>"
+ "<keyval>"
+ "<key>" + metadata2.getAllKeys().get(0) + "</key>"
+ "<val>" + metadata2.getAllValues().get(0) + "</val>"
+ "</keyval>"
+ "</metadata>"
+ "<references>"
+ "<reference>"
+ "<productId>" + product2.getProductId() + "</productId>"
+ "<refIndex>0</refIndex>"
+ "<dataStoreReference>"
+ reference2.getDataStoreReference()
+ "</dataStoreReference>"
+ "<originalReference>"
+ reference2.getOrigReference()
+ "</originalReference>"
+ "<mimeType>"
+ reference2.getMimeType().getName()
+ "</mimeType>"
+ "<fileSize>" + reference2.getFileSize() + "</fileSize>"
+ "</reference>"
+ "</references>"
+ "</product>"
+ "</products>"
+ "</dataset>";