Skip to content

Commit b425297

Browse files
authored
Merge pull request #399 from ChinthakaJ98/unit-tests-01
Add unit tests for DirectoryTreeBuilder
2 parents f5e61db + f8cc68e commit b425297

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/synapse/directorytree/builder/DirectoryTreeBuilderTest.java

+33
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232
import java.io.File;
3333
import java.nio.file.Files;
3434
import java.nio.file.Paths;
35+
import java.util.ArrayList;
36+
import java.util.Arrays;
37+
import java.util.List;
3538

3639
import static org.junit.jupiter.api.Assertions.assertEquals;
3740
import static org.junit.jupiter.api.Assertions.assertNull;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
3842
import static org.mockito.Mockito.any;
3943
import static org.mockito.Mockito.mockStatic;
4044

@@ -97,6 +101,35 @@ void getProjectExplorerModelWithInvalidProjectFolder() {
97101
assertNull(result);
98102
}
99103

104+
@Test
105+
void getProjectIdentifiersWithArtifactList() {
106+
String resourcePath = "/synapse/resource.finder/test_project";
107+
String projectPath = new File(DirectoryTreeBuilderTest.class.getResource(resourcePath).getPath()).getAbsolutePath();
108+
connectorHolderMock.when(() -> ConnectorHolder.isValidConnector(any())).thenReturn(true);
109+
String apiPath = new File(DirectoryTreeBuilderTest.class.getResource(resourcePath + "/src/main/wso2mi/artifacts/apis/testApi.xml").
110+
getPath()).getAbsolutePath();
111+
String sequencePath = new File(DirectoryTreeBuilderTest.class.getResource(resourcePath + "/src/main/wso2mi/artifacts/sequences/testSequence1.xml")
112+
.getPath()).getAbsolutePath();
113+
List<String> artifactIdentifierList = Arrays.asList("apis" + File.separator + "testApi",
114+
"sequences" + File.separator + "testSequence1");
115+
List<String> result = DirectoryTreeBuilder.getProjectIdentifiers(new WorkspaceFolder(projectPath),
116+
Arrays.asList(apiPath, sequencePath));
117+
connectorHolderMock.close();
118+
119+
assertEquals(artifactIdentifierList, result);
120+
}
121+
122+
@Test
123+
void getProjectIdentifiersWithEmptyArtifactList() {
124+
String path = DirectoryTreeBuilderTest.class.getResource("/synapse/resource.finder/test_project").getPath();
125+
String projectPath = new File(path).getAbsolutePath();
126+
connectorHolderMock.when(() -> ConnectorHolder.isValidConnector(any())).thenReturn(true);
127+
List<String> result = DirectoryTreeBuilder.getProjectIdentifiers(new WorkspaceFolder(projectPath), new ArrayList<>());
128+
connectorHolderMock.close();
129+
130+
assertTrue(result.isEmpty());
131+
}
132+
100133
private static JsonObject sanitizeJson(JsonObject jsonObject) {
101134
JsonObject sanitizedJson = new JsonObject();
102135
for (String key : jsonObject.keySet()) {

0 commit comments

Comments
 (0)