diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/DebuggerHelper.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/DebuggerHelper.java index 5bd4c485e..8c32c3051 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/DebuggerHelper.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/DebuggerHelper.java @@ -72,6 +72,11 @@ public DebuggerHelper(String filePath) { } } + public DebuggerHelper(STNode syntaxTree) { + + this.syntaxTree = syntaxTree; + } + /** * This method is used to validate the breakpoints. * diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/Breakpoint.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/Breakpoint.java index 729d00c80..658b81897 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/Breakpoint.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/Breakpoint.java @@ -18,6 +18,8 @@ package org.eclipse.lemminx.customservice.synapse.debugger.entity; +import java.util.Objects; + public class Breakpoint { int line; @@ -53,4 +55,28 @@ public void setColumn(Integer column) { this.column = column; } + + @Override + public boolean equals(Object o) { + + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Breakpoint that = (Breakpoint) o; + return line == that.line && Objects.equals(column, that.column); + } + + @Override + public int hashCode() { + + return Objects.hash(line, column); + } + + @Override + public String toString() { + + return "Breakpoint{" + + "line=" + line + + ", column=" + column + + '}'; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ApiDebugInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ApiDebugInfo.java index 9866eb8b9..3d649195c 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ApiDebugInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ApiDebugInfo.java @@ -54,6 +54,31 @@ public void setUrlMapping(String urlMapping) { this.urlMapping = urlMapping; } + public String getApiKey() { + + return apiKey; + } + + public String getMethod() { + + return method; + } + + public String getUriTemplate() { + + return uriTemplate; + } + + public String getUrlMapping() { + + return urlMapping; + } + + public String getSequenceType() { + + return sequenceType; + } + public JsonElement toJson() { JsonObject rootNode = new JsonObject(); @@ -76,4 +101,19 @@ public JsonElement toJson() { rootNode.addProperty("mediation-component", "sequence"); return rootNode; } + + @Override + public String toString() { + + return "ApiDebugInfo{" + + "apiKey='" + apiKey + '\'' + + ", method='" + method + '\'' + + ", uriTemplate='" + uriTemplate + '\'' + + ", urlMapping='" + urlMapping + '\'' + + ", sequenceType='" + sequenceType + '\'' + + ", mediatorPosition='" + mediatorPosition + '\'' + + ", isValid=" + isValid + + ", error='" + error + '\'' + + '}'; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/DebugInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/DebugInfo.java index e77dde3d9..5a7d6f61c 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/DebugInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/DebugInfo.java @@ -74,4 +74,14 @@ public IDebugInfo clone() throws CloneNotSupportedException { return (IDebugInfo) super.clone(); } + + @Override + public String toString() { + + return "DebugInfo{" + + "mediatorPosition='" + mediatorPosition + '\'' + + ", isValid=" + isValid + + ", error='" + error + '\'' + + '}'; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/InboundDebugInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/InboundDebugInfo.java index 8f706ff28..f7fe17de9 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/InboundDebugInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/InboundDebugInfo.java @@ -27,4 +27,14 @@ public JsonElement toJson() { return null; } + + @Override + public String toString() { + + return "InboundDebugInfo{" + + "mediatorPosition='" + mediatorPosition + '\'' + + ", isValid=" + isValid + + ", error='" + error + '\'' + + '}'; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ProxyDebugInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ProxyDebugInfo.java index c14c2f28a..4f481f046 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ProxyDebugInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/ProxyDebugInfo.java @@ -36,6 +36,16 @@ public void setSequenceType(String sequenceType) { this.sequenceType = sequenceType; } + public String getProxyKey() { + + return proxyKey; + } + + public String getSequenceType() { + + return sequenceType; + } + @Override public JsonElement toJson() { @@ -51,4 +61,16 @@ public JsonElement toJson() { rootNode.addProperty("mediation-component", "sequence"); return rootNode; } + + @Override + public String toString() { + + return "ProxyDebugInfo{" + + "proxyKey='" + proxyKey + '\'' + + ", sequenceType='" + sequenceType + '\'' + + ", mediatorPosition='" + mediatorPosition + '\'' + + ", isValid=" + isValid + + ", error='" + error + '\'' + + '}'; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/SequenceDebugInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/SequenceDebugInfo.java index 45d1a3ff6..7df0ee8c9 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/SequenceDebugInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/SequenceDebugInfo.java @@ -45,4 +45,15 @@ public JsonElement toJson() { return rootNode; } + + @Override + public String toString() { + + return "SequenceDebugInfo{" + + "sequenceKey='" + sequenceKey + '\'' + + ", mediatorPosition='" + mediatorPosition + '\'' + + ", isValid=" + isValid + + ", error='" + error + '\'' + + '}'; + } } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/TemplateDebugInfo.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/TemplateDebugInfo.java index de131e9d2..c0759cdca 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/TemplateDebugInfo.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/debugger/entity/debuginfo/TemplateDebugInfo.java @@ -30,6 +30,11 @@ public void setTemplateKey(String templateKey) { this.templateKey = templateKey; } + public String getTemplateKey() { + + return templateKey; + } + @Override public JsonElement toJson() { @@ -43,4 +48,15 @@ public JsonElement toJson() { return rootNode; } + + @Override + public String toString() { + + return "TemplateDebugInfo{" + + "templateKey='" + templateKey + '\'' + + ", mediatorPosition='" + mediatorPosition + '\'' + + ", isValid=" + isValid + + ", error='" + error + '\'' + + '}'; + } } diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/APITest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/APITest.java new file mode 100644 index 000000000..20ef5413b --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/APITest.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.eclipse.lemminx.customservice.synapse.debugger.entity.debuginfo.ApiDebugInfo; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class APITest extends AbstractDebuggerTest { + + @Override + protected String getResourcePath() { + + return "/synapse/debugger/api.xml"; + } + + @Test + public void test_URLResource() { + + Breakpoint breakpoint = new Breakpoint(22, 12); + ApiDebugInfo debugInfo = (ApiDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("/postUrl", debugInfo.getUrlMapping()); + assertEquals("POST", debugInfo.getMethod()); + assertEquals("api_inseq", debugInfo.getSequenceType()); + } + + @Test + public void test_URIResource() { + + Breakpoint breakpoint = new Breakpoint(48, 12); + ApiDebugInfo debugInfo = (ApiDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("/postUri/{path1}?query1={query1}", debugInfo.getUriTemplate()); + assertEquals("POST", debugInfo.getMethod()); + assertEquals("api_inseq", debugInfo.getSequenceType()); + } + + @Test + public void testMultipleBreakpoint_APIInSequence() throws Exception { + + Breakpoint breakpoint1 = new Breakpoint(22, 12); + Breakpoint breakpoint2 = new Breakpoint(25, 12); + testDebugInfo(List.of(breakpoint1, breakpoint2), List.of("0", "1")); + } + + @Test + public void test_APIOutSequence() { + + Breakpoint breakpoint = new Breakpoint(30, 12); + + ApiDebugInfo debugInfo = (ApiDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("api_outseq", debugInfo.getSequenceType()); + assertEquals("POST", debugInfo.getMethod()); + assertEquals("/postUrl", debugInfo.getUrlMapping()); + assertEquals("api_outseq", debugInfo.getSequenceType()); + + testStepOverInfo(breakpoint, List.of(new Breakpoint(33, 12))); + } + + @Test + public void testMultipleBreakpoint_APIOutSequence() throws Exception { + + Breakpoint breakpoint1 = new Breakpoint(30, 12); + Breakpoint breakpoint2 = new Breakpoint(33, 12); + testDebugInfo(List.of(breakpoint1, breakpoint2), List.of("0", "1")); + } + + @Test + public void test_APIFaultSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(38, 12); + ApiDebugInfo debugInfo = (ApiDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("api_faultseq", debugInfo.getSequenceType()); + assertEquals("POST", debugInfo.getMethod()); + assertEquals("/postUrl", debugInfo.getUrlMapping()); + assertEquals("api_faultseq", debugInfo.getSequenceType()); + + testStepOverInfo(breakpoint, List.of(new Breakpoint(41, 12))); + } + + @Test + public void testMultipleBreakpoint_APIFaultSequence() throws Exception { + + Breakpoint breakpoint1 = new Breakpoint(38, 12); + Breakpoint breakpoint2 = new Breakpoint(41, 12); + testDebugInfo(List.of(breakpoint1, breakpoint2), List.of("0", "1")); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/AbstractDebuggerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/AbstractDebuggerTest.java new file mode 100644 index 000000000..c41c391f9 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/AbstractDebuggerTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger; + +import org.eclipse.lemminx.customservice.synapse.debugger.DebuggerHelper; +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.eclipse.lemminx.customservice.synapse.debugger.entity.StepOverInfo; +import org.eclipse.lemminx.customservice.synapse.debugger.entity.debuginfo.IDebugInfo; +import org.eclipse.lemminx.customservice.synapse.syntaxTree.SyntaxTreeGenerator; +import org.eclipse.lemminx.customservice.synapse.syntaxTree.pojo.STNode; +import org.eclipse.lemminx.customservice.synapse.utils.Utils; +import org.eclipse.lemminx.dom.DOMDocument; +import org.eclipse.lemminx.synapse.TestUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class AbstractDebuggerTest { + + protected STNode testStNode; + + protected abstract String getResourcePath(); + + @BeforeAll + public void init() throws Exception { + + String testResourcePath = getResourcePath(); + String resourceFilePath = TestUtils.getResourceFilePath(testResourcePath); + DOMDocument document = Utils.getDOMDocumentFromPath(resourceFilePath); + this.testStNode = SyntaxTreeGenerator.buildTree(document.getDocumentElement()); + } + + public List getDebugInfo(List breakpoints) { + + DebuggerHelper debuggerHelper = new DebuggerHelper(testStNode); + return debuggerHelper.generateDebugInfo(breakpoints); + } + + public void testDebugInfo(List breakpoints, List expectedMediatorPositions) throws + IOException { + + List debugInfos = getDebugInfo(breakpoints); + + int i = 0; + for (IDebugInfo debugInfo : debugInfos) { + String actualMediatorPosition = debugInfo.getMediatorPosition(); + String expectedMediatorPosition = expectedMediatorPositions.get(i++); + + assertEquals(expectedMediatorPosition, actualMediatorPosition); + } + } + + public void testStepOverInfo(Breakpoint breakpoint, List expectedStepOverBreakpoints) { + + DebuggerHelper debuggerHelper = new DebuggerHelper(testStNode); + StepOverInfo stepOverInfo = debuggerHelper.getStepOverBreakpoints(breakpoint); + + assertEquals(expectedStepOverBreakpoints.size(), stepOverInfo.size()); + assertEquals(expectedStepOverBreakpoints, stepOverInfo.getStepOverBreakpoints()); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/ProxyTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/ProxyTest.java new file mode 100644 index 000000000..e5f100171 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/ProxyTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.eclipse.lemminx.customservice.synapse.debugger.entity.debuginfo.ProxyDebugInfo; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ProxyTest extends AbstractDebuggerTest { + + @Override + protected String getResourcePath() { + + return "/synapse/debugger/proxy.xml"; + } + + @Test + public void test_ProxyInSequence() { + + Breakpoint breakpoint = new Breakpoint(21, 12); + ProxyDebugInfo debugInfo = (ProxyDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("debugger", debugInfo.getProxyKey()); + assertEquals("proxy_inseq", debugInfo.getSequenceType()); + + testStepOverInfo(breakpoint, List.of(new Breakpoint(24, 12))); + } + + @Test + public void testMultipleBreakpoint_ProxyInSequence() throws IOException { + + Breakpoint breakpoint1 = new Breakpoint(21, 12); + Breakpoint breakpoint2 = new Breakpoint(24, 12); + testDebugInfo(List.of(breakpoint1, breakpoint2), List.of("0", "1")); + } + + @Test + public void test_ProxyFaultSequence() { + + Breakpoint breakpoint = new Breakpoint(29, 12); + ProxyDebugInfo debugInfo = (ProxyDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("debugger", debugInfo.getProxyKey()); + assertEquals("proxy_faultseq", debugInfo.getSequenceType()); + + testStepOverInfo(breakpoint, List.of(new Breakpoint(32, 12))); + } + + @Test + public void testMultipleBreakpoint_ProxyOutSequence() throws IOException { + + Breakpoint breakpoint1 = new Breakpoint(29, 12); + Breakpoint breakpoint2 = new Breakpoint(32, 12); + testDebugInfo(List.of(breakpoint1, breakpoint2), List.of("0", "1")); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/TemplateTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/TemplateTest.java new file mode 100644 index 000000000..cce993ab0 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/TemplateTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.eclipse.lemminx.customservice.synapse.debugger.entity.debuginfo.TemplateDebugInfo; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TemplateTest extends AbstractDebuggerTest { + + @Override + protected String getResourcePath() { + + return "/synapse/debugger/template.xml"; + } + + @Test + public void test_SingleBreakpoint() { + + Breakpoint breakpoint = new Breakpoint(23, 8); + TemplateDebugInfo debugInfo = (TemplateDebugInfo) getDebugInfo(List.of(breakpoint)).get(0); + assertEquals("0", debugInfo.getMediatorPosition()); + assertEquals("debugger", debugInfo.getTemplateKey()); + + testStepOverInfo(breakpoint, List.of(new Breakpoint(26, 8))); + } + + @Test + public void testMultipleBreakpoint() throws IOException { + + Breakpoint breakpoint1 = new Breakpoint(23, 8); + Breakpoint breakpoint2 = new Breakpoint(26, 8); + testDebugInfo(List.of(breakpoint1, breakpoint2), List.of("0", "1")); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/AbstractMediatorDebuggerTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/AbstractMediatorDebuggerTest.java new file mode 100644 index 000000000..11506bf3b --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/AbstractMediatorDebuggerTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.synapse.debugger.AbstractDebuggerTest; + +public abstract class AbstractMediatorDebuggerTest extends AbstractDebuggerTest { + + private String MEDIATOR_RESOURCE_FOLDER = "/synapse/debugger/mediators/"; + + @Override + protected String getResourcePath() { + + return MEDIATOR_RESOURCE_FOLDER + getTestResourceName(); + } + + protected abstract String getTestResourceName(); +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/AggregateMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/AggregateMediatorTest.java new file mode 100644 index 000000000..30b8997c8 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/AggregateMediatorTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.List; + +public class AggregateMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "aggregateMediator.xml"; + } + + @Test + public void testAggregateMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(28, 12), new Breakpoint(33, 4))); + } + + @Test + public void testMediatorInOnCompleteSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(28, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(33, 4))); + } + + @Test + public void testAfterAggregateMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(33, 4); + testDebugInfo(List.of(breakpoint), List.of("2")); + testStepOverInfo(breakpoint, Collections.emptyList()); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/CacheMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/CacheMediatorTest.java new file mode 100644 index 000000000..0fbc2db41 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/CacheMediatorTest.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.List; + +public class CacheMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "cacheMediator.xml"; + } + + @Test + public void testCacheMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(25, 12), new Breakpoint(46, 4))); + } + + @Test + public void testMediatorInOnCacheHitSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(25, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(26, 12))); + } + + @Test + public void testComplexMediatorInOnCacheHitSequence() throws Exception { + + testDebugInfo(List.of(new Breakpoint(28, 20)), List.of("1 1 1 0")); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/CloneMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/CloneMediatorTest.java new file mode 100644 index 000000000..6c4aa5f94 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/CloneMediatorTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class CloneMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "cloneMediator.xml"; + } + + @Test + public void testCloneMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(26, 16), new Breakpoint(33, 16))); + } + + @Test + public void testMediatorInFirstTargetSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(26, 16); + testDebugInfo(List.of(breakpoint), List.of("1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(39, 4))); + } + + @Test + public void testMediatorInSecondTargetSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(33, 16); + testDebugInfo(List.of(breakpoint), List.of("1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(39, 4))); + } + + @Test + public void testAllAtOnce() throws IOException { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(26, 16)); + expected.add("1 0 0"); + + breakpoints.add(new Breakpoint(33, 16)); + expected.add("1 1 0"); + + breakpoints.add(new Breakpoint(39, 4)); + expected.add("2"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/FilterMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/FilterMediatorTest.java new file mode 100644 index 000000000..691780bbf --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/FilterMediatorTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class FilterMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "filterMediator.xml"; + } + + @Test + public void testFilterMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(25, 12), new Breakpoint(42, 12))); + } + + @Test + public void testMediatorInThenSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(25, 12); + testDebugInfo(List.of(breakpoint), List.of("1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(28, 12))); + } + + @Test + public void testFilterMediatorInThenSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(28, 12); + testDebugInfo(List.of(breakpoint), List.of("1 1 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(30, 20), new Breakpoint(35, 20))); + } + + @Test + public void testThenSequenceOfFilterMediatorInThenSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(30, 20); + testDebugInfo(List.of(breakpoint), List.of("1 1 1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(59, 4))); + } + + @Test + public void testElseSequenceOfFilterMediatorInThenSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(35, 20); + testDebugInfo(List.of(breakpoint), List.of("1 1 1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(59, 4))); + } + + @Test + public void testMediatorInElseSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(42, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(45, 12))); + } + + @Test + public void testFilterMediatorInElseSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(45, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(47, 20), new Breakpoint(52, 20))); + } + + @Test + public void testThenSequenceOfFilterMediatorInElseSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(47, 20); + testDebugInfo(List.of(breakpoint), List.of("1 0 1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(59, 4))); + } + + @Test + public void testElseSequenceOfFilterMediatorInElseSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(52, 20); + testDebugInfo(List.of(breakpoint), List.of("1 0 1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(59, 4))); + } + + @Test + public void testAllBreakpointAtOnce() throws Exception { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(25, 12)); + expected.add("1 1 0"); + + breakpoints.add(new Breakpoint(28, 12)); + expected.add("1 1 1"); + + breakpoints.add(new Breakpoint(30, 20)); + expected.add("1 1 1 1 0"); + + breakpoints.add(new Breakpoint(35, 20)); + expected.add("1 1 1 0 0"); + + breakpoints.add(new Breakpoint(42, 16)); + expected.add("1 0 0"); + + breakpoints.add(new Breakpoint(45, 12)); + expected.add("1 0 1"); + + breakpoints.add(new Breakpoint(47, 20)); + expected.add("1 0 1 1 0"); + + breakpoints.add(new Breakpoint(52, 20)); + expected.add("1 0 1 0 0"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ForeachMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ForeachMediatorTest.java new file mode 100644 index 000000000..418758c2e --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ForeachMediatorTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class ForeachMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "foreachMediator.xml"; + } + + @Test + public void testForeachMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(26, 12))); + } + + @Test + public void testMediatorInForeachSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(26, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(29, 12))); + } + + @Test + public void testNestedForeachInForeachSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(29, 12); + testDebugInfo(List.of(breakpoint), List.of("1 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(32, 20))); + } + + @Test + public void testForeachSequenceOfNestedForeach() throws Exception { + + Breakpoint breakpoint = new Breakpoint(32, 20); + testDebugInfo(List.of(breakpoint), List.of("1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(39, 4))); + } + + @Test + public void testAllBreakpointAtOnce() throws Exception { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(26, 12)); + expected.add("1 0"); + + breakpoints.add(new Breakpoint(29, 12)); + expected.add("1 1"); + + breakpoints.add(new Breakpoint(32, 20)); + expected.add("1 1 0"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/IterateMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/IterateMediatorTest.java new file mode 100644 index 000000000..adcff33e3 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/IterateMediatorTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class IterateMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "iterateMediator.xml"; + } + + @Test + public void testIterateMediator() throws Exception { + + testDebugInfo(List.of(new Breakpoint(23, 4)), List.of("1")); + } + + @Test + public void testMediatorInIterateSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(26, 16); + testDebugInfo(List.of(new Breakpoint(26, 16)), List.of("1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(29, 16))); + } + + @Test + public void testNestedIterateInIterateSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(29, 16); + testDebugInfo(List.of(breakpoint), List.of("1 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(32, 28))); + } + + @Test + public void testIterateSequenceOfNestedIterate() throws Exception { + + Breakpoint breakpoint = new Breakpoint(32, 28); + testDebugInfo(List.of(breakpoint), List.of("1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(41, 4))); + } + + @Test + public void testAllBreakpointAtOnce() throws Exception { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(26, 16)); + expected.add("1 0"); + + breakpoints.add(new Breakpoint(29, 16)); + expected.add("1 1"); + + breakpoints.add(new Breakpoint(32, 28)); + expected.add("1 1 0"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ScatterGatherMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ScatterGatherMediatorTest.java new file mode 100644 index 000000000..4dec02c74 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ScatterGatherMediatorTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class ScatterGatherMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "scatterGatherMediator.xml"; + } + + @Test + public void testScatterGatherMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(26, 12), new Breakpoint(44, 12))); + } + + @Test + public void testMediatorInSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(26, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(29, 12))); + } + + @Test + public void testNestedScatterGatherInFirstSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(29, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(32, 20), new Breakpoint(37, 20))); + } + + @Test + public void tesSequenceOfNestedScatterGatherInFirstSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(32, 20); + testDebugInfo(List.of(breakpoint), List.of("1 0 1 0 0")); + } + + @Test + public void testNestedScatterGatherInSecondSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(47, 12); + testDebugInfo(List.of(breakpoint), List.of("1 1 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(50, 20), new Breakpoint(55, 20))); + } + + @Test + public void testSequenceOfNestedScatterGatherInSecondSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(50, 20); + testDebugInfo(List.of(breakpoint), List.of("1 1 1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(62, 4))); + } + + @Test + public void testAllBreakpointAtOnce() throws Exception { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(26, 12)); + expected.add("1 0 0"); + + breakpoints.add(new Breakpoint(29, 12)); + expected.add("1 0 1"); + + breakpoints.add(new Breakpoint(32, 20)); + expected.add("1 0 1 0 0"); + + breakpoints.add(new Breakpoint(47, 12)); + expected.add("1 1 1"); + + breakpoints.add(new Breakpoint(50, 20)); + expected.add("1 1 1 0 0"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/SimpleMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/SimpleMediatorTest.java new file mode 100644 index 000000000..49eb7a2e7 --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/SimpleMediatorTest.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * This test will cover all the mediators that doesn't support child mediators. + */ +public class SimpleMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "simpleMediator.xml"; + } + + @Test + public void testSimpleMediator1() throws IOException { + + Breakpoint breakpoint = new Breakpoint(20, 4); + testDebugInfo(List.of(breakpoint), List.of("0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(21, 4))); + } + + @Test + public void testSimpleMediator2() throws IOException { + + Breakpoint breakpoint = new Breakpoint(21, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, Collections.emptyList()); + } + + @Test + public void testMultipleBreakpoints() throws IOException { + + List breakpoints = List.of(new Breakpoint(20, 4), new Breakpoint(21, 4)); + List expectedMediatorPositions = List.of("0", "1"); + testDebugInfo(breakpoints, expectedMediatorPositions); + } + + @Test + public void testInvalidBreakpoint() throws IOException { + + Breakpoint invalidBreakpoint = new Breakpoint(100, 4); + List expectedMediatorPositions = new ArrayList<>(); + expectedMediatorPositions.add(null); + testDebugInfo(List.of(invalidBreakpoint), expectedMediatorPositions); + } + + @Test + public void testMultipleInvalidBreakpoints() throws Exception { + + List breakpoints = new ArrayList<>(); + breakpoints.add(new Breakpoint(19, 0)); + breakpoints.add(new Breakpoint(22, 8)); + breakpoints.add(new Breakpoint(23, 4)); + breakpoints.add(new Breakpoint(24, 0)); + breakpoints.add(new Breakpoint(25, 0)); + + List expectedMediatorPositions = new ArrayList<>(); + expectedMediatorPositions.add(null); + expectedMediatorPositions.add(null); + expectedMediatorPositions.add(null); + expectedMediatorPositions.add(null); + expectedMediatorPositions.add(null); + + testDebugInfo(breakpoints, expectedMediatorPositions); + } + + @Test + public void testValidAndInvalidBreakpoints() throws Exception { + + List breakpoints = new ArrayList<>(); + breakpoints.add(new Breakpoint(19, 0)); + breakpoints.add(new Breakpoint(20, 4)); + breakpoints.add(new Breakpoint(21, 4)); + breakpoints.add(new Breakpoint(100, 4)); + + List expectedMediatorPositions = new ArrayList<>(); + expectedMediatorPositions.add(null); + expectedMediatorPositions.add("0"); + expectedMediatorPositions.add("1"); + expectedMediatorPositions.add(null); + + testDebugInfo(breakpoints, expectedMediatorPositions); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/SwitchMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/SwitchMediatorTest.java new file mode 100644 index 000000000..65e21cf0f --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/SwitchMediatorTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class SwitchMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "switchMediator.xml"; + } + + @Test + public void testSwitchMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(69, 12), new Breakpoint(25, 12), new Breakpoint(47, 12))); + } + + @Test + public void testMediatorInFirstCase() throws Exception { + + Breakpoint breakpoint = new Breakpoint(25, 12); + testDebugInfo(List.of(breakpoint), List.of("1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(28, 12))); + } + + @Test + public void testFirstCaseInTheNestedSwitchInFirstCase() throws Exception { + + Breakpoint breakpoint = new Breakpoint(30, 20); + testDebugInfo(List.of(breakpoint), List.of("1 1 1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(91, 4))); + } + + @Test + public void testMediatorInSecondCase() throws Exception { + + Breakpoint breakpoint = new Breakpoint(47, 12); + testDebugInfo(List.of(breakpoint), List.of("1 2 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(50, 12))); + } + + @Test + public void testSecondCaseInTheNestedSwitchOfSecondCase() throws Exception { + + Breakpoint breakpoint = new Breakpoint(52, 20); + testDebugInfo(List.of(breakpoint), List.of("1 2 1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(91, 4))); + } + + @Test + public void testMediatorInDefaultCase() throws Exception { + + Breakpoint breakpoint = new Breakpoint(69, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(72, 12))); + } + + @Test + public void testDefaultCaseInTheNestedSwitchOfDefaultCase() throws Exception { + + Breakpoint breakpoint = new Breakpoint(84, 20); + testDebugInfo(List.of(breakpoint), List.of("1 0 1 0 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(91, 4))); + } + + @Test + public void testAllBreakpointAtOnce() throws Exception { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(25, 12)); + expected.add("1 1 0"); + + breakpoints.add(new Breakpoint(30, 20)); + expected.add("1 1 1 1 0"); + + breakpoints.add(new Breakpoint(47, 12)); + expected.add("1 2 0"); + + breakpoints.add(new Breakpoint(52, 20)); + expected.add("1 2 1 1 0"); + + breakpoints.add(new Breakpoint(69, 12)); + expected.add("1 0 0"); + + breakpoints.add(new Breakpoint(84, 20)); + expected.add("1 0 1 0 0"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ValidateMediatorTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ValidateMediatorTest.java new file mode 100644 index 000000000..f2ab2671e --- /dev/null +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/debugger/mediators/ValidateMediatorTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.eclipse.lemminx.synapse.debugger.mediators; + +import org.eclipse.lemminx.customservice.synapse.debugger.entity.Breakpoint; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +public class ValidateMediatorTest extends AbstractMediatorDebuggerTest { + + @Override + protected String getTestResourceName() { + + return "validateMediator.xml"; + } + + @Test + public void testValidateMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(23, 4); + testDebugInfo(List.of(breakpoint), List.of("1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(28, 12), new Breakpoint(43, 4))); + } + + @Test + public void testMediatorInOnFailSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(28, 12); + testDebugInfo(List.of(breakpoint), List.of("1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(31, 12))); + } + + @Test + public void testValidateMediatorInOnFailSequence() throws Exception { + + Breakpoint breakpoint = new Breakpoint(31, 12); + testDebugInfo(List.of(breakpoint), List.of("1 1")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(36, 20), new Breakpoint(43, 4))); + } + + @Test + public void testOnFailSequenceOfNestedValidateMediator() throws Exception { + + Breakpoint breakpoint = new Breakpoint(36, 20); + testDebugInfo(List.of(breakpoint), List.of("1 1 0")); + testStepOverInfo(breakpoint, List.of(new Breakpoint(43, 4))); + } + + @Test + public void testAllBreakpointAtOnce() throws Exception { + + List breakpoints = new ArrayList<>(); + List expected = new ArrayList<>(); + + breakpoints.add(new Breakpoint(23, 4)); + expected.add("1"); + + breakpoints.add(new Breakpoint(28, 12)); + expected.add("1 0"); + + breakpoints.add(new Breakpoint(31, 12)); + expected.add("1 1"); + + breakpoints.add(new Breakpoint(36, 20)); + expected.add("1 1 0"); + + testDebugInfo(breakpoints, expected); + } +} diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/api.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/api.xml new file mode 100644 index 000000000..40c0699ee --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/api.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/aggregateMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/aggregateMediator.xml new file mode 100644 index 000000000..dd847f08c --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/aggregateMediator.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/cacheMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/cacheMediator.xml new file mode 100644 index 000000000..57b1a0a02 --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/cacheMediator.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + * + + + .* + false + false + org.wso2.carbon.mediator.cache.digest.HttpRequestHashGenerator + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/cloneMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/cloneMediator.xml new file mode 100644 index 000000000..4dbd98a1a --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/cloneMediator.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/filterMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/filterMediator.xml new file mode 100644 index 000000000..e37bf5eae --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/filterMediator.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/foreachMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/foreachMediator.xml new file mode 100644 index 000000000..c1347365f --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/foreachMediator.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/iterateMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/iterateMediator.xml new file mode 100644 index 000000000..2aa20a0b5 --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/iterateMediator.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/scatterGatherMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/scatterGatherMediator.xml new file mode 100644 index 000000000..fdcf059f2 --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/scatterGatherMediator.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/simpleMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/simpleMediator.xml new file mode 100644 index 000000000..cc2da4b1d --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/simpleMediator.xml @@ -0,0 +1,25 @@ + + + + + + + debugger test + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/switchMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/switchMediator.xml new file mode 100644 index 000000000..b70a2a9a8 --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/switchMediator.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/validateMediator.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/validateMediator.xml new file mode 100644 index 000000000..78fd29706 --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/mediators/validateMediator.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/proxy.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/proxy.xml new file mode 100644 index 000000000..bd7d1347d --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/proxy.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.lemminx/src/test/resources/synapse/debugger/template.xml b/org.eclipse.lemminx/src/test/resources/synapse/debugger/template.xml new file mode 100644 index 000000000..0c6b7f234 --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/synapse/debugger/template.xml @@ -0,0 +1,31 @@ + + +