-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ballerina-platform/ballerin…
…a-dev-tools into oas-client
- Loading branch information
Showing
11 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../src/main/java/io/ballerina/flowmodelgenerator/extension/request/ImportModuleRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 io.ballerina.flowmodelgenerator.extension.request; | ||
|
||
/** | ||
* Represents a request for module snippet. | ||
* | ||
* @param filePath The file path which contains the expression | ||
* @param importStatement The import statement to be applied | ||
*/ | ||
public record ImportModuleRequest(String filePath, String importStatement) { | ||
} |
37 changes: 37 additions & 0 deletions
37
...ion/src/main/java/io/ballerina/flowmodelgenerator/extension/response/SuccessResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 io.ballerina.flowmodelgenerator.extension.response; | ||
|
||
/** | ||
* This is a class to indicate if the API success or not. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public class SuccessResponse extends AbstractFlowModelResponse { | ||
|
||
private boolean success; | ||
|
||
public boolean success() { | ||
return this.success; | ||
} | ||
|
||
public void setSuccess(boolean success) { | ||
this.success = success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...s-extension/src/test/java/io/ballerina/flowmodelgenerator/extension/ImportModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* 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 io.ballerina.flowmodelgenerator.extension; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.reflect.TypeToken; | ||
import io.ballerina.flowmodelgenerator.core.ExpressionEditorContext; | ||
import io.ballerina.flowmodelgenerator.extension.request.ExpressionEditorDiagnosticsRequest; | ||
import io.ballerina.flowmodelgenerator.extension.request.ImportModuleRequest; | ||
import io.ballerina.tools.text.LinePosition; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
/** | ||
* This is a test class that tests the module snippet API. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public class ImportModuleTest extends AbstractLSTest { | ||
|
||
@Test(dataProvider = "data-provider") | ||
public void test(Path config) throws IOException { | ||
Path configJsonPath = configDir.resolve(config); | ||
TestConfig testConfig = gson.fromJson(Files.newBufferedReader(configJsonPath), TestConfig.class); | ||
String sourcePath = getSourcePath(testConfig.filePath()); | ||
notifyDidOpen(sourcePath); | ||
|
||
// Send module snippet request | ||
ImportModuleRequest moduleSnippetRequest = new ImportModuleRequest(sourcePath, testConfig.importStatement()); | ||
JsonObject successResponse = getResponse(moduleSnippetRequest); | ||
successResponse.get("success").getAsBoolean(); | ||
Assert.assertTrue(successResponse.get("success").getAsBoolean(), "Module snippet request failed"); | ||
|
||
// Send diagnostics request | ||
ExpressionEditorContext.Info info = | ||
new ExpressionEditorContext.Info(testConfig.expression(), LinePosition.from(1, 0), | ||
0, new JsonObject(), null, null); | ||
ExpressionEditorDiagnosticsRequest diagnosticsRequest = | ||
new ExpressionEditorDiagnosticsRequest(sourcePath, info); | ||
JsonObject response = getResponse(diagnosticsRequest, "expressionEditor/diagnostics"); | ||
List<Diagnostic> diagnostics = gson.fromJson(response.get("diagnostics").getAsJsonArray(), | ||
new TypeToken<List<Diagnostic>>() { }.getType()); | ||
notifyDidClose(sourcePath); | ||
|
||
// Check for undefined import/function diagnostic codes | ||
for (Diagnostic diagnostic : diagnostics) { | ||
String code = diagnostic.getCode().getLeft(); | ||
Assert.assertFalse(UNDEFINED_DIAGNOSTICS_CODES.contains(code), | ||
"Undefined diagnostic code found: " + code); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getResourceDir() { | ||
return "import_module"; | ||
} | ||
|
||
@Override | ||
protected String getApiName() { | ||
return "importModule"; | ||
} | ||
|
||
@Override | ||
protected String getServiceName() { | ||
return "expressionEditor"; | ||
} | ||
|
||
@Override | ||
protected Class<? extends AbstractLSTest> clazz() { | ||
return ImportModuleTest.class; | ||
} | ||
|
||
private record TestConfig(String description, String filePath, String importStatement, String expression) { | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...es/flow-model-generator-ls-extension/src/test/resources/import_module/config/config1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"description": "", | ||
"filePath": "source.bal", | ||
"importStatement": "import ballerina/log;\n", | ||
"expression": "log:p" | ||
} |
6 changes: 6 additions & 0 deletions
6
...es/flow-model-generator-ls-extension/src/test/resources/import_module/config/config2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"description": "", | ||
"filePath": "source.bal", | ||
"importStatement": "import ballerina/io;\n", | ||
"expression": "io:print" | ||
} |
10 changes: 10 additions & 0 deletions
10
...ules/flow-model-generator-ls-extension/src/test/resources/import_module/source/source.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import ballerina/io; | ||
|
||
public function testFunctionCall() { | ||
int result = 10; | ||
io:println("Result: ", result); | ||
} | ||
|
||
function fn() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters