Skip to content

Commit

Permalink
#598 - Update test dependencies, avoid usage of deprecated methods an…
Browse files Browse the repository at this point in the history
…d update unit test implementations
  • Loading branch information
dstenger committed Nov 17, 2023
1 parent bc10569 commit 6804220
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 91 deletions.
68 changes: 36 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,6 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlmatchers</groupId>
<artifactId>xml-matchers</artifactId>
<version>1.0-RC1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand All @@ -135,11 +123,6 @@
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
Expand Down Expand Up @@ -221,16 +204,6 @@
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.14.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
Expand All @@ -256,11 +229,6 @@
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-fileupload2-jakarta</artifactId>
Expand All @@ -286,6 +254,42 @@
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.15.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
6 changes: 2 additions & 4 deletions teamengine-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.xmlmatchers</groupId>
<artifactId>xml-matchers</artifactId>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
Expand All @@ -89,12 +89,10 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.occamlab.te;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.xmlmatchers.XmlMatchers.hasXPath;
import static org.xmlmatchers.transform.XmlConverters.the;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.matchers.EvaluateXPathMatcher.hasXPath;
import static org.xmlunit.matchers.HasXPathMatcher.hasXPath;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import javax.xml.namespace.NamespaceContext;

import org.junit.Test;
import org.xmlmatchers.XmlMatchers;
import org.xmlmatchers.namespace.SimpleNamespaceContext;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
Expand Down Expand Up @@ -42,20 +38,20 @@ public void testGenerateEarlReport()

ctlEarlReporter.generateEarlReport( earlReport, reportStream, testSuiteName, parames );

assertThat( the( earlReport.toString() ), hasXPath( "/rdf:RDF", nsContext() ) );
assertThat( the( earlReport.toString() ),
hasXPath( "count(//earl:TestRequirement)", equalTo( "4" ), nsContext() ) );
assertThat( the( earlReport.toString() ),
hasXPath( "//earl:TestRequirement[@rdf:about='queryable']/cite:isBasic", equalTo( "false" ), nsContext() ) );
assertThat( the( earlReport.toString() ),
hasXPath( "//earl:TestRequirement[@rdf:about='basic']/cite:isBasic", equalTo( "true" ), nsContext() ) );
assertThat(earlReport.toString(), hasXPath("/rdf:RDF").withNamespaceContext(nsContext()));
assertThat(earlReport.toString(),
hasXPath("count(//earl:TestRequirement)", equalTo("4")).withNamespaceContext(nsContext()));
assertThat(earlReport.toString(),
hasXPath("//earl:TestRequirement[@rdf:about='queryable']/cite:isBasic", equalTo("false")).withNamespaceContext(nsContext()));
assertThat(earlReport.toString(),
hasXPath("//earl:TestRequirement[@rdf:about='basic']/cite:isBasic", equalTo("true")).withNamespaceContext(nsContext()));
}

