From 2e5357daf53e4af766c415bd85d2effb4b015e0b Mon Sep 17 00:00:00 2001 From: David Dieppois <75264909+ddieppois@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:30:27 -0500 Subject: [PATCH] Test coverage increase (#68) * 666-UpdateCQL3.x Updated pom.xml with latest version of CQL engine, evaluator, picocli and hapi. * 666-UpdateCQL3.x Updated version to 2.1.1 * 666-UpdateCQL3.x Updated version to 3.0.0 * 666-UpdateCQL3.x Reverted to proper version * 666-UpdateCQL3.x Current state * 666-UpdateCQL3.x Working build with update Todo: Remove evaluator JABX * 666-UpdateCQL3.x Updated to version 3.0.0 Need to remove Jabx * 666-UpdateCQL3.x Updated to version 3.0.0 Fixed startup issue with LsService! Updated cql to elm pom version Need to remove Jabx * 666-UpdateCQL3.x Updated latest version of jaxb * 666-UpdateCQL3.x Removed unused libraries from pom.xml Working version of cql-language-server! * 666-UpdateCQL3.x Cleanup * Test Coverage Increase Added complete test class for ViewElmCommandContribution * Remove Java 9 profile since we're now baselined at 11 --------- Co-authored-by: Jonathan Percival --- .../command/ViewElmCommandContribution.java | 2 +- .../ViewElmCommandContributionTest.java | 52 +++++++++++++++++++ .../org/opencds/cqf/cql/ls/server/One.xml | 25 +++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContributionTest.java create mode 100644 ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml diff --git a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java index 6f645ad..a2793ac 100644 --- a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java +++ b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContribution.java @@ -62,7 +62,7 @@ private CompletableFuture viewElm(ExecuteCommandParams params) { } } - public static String convertToXml(Library library) throws IOException { + private static String convertToXml(Library library) throws IOException { StringWriter writer = new StringWriter(); ElmLibraryWriterFactory.getWriter(LibraryContentType.XML.mimeType()).write(library, writer); return writer.getBuffer().toString(); diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContributionTest.java new file mode 100644 index 0000000..6441c62 --- /dev/null +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/ViewElmCommandContributionTest.java @@ -0,0 +1,52 @@ +package org.opencds.cqf.cql.ls.server.command; + +import com.google.gson.JsonParser; +import org.eclipse.lsp4j.ExecuteCommandParams; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.ls.core.ContentService; +import org.opencds.cqf.cql.ls.server.manager.CompilerOptionsManager; +import org.opencds.cqf.cql.ls.server.manager.CqlCompilationManager; +import org.opencds.cqf.cql.ls.server.manager.IgContextManager; +import org.opencds.cqf.cql.ls.server.service.TestContentService; +import org.springframework.boot.test.context.SpringBootTest; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collections; + +import static org.junit.jupiter.api.Assertions.*; + +class ViewElmCommandContributionTest { + + private static ViewElmCommandContribution viewElmCommandContribution; + @BeforeAll + static void beforeAll() { + ContentService cs = new TestContentService(); + CqlCompilationManager cqlCompilationManager = + new CqlCompilationManager(cs, new CompilerOptionsManager(cs), new IgContextManager(cs)); + viewElmCommandContribution = new ViewElmCommandContribution(cqlCompilationManager); + } + + @Test + void getCommands() { + assertEquals(1, viewElmCommandContribution.getCommands().size()); + assertEquals("org.opencds.cqf.cql.ls.viewElm", viewElmCommandContribution.getCommands().toArray()[0]); + } + + @Test + void executeCommand() { + ExecuteCommandParams params = new ExecuteCommandParams(); + params.setCommand("org.opencds.cqf.cql.ls.viewElm"); + params.setArguments(Collections.singletonList(JsonParser.parseString("\"\\/org\\/opencds\\/cqf\\/cql\\/ls\\/server\\/One.cql\""))); + viewElmCommandContribution.executeCommand(params).thenAccept(result -> { + try { + String expectedXml = new String(Files.readAllBytes(Paths.get("src/test/resources/One.xml"))).trim().replaceAll("\\s+", ""); + assertEquals(expectedXml, result.toString().trim().replaceAll("\\s+", "")); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } +} \ No newline at end of file diff --git a/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml b/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml new file mode 100644 index 0000000..c5fe2a4 --- /dev/null +++ b/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml @@ -0,0 +1,25 @@ + + + + + + library One + + + + + + + + + + + + define "One": + 1 + + + + + + \ No newline at end of file