-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from LakshanWeerasinghe/fix-trigger-issues
Fix several issues related to creating triggers and loading triggers
- Loading branch information
Showing
16 changed files
with
1,577 additions
and
4 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
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
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
120 changes: 120 additions & 0 deletions
120
...-extension/src/test/java/io/ballerina/servicemodelgenerator/extension/AddServiceTest.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,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 io.ballerina.servicemodelgenerator.extension; | ||
|
||
import com.google.gson.JsonObject; | ||
import com.google.gson.reflect.TypeToken; | ||
import io.ballerina.servicemodelgenerator.extension.model.Service; | ||
import io.ballerina.servicemodelgenerator.extension.request.ServiceSourceRequest; | ||
import org.eclipse.lsp4j.TextEdit; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Tests for the service model source generator addService service. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
public class AddServiceTest extends AbstractLSTest { | ||
|
||
private static final Type TEXT_EDIT_LIST_TYPE = new TypeToken<Map<String, List<TextEdit>>>() { | ||
}.getType(); | ||
|
||
@Override | ||
@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); | ||
|
||
ServiceSourceRequest request = new ServiceSourceRequest( | ||
sourceDir.resolve(testConfig.filePath()).toAbsolutePath().toString(), testConfig.service()); | ||
JsonObject jsonMap = getResponse(request).getAsJsonObject("textEdits"); | ||
|
||
Map<String, List<TextEdit>> actualTextEdits = gson.fromJson(jsonMap, TEXT_EDIT_LIST_TYPE); | ||
|
||
boolean assertFailure = false; | ||
|
||
if (actualTextEdits.size() != testConfig.output().size()) { | ||
log.info("The number of text edits does not match the expected output."); | ||
assertFailure = true; | ||
} | ||
|
||
Map<String, List<TextEdit>> newMap = new HashMap<>(); | ||
for (Map.Entry<String, List<TextEdit>> entry : actualTextEdits.entrySet()) { | ||
Path fullPath = Paths.get(entry.getKey()); | ||
String relativePath = sourceDir.relativize(fullPath).toString(); | ||
|
||
List<TextEdit> textEdits = testConfig.output().get(relativePath.replace("\\", "/")); | ||
if (textEdits == null) { | ||
log.info("No text edits found for the file: " + relativePath); | ||
assertFailure = true; | ||
} else if (!assertArray("text edits", entry.getValue(), textEdits)) { | ||
assertFailure = true; | ||
} | ||
|
||
newMap.put(relativePath, entry.getValue()); | ||
} | ||
|
||
if (assertFailure) { | ||
TestConfig updatedConfig = | ||
new TestConfig(testConfig.filePath(), testConfig.description(), testConfig.service(), newMap); | ||
// updateConfig(configJsonPath, updatedConfig); | ||
Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.description(), configJsonPath)); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getResourceDir() { | ||
return "add_service"; | ||
} | ||
|
||
@Override | ||
protected Class<? extends AbstractLSTest> clazz() { | ||
return AddServiceTest.class; | ||
} | ||
|
||
@Override | ||
protected String getApiName() { | ||
return "addService"; | ||
} | ||
|
||
/** | ||
* Represents the test configuration for the source generator test. | ||
* | ||
* @param filePath The path to the source file. | ||
* @param description The description of the test. | ||
* @param service The service to be added. | ||
* @param output The expected output. | ||
*/ | ||
private record TestConfig(String filePath, String description, Service service, | ||
Map<String, List<TextEdit>> output) { | ||
public String description() { | ||
return description == null ? "" : description; | ||
} | ||
} | ||
} |
Oops, something went wrong.