Skip to content

Add test cases for debugger helper #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public DebuggerHelper(String filePath) {
}
}

public DebuggerHelper(STNode syntaxTree) {

this.syntaxTree = syntaxTree;
}

/**
* This method is used to validate the breakpoints.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.eclipse.lemminx.customservice.synapse.debugger.entity;

import java.util.Objects;

public class Breakpoint {

int line;
Expand Down Expand Up @@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ public JsonElement toJson() {

return null;
}

@Override
public String toString() {

return "InboundDebugInfo{" +
"mediatorPosition='" + mediatorPosition + '\'' +
", isValid=" + isValid +
", error='" + error + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ public JsonElement toJson() {

return rootNode;
}

@Override
public String toString() {

return "SequenceDebugInfo{" +
"sequenceKey='" + sequenceKey + '\'' +
", mediatorPosition='" + mediatorPosition + '\'' +
", isValid=" + isValid +
", error='" + error + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public void setTemplateKey(String templateKey) {
this.templateKey = templateKey;
}

public String getTemplateKey() {

return templateKey;
}

@Override
public JsonElement toJson() {

Expand All @@ -43,4 +48,15 @@ public JsonElement toJson() {

return rootNode;
}

@Override
public String toString() {

return "TemplateDebugInfo{" +
"templateKey='" + templateKey + '\'' +
", mediatorPosition='" + mediatorPosition + '\'' +
", isValid=" + isValid +
", error='" + error + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Loading
Loading