From 8a44fa1ea5694a028c2f49070c4720ab2ebd464f Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Fri, 20 Dec 2024 11:41:51 +0530 Subject: [PATCH 1/2] add integration test for new resource file key usage in xslt mediator --- ...gistryEntryXsltTransformationTestCase.java | 9 +++ .../mi-resources/xslt/transform.xslt | 43 +++++++++++++ .../mi-resources/xslt/transform_back.xslt | 45 ++++++++++++++ .../xsltInResourcesTestProxy.xml | 60 +++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform.xslt create mode 100644 integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform_back.xslt create mode 100644 integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/repository/deployment/server/synapse-configs/default/proxy-services/xsltInResourcesTestProxy.xml diff --git a/integration/mediation-tests/tests-mediator-2/src/test/java/org/wso2/carbon/esb/mediator/test/xslt/RegistryEntryXsltTransformationTestCase.java b/integration/mediation-tests/tests-mediator-2/src/test/java/org/wso2/carbon/esb/mediator/test/xslt/RegistryEntryXsltTransformationTestCase.java index 1c38760328..53f95be906 100644 --- a/integration/mediation-tests/tests-mediator-2/src/test/java/org/wso2/carbon/esb/mediator/test/xslt/RegistryEntryXsltTransformationTestCase.java +++ b/integration/mediation-tests/tests-mediator-2/src/test/java/org/wso2/carbon/esb/mediator/test/xslt/RegistryEntryXsltTransformationTestCase.java @@ -58,6 +58,15 @@ public void xsltTransformationFromGovernanceRegistry() throws Exception { assertNotNull(response, "Response message null"); assertTrue(response.toString().contains("Code"), "Response does not contain the key word: Code"); assertTrue(response.toString().contains("IBM"), "Response does not contain the key word: IBM"); + } + @Test(groups = { + "wso2.esb" }, description = "Do XSLT transformation by selecting the xslt file from resources.") + public void xsltTransformationFromResources() throws Exception { + OMElement response = axis2Client + .sendCustomQuoteRequest(getProxyServiceURLHttp("xsltInResourcesTestProxy"), null, "IBM"); + assertNotNull(response, "Response message null"); + assertTrue(response.toString().contains("Code"), "Response does not contain the key word: Code"); + assertTrue(response.toString().contains("IBM"), "Response does not contain the key word: IBM"); } } diff --git a/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform.xslt b/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform.xslt new file mode 100644 index 0000000000..a76afeb750 --- /dev/null +++ b/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform.xslt @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform_back.xslt b/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform_back.xslt new file mode 100644 index 0000000000..add8418630 --- /dev/null +++ b/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/registry/governance/mi-resources/xslt/transform_back.xslt @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/repository/deployment/server/synapse-configs/default/proxy-services/xsltInResourcesTestProxy.xml b/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/repository/deployment/server/synapse-configs/default/proxy-services/xsltInResourcesTestProxy.xml new file mode 100644 index 0000000000..d75d719075 --- /dev/null +++ b/integration/mediation-tests/tests-mediator-2/src/test/resources/artifacts/ESB/server/repository/deployment/server/synapse-configs/default/proxy-services/xsltInResourcesTestProxy.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + From 8a3bd05a064b74d892c18c57ad4be8389ded230a Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Fri, 20 Dec 2024 11:42:53 +0530 Subject: [PATCH 2/2] add unit test for resource file key lookup --- .../registry/TestMicroIntegratorRegistry.java | 16 ++++++++++++++++ 1 file changed, 16 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 9385099d4c..ce0741ddbd 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 @@ -76,6 +76,14 @@ public void deployRegistryResource() { String emptyMediaTypeFilePath = "conf:/custom/QueueName"; String emptyMediaTypeFileContent = "ordersQueue"; microIntegratorRegistry.newNonEmptyResource(emptyMediaTypeFilePath, false, "", emptyMediaTypeFileContent, ""); + + String resourceFilePath = "gov:mi-resources/custom/checkJsScript.js"; + String resourceContent = "function checkLog(mc) {\n" + + "\tvar log = mc.getServiceLog();\n" + + "\tlog.info(\"Logging inside Script Mediator\");\n" + + "}\n"; + + microIntegratorRegistry.newNonEmptyResource(resourceFilePath, false, "application/javascript", resourceContent, ""); } @Test @@ -123,6 +131,14 @@ public void testRegistryResourceRead() throws IOException { Assert.assertEquals("Media type should be as expected", "application/javascript", mediaType); } + @Test + public void testResourceRead() { + + OMNode omNode = microIntegratorRegistry.lookup("resources:custom/checkJsScript.js"); + String mediaType = ((DataHandler) ((OMTextImpl) omNode).getDataHandler()).getContentType(); + Assert.assertEquals("Media type should be as expected", "application/javascript", mediaType); + } + @Test public void testRegistryPropertiesDeploymentAndLookup() throws IOException {