public void GeneralCollectionRenameTest() throws RegistryException { Resource r1 = registry.newResource(); r1.setProperty("test", "rename"); r1.setContent("some text"); registry.put("/c2/rename3/c1/dummy", r1); registry.rename("/c2/rename3", "rename4"); boolean failed = false; try { Resource originalR1 = registry.get("/c2/rename3/c1/dummy"); } catch (RegistryException e) { failed = true; } assertTrue( "Resource should not be " + "accessible from the old path after renaming the parent.", failed); Resource newR1 = registry.get("/c2/rename4/c1/dummy"); assertEquals( "Resource should contain a property with name test and value rename.", newR1.getProperty("test"), "rename"); }
@Test(groups = {"wso2.greg"}) public void ContinuousDelete() throws RegistryException, InterruptedException { int iterations = 100; for (int i = 0; i < iterations; i++) { Resource res1 = registry.newResource(); byte[] r1content = "R2 content".getBytes(); res1.setContent(r1content); String path = "/con-delete/test/" + i + 1; registry.put(path, res1); Resource resource1 = registry.get(path); assertEquals( new String((byte[]) resource1.getContent()), new String((byte[]) res1.getContent()), "File content is not matching"); registry.delete(path); boolean value = false; if (registry.resourceExists(path)) { value = true; } assertFalse(value, "Resource found at the path"); res1.discard(); resource1.discard(); Thread.sleep(100); } }
public void ResourceCopyTest() throws RegistryException { Resource r1 = registry.newResource(); r1.setProperty("test", "copy"); r1.setContent("c"); registry.put("/test1/copy/c1/copy1", r1); Collection c1 = registry.newCollection(); registry.put("/test1/move", c1); registry.copy("/test1/copy/c1/copy1", "/test1/copy/c2/copy2"); Resource newR1 = registry.get("/test1/copy/c2/copy2"); assertEquals( "Copied resource should have a property named 'test' with value 'copy'.", newR1.getProperty("test"), "copy"); Resource oldR1 = registry.get("/test1/copy/c1/copy1"); assertEquals( "Original resource should have a property named 'test' with value 'copy'.", oldR1.getProperty("test"), "copy"); String newContent = new String((byte[]) newR1.getContent()); String oldContent = new String((byte[]) oldR1.getContent()); assertEquals("Contents are not equal in copied resources", newContent, oldContent); }
@Test(groups = {"wso2.greg"}) public void CommentDelete() throws Exception { String r1Path = "/_c1d1/c1"; Collection r1 = registry.newCollection(); registry.put(r1Path, r1); String c1Path = registry.addComment(r1Path, new Comment("test comment1")); registry.addComment(r1Path, new Comment("test comment2")); Comment[] comments1 = registry.getComments(r1Path); assertEquals(comments1.length, 2, "There should be two comments."); String[] cTexts1 = {comments1[0].getText(), comments1[1].getText()}; assertTrue(containsString(cTexts1, "test comment1"), "comment is missing"); assertTrue(containsString(cTexts1, "test comment2"), "comment is missing"); registry.delete(comments1[0].getPath()); Comment[] comments2 = registry.getComments(r1Path); assertEquals(comments2.length, 1, "There should be one comment."); String[] cTexts2 = {comments2[0].getText()}; assertTrue(containsString(cTexts2, "test comment2"), "comment is missing"); assertTrue(!containsString(cTexts2, "test comment1"), "deleted comment still exists"); }
@Before public void setUp() throws Exception { super.setUp(); boolean exists = false; try { RemoteRegistry wso2 = RSProviderUtil.getRegistry(); exists = wso2.resourceExists("/"); for (String resource : resources) { if (wso2.resourceExists(resource)) { wso2.delete(resource); } } } catch (Exception ex) { } assertTrue(exists); }
@Test(groups = {"wso2.greg"}) public void ContinuousUpdate() throws RegistryException, InterruptedException { int iterations = 100; for (int i = 0; i < iterations; i++) { Resource res1 = registry.newResource(); byte[] r1content = "R2 content".getBytes(); res1.setContent(r1content); String path = "/con-delete/test-update/" + i + 1; registry.put(path, res1); Resource resource1 = registry.get(path); assertEquals( new String((byte[]) resource1.getContent()), new String((byte[]) res1.getContent()), "File content is not matching"); Resource resource = new ResourceImpl(); byte[] r1content1 = "R2 content updated".getBytes(); resource.setContent(r1content1); resource.setProperty("abc", "abc"); registry.put(path, resource); Resource resource2 = registry.get(path); assertEquals( new String((byte[]) resource2.getContent()), new String((byte[]) resource.getContent()), "File content is not matching"); resource.discard(); res1.discard(); resource1.discard(); resource2.discard(); Thread.sleep(100); } }
public void RootLevelResourceRenameTest() throws RegistryException { Resource r1 = registry.newResource(); r1.setProperty("test", "rename"); r1.setContent("some text"); registry.put("/rename2", r1); registry.rename("/rename2", "/rename4"); boolean failed = false; try { registry.get("/rename2"); } catch (RegistryException e) { failed = true; } assertTrue("Resource should not be accessible from the old path after renaming.", failed); Resource newR1 = registry.get("/rename4"); assertEquals( "Resource should contain a property with name test and value rename.", newR1.getProperty("test"), "rename"); }
@Test public void updateTest() throws Exception { boolean clean = false; try { RemoteRegistry wso2 = RSProviderUtil.getRegistry(); clean = !wso2.resourceExists(resources[0]); } catch (RegistryException e) { } assertTrue(clean); // first, create the complete asset CreateCompleteAssetResponse response = createAsset(); assertEquals(AckValue.SUCCESS, response.getAck()); assertEquals(null, response.getErrorMessage()); // then, update the complete asset, replacing all its related objects UpdateAssetDependenciesResponse responseUpdate = updateDependencies(response.getAssetKey().getAssetId()); assertEquals(AckValue.SUCCESS, responseUpdate.getAck()); assertEquals(null, responseUpdate.getErrorMessage()); validateAsset(response.getAssetKey().getAssetId()); }
public void CollectionCopyTest() throws RegistryException { Resource r1 = registry.newResource(); r1.setProperty("test", "copy"); r1.setContent("c"); registry.put("/test1/copy/copy3/c3/resource1", r1); Collection c1 = registry.newCollection(); registry.put("/test1/move", c1); registry.copy("/test1/copy/copy3", "/test1/newc/copy3"); Resource newR1 = registry.get("/test1/newc/copy3/c3/resource1"); assertEquals( "Copied resource should have a property named 'test' with value 'copy'.", newR1.getProperty("test"), "copy"); Resource oldR1 = registry.get("/test1/copy/copy3/c3/resource1"); assertEquals( "Original resource should have a property named 'test' with value 'copy'.", oldR1.getProperty("test"), "copy"); }
@Test(groups = {"wso2.greg"}) public void AddComment() throws Exception { Resource r1 = registry.newResource(); String path = "/d112/r3"; byte[] r1content = "R1 content".getBytes(); r1.setContent(r1content); registry.put(path, r1); String comment1 = "this is qa comment 4"; String comment2 = "this is qa comment 5"; Comment c1 = new Comment(); c1.setResourcePath(path); c1.setText("This is default comment"); c1.setUser("admin1"); registry.addComment(path, c1); registry.addComment(path, new Comment(comment1)); registry.addComment(path, new Comment(comment2)); Comment[] comments = registry.getComments(path); boolean commentFound = false; for (Comment comment : comments) { if (comment.getText().equals(comment1)) { commentFound = true; // System.out.println(comment.getPath()); assertEquals(comment.getText(), comment1); assertEquals(comment.getUser(), "admin"); assertEquals(comment.getResourcePath(), path); // System.out.println(comment.getPath()); // break; } if (comment.getText().equals(comment2)) { commentFound = true; assertEquals(comment.getText(), comment2); assertEquals(comment.getUser(), "admin"); assertEquals(comment.getResourcePath(), path); // break; } if (comment.getText().equals("This is default comment")) { commentFound = true; assertEquals(comment.getText(), "This is default comment"); assertEquals(comment.getUser(), "admin"); // break; } } assertTrue(commentFound, "No comment is associated with the resource" + path); Resource commentsResource = registry.get("/d112/r3;comments"); assertTrue( commentsResource instanceof Collection, "Comment collection resource should be a directory."); comments = (Comment[]) commentsResource.getContent(); List commentTexts = new ArrayList(); for (Comment comment : comments) { Resource commentResource = registry.get(comment.getPath()); commentTexts.add(new String((byte[]) commentResource.getContent())); } assertTrue( commentTexts.contains(comment1), comment1 + " is not associated with the resource /d112/r3."); assertTrue( commentTexts.contains(comment2), comment2 + " is not associated with the resource /d112/r3."); }
@Test(groups = {"wso2.greg"}) public void EditComment() throws Exception { Resource r1 = registry.newResource(); byte[] r1content = "R1 content".getBytes(); r1.setContent(r1content); r1.setDescription("this is a resource to edit comment"); registry.put("/c101/c11/r1", r1); Comment c1 = new Comment(); c1.setResourcePath("/c10/c11/r1"); c1.setText("This is default comment "); c1.setUser("admin"); registry.addComment("/c101/c11/r1", c1); Comment[] comments = registry.getComments("/c101/c11/r1"); boolean commentFound = false; for (Comment comment : comments) { if (comment.getText().equals(c1.getText())) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // //System.out.println("\n"); // break; } } assertTrue( commentFound, "comment:" + c1.getText() + " is not associated with the artifact /c101/c11/r1"); try { Resource commentsResource = registry.get("/c101/c11/r1;comments"); assertTrue(commentsResource instanceof Collection, "Comment resource should be a directory."); comments = (Comment[]) commentsResource.getContent(); List commentTexts = new ArrayList(); for (Comment comment : comments) { Resource commentResource = registry.get(comment.getPath()); commentTexts.add(new String((byte[]) commentResource.getContent())); } assertTrue( commentTexts.contains(c1.getText()), c1.getText() + " is not associated for resource /c101/c11/r1."); registry.editComment(comments[0].getPath(), "This is the edited comment"); comments = registry.getComments("/c101/c11/r1"); // System.out.println(comments); Resource resource = registry.get(comments[0].getPath()); assertEquals(new String((byte[]) resource.getContent()), "This is the edited comment"); } catch (RegistryException e) { e.printStackTrace(); fail("Failed to get comments form URL:/c101/c11/r1;comments"); } /*Edit comment goes here*/ registry.editComment("/c101/c11/r1", "This is the edited comment"); }
@Test(groups = {"wso2.greg"}) public void AddCommenttoRoot() { String comment1 = "this is qa comment 1 for root"; String comment2 = "this is qa comment 2 for root"; Comment c1 = new Comment(); c1.setResourcePath("/"); c1.setText("This is default comment for root"); c1.setUser("admin"); try { registry.addComment("/", c1); registry.addComment("/", new Comment(comment1)); registry.addComment("/", new Comment(comment2)); } catch (RegistryException e) { fail("Valid commenting for resources scenario failed"); } Comment[] comments = null; try { comments = registry.getComments("/"); } catch (RegistryException e) { fail("Failed to get comments for the resource /"); } boolean commentFound = false; for (Comment comment : comments) { if (comment.getText().equals(comment1)) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // //System.out.println("\n"); // break; } if (comment.getText().equals(comment2)) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // //System.out.println("\n"); // break; } if (comment.getText().equals(c1.getText())) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // //System.out.println("\n"); // break; } } assertTrue(commentFound, "comment '" + comment1 + " is not associated with the artifact /"); try { Resource commentsResource = registry.get("/;comments"); assertTrue( commentsResource instanceof Collection, "Comment collection resource should be a directory."); comments = (Comment[]) commentsResource.getContent(); List commentTexts = new ArrayList(); for (Comment comment : comments) { Resource commentResource = registry.get(comment.getPath()); commentTexts.add(new String((byte[]) commentResource.getContent())); } assertTrue(commentTexts.contains(comment1), comment1 + " is not associated for resource /."); assertTrue(commentTexts.contains(comment2), comment2 + " is not associated for resource /."); } catch (RegistryException e) { fail("Failed to get comments form URL: /;comments"); } }
@Test(groups = {"wso2.greg"}) public void AddCommentToResource() throws Exception { Resource r1 = registry.newResource(); byte[] r1content = "R1 content".getBytes(); r1.setContent(r1content); registry.put("/d1/r3", r1); String comment1 = "this is qa comment 4"; String comment2 = "this is qa comment 5"; Comment c1 = new Comment(); c1.setResourcePath("/d1/r3"); c1.setText("This is default comment"); c1.setUser("admin"); registry.addComment("/d1/r3", c1); registry.addComment("/d1/r3", new Comment(comment1)); registry.addComment("/d1/r3", new Comment(comment2)); Comment[] comments = registry.getComments("/d1/r3"); boolean commentFound = false; for (Comment comment : comments) { if (comment.getText().equals(comment1)) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // break; } if (comment.getText().equals(comment2)) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // break; } if (comment.getText().equals("This is default comment")) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // break; } } assertTrue( commentFound, "comment '" + comment1 + " is not associated with the artifact /d1/r3"); Resource commentsResource = registry.get("/d1/r3;comments"); assertTrue( commentsResource instanceof Collection, "Comment collection resource should be a directory."); comments = (Comment[]) commentsResource.getContent(); List commentTexts = new ArrayList(); for (Comment comment : comments) { Resource commentResource = registry.get(comment.getPath()); commentTexts.add(new String((byte[]) commentResource.getContent())); } assertTrue( commentTexts.contains(comment1), comment1 + " is not associated for resource /d1/r3."); assertTrue( commentTexts.contains(comment2), comment2 + " is not associated for resource /d1/r3."); /*try { //registry.delete("/d12"); } catch (RegistryException e) { fail("Failed to delete test resources."); } */ }
// All the following methods are used in the above methods. So no need to add them to the test // suit. public static boolean resourceExists(RemoteRegistry registry, String fileName) throws Exception { boolean value; value = registry.resourceExists(fileName); return value; }
/** * @param args * @throws RegistryException * @throws IOException */ public static void main(String[] args) throws RegistryException, IOException { System.setProperty( "javax.net.ssl.trustStore", "/home/saminda/Downloads/wso2esb-3.0.0-SNAPSHOT/resources/security/client-truststore.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); System.setProperty("javax.net.ssl.trustStoreType", "JKS"); RemoteRegistry registry = new RemoteRegistry(new URL("https://localhost:9443/registry"), "admin", "admin"); Resource resource3 = registry.get("/repository/components/org.wso2.carbon.event/index/TopicIndex;version:600"); new FileOutputStream(new File("/home/saminda/tmp/test123356.txt")) .write((byte[]) resource3.getContent()); System.exit(0); // Map parameters2 = new HashMap(); // parameters2.put("query", "SELECT A.REG_PATH_ID, A.REG_NAME FROM REG_RESOURCE A WHERE // A.REG_NAME LIKE ?"); // parameters2.put("1","%wsdl%"); // Resource result2 = registry.executeQuery("/custom-queries3", parameters2); // // System.exit(1); String sql1 = "SELECT A.REG_PATH_ID, A.REG_NAME FROM REG_PATH B, REG_RESOURCE A WHERE ((A.REG_NAME LIKE 'abc') OR ((A.REG_NAME IS NULL) AND (B.REG_PATH_VALUE LIKE 'abc') AND (A.REG_PATH_ID=B.REG_PATH_ID)))"; Resource q1 = registry.newResource(); q1.setContent(sql1); q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); q1.addProperty( RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.RESOURCES_RESULT_TYPE); registry.put("/custom-queries", q1); // then you should give the parameters and the query location you just put Map parameters = new HashMap(); // parameters.put("1", "%coll%ctio%"); Resource result = registry.executeQuery("/custom-queries", parameters); String[] paths = (String[]) result.getContent(); for (String path : paths) { System.out.println(path); } // ResourceImpl r=(ResourceImpl)registry.get("/AuthenticationAdminService.wsdl"); //// System.out.println(r.get); // String[] versions = registry.getVersions("/AuthenticationAdminService.wsdl"); // for (String v : versions) { // System.out.println(v); // } System.exit(0); Resource resource = registry.get("/carbon"); // ResourceImpl r=(ResourceImpl)resource; System.out.println(resource.getMediaType()); resource.setMediaType("samindaaaaaaaaaaaaa"); registry.put("/carbon", resource); resource = registry.get("/carbon"); System.out.println(resource.getMediaType()); System.exit(0); File file = new File("/home/saminda/tmp/testexport"); registry.get("/"); // RegistryClientUtils.exportFromRegistry(file, "/carbon", registry); // ClientOptions.getClientOptions().setUsername("admin"); // ClientOptions.getClientOptions().setPassword("admin"); // ClientOptions.getClientOptions().setWorkingDir(file.getAbsolutePath()); // ClientOptions.getClientOptions().setRegistryUrl("https://localhost:9445/registry"); // ClientOptions.getClientOptions().setCheckoutPath("/carbon"); // //// ClientOptions.getClientOptions().setUserUrl("https://localhost:9445/registry/carbon"); // // ClientOptions.getClientOptions().setUserUrl(ClientOptions.getClientOptions().getRegistryUrl()+ClientOptions.getClientOptions().getCheckoutPath()); // // // new Checkout().execute(); // Object content = registry.get("/carbon/xslt/LocalEntry.xslt").getContent(); // byte[] b=(byte[])content; // // FileOutputStream fos = new FileOutputStream("/home/saminda/tmp/abc.txt"); // fos.write(b); // fos.close(); // String a="/carbon/"; // String[] s = a.split("/"); // for (String p : s) { // System.out.println(p); // } }
@AfterClass(alwaysRun = true) public void cleanArtifact() throws RegistryException { registry.delete("/con-delete"); }