Skip to content

Commit

Permalink
Removes JAXB API in sql-federation-optimizer test
Browse files Browse the repository at this point in the history
  • Loading branch information
linghengqian committed Dec 12, 2023
1 parent 112635d commit 97edd1c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 39 deletions.
14 changes: 2 additions & 12 deletions kernel/sql-federation/optimizer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;

import javax.xml.bind.JAXBException;
import java.io.IOException;
import java.sql.Types;
import java.util.Arrays;
Expand Down Expand Up @@ -252,7 +251,7 @@ void assertCompile(final TestCase testcase) {

private static class TestCaseArgumentsProvider implements ArgumentsProvider {

@SneakyThrows({IOException.class, JAXBException.class})
@SneakyThrows(IOException.class)
@Override
public Stream<? extends Arguments> provideArguments(final ExtensionContext extensionContext) {
return TestCasesLoader.getInstance().generate().stream().map(Arguments::of);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@

package org.apache.shardingsphere.sqlfederation.optimizer.it;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;

/**
* JAXB definition of test case.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
public final class TestCase {

@XmlAttribute(name = "sql")
@JacksonXmlProperty(localName = "sql", isAttribute = true)
private String sql;

@XmlElement(name = "assertion")
@JacksonXmlProperty(localName = "assertion")
private TestCaseAssertion assertion;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@

package org.apache.shardingsphere.sqlfederation.optimizer.it;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;

/**
* JAXB definition of test case assertion.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@Getter
@Setter
public final class TestCaseAssertion {

@XmlAttribute(name = "expected-result")
@JacksonXmlProperty(localName = "expected-result", isAttribute = true)
private String expectedResult;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@

package org.apache.shardingsphere.sqlfederation.optimizer.it;

import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.Getter;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collection;
import java.util.LinkedList;

/**
* JAXB definition of test cases.
*/
@XmlRootElement(name = "test-cases")
@JacksonXmlRootElement(localName = "test-cases")
@Getter
public final class TestCases {

@XmlElement(name = "test-case")
@JacksonXmlProperty(localName = "test-case")
private final Collection<TestCase> testCases = new LinkedList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package org.apache.shardingsphere.sqlfederation.optimizer.it;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;

import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
Expand All @@ -33,6 +34,8 @@ public final class TestCasesLoader {

private static final TestCasesLoader INSTANCE = new TestCasesLoader();

private static final ObjectMapper XML_MAPPER = XmlMapper.builder().defaultUseWrapper(false).build();

/**
* Get singleton instance.
*
Expand All @@ -47,9 +50,8 @@ public static TestCasesLoader getInstance() {
*
* @return collection of test cases
* @throws IOException exception for read file.
* @throws JAXBException exception for parse xml file.
*/
public Collection<TestCase> generate() throws IOException, JAXBException {
public Collection<TestCase> generate() throws IOException {
Collection<TestCase> result = new LinkedList<>();
URL queryCaseUrl = Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("cases/federation-query-sql-cases.xml"));
URL deleteCaseUrl = Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("cases/federation-delete-sql-cases.xml"));
Expand All @@ -58,9 +60,9 @@ public Collection<TestCase> generate() throws IOException, JAXBException {
return result;
}

private Collection<TestCase> loadTestCase(final URL url) throws IOException, JAXBException {
private Collection<TestCase> loadTestCase(final URL url) throws IOException {
try (FileReader reader = new FileReader(url.getFile())) {
TestCases testCases = (TestCases) JAXBContext.newInstance(TestCases.class).createUnmarshaller().unmarshal(reader);
TestCases testCases = XML_MAPPER.readValue(reader, TestCases.class);
return testCases.getTestCases();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class JDBCRepositorySQLLoader {

private static final Collection<String> JAR_URL_PROTOCOLS = new HashSet<>(Arrays.asList("jar", "war", "zip", "wsjar", "vfszip"));

private static final ObjectMapper XML_MAPPER = new XmlMapper();
private static final ObjectMapper XML_MAPPER = XmlMapper.builder().defaultUseWrapper(false).build();

/**
* Load JDBC repository SQL.
Expand Down

0 comments on commit 97edd1c

Please sign in to comment.