ByteArrayInputStream in = new ByteArrayInputStream("abc".getBytes());
asset2.updateBinaryContentAttachment(in);
asset2.updateFormat("xls");
asset2.checkin("");
RestAPI api = new RestAPI(repo);
api.setAssetValidator(new AssetValidator());
Thread.sleep(42);
api.put("packages/testRestPut/asset1.drl", Calendar.getInstance(), new ByteArrayInputStream("qaz".getBytes()), "a new comment");
AssetItem asset1_ = pkg.loadAsset("asset1");
assertEquals("qaz", asset1_.getContent());
assertEquals("a new comment", asset1_.getCheckinComment());
assertTrue(asset1_.getLastModified().after(cd));
api.put("packages/testRestPut/asset2.xls", Calendar.getInstance(), new ByteArrayInputStream("def".getBytes()), "a new comment");
AssetItem asset2_ = pkg.loadAsset("asset2");
assertEquals("def", new String(asset2_.getBinaryContentAsBytes()));
assertEquals("a new comment", asset2_.getCheckinComment());
assertTrue(asset2_.getLastModified().after(cd));
//now check updating the package header
api.put("packages/testRestPut/.package", Calendar.getInstance(), new ByteArrayInputStream("whee".getBytes()), "hey");
pkg = repo.loadModule("testRestPut");
assertEquals("whee", pkg.getStringProperty(ModuleItem.HEADER_PROPERTY_NAME));
try {
api.put("packages/testRestPut/asset1.drl", cd, new ByteArrayInputStream("qaz".getBytes()), "a new comment");
fail("should not be able to do this as it is stale timestamp.");
} catch (Exception e) {
assertNotNull(e.getMessage());
}
try {
api.put("packages/testRestPut/.package", cd, new ByteArrayInputStream("whee".getBytes()), "hey");
fail("should not be able to do this as it is stale timestamp.");
} catch (Exception e) {
assertNotNull(e.getMessage());
}