r1.setDescription("This is a file to be renamed");
byte[] r1content = "R2 content".getBytes();
r1.setContent(r1content);
r1.setMediaType("txt");
Comment c1 = new Comment();
c1.setResourcePath(path);
c1.setText("This is a test comment1");
Comment c2 = new Comment();
c2.setResourcePath(path);
c2.setText("This is a test comment2");
r1.setProperty("key1", "value1");
r1.setProperty("key2", "value2");
registry.put(path, r1);
registry.addComment(path, c1);
registry.addComment(path, c2);
registry.applyTag(path, "tag1");
registry.applyTag(path, "tag2");
registry.applyTag(path, "tag3");
registry.rateResource(path, 4);
Resource r2 = registry.get(path);
assertEquals("Properties are not equal", r1.getProperty("key1"), r2.getProperty("key1"));
assertEquals("Properties are not equal", r1.getProperty("key2"), r2.getProperty("key2"));
assertEquals("File content is not matching", new String((byte[]) r1.getContent()),
new String((byte[]) r2.getContent()));
assertTrue(c1.getText() + " is not associated for resource" + path,
containsComment(commentPath, c1.getText()));
assertTrue(c2.getText() + " is not associated for resource" + path,
containsComment(commentPath, c2.getText()));
assertTrue("Tag1 is not exist", containsTag(path, "tag1"));
assertTrue("Tag2 is not exist", containsTag(path, "tag2"));
assertTrue("Tag3 is not exist", containsTag(path, "tag3"));
float rating = registry.getAverageRating(path);
assertEquals("Rating is not mathching", rating, (float) 4.0, (float) 0.01);
assertEquals("Media type not exist", r1.getMediaType(), r2.getMediaType());
// assertEquals("Authour name is not exist", r1.getAuthorUserName(), r2.getAuthorUserName());
assertEquals("Description is not exist", r1.getDescription(), r2.getDescription());
String new_path_returned;
new_path_returned = registry.rename(path, new_path);
assertEquals("New resource path is not equal", new_path, new_path_returned);
/*get renamed resource details*/
Resource r1Renamed = registry.get(new_path);
assertEquals("File content is not matching", new String((byte[]) r2.getContent()),
new String((byte[]) r1Renamed.getContent()));
assertEquals("Properties are not equal", r2.getProperty("key1"),
r1Renamed.getProperty("key1"));
assertEquals("Properties are not equal", r2.getProperty("key2"),
r1Renamed.getProperty("key2"));
assertTrue(c1.getText() + " is not associated for resource" + new_path,
containsComment(commentPathNew, c1.getText()));
assertTrue(c2.getText() + " is not associated for resource" + new_path,
containsComment(commentPathNew, c2.getText()));
assertTrue("Tag1 is not copied", containsTag(new_path, "tag1"));
assertTrue("Tag2 is not copied", containsTag(new_path, "tag2"));
assertTrue("Tag3 is not copied", containsTag(new_path, "tag3"));
float rating1 = registry.getAverageRating(new_path);