From 05922fa0124ec6c21a0948d1c6f6b581239e7d4c Mon Sep 17 00:00:00 2001 From: Arunan Date: Fri, 15 Mar 2024 19:40:39 +0530 Subject: [PATCH] Add unit tests for Registry collection properties deployment and lookup --- .../registry/TestMicroIntegratorRegistry.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/components/mediation/registry/org.wso2.micro.integrator.registry/src/test/java/org/wso2/micro/integrator/registry/TestMicroIntegratorRegistry.java b/components/mediation/registry/org.wso2.micro.integrator.registry/src/test/java/org/wso2/micro/integrator/registry/TestMicroIntegratorRegistry.java index 00e2faa587..9385099d4c 100644 --- a/components/mediation/registry/org.wso2.micro.integrator.registry/src/test/java/org/wso2/micro/integrator/registry/TestMicroIntegratorRegistry.java +++ b/components/mediation/registry/org.wso2.micro.integrator.registry/src/test/java/org/wso2/micro/integrator/registry/TestMicroIntegratorRegistry.java @@ -123,6 +123,46 @@ public void testRegistryResourceRead() throws IOException { Assert.assertEquals("Media type should be as expected", "application/javascript", mediaType); } + @Test + public void testRegistryPropertiesDeploymentAndLookup() throws IOException { + + String filePath = "gov:/custom/payload/template.json"; + String content = "{\"Hello\":\"World\"}"; + Properties properties = new Properties(); + properties.setProperty("token", "12345"); + properties.setProperty("owner", "John"); + microIntegratorRegistry.addNewNonEmptyResource(filePath, false, "application/json", content, properties); + + File resourceFile = Paths.get(governanceRegistry.toString(), "custom", "payload", "template.json").toFile(); + File propertiesFile = Paths.get(governanceRegistry.toString(), "custom", "payload", "template.json.properties").toFile(); + Assert.assertTrue("template.json file should be created", resourceFile.exists()); + Assert.assertTrue("template.json.properties file should be created", propertiesFile.exists()); + + Properties readProperties = microIntegratorRegistry.getResourceProperties(filePath); + Assert.assertEquals("Properties should be as expected", "12345", readProperties.getProperty("token")); + Assert.assertEquals("Properties should be as expected", "John", readProperties.getProperty("owner")); + + } + + @Test + public void testRegistryCollectionPropertiesDeploymentAndLookup() throws IOException { + + String filePath = "gov:/custom/folder"; + Properties properties = new Properties(); + properties.setProperty("token", "12345"); + properties.setProperty("owner", "John"); + microIntegratorRegistry.addNewNonEmptyResource(filePath, true, "application/json", "", properties); + + File propertiesFile = Paths.get(governanceRegistry.toString(), "custom", "folder.collections.properties").toFile(); + Assert.assertTrue("folder.collection.properties file should be created", propertiesFile.exists()); + + Properties readProperties = microIntegratorRegistry.getResourceProperties(filePath); + Assert.assertEquals("Properties should be as expected", "12345", readProperties.getProperty("token")); + Assert.assertEquals("Properties should be as expected", "John", readProperties.getProperty("owner")); + + microIntegratorRegistry.delete(filePath); + } + @Test public void testRegistryResourceReadWithEmptyMediaType() { OMNode omNode = microIntegratorRegistry.lookup("conf:/custom/QueueName");