Skip to content

Commit

Permalink
Fix small bugs for jdk11 compability (#2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisihab committed Oct 21, 2021
1 parent 932fb7c commit c61d576
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 42 deletions.
4 changes: 2 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>transaction-api</artifactId>
<version>1.1</version>
<artifactId>javax.transaction-api</artifactId>
<version>1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;

Expand Down Expand Up @@ -138,7 +139,7 @@ public static Set<XSD> mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(IScop
Set<XSD> xsds = xsdsGroupedByNamespace.get(namespace);
// Get attributes of root elements and get import elements from all XSD's
List<Attribute> rootAttributes = new ArrayList<Attribute>();
List<Attribute> rootNamespaceAttributes = new ArrayList<Attribute>();
List<Namespace> rootNamespaceAttributes = new ArrayList<Namespace>();
List<XMLEvent> imports = new ArrayList<XMLEvent>();
for (XSD xsd: xsds) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Expand Down Expand Up @@ -209,7 +210,7 @@ public static void xsdToXmlStreamWriter(final XSD xsd, XMLStreamWriter xmlStream
* stripSchemaLocationFromImport is true it will be removed.
* @throws java.io.IOException, XMLStreamException
*/
public static void xsdToXmlStreamWriter(final XSD xsd, XMLStreamWriter xmlStreamWriter, boolean standalone, boolean stripSchemaLocationFromImport, boolean skipRootStartElement, boolean skipRootEndElement, List<Attribute> rootAttributes, List<Attribute> rootNamespaceAttributes, List<XMLEvent> imports, boolean noOutput) throws IOException, ConfigurationException {
public static void xsdToXmlStreamWriter(final XSD xsd, XMLStreamWriter xmlStreamWriter, boolean standalone, boolean stripSchemaLocationFromImport, boolean skipRootStartElement, boolean skipRootEndElement, List<Attribute> rootAttributes, List<Namespace> rootNamespaceAttributes, List<XMLEvent> imports, boolean noOutput) throws IOException, ConfigurationException {
Map<String, String> namespacesToCorrect = new HashMap<String, String>();
NamespaceCorrectingXMLStreamWriter namespaceCorrectingXMLStreamWriter = new NamespaceCorrectingXMLStreamWriter(xmlStreamWriter, namespacesToCorrect);
final XMLStreamEventWriter streamEventWriter = new XMLStreamEventWriter(namespaceCorrectingXMLStreamWriter);
Expand Down Expand Up @@ -257,11 +258,11 @@ public static void xsdToXmlStreamWriter(final XSD xsd, XMLStreamWriter xmlStream
rootAttributes.add(attribute);
}
}
iterator = startElement.getNamespaces();
while (iterator.hasNext()) {
Attribute attribute = iterator.next();
Iterator<Namespace> namespaceIterator = startElement.getNamespaces();
while (namespaceIterator.hasNext()) {
Namespace attribute = namespaceIterator.next();
boolean add = true;
for (Attribute attribute2 : rootNamespaceAttributes) {
for (Namespace attribute2 : rootNamespaceAttributes) {
if (XmlUtils.attributesEqual(attribute, attribute2)) {
add = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ public SaxException() {
}

public SaxException(Exception e) {
super(e);
try {
initCause(e); // this fixes stacktrace under IBM JDK, does nothing under standard JDK
} catch (Exception e2) { // Jboss throws 'IllegalStateException: Can't overwrite cause'
addSuppressed(e2);
}
this(null, e);
}

public SaxException(String message, Exception e) {
Expand Down
20 changes: 14 additions & 6 deletions core/src/test/java/nl/nn/adapterframework/jdbc/JdbcTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.sql.DataSource;

import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.runner.RunWith;
Expand All @@ -19,19 +20,20 @@

import liquibase.Contexts;
import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.FileSystemResourceAccessor;
import liquibase.resource.ClassLoaderResourceAccessor;
import nl.nn.adapterframework.jdbc.JdbcQuerySenderBase.QueryType;
import nl.nn.adapterframework.jdbc.dbms.DbmsSupportFactory;
import nl.nn.adapterframework.jdbc.dbms.IDbmsSupport;
import nl.nn.adapterframework.testutil.TestFileUtils;
import nl.nn.adapterframework.testutil.URLDataSourceFactory;
import nl.nn.adapterframework.util.JdbcUtil;
import nl.nn.adapterframework.util.LogUtil;

@RunWith(Parameterized.class)
public abstract class JdbcTestBase {
private final static String IBISSTORE_CHANGESET_PATH = "/Migrator/Ibisstore_4_unittests_changeset.xml";
private final static String IBISSTORE_CHANGESET_PATH = "Migrator/Ibisstore_4_unittests_changeset.xml";
protected static Logger log = LogUtil.getLogger(JdbcTestBase.class);

protected Liquibase liquibase;
Expand Down Expand Up @@ -66,10 +68,16 @@ public void setup() throws Exception {
prepareDatabase();
}

@After
public void teardown() throws Exception {
if(liquibase != null) {
liquibase.dropAll();
}
}

protected void createDbTable() throws Exception {
FileSystemResourceAccessor resourceAccessor = new FileSystemResourceAccessor(TestFileUtils.getTestFileURL("/").getPath());
String changesetFilePath = TestFileUtils.getTestFileURL(IBISSTORE_CHANGESET_PATH).getPath();
liquibase = new Liquibase(changesetFilePath, resourceAccessor, new JdbcConnection(getConnection()));
Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(getConnection()));
liquibase = new Liquibase(IBISSTORE_CHANGESET_PATH, new ClassLoaderResourceAccessor(), db);
liquibase.update(new Contexts());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Date;
import java.util.zip.DeflaterOutputStream;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -42,12 +41,6 @@ public void setup() throws Exception {
createDbTable();
}


@After
public void teardown() throws Exception {
liquibase.dropAll();
}

@Test
public void testQueryTextAndBrowseMessage() throws Exception {
testQueryTextAndBrowseMessageHelper(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -76,11 +75,6 @@ private Adapter setupAdapter() throws ConfigurationException {
return adapter;
}

@After
public void teardown() throws Exception {
liquibase.dropAll();
}

@Test
public void testCleanupDatabaseJobMaxRowsZero() throws Exception {
jobDef.setName(cleanupJobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URL;
Expand All @@ -10,7 +11,6 @@

import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -76,8 +76,8 @@ public void checkPersistance() {
AppConstants constants3 = AppConstants.getInstance(classLoader);
constants3.put("constants3", "3");

Assert.assertEquals(constants, constants1);
Assert.assertEquals(constants2, constants3);
assertTrue("Singleton instance is not identical", constants == constants1);
assertTrue("Singleton instance is not identical", constants2 == constants3);

assertEquals("1", constants.get("constants1"));
assertEquals("2", constants.get("constants2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.sql.PreparedStatement;
import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -44,11 +43,6 @@ public void setup() throws Exception {
listener = new JavaListener();
}

@After
public void teardown() throws Exception {
liquibase.dropAll();
}

@Test
public void testMessageFilter() throws Exception {
String messageRoot = "message";
Expand Down

0 comments on commit c61d576

Please sign in to comment.