public void testPermaLinksForResources() throws Exception { Resource r1 = registry.newResource(); r1.setContent("r1c1"); registry.put("/test/v13/r1", r1); registry.put("/test/v13/r1", r1); String[] r1Versions = registry.getVersions("/test/v13/r1"); Resource r1e1 = registry.get(r1Versions[0]); assertEquals("Permalink incorrect", r1e1.getPermanentPath(), r1Versions[0]); r1e1.setContent("r1c2"); registry.put("/test/v13/r1", r1e1); r1Versions = registry.getVersions("/test/v13/r1"); Resource r1e2 = registry.get(r1Versions[0]); assertEquals("Permalink incorrect", r1e2.getPermanentPath(), r1Versions[0]); registry.restoreVersion(r1Versions[1]); Resource r1e3 = registry.get(r1Versions[1]); assertEquals("Permalink incorrect", r1e3.getPermanentPath(), r1Versions[1]); }
public void testResourceContentVersioning() throws Exception { Resource r1 = registry.newResource(); r1.setContent("content 1".getBytes()); registry.put("/v2/r1", r1); Resource r12 = registry.get("/v2/r1"); r12.setContent("content 2".getBytes()); registry.put("/v2/r1", r12); registry.put("/v2/r1", r12); String[] r1Versions = registry.getVersions("/v2/r1"); Resource r1vv1 = registry.get(r1Versions[1]); assertEquals( "r1's first version's content should be 'content 1'", new String((byte[]) r1vv1.getContent()), "content 1"); Resource r1vv2 = registry.get(r1Versions[0]); assertEquals( "r1's second version's content should be 'content 2'", new String((byte[]) r1vv2.getContent()), "content 2"); }
private void editingMultivaluedProperties() { String path = "/props/t3/r1"; Resource r1 = registry.newResource(); try { r1.setContent("r1 content"); r1.addProperty("p1", "v1"); r1.addProperty("p1", "v2"); r1.setProperty("test", "value2"); r1.setProperty("test2", "value2"); registry.put(path, r1); Resource r1e1 = registry.get(path); r1e1.setContent("r1 content"); r1e1.editPropertyValue("p1", "v1", "v3"); registry.put(path, r1e1); Resource r1e2 = registry.get(path); assertFalse("Property is not edited.", r1e2.getPropertyValues("p1").contains("v1")); assertTrue("Property is not edited.", r1e2.getPropertyValues("p1").contains("v3")); assertTrue("Wrong property is removed.", r1e2.getPropertyValues("p1").contains("v2")); deleteResources("/props"); log.info("editingMultivaluedProperties- Passed"); } catch (RegistryException e) { log.error("editingMultivaluedProperties RegistryException thrown :" + e.getMessage()); Assert.fail("editingMultivaluedProperties RegistryException thrown :" + e.getMessage()); } }
private void removingProperties() { String path = "/props/t1/r1"; Resource r1 = registry.newResource(); try { r1.setContent("r1 content"); r1.setProperty("p1", "v1"); r1.setProperty("p2", "v2"); registry.put(path, r1); Resource r1e1 = registry.get(path); r1e1.setContent("r1 content"); r1e1.removeProperty("p1"); registry.put(path, r1e1); Resource r1e2 = registry.get(path); assertEquals("Property is not removed.", r1e2.getProperty("p1"), null); assertNotNull("Wrong property is removed.", r1e2.getProperty("p2")); deleteResources("/props"); log.info("removingProperties - Passed"); } catch (RegistryException e) { log.error("removingProperties RegistryException thrown :" + e.getMessage()); Assert.fail("removingProperties RegistryException thrown :" + e.getMessage()); } }
public void testDefaultQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); r1.setDescription("production ready."); String r1Path = "/c3/r1"; registry.put(r1Path, r1); Resource r2 = registry.newResource(); String r2Content = "content for r2 :)"; r2.setContent(r2Content); r2.setDescription("ready for production use."); String r2Path = "/c3/r2"; registry.put(r2Path, r2); Resource r3 = registry.newResource(); String r3Content = "content for r3 :)"; r3.setContent(r3Content); r3.setDescription("only for government use."); String r3Path = "/c3/r3"; registry.put(r3Path, r3); registry.applyTag("/c3/r1", "java"); registry.applyTag("/c3/r2", "jsp"); registry.applyTag("/c3/r3", "ajax"); String sql1 = "SELECT RT.REG_TAG_ID FROM REG_RESOURCE_TAG RT, REG_RESOURCE R " + "WHERE (R.REG_VERSION=RT.REG_VERSION OR " + "(R.REG_PATH_ID=RT.REG_PATH_ID AND R.REG_NAME=RT.REG_RESOURCE_NAME)) " + "AND R.REG_DESCRIPTION LIKE ? ORDER BY RT.REG_TAG_ID"; Resource q1 = systemRegistry.newResource(); q1.setContent(sql1); q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); q1.addProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.TAGS_RESULT_TYPE); systemRegistry.put("/qs/q3", q1); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("1", "%production%"); Collection result = registry.executeQuery("/qs/q3", parameters); String[] tagPaths = result.getChildren(); assertEquals("There should be two matching tags.", tagPaths.length, 2); Resource tag2 = registry.get(tagPaths[0]); assertEquals("First matching tag should be 'java'", (String) tag2.getContent(), "java"); Resource tag1 = registry.get(tagPaths[1]); assertEquals("Second matching tag should be 'jsp'", (String) tag1.getContent(), "jsp"); }
public void testPermaLinksForCollections() throws Exception { Collection c1 = registry.newCollection(); registry.put("/test/v14/c1", c1); registry.createVersion("/test/v14/c1"); String[] c1Versions = registry.getVersions("/test/v14/c1"); Resource c1e1 = registry.get(c1Versions[0]); assertEquals("Permalink incorrect", c1e1.getPermanentPath(), c1Versions[0]); Resource r1 = registry.newResource(); r1.setContent("r1c1"); registry.put("/test/v14/c1/r1", r1); registry.createVersion("/test/v14/c1"); c1Versions = registry.getVersions("/test/v14/c1"); Resource c1e2 = registry.get(c1Versions[0]); assertEquals("Permalink incorrect", c1e2.getPermanentPath(), c1Versions[0]); registry.restoreVersion(c1Versions[1]); Resource c1e3 = registry.get(c1Versions[1]); assertEquals("Permalink incorrect", c1e3.getPermanentPath(), c1Versions[1]); }
/** * custom query for all the tags search is set as a resource and saved at the config * registry.space */ private boolean setTagSearchQuery() { if (log.isDebugEnabled()) { log.debug("tag search customs query is set"); } String tagsQueryPath = RegistryConstants.CONFIG_REGISTRY_BASE_PATH + RegistryConstants.QUERIES_COLLECTION_PATH + "/tags"; try { if (!super.getUserRegistry().resourceExists(tagsQueryPath)) { // set-up query for tag-search. Resource resource = super.getUserRegistry().newResource(); resource.setContent( "SELECT RT.REG_TAG_ID FROM REG_RESOURCE_TAG RT ORDER BY " + "RT.REG_TAG_ID"); resource.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); resource.addProperty( RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.TAGS_RESULT_TYPE); super.getUserRegistry().put(tagsQueryPath, resource); } return true; } catch (RegistryException e) { log.error(e.getCause(), e); return false; } }
@Test(groups = {"wso2.greg"}) public void addAssociationToResource() throws Exception { Resource r2 = registry.newResource(); String path = "/testk12/testa/testbsp/test.txt"; r2.setContent(new String("this is the content").getBytes()); r2.setDescription("this is test desc"); r2.setMediaType("plain/text"); r2.setProperty("test2", "value2"); registry.put(path, r2); registry.addAssociation(path, "/vtr2121/test", "testasstype1"); registry.addAssociation(path, "/vtr2122/test", "testasstype2"); registry.addAssociation(path, "/vtr2123/test", "testasstype3"); assertTrue( associationPathExists(path, "/vtr2121/test"), "association Destination path not exist"); assertTrue( associationPathExists(path, "/vtr2122/test"), "association Destination path not exist"); assertTrue( associationPathExists(path, "/vtr2123/test"), "association Destination path not exist"); assertTrue(associationTypeExists(path, "testasstype1"), "association Type not exist"); assertTrue(associationTypeExists(path, "testasstype2"), "association Type not exist"); assertTrue(associationTypeExists(path, "testasstype3"), "association Type not exist"); assertTrue(associationSourcepathExists(path, path), "association Source path not exist"); assertTrue(associationSourcepathExists(path, path), "association Source path not exist"); assertTrue(associationSourcepathExists(path, path), "association Source path not exist"); }
@Test( groups = {"wso2.greg"}, dependsOnMethods = {"addAssociationToResource"}) public void getResourceAssociation() throws Exception { Resource r2 = registry.newResource(); String path = "/testk1234/testa/testbsp/test.txt"; r2.setContent(new String("this is the content").getBytes()); r2.setDescription("this is test desc"); r2.setMediaType("plain/text"); r2.setProperty("test2", "value2"); registry.addAssociation(path, "/vtr2121/test", "testasstype1"); registry.addAssociation(path, "/vtr2122/test", "testasstype2"); registry.addAssociation(path, "/vtr2123/test", "testasstype3"); assertTrue( getAssocitionbyDestinationByType(path, "testasstype1", "/vtr2121/test"), "association Destination path not exist"); assertTrue( getAssocitionbyDestinationByType(path, "testasstype2", "/vtr2122/test"), "association Destination path not exist"); assertTrue( getAssocitionbyDestinationByType(path, "testasstype3", "/vtr2123/test"), "association Destination path not exist"); assertTrue(getAssocitionbyType(path, "testasstype1"), "association Type not exist"); assertTrue(getAssocitionbyType(path, "testasstype2"), "association Type not exist"); assertTrue(getAssocitionbyType(path, "testasstype3"), "association Type not exist"); assertTrue( getAssocitionbySourceByType(path, "testasstype1"), "association Source path not exist"); assertTrue( getAssocitionbySourceByType(path, "testasstype2"), "association Source path not exist"); assertTrue( getAssocitionbySourceByType(path, "testasstype3"), "association Source path not exist"); }
public void persist(String path, byte[] resourceBytes, String tag) throws RegistryException { UserRegistry registry = initRegistry(); try { registry.beginTransaction(); Resource nodeResource = registry.newResource(); nodeResource.setContent(resourceBytes); // store the resource in the registry registry.put(path, nodeResource); if (tag != null) { // apply the tag registry.applyTag(path, tag); } // commit registry.commitTransaction(); } catch (RegistryException e) { String errorMsg = "Failed to persist the given resource in registry path " + path; log.error(errorMsg, e); // rollback try { registry.rollbackTransaction(); } catch (RegistryException e1) { errorMsg = "Failed to rollback the transaction in registry path " + path; log.error(errorMsg, e1); throw e1; } throw e; } }
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); }
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 rootLevelCollectionRename() throws Exception { Resource r1 = registry.newResource(); r1.setProperty("test", "rename"); r1.setContent("some text"); registry.put("/rename34k/c1/dummy", r1); registry.rename("/rename34k", "/rename44k"); boolean failed = false; try { registry.get("/rename34k/c1/dummy"); } catch (Exception e) { failed = true; } assertTrue( failed, "Resource should not be " + "accessible from the old path after renaming the parent."); Resource newR1 = registry.get("/rename44k/c1/dummy"); assertEquals( newR1.getProperty("test"), "rename", "Resource should contain a property with name test and value 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 static boolean addHandler(Registry configSystemRegistry, String payload) throws RegistryException, XMLStreamException { String name; OMElement element = AXIOMUtil.stringToOM(payload); if (element != null) { name = element.getAttributeValue(new QName("class")); } else return false; if (isHandlerNameInUse(name)) throw new RegistryException("The added handler name is already in use!"); String path = getContextRoot() + name; Resource resource; if (!handlerExists(configSystemRegistry, name)) { resource = new ResourceImpl(); } else { throw new RegistryException("The added handler name is already in use!"); } resource.setContent(payload); try { configSystemRegistry.beginTransaction(); configSystemRegistry.put(path, resource); generateHandler(configSystemRegistry, path); configSystemRegistry.commitTransaction(); } catch (Exception e) { configSystemRegistry.rollbackTransaction(); throw new RegistryException("Unable to generate handler", e); } return true; }
private void multiValuedProperties() { String path = "/propTest/r1"; Resource r1 = registry.newResource(); try { r1.setContent("Some content for r1"); r1.addProperty("p1", "p1v1"); r1.addProperty("p1", "p1v2"); registry.put(path, r1); Resource r1b = registry.get(path); List propValues = r1b.getPropertyValues("p1"); assertTrue( "Property p1 of /propTest/r1 should contain the value p1v1", propValues.contains("p1v1")); assertTrue( "Property p1 of /propTest/r1 should contain the value p1v2", propValues.contains("p1v2")); deleteResources("/propTest"); log.info("multiValuedProperties - Passed"); } catch (RegistryException e) { log.error("multiValuedProperties RegistryException thrown :" + e.getMessage()); Assert.fail("multiValuedProperties RegistryException thrown :" + e.getMessage()); } }
public void testRootLevelVersioning() throws Exception { Resource r1 = registry.newResource(); r1.setContent("r1c1"); registry.put("/vtr1", r1); registry.createVersion("/"); Collection c2 = registry.newCollection(); registry.put("/vtc2", c2); registry.createVersion("/"); String[] rootVersions = registry.getVersions("/"); Collection rootv0 = (Collection) registry.get(rootVersions[0]); String[] rootv0Children = (String[]) rootv0.getContent(); assertTrue( "Root should have child vtr1", RegistryUtils.containsAsSubString("/vtr1", rootv0Children)); assertTrue( "Root should have child vtc2", RegistryUtils.containsAsSubString("/vtc2", rootv0Children)); Collection rootv1 = (Collection) registry.get(rootVersions[1]); String[] rootv1Children = (String[]) rootv1.getContent(); assertTrue( "Root should have child vtr1", RegistryUtils.containsAsSubString("/vtr1", rootv1Children)); assertFalse( "Root should not have child vtc2", RegistryUtils.containsAsSubString("/vtc2", rootv1Children)); }
public void testBackwardCompatibility() throws RegistryException { Registry rootRegistry = embeddedRegistryService.getSystemRegistry(); Resource r1 = rootRegistry.newResource(); r1.setContent("r1 content"); rootRegistry.put("/test/comments/r1", r1); rootRegistry.addComment( "/test/comments/r1", new Comment("backward-compatibility1 on this resource :)")); rootRegistry.addComment( "/test/comments/r1", new Comment("backward-compatibility2 on this resource :)")); String sql = "SELECT REG_COMMENT_ID FROM REG_COMMENT C, REG_RESOURCE_COMMENT RC " + "WHERE C.REG_COMMENT_TEXT LIKE ? AND C.REG_ID=RC.REG_COMMENT_ID"; Resource queryR = rootRegistry.newResource(); queryR.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); queryR.addProperty( RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.COMMENTS_RESULT_TYPE); rootRegistry.put("/beep/x", queryR); Map<String, String> params = new HashMap<String, String>(); params.put("query", sql); params.put(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.COMMENTS_RESULT_TYPE); params.put("1", "backward-compatibility1%"); Collection qResults = rootRegistry.executeQuery("/beep/x", params); String[] qPaths = (String[]) qResults.getContent(); assertEquals("Query result count should be 1", qPaths.length, 1); }
public void testResourcePropertyVersioning() throws Exception { Resource r1 = registry.newResource(); r1.setContent("content 1"); r1.addProperty("p1", "v1"); registry.put("/v4/r1", r1); Resource r1v2 = registry.get("/v4/r1"); r1v2.addProperty("p2", "v2"); registry.put("/v4/r1", r1v2); registry.put("/v4/r1", r1v2); String[] r1Versions = registry.getVersions("/v4/r1"); Resource r1vv1 = registry.get(r1Versions[1]); assertEquals( "r1's first version should contain a property p1 with value v1", r1vv1.getProperty("p1"), "v1"); Resource r1vv2 = registry.get(r1Versions[0]); assertEquals( "r1's second version should contain a property p1 with value v1", r1vv2.getProperty("p1"), "v1"); assertEquals( "r1's second version should contain a property p2 with value v2", r1vv2.getProperty("p2"), "v2"); }
private void populateResource() throws RegistryException { Resource initialResource = registry.newResource(); // Adding the resource for the first time // user admin will be the creator and updater of this resource. initialResource.setContent("Test content"); registry.put(resourcePath, initialResource); }
public void testWithoutTableParamsQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); r1.setDescription("production ready."); String r1Path = "/c1/r1"; registry.put(r1Path, r1); Resource r2 = registry.newResource(); String r2Content = "content for r2 :)"; r2.setContent(r2Content); r2.setDescription("ready for production use."); String r2Path = "/c2/r2"; registry.put(r2Path, r2); Resource r3 = registry.newResource(); String r3Content = "content for r3 :)"; r3.setContent(r3Content); r3.setDescription("only for government use."); String r3Path = "/c2/r3"; registry.put(r3Path, r3); String sql1 = "SELECT REG_PATH_ID, REG_NAME FROM REG_RESOURCE, " + "REG_TAG WHERE REG_DESCRIPTION LIKE ?"; Resource q1 = systemRegistry.newResource(); q1.setContent(sql1); q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); q1.addProperty( RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.RESOURCES_RESULT_TYPE); systemRegistry.put("/qs/q1", q1); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("1", "%production%"); Resource result = registry.executeQuery("/qs/q1", parameters); assertTrue( "Search with result type Resource should return a directory.", result instanceof org.wso2.carbon.registry.core.Collection); List<String> matchingPaths = new ArrayList<String>(); String[] paths = (String[]) result.getContent(); matchingPaths.addAll(Arrays.asList(paths)); assertTrue("Path /c1/r1 should be in the results.", matchingPaths.contains("/c1/r1")); assertTrue("Path /c2/r2 should be in the results.", matchingPaths.contains("/c2/r2")); }
/** * @param policyStoreDTO * @return */ public static void addPolicyToPDP(PolicyStoreDTO policyStoreDTO) throws EntitlementException { Registry registry; String policyPath; Collection policyCollection; Resource resource; Map.Entry<PolicyStoreManageModule, Properties> entry = EntitlementServiceComponent.getEntitlementConfig() .getPolicyStore() .entrySet() .iterator() .next(); String policyStorePath = entry.getValue().getProperty("policyStorePath"); if (policyStorePath == null) { policyStorePath = "/repository/identity/Entitlement/actualStore/"; } if (policyStoreDTO == null || policyStoreDTO.getPolicy() == null || policyStoreDTO.getPolicy().trim().length() == 0 || policyStoreDTO.getPolicyId() == null || policyStoreDTO.getPolicyId().trim().length() == 0) { return; } try { registry = EntitlementServiceComponent.getRegistryService().getGovernanceSystemRegistry(); if (registry.resourceExists(policyStorePath)) { policyCollection = (Collection) registry.get(policyStorePath); } else { policyCollection = registry.newCollection(); } registry.put(policyStorePath, policyCollection); policyPath = policyStorePath + policyStoreDTO.getPolicyId(); if (registry.resourceExists(policyPath)) { resource = registry.get(policyPath); } else { resource = registry.newResource(); } resource.setProperty("policyOrder", Integer.toString(policyStoreDTO.getPolicyOrder())); resource.setContent(policyStoreDTO.getPolicy()); resource.setMediaType("application/xacml-policy+xml"); AttributeDTO[] attributeDTOs = policyStoreDTO.getAttributeDTOs(); if (attributeDTOs != null) { setAttributesAsProperties(attributeDTOs, resource); } registry.put(policyPath, resource); } catch (RegistryException e) { log.error(e); throw new EntitlementException("Error while adding policy to PDP", e); } }
/** * Saves a swagger document in the registry. * * @param contentStream resource content. * @param path resource path. * @param documentVersion version of the swagger document. * @throws RegistryException If fails to add the swagger document to registry. */ private boolean addSwaggerDocumentToRegistry( ByteArrayOutputStream contentStream, String path, String documentVersion) throws RegistryException { Resource resource; /* Checks if a resource is already exists in the given path. If exists, Compare resource contents and if updated, updates the document, if not skip the updating process If not exists, Creates a new resource and add to the resource path. */ if (registry.resourceExists(path)) { resource = registry.get(path); Object resourceContentObj = resource.getContent(); String resourceContent; if (resourceContentObj instanceof String) { resourceContent = (String) resourceContentObj; resource.setContent(RegistryUtils.encodeString(resourceContent)); } else if (resourceContentObj instanceof byte[]) { resourceContent = RegistryUtils.decodeBytes((byte[]) resourceContentObj); } else { throw new RegistryException(CommonConstants.INVALID_CONTENT); } if (resourceContent.equals(contentStream.toString())) { log.info("Old content is same as the new content. Skipping the put action."); return false; } } else { // If a resource does not exist in the given path. resource = new ResourceImpl(); } String resourceId = (resource.getUUID() == null) ? UUID.randomUUID().toString() : resource.getUUID(); resource.setUUID(resourceId); resource.setMediaType(CommonConstants.SWAGGER_MEDIA_TYPE); resource.setContent(contentStream.toByteArray()); resource.addProperty(RegistryConstants.VERSION_PARAMETER_NAME, documentVersion); CommonUtil.copyProperties(this.requestContext.getResource(), resource); registry.put(path, resource); return true; }
@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 testResourceRestore() throws Exception { Resource r1 = registry.newResource(); r1.setContent("content 1".getBytes()); registry.put("/test/v10/r1", r1); Resource r1e1 = registry.get("/test/v10/r1"); r1e1.setContent("content 2".getBytes()); registry.put("/test/v10/r1", r1e1); registry.put("/test/v10/r1", r1e1); String[] r1Versions = registry.getVersions("/test/v10/r1"); registry.restoreVersion(r1Versions[1]); Resource r1r1 = registry.get("/test/v10/r1"); assertEquals( "Restored resource should have content 'content 1'", "content 1", new String((byte[]) r1r1.getContent())); }
public void testWithoutWhereQuery() throws Exception { Resource r1 = registry.newResource(); String r1Content = "this is r1 content"; r1.setContent(r1Content.getBytes()); r1.setDescription("production ready."); String r1Path = "/c1/r1"; registry.put(r1Path, r1); Resource r2 = registry.newResource(); String r2Content = "content for r2 :)"; r2.setContent(r2Content); r2.setDescription("ready for production use."); String r2Path = "/c2/r2"; registry.put(r2Path, r2); Resource r3 = registry.newResource(); String r3Content = "content for r3 :)"; r3.setContent(r3Content); r3.setDescription("only for government use."); String r3Path = "/c2/r3"; registry.put(r3Path, r3); String sql1 = "SELECT REG_PATH_ID, REG_NAME FROM REG_RESOURCE, REG_TAG"; Resource q1 = systemRegistry.newResource(); q1.setContent(sql1); q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE); q1.addProperty( RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.RESOURCES_RESULT_TYPE); systemRegistry.put("/qs/q1", q1); Map parameters = new HashMap(); Resource result = registry.executeQuery("/qs/q1", parameters); assertTrue( "Search with result type Resource should return a directory.", result instanceof org.wso2.carbon.registry.core.Collection); String[] paths = (String[]) result.getContent(); assertTrue("Should return all the resources", paths.length >= 3); }
public void testCreateVersions() throws Exception { Resource r1 = registry.newResource(); r1.setContent("some content"); registry.put("/version/r1", r1); registry.put("/version/r1", r1); // registry.createVersion("/version/r1"); String[] r1Versions = registry.getVersions("/version/r1"); assertEquals("/version/r1 should have 1 version.", r1Versions.length, 1); Resource r1v2 = registry.get("/version/r1"); r1v2.setContent("another content"); registry.put("/version/r1", r1v2); // registry.createVersion("/version/r1"); r1Versions = registry.getVersions("/version/r1"); assertEquals("/version/r1 should have 2 version.", r1Versions.length, 2); }
/** * Persist the keystore in the gov.registry * * @param keyStore created Keystore of the tenant * @param PKCertificate pub. key of the tenant * @throws KeyStoreMgtException Exception when storing the keystore in the registry */ private void persistKeyStore(KeyStore keyStore, X509Certificate PKCertificate) throws KeyStoreMgtException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); keyStore.store(outputStream, password.toCharArray()); outputStream.flush(); outputStream.close(); String keyStoreName = generateKSNameFromDomainName(); // Use the keystore using the keystore admin KeyStoreAdmin keystoreAdmin = new KeyStoreAdmin(tenantId, govRegistry); keystoreAdmin.addKeyStore( outputStream.toByteArray(), keyStoreName, password, " ", "JKS", password); // Create the pub. key resource Resource pubKeyResource = govRegistry.newResource(); pubKeyResource.setContent(PKCertificate.getEncoded()); pubKeyResource.addProperty( SecurityConstants.PROP_TENANT_PUB_KEY_FILE_NAME_APPENDER, generatePubKeyFileNameAppender()); govRegistry.put(RegistryResources.SecurityManagement.TENANT_PUBKEY_RESOURCE, pubKeyResource); // associate the public key with the keystore govRegistry.addAssociation( RegistryResources.SecurityManagement.KEY_STORES + "/" + keyStoreName, RegistryResources.SecurityManagement.TENANT_PUBKEY_RESOURCE, SecurityConstants.ASSOCIATION_TENANT_KS_PUB_KEY); } catch (RegistryException e) { String msg = "Error when writing the keystore/pub.cert to registry"; log.error(msg, e); throw new KeyStoreMgtException(msg, e); } catch (Exception e) { String msg = "Error when processing keystore/pub. cert to be stored in registry"; log.error(msg, e); throw new KeyStoreMgtException(msg, e); } }
private void singleValuedProperties() { String path = "/propTest/r2"; Resource r2 = registry.newResource(); try { r2.setContent("Some content for r2"); r2.addProperty("p1", "p1v1"); registry.put(path, r2); Resource r2b = registry.get(path); String p1Value = r2b.getProperty("p1"); assertEquals("Property p1 of /propTest/r2 should contain the value p1v1", p1Value, "p1v1"); deleteResources("/propTest"); log.info("singleValuedProperties - Passed"); } catch (RegistryException e) { log.error("singleValuedProperties RegistryException thrown :" + e.getMessage()); Assert.fail("singleValuedProperties RegistryException thrown :" + e.getMessage()); } }
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"); }