private NamespaceContext nsContext() {
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext = nsContext.withBinding( "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" );
nsContext = nsContext.withBinding( "earl", "http://www.w3.org/ns/earl#" );
nsContext = nsContext.withBinding( "cite", "http://cite.opengeospatial.org/" );
private Map<String, String> nsContext() {
Map<String, String> nsContext = new HashMap<>();
nsContext.put("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
nsContext.put("earl", "http://www.w3.org/ns/earl#");
nsContext.put("cite", "http://cite.opengeospatial.org/");
return nsContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.xmlmatchers.XmlMatchers.hasXPath;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.xmlunit.matchers.EvaluateXPathMatcher.hasXPath;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -13,15 +13,12 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;

import javax.xml.namespace.NamespaceContext;
import javax.xml.transform.Source;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.xmlmatchers.namespace.SimpleNamespaceContext;
import org.xmlmatchers.transform.XmlConverters;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
Expand Down Expand Up @@ -61,19 +58,19 @@ public void testEarlHtmlReport_Ctl_WithHierarchy_WithInheritedFailure()
File indexHtmlFile = new File( outputDirectory, "result/index.html" );
assertThat( indexHtmlFile.exists(), is( true ) );

Source indexHtml = the( indexHtmlFile );
String indexHtml = retreiveString(indexHtmlFile);
// 7 rows plus the header row
assertThat( indexHtml,
hasXPath( "count(//html:table[@id='queryable']/html:tbody/html:tr)", equalTo( "8" ), nsContext() ) );

assertThat( indexHtml,
hasXPath( "//html:span[@id='testsInTotal_data-independent']", equalTo( "207" ), nsContext() ) );
assertThat( indexHtml,
hasXPath( "//html:span[@id='testsFailed_data-independent']", equalTo( "1" ), nsContext() ) );
assertThat( indexHtml,
hasXPath( "//html:span[@id='testsInTotal_data-preconditions']", equalTo( "0" ), nsContext() ) );
assertThat( indexHtml, hasXPath( "//html:span[@id='testsInTotal_basic']", equalTo( "11" ), nsContext() ) );
assertThat( indexHtml, hasXPath( "//html:span[@id='testsInTotal_queryable']", equalTo( "7" ), nsContext() ) );
assertThat(indexHtml,
hasXPath("count(//html:table[@id='queryable']/html:tbody/html:tr)", equalTo("8")).withNamespaceContext(nsContext()));

assertThat(indexHtml,
hasXPath("//html:span[@id='testsInTotal_data-independent']", equalTo("207")).withNamespaceContext(nsContext()));
assertThat(indexHtml,
hasXPath("//html:span[@id='testsFailed_data-independent']", equalTo("1")).withNamespaceContext(nsContext()));
assertThat(indexHtml,
hasXPath("//html:span[@id='testsInTotal_data-preconditions']", equalTo("0")).withNamespaceContext(nsContext()));
assertThat(indexHtml, hasXPath("//html:span[@id='testsInTotal_basic']", equalTo("11")).withNamespaceContext(nsContext()));
assertThat(indexHtml, hasXPath("//html:span[@id='testsInTotal_queryable']", equalTo("7")).withNamespaceContext(nsContext()));
}

@Test
Expand All @@ -87,23 +84,23 @@ public void testEarlHtmlReport_Ctl_WithHierarchy_MissingElements()
File indexHtmlFile = new File( outputDirectory, "result/index.html" );
assertThat( indexHtmlFile.exists(), is( true ) );

Source indexHtml = the( indexHtmlFile );
String indexHtml = retreiveString(indexHtmlFile);
// 7 rows plus the header row
assertThat( indexHtml,
hasXPath( "count(//html:table[@id='queryable']/html:tbody/html:tr)", equalTo( "8" ), nsContext() ) );
assertThat(indexHtml,
hasXPath("count(//html:table[@id='queryable']/html:tbody/html:tr)", equalTo("8")).withNamespaceContext(nsContext()));

assertThat( indexHtml, hasXPath( "//html:span[@id='testsPassed_queryable']", equalTo( "7" ), nsContext() ) );
assertThat( indexHtml, hasXPath( "//html:span[@id='testsFailed_queryable']", equalTo( "0" ), nsContext() ) );
assertThat( indexHtml, hasXPath( "//html:span[@id='testsSkipped_queryable']", equalTo( "0" ), nsContext() ) );
assertThat( indexHtml, hasXPath( "//html:span[@id='testsInTotal_queryable']", equalTo( "7" ), nsContext() ) );
assertThat(indexHtml, hasXPath("//html:span[@id='testsPassed_queryable']", equalTo("7")).withNamespaceContext(nsContext()));
assertThat(indexHtml, hasXPath("//html:span[@id='testsFailed_queryable']", equalTo("0")).withNamespaceContext(nsContext()));
assertThat(indexHtml, hasXPath("//html:span[@id='testsSkipped_queryable']", equalTo("0")).withNamespaceContext(nsContext()));
assertThat(indexHtml, hasXPath("//html:span[@id='testsInTotal_queryable']", equalTo("7")).withNamespaceContext(nsContext()));
}

private Source the( File indexHtmlFile )
throws Exception {
private String retreiveString(File indexHtmlFile)
throws Exception {
OutputStream indexHtml = new ByteArrayOutputStream();
IOUtils.copy( new FileInputStream( indexHtmlFile ), indexHtml );
IOUtils.copy(new FileInputStream(indexHtmlFile), indexHtml);
indexHtml.close();
return XmlConverters.the( indexHtml.toString() );
return indexHtml.toString();
}

private String createTempDirectoryAndCopyResources( String earlReport )
Expand All @@ -121,9 +118,9 @@ private String createTempDirectoryAndCopyResources( String earlReport )
return outputDirectory.getAbsolutePath();
}

private NamespaceContext nsContext() {
SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
nsContext = nsContext.withBinding( "html", "http://www.w3.org/1999/xhtml" );
private Map<String, String> nsContext() {
Map<String, String> nsContext = new HashMap<>();
nsContext.put( "html", "http://www.w3.org/1999/xhtml" );
return nsContext;
}
}
1 change: 0 additions & 1 deletion teamengine-realm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
Expand Down
2 changes: 0 additions & 2 deletions teamengine-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
Expand Down

0 comments on commit 6804220

Please sign in to comment.