diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..779f99a12 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a786d212a..67d9aba55 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,3 +22,15 @@ jobs: java-version: 1.8 - name: Build with Maven run: mvn -B package --file pom.xml + - name: Store JVM Crash and Surefire Logs + if: always() # Forces this step to run even if the Maven build fails + uses: actions/upload-artifact@v4 + with: + name: maven-crash-logs + path: | + **/hs_err_pid*.log + **/target/surefire-reports/*.dump* + **/target/surefire-reports/*.txt + - name: Check System Logs for Memory (OOM) Kills + if: always() + run: dmesg | grep -i -E 'oom[-_]killer|killed process' || echo "No OS-level OOM kills detected." diff --git a/.gitignore b/.gitignore index 9533b9311..1f36c6463 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /.project /.settings/ /.DS_Store +/.metadata/ diff --git a/mockrunner-all/pom.xml b/mockrunner-all/pom.xml index 4b7793a67..69dd78b36 100644 --- a/mockrunner-all/pom.xml +++ b/mockrunner-all/pom.xml @@ -5,8 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT - .. + 2.0.8-SNAPSHOT mockrunner-all @@ -17,75 +16,75 @@ com.mockrunner mockrunner-core - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-jms - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-jms - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-ejb - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-ejb - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-jdbc - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-jdbc - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-jca - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-servlet - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-servlet - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT tests test com.mockrunner mockrunner-tag - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-struts - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT com.mockrunner mockrunner-struts - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT tests test @@ -105,6 +104,10 @@ jboss jboss-j2ee + + org.jboss.spec.javax.rmi + jboss-rmi-api_1.0_spec + @@ -154,7 +157,7 @@ - + release-module-exclusives diff --git a/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java b/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java index 87d61d692..a5987cdad 100644 --- a/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java +++ b/mockrunner-all/src/main/java/com/mockrunner/base/HTMLOutputTestCase.java @@ -56,7 +56,7 @@ protected org.w3c.dom.Document getOutputAsW3CDocument() /** * Delegates to {@link HTMLOutputModule#getOutputAsJDOMDocument} */ - protected org.jdom.Document getOutputAsJDOMDocument() + protected org.jdom2.Document getOutputAsJDOMDocument() { return getHTMLOutputModule().getOutputAsJDOMDocument(); } diff --git a/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java b/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java index 2ae4fdd49..38bfdb578 100644 --- a/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java +++ b/mockrunner-all/src/test/java/com/mockrunner/test/web/HTMLOutputModuleTest.java @@ -17,7 +17,7 @@ import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import org.jdom.Element; +import org.jdom2.Element; import org.junit.Before; import org.junit.Test; diff --git a/mockrunner-core/pom.xml b/mockrunner-core/pom.xml index 7e7d581b9..b28165348 100644 --- a/mockrunner-core/pom.xml +++ b/mockrunner-core/pom.xml @@ -5,8 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT - .. + 2.0.8-SNAPSHOT mockrunner-core @@ -31,8 +30,8 @@ - jdom - jdom + org.jdom + jdom2 diff --git a/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java b/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java index 5983a0b3f..282198e41 100644 --- a/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java +++ b/mockrunner-core/src/main/java/com/mockrunner/test/util/XmlUtilTest.java @@ -5,8 +5,8 @@ import junit.framework.TestCase; -import org.jdom.Document; -import org.jdom.Element; +import org.jdom2.Document; +import org.jdom2.Element; import com.mockrunner.util.web.XmlUtil; diff --git a/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java b/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java index aab42bceb..8ae749abf 100644 --- a/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java +++ b/mockrunner-core/src/main/java/com/mockrunner/util/web/XmlUtil.java @@ -5,9 +5,9 @@ import org.apache.xerces.parsers.DOMParser; import org.cyberneko.html.HTMLConfiguration; -import org.jdom.Element; -import org.jdom.input.DOMBuilder; -import org.jdom.output.XMLOutputter; +import org.jdom2.Element; +import org.jdom2.input.DOMBuilder; +import org.jdom2.output.XMLOutputter; import org.xml.sax.InputSource; import com.mockrunner.base.NestedApplicationException; @@ -34,10 +34,10 @@ public class XmlUtil * * * the method returns the h1 tag as Element. - * @param document the org.jdom.Document + * @param document the org.jdom2.Document * @return the body Element */ - public static Element getBodyFragmentFromJDOMDocument(org.jdom.Document document) + public static Element getBodyFragmentFromJDOMDocument(org.jdom2.Document document) { Element element = document.getRootElement().getChild("BODY"); if(null == element) @@ -57,17 +57,17 @@ public static Element getBodyFragmentFromJDOMDocument(org.jdom.Document document * @return the body element * @deprecated use {@link #getBodyFragmentFromJDOMDocument} */ - public static Element getBodyFragmentJDOMDocument(org.jdom.Document document) + public static Element getBodyFragmentJDOMDocument(org.jdom2.Document document) { return getBodyFragmentFromJDOMDocument(document); } /** * Returns the documents XML content as a string. - * @param document the org.jdom.Document + * @param document the org.jdom2.Document * @return the output as string */ - public static String createStringFromJDOMDocument(org.jdom.Document document) + public static String createStringFromJDOMDocument(org.jdom2.Document document) { try { @@ -83,9 +83,9 @@ public static String createStringFromJDOMDocument(org.jdom.Document document) * Creates a JDOM Document from a specified * W3C Document. * @param document the org.w3c.dom.Document - * @return the org.jdom.Document + * @return the org.jdom2.Document */ - public static org.jdom.Document createJDOMDocument(org.w3c.dom.Document document) + public static org.jdom2.Document createJDOMDocument(org.w3c.dom.Document document) { return new DOMBuilder().build(document); } diff --git a/mockrunner-ejb/pom.xml b/mockrunner-ejb/pom.xml index 20f0dc1a5..1f63ece60 100644 --- a/mockrunner-ejb/pom.xml +++ b/mockrunner-ejb/pom.xml @@ -1,116 +1,145 @@ - 4.0.0 - - com.mockrunner - mockrunner - 2.0.7-SNAPSHOT - .. - + 4.0.0 + + com.mockrunner + mockrunner + 2.0.8-SNAPSHOT + - mockrunner-ejb - MockRunner-EJB - Mock classes for enterprise java beans + mockrunner-ejb + MockRunner-EJB + Mock classes for enterprise java beans - - - junit - junit - provided - - - com.mockrunner - mockrunner-core - - - commons-beanutils - commons-beanutils - - - org.mockejb - mockejb - - - jboss - jboss-j2ee - true - - + + + junit + junit + provided + + + com.mockrunner + mockrunner-core + + + commons-beanutils + commons-beanutils + + + org.mockejb + mockejb + + + cglib + cglib-full + + + + + cglib + cglib-nodep + 3.3.0 + + + org.jacorb + jacorb + 3.9 + + + jboss + jboss-j2ee + true + + + org.jboss.spec.javax.rmi + jboss-rmi-api_1.0_spec + test + + - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - verify - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadoc - verify - - jar - - - - - ${javadoc-executable-path} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - none - -Xdoclint:none - - - - - - - - release-module-exclusives - - - - performRelease - true - - - - - - com.github.github - site-maven-plugin - - ${project.artifactId} - Ejb Site - - - - github-site - - site - - site - - - - - - - + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadoc + verify + + jar + + + + + ${javadoc-executable-path} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + none + -Xdoclint:none + + + + org.apache.maven.plugins + maven-surefire-plugin + + --add-opens=java.base/java.lang=ALL-UNNAMED + 0 + false + + + + + + + + release-module-exclusives + + + + performRelease + true + + + + + + com.github.github + site-maven-plugin + + ${project.artifactId} + Ejb Site + + + + github-site + + site + + site + + + + + + + diff --git a/mockrunner-jca/pom.xml b/mockrunner-jca/pom.xml index 094db9730..c531475a1 100644 --- a/mockrunner-jca/pom.xml +++ b/mockrunner-jca/pom.xml @@ -5,8 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT - .. + 2.0.8-SNAPSHOT mockrunner-jca diff --git a/mockrunner-jdbc/pom.xml b/mockrunner-jdbc/pom.xml index 44cf19bae..a595cf37f 100644 --- a/mockrunner-jdbc/pom.xml +++ b/mockrunner-jdbc/pom.xml @@ -5,8 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT - .. + 2.0.8-SNAPSHOT mockrunner-jdbc diff --git a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java index 24d7c4617..c8faf67d8 100644 --- a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java +++ b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactory.java @@ -7,9 +7,9 @@ import java.util.List; import java.util.Map; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.input.SAXBuilder; import com.mockrunner.base.NestedApplicationException; import com.mockrunner.mock.jdbc.MockResultSet; diff --git a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java index 837ac29d3..b9d3fb098 100644 --- a/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java +++ b/mockrunner-jdbc/src/main/java/com/mockrunner/jdbc/XMLResultSetFactorySQLDeveloperSupport.java @@ -4,9 +4,9 @@ import java.util.Iterator; import java.util.List; -import org.jdom.Document; -import org.jdom.Element; -import org.jdom.input.SAXBuilder; +import org.jdom2.Document; +import org.jdom2.Element; +import org.jdom2.input.SAXBuilder; import com.mockrunner.base.NestedApplicationException; import com.mockrunner.mock.jdbc.MockResultSet; diff --git a/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java b/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java index c6ef37f25..fab2a8cf6 100644 --- a/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java +++ b/mockrunner-jdbc/src/main/java/com/mockrunner/mock/jdbc/MockSQLXML.java @@ -32,13 +32,13 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.jdom.Document; -import org.jdom.input.DOMBuilder; -import org.jdom.input.SAXBuilder; -import org.jdom.input.SAXHandler; -import org.jdom.output.DOMOutputter; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; +import org.jdom2.Document; +import org.jdom2.input.DOMBuilder; +import org.jdom2.input.SAXBuilder; +import org.jdom2.input.sax.SAXHandler; +import org.jdom2.output.DOMOutputter; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; import org.w3c.dom.Node; import org.xml.sax.InputSource; @@ -146,6 +146,7 @@ protected XMLInputFactory createXMLInputFactory() protected SAXBuilder createJDOMSAXBuilder() { + SAXBuilder builder = new SAXBuilder(); builder.setValidation(false); return builder; diff --git a/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java b/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java index 074832ebc..47059016a 100644 --- a/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java +++ b/mockrunner-jdbc/src/test/java/com/mockrunner/test/jdbc/MockSQLXMLTest.java @@ -24,11 +24,11 @@ import junit.framework.TestCase; -import org.jdom.Document; -import org.jdom.input.DOMBuilder; -import org.jdom.input.SAXBuilder; -import org.jdom.output.Format; -import org.jdom.output.XMLOutputter; +import org.jdom2.Document; +import org.jdom2.input.DOMBuilder; +import org.jdom2.input.SAXBuilder; +import org.jdom2.output.Format; +import org.jdom2.output.XMLOutputter; import org.xml.sax.ContentHandler; import org.xml.sax.helpers.AttributesImpl; diff --git a/mockrunner-jms-spring/pom.xml b/mockrunner-jms-spring/pom.xml index 3cb9a0c18..5566d6238 100644 --- a/mockrunner-jms-spring/pom.xml +++ b/mockrunner-jms-spring/pom.xml @@ -6,7 +6,6 @@ com.mockrunner mockrunner 2.0.0-SNAPSHOT - .. mockrunner-jms-spring @@ -51,8 +50,8 @@ true - org.apache.tomcat - servlet-api + javax.servlet + javax.servlet-api true @@ -137,7 +136,7 @@ - + release-module-exclusives diff --git a/mockrunner-jms/pom.xml b/mockrunner-jms/pom.xml index c594db51b..26a25b003 100644 --- a/mockrunner-jms/pom.xml +++ b/mockrunner-jms/pom.xml @@ -5,8 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT - .. + 2.0.8-SNAPSHOT mockrunner-jms @@ -30,8 +29,8 @@ true - org.apache.tomcat - servlet-api + javax.servlet + javax.servlet-api true @@ -80,7 +79,7 @@ - + release-module-exclusives diff --git a/mockrunner-servlet/pom.xml b/mockrunner-servlet/pom.xml index 5163d2cc8..5cbfee7e2 100644 --- a/mockrunner-servlet/pom.xml +++ b/mockrunner-servlet/pom.xml @@ -1,138 +1,152 @@ - 4.0.0 - - com.mockrunner - mockrunner - 2.0.7-SNAPSHOT - .. - + 4.0.0 + + com.mockrunner + mockrunner + 2.0.8-SNAPSHOT + - mockrunner-servlet - MockRunner-Servlet - Mock classes for servlets + mockrunner-servlet + MockRunner-Servlet + Mock classes for servlets - - - junit - junit - provided - - - com.mockrunner - mockrunner-core - - - com.mockrunner - mockrunner-core - xml - features - - - commons-logging - commons-logging - - - org.apache.tomcat - servlet-api - - - org.apache.tomcat - jasper - - - - - - org.apache.felix - maven-bundle-plugin - - - - com.mockrunner.base, - com.mockrunner.example.servlet, - com.mockrunner.mock.web, - com.mockrunner.servlet - Export-Package> - - - - - org.apache.karaf.tooling - karaf-maven-plugin - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - verify - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadoc - verify - - jar - - - - - ${javadoc-executable-path} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - ${project.build.sourceEncoding} - none - -Xdoclint:none - - - - + + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.assertj + assertj-core + test + + + com.mockrunner + mockrunner-core + test + + + com.mockrunner + mockrunner-core + + + com.mockrunner + mockrunner-core + xml + features + + + commons-logging + commons-logging + + + javax.servlet + javax.servlet-api + + + org.apache.tomcat + jasper + + + + + + org.apache.felix + maven-bundle-plugin + + + + com.mockrunner.base, + com.mockrunner.example.servlet, + com.mockrunner.mock.web, + com.mockrunner.servlet + + + + + + org.apache.karaf.tooling + karaf-maven-plugin + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + verify + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadoc + verify + + jar + + + + + ${javadoc-executable-path} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + ${project.build.sourceEncoding} + none + -Xdoclint:none + + + + - - - release-module-exclusives - - - - performRelease - true - - - - - - com.github.github - site-maven-plugin - - ${project.artifactId} - Servlet Site - - - - github-site - - site - - site - - - - - - - + + + release-module-exclusives + + + + performRelease + true + + + + + + com.github.github + site-maven-plugin + + ${project.artifactId} + Servlet Site + + + + github-site + + site + + site + + + + + + + diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java b/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java index 16fd09b43..7859ffc09 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/base/BasicHTMLOutputTestCase.java @@ -56,7 +56,7 @@ protected org.w3c.dom.Document getOutputAsW3CDocument() /** * Delegates to {@link HTMLOutputModule#getOutputAsJDOMDocument} */ - protected org.jdom.Document getOutputAsJDOMDocument() + protected org.jdom2.Document getOutputAsJDOMDocument() { return getHTMLOutputModule().getOutputAsJDOMDocument(); } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java b/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java index f6d0777da..269590782 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/base/HTMLOutputModule.java @@ -66,10 +66,10 @@ public org.w3c.dom.Document getOutputAsW3CDocument() * to parse the string output yourself. Please note that * HTML parsing is not very fast and may slow down * your test suite. - * @return the output as org.jdom.Document + * @return the output as org.jdom2.Document * @throws RuntimeException if a parsing error occurs */ - public org.jdom.Document getOutputAsJDOMDocument() + public org.jdom2.Document getOutputAsJDOMDocument() { return XmlUtil.createJDOMDocument(getOutputAsW3CDocument()); } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockAsyncContext.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockAsyncContext.java new file mode 100644 index 000000000..de0ce4f71 --- /dev/null +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockAsyncContext.java @@ -0,0 +1,102 @@ +package com.mockrunner.mock.web; + +import javax.servlet.AsyncContext; +import javax.servlet.AsyncListener; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +public class MockAsyncContext implements AsyncContext { + + private ServletRequest request; + private ServletResponse response; + private boolean hasOriginalRequestAndResponse; + private long timeout; + + @Override + public ServletRequest getRequest() { + return request; + } + + public MockAsyncContext setRequest(ServletRequest request) { + this.request = request; + return this; + } + + @Override + public ServletResponse getResponse() { + return response; + } + + public MockAsyncContext setResponse(ServletResponse response) { + this.response = response; + return this; + } + + @Override + public boolean hasOriginalRequestAndResponse() { + return hasOriginalRequestAndResponse; + } + + public MockAsyncContext setHasOriginalRequestAndResponse(boolean hasOriginalRequestAndResponse) { + this.hasOriginalRequestAndResponse = hasOriginalRequestAndResponse; + return this; + } + + @Override + public void dispatch() { + // No-op + } + + @Override + public void dispatch(String path) { + // No-op + } + + @Override + public void dispatch(ServletContext context, String path) { + // No-op + } + + @Override + public void complete() { + // No-op + } + + @Override + public void start(Runnable run) { + // No-op + } + + @Override + public void addListener(AsyncListener listener) { + // No-op + } + + @Override + public void addListener(AsyncListener listener, ServletRequest servletRequest, ServletResponse servletResponse) { + // No-op + } + + @Override + public T createListener(Class clazz) throws ServletException { + return (T) new MockAsyncListener(); + } + + @Override + public void setTimeout(long timeout) { + this.timeout = timeout; + } + + public MockAsyncContext setTimeoutFluent(long timeout) { + this.timeout = timeout; + return this; + } + + @Override + public long getTimeout() { + return timeout; + } + +} diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockAsyncListener.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockAsyncListener.java new file mode 100644 index 000000000..fc3e2b056 --- /dev/null +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockAsyncListener.java @@ -0,0 +1,31 @@ +package com.mockrunner.mock.web; + +import java.io.IOException; + +import javax.servlet.AsyncEvent; +import javax.servlet.AsyncListener; + +public class MockAsyncListener implements AsyncListener { + + @Override + public void onComplete(AsyncEvent event) throws IOException { + // No-op + } + + @Override + public void onTimeout(AsyncEvent event) throws IOException { + // No-op + } + + @Override + public void onError(AsyncEvent event) throws IOException { + // No-op + + } + + @Override + public void onStartAsync(AsyncEvent event) throws IOException { + // No-op + } + +} diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockDynamic.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockDynamic.java new file mode 100644 index 000000000..319baa725 --- /dev/null +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockDynamic.java @@ -0,0 +1,101 @@ +package com.mockrunner.mock.web; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.MultipartConfigElement; +import javax.servlet.ServletRegistration.Dynamic; +import javax.servlet.ServletSecurityElement; + +public class MockDynamic implements Dynamic { + HashSet mappings = new HashSet<>(); + private String runAsRole; + private String name; + private Map initParameters = new HashMap<>(); + + @Override + public Set addMapping(String... urlPatterns) { + for (String pattern : urlPatterns) { + mappings.add(pattern); + } + + return Collections.emptySet(); + } + + @Override + public Collection getMappings() { + return mappings; + } + + @Override + public String getRunAsRole() { + return runAsRole; + } + + @Override + public String getName() { + return name; + } + + public MockDynamic setName(String name) { + this.name = name; + return this; + } + + @Override + public String getClassName() { + return null; + } + + @Override + public boolean setInitParameter(String name, String value) { + initParameters.put(name, value); + return true; + } + + @Override + public String getInitParameter(String name) { + return initParameters.get(name); + } + + @Override + public Set setInitParameters(Map initParameters) { + this.initParameters.putAll(initParameters); + return Collections.emptySet(); + } + + @Override + public Map getInitParameters() { + return initParameters; + } + + @Override + public void setAsyncSupported(boolean isAsyncSupported) { + // No-op + } + + @Override + public void setLoadOnStartup(int loadOnStartup) { + // No-op + } + + @Override + public Set setServletSecurity(ServletSecurityElement constraint) { + return Collections.emptySet(); + } + + @Override + public void setMultipartConfig(MultipartConfigElement multipartConfig) { + // No-op + } + + @Override + public void setRunAsRole(String roleName) { + runAsRole = roleName; + } + +} diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockFilterRegistrationDynamic.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockFilterRegistrationDynamic.java new file mode 100644 index 000000000..1d5f19839 --- /dev/null +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockFilterRegistrationDynamic.java @@ -0,0 +1,86 @@ +package com.mockrunner.mock.web; + +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.servlet.DispatcherType; +import javax.servlet.FilterRegistration.Dynamic; + +public class MockFilterRegistrationDynamic implements Dynamic { + + private String name; + private String className; + private Map initParameters = new HashMap<>(); + + @Override + public void addMappingForServletNames(EnumSet dispatcherTypes, boolean isMatchAfter, String... servletNames) { + // No-op + } + + @Override + public Collection getServletNameMappings() { + return Collections.emptyList(); + } + + @Override + public void addMappingForUrlPatterns(EnumSet dispatcherTypes, boolean isMatchAfter, String... urlPatterns) { + // No-op + } + + @Override + public Collection getUrlPatternMappings() { + return Collections.emptyList(); + } + + @Override + public String getName() { + return name; + } + + public MockFilterRegistrationDynamic setName(String name) { + this.name = name; + return this; + } + + @Override + public String getClassName() { + return className; + } + + public MockFilterRegistrationDynamic setClassName(String className) { + this.className = className; + return this; + } + + @Override + public boolean setInitParameter(String name, String value) { + initParameters.put(name, value); + return true; + } + + @Override + public String getInitParameter(String name) { + return initParameters.get(name); + } + + @Override + public Set setInitParameters(Map initParameters) { + this.initParameters.putAll(initParameters); + return Collections.emptySet(); + } + + @Override + public Map getInitParameters() { + return initParameters; + } + + @Override + public void setAsyncSupported(boolean isAsyncSupported) { + // No-op + } + +} diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletRequest.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletRequest.java index 1ea37f853..52a4a7c7c 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletRequest.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletRequest.java @@ -11,6 +11,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Enumeration; @@ -18,16 +19,25 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.UUID; import java.util.Vector; +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; +import javax.servlet.ServletException; import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; import javax.servlet.ServletRequestAttributeEvent; import javax.servlet.ServletRequestAttributeListener; +import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpUpgradeHandler; +import javax.servlet.http.Part; import com.mockrunner.base.NestedApplicationException; import com.mockrunner.util.common.CaseAwareMap; @@ -64,6 +74,7 @@ public class MockHttpServletRequest implements HttpServletRequest private Map roles; private String characterEncoding; private int contentLength; + private long contentLengthLong; private String contentType; private List cookies; private MockServletInputStream bodyContent; @@ -74,6 +85,10 @@ public class MockHttpServletRequest implements HttpServletRequest private boolean sessionCreated; private List attributeListener; private boolean isAsyncSupported; + private AsyncContext asyncContext; + private DispatcherType dispatcherType; + private boolean authenticated; + private ArrayList parts = new ArrayList<>(); public MockHttpServletRequest() { @@ -166,6 +181,7 @@ public void resetAll() remoteAddr = "127.0.0.1"; roles = new HashMap(); contentLength = -1; + contentLengthLong = -1L; cookies = null; localAddr = "127.0.0.1"; localName = "localhost"; @@ -672,6 +688,16 @@ public MockHttpServletRequest setContentLength(int contentLength) return this; } + @Override + public long getContentLengthLong() { + return contentLengthLong; + } + + public MockHttpServletRequest setContentLengthLong(long contentLength) { + contentLengthLong = contentLength; + return this; + } + public String getContentType() { return contentType; @@ -815,6 +841,12 @@ public MockHttpServletRequest setLocalName(String localName) return this; } + public ServletContext getServletContext() + { + if(null == session) return new MockServletContext(); + return session.getServletContext(); + } + public int getLocalPort() { return localPort; @@ -848,6 +880,94 @@ public MockHttpServletRequest setAsyncSupported(boolean isAsyncSupported) return this; } + @Override + public AsyncContext startAsync() throws IllegalStateException { + asyncContext = asyncContext == null ? new MockAsyncContext() : asyncContext; + return asyncContext; + } + + @Override + public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException { + asyncContext = asyncContext == null ? new MockAsyncContext().setRequest(servletRequest).setRequest(servletRequest) : asyncContext; + return asyncContext; + } + + @Override + public boolean isAsyncStarted() { + return asyncContext != null; + } + + @Override + public AsyncContext getAsyncContext() { + return asyncContext; + } + + public MockHttpServletRequest setAsyncContext(AsyncContext asyncContext) { + this.asyncContext = asyncContext; + return this; + } + + @Override + public DispatcherType getDispatcherType() { + return dispatcherType; + } + + public MockHttpServletRequest getDispatcherType(DispatcherType dispatcherType) { + this.dispatcherType = dispatcherType; + return this; + } + + @Override + public String changeSessionId() { + session = session == null ? new MockHttpSession() : session; + if (session instanceof MockHttpSession) { + ((MockHttpSession) session).setSessionId(UUID.randomUUID().toString()); + } + + return session.getId(); + } + + @Override + public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { + return authenticated; + } + + public MockHttpServletRequest setAuthenticated(boolean authenticated) { + this.authenticated = authenticated; + return this; + } + + @Override + public void login(String username, String password) throws ServletException { + // No-op + } + + @Override + public void logout() throws ServletException { + // No-op + } + + @Override + public Collection getParts() throws IOException, ServletException { + return parts ; + } + + public MockHttpServletRequest setParts(Collection newParts) { + this.parts.clear(); + this.parts.addAll(newParts); + return this; + } + + @Override + public Part getPart(String name) throws IOException, ServletException { + return parts.stream().filter(p -> p.getName() == name).findFirst().orElse(null); + } + + @Override + public T upgrade(Class handlerClass) throws IOException, ServletException { + return (T) new MockHttpUpgradeHandler(); + } + private void handleAttributeListenerCalls(String key, Object value, Object oldValue) { if(null != oldValue) @@ -897,10 +1017,4 @@ private void callAttributeListenersRemovedMethod(String key, Object value) ((ServletRequestAttributeListener) anAttributeListener).attributeRemoved(event); } } - - private ServletContext getServletContext() - { - if(null == session) return new MockServletContext(); - return session.getServletContext(); - } } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletResponse.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletResponse.java index ced9ba08d..25684cbf0 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletResponse.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpServletResponse.java @@ -176,6 +176,12 @@ public void setIntHeader(String key, int value) setHeader(key, stringValue); } + public void setLongHeader(String key, long value) + { + String stringValue = Long.toString(value); + setHeader(key, stringValue); + } + public void setStatus(int code, String message) { statusCode = code; @@ -258,7 +264,12 @@ public void setContentLength(int length) { setIntHeader("Content-Length", length); } - + + @Override + public void setContentLengthLong(long len) { + setLongHeader("Content-Length", len); + } + public String getContentType() { return getHeader("Content-Type"); diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpSession.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpSession.java index 336ffaed2..97e614503 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpSession.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpSession.java @@ -102,6 +102,10 @@ public synchronized String getId() return sessionId; } + public void setSessionId(String sessionId) { + this.sessionId = sessionId; + } + public synchronized Object getValue(String key) { if (!isValid) throw new IllegalStateException("session invalid"); diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpUpgradeHandler.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpUpgradeHandler.java new file mode 100644 index 000000000..d499804e2 --- /dev/null +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockHttpUpgradeHandler.java @@ -0,0 +1,18 @@ +package com.mockrunner.mock.web; + +import javax.servlet.http.HttpUpgradeHandler; +import javax.servlet.http.WebConnection; + +public class MockHttpUpgradeHandler implements HttpUpgradeHandler { + + @Override + public void init(WebConnection wc) { + // No-op + } + + @Override + public void destroy() { + // No-op + } + +} diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletContext.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletContext.java index 6d0c67cae..f7f4cf354 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletContext.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletContext.java @@ -8,6 +8,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Enumeration; +import java.util.EventListener; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -15,12 +16,19 @@ import java.util.Set; import java.util.Vector; +import javax.servlet.Filter; +import javax.servlet.FilterRegistration; import javax.servlet.RequestDispatcher; import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletContextAttributeEvent; import javax.servlet.ServletContextAttributeListener; import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; +import javax.servlet.ServletRegistration.Dynamic; +import javax.servlet.SessionCookieConfig; +import javax.servlet.SessionTrackingMode; +import javax.servlet.descriptor.JspConfigDescriptor; import com.mockrunner.util.common.StreamUtil; @@ -46,6 +54,11 @@ public class MockServletContext implements ServletContext private int minorVersion; private int effectiveMajorVersion; private int effectiveMinorVersion; + private Set sessionTrackingModes; + private String virtualServerName; + private int sessonTimeOut; + private String requestCharacterSetEncoding; + private String responseCharacterSetEncoding; public MockServletContext() { @@ -455,4 +468,176 @@ private synchronized void callAttributeListenersRemovedMethod(String key, Object ((ServletContextAttributeListener) anAttributeListener).attributeRemoved(event); } } + + @Override + public Dynamic addServlet(String servletName, String className) { + return new MockDynamic(); + } + + @Override + public Dynamic addServlet(String servletName, Servlet servlet) { + return new MockDynamic(); + } + + @Override + public Dynamic addServlet(String servletName, Class servletClass) { + return new MockDynamic(); + } + + @Override + public Dynamic addJspFile(String servletName, String jspFile) { + return new MockDynamic(); + } + + @Override + public T createServlet(Class clazz) throws ServletException { + try { + return clazz.newInstance(); + } catch (Exception e) { + throw new ServletException(e); + } + } + + @Override + public ServletRegistration getServletRegistration(String servletName) { + return null; + } + + @Override + public Map getServletRegistrations() { + return Collections.emptyMap(); + } + + @Override + public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className) { + return new MockFilterRegistrationDynamic().setName(filterName).setClassName(className); + } + + @Override + public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Filter filter) { + return new MockFilterRegistrationDynamic().setName(filterName).setClassName(filter.getClass().getCanonicalName()); + } + + @Override + public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class filterClass) { + return new MockFilterRegistrationDynamic().setName(filterName).setClassName(filterClass.getCanonicalName()); + } + + @Override + public T createFilter(Class clazz) throws ServletException { + try { + return clazz.newInstance(); + } catch (Exception e) { + throw new ServletException(e); + } + } + + @Override + public FilterRegistration getFilterRegistration(String filterName) { + return null; + } + + @Override + public Map getFilterRegistrations() { + return Collections.emptyMap(); + } + + @Override + public SessionCookieConfig getSessionCookieConfig() { + return new MockSessionCookieConfig(); + } + + @Override + public void setSessionTrackingModes(Set sessionTrackingModes) { + this.sessionTrackingModes = sessionTrackingModes; + } + + @Override + public Set getDefaultSessionTrackingModes() { + return sessionTrackingModes; + } + + @Override + public Set getEffectiveSessionTrackingModes() { + return sessionTrackingModes; + } + + @Override + public void addListener(String className) { + // No-op + } + + @Override + public void addListener(T t) { + // No-op + } + + @Override + public void addListener(Class listenerClass) { + // No-op + } + + @Override + public T createListener(Class clazz) throws ServletException { + try { + return clazz.newInstance(); + } catch (Exception e) { + throw new ServletException(e); + } + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() { + return null; + } + + @Override + public ClassLoader getClassLoader() { + return getClassLoader(); + } + + @Override + public void declareRoles(String... roleNames) { + // No-op + } + + @Override + public String getVirtualServerName() { + return virtualServerName; + } + + public MockServletContext setVirtualServerName(String virtualServerName) { + this.virtualServerName = virtualServerName; + return this; + } + + @Override + public int getSessionTimeout() { + return sessonTimeOut; + } + + @Override + public void setSessionTimeout(int sessionTimeout) { + this.sessonTimeOut = sessionTimeout; + } + + @Override + public String getRequestCharacterEncoding() { + return requestCharacterSetEncoding; + } + + @Override + public void setRequestCharacterEncoding(String encoding) { + this.requestCharacterSetEncoding = encoding; + } + + @Override + public String getResponseCharacterEncoding() { + return responseCharacterSetEncoding; + } + + @Override + public void setResponseCharacterEncoding(String encoding) { + this.responseCharacterSetEncoding = encoding; + } } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletInputStream.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletInputStream.java index cd65cfc0e..e174ef2ee 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletInputStream.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletInputStream.java @@ -3,6 +3,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; /** @@ -11,14 +12,29 @@ public class MockServletInputStream extends ServletInputStream { private ByteArrayInputStream stream; - + public MockServletInputStream(byte[] data) { stream = new ByteArrayInputStream(data); } - + public int read() throws IOException { return stream.read(); } + + @Override + public boolean isFinished() { + return stream.available() == 0; + } + + @Override + public boolean isReady() { + return stream.available() > 0; + } + + @Override + public void setReadListener(ReadListener readListener) { + // No-op + } } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletOutputStream.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletOutputStream.java index 80c606f26..99055a402 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletOutputStream.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockServletOutputStream.java @@ -4,6 +4,7 @@ import java.io.IOException; import javax.servlet.ServletOutputStream; +import javax.servlet.WriteListener; import com.mockrunner.base.NestedApplicationException; @@ -14,56 +15,66 @@ public class MockServletOutputStream extends ServletOutputStream { private ByteArrayOutputStream buffer; private String encoding; - + public MockServletOutputStream() { this("ISO-8859-1"); } - + public MockServletOutputStream(String encoding) { buffer = new ByteArrayOutputStream(); this.encoding = encoding; } - + public void setEncoding(String encoding) { this.encoding = encoding; } - + public void write(int value) throws IOException { buffer.write(value); } - + public String getContent() { try { buffer.flush(); return buffer.toString(encoding); - } + } catch(IOException exc) { throw new NestedApplicationException(exc); } } - + public byte[] getBinaryContent() { try { buffer.flush(); return buffer.toByteArray(); - } + } catch(IOException exc) { throw new NestedApplicationException(exc); } } - + public void clearContent() { buffer = new ByteArrayOutputStream(); } + + @Override + public boolean isReady() { + return true; + } + + @Override + public void setWriteListener(WriteListener writeListener) { + // No-op + } } diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockSessionCookieConfig.java b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockSessionCookieConfig.java index d2de19998..cb0203eaa 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockSessionCookieConfig.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/mock/web/MockSessionCookieConfig.java @@ -1,10 +1,11 @@ package com.mockrunner.mock.web; +import javax.servlet.SessionCookieConfig; /** * Mock implementation of SessionCookieConfig. */ -public class MockSessionCookieConfig //implements SessionCookieConfig +public class MockSessionCookieConfig implements SessionCookieConfig { private String comment; private String domain; diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java b/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java index ea3bf4e5b..f6df475b9 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java +++ b/mockrunner-servlet/src/main/java/com/mockrunner/servlet/BasicServletTestCaseAdapter.java @@ -5,9 +5,6 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; -import org.junit.After; -import org.junit.Before; - import com.mockrunner.base.BasicHTMLOutputTestCase; import com.mockrunner.base.HTMLOutputModule; import com.mockrunner.mock.web.WebMockObjectFactory; @@ -38,7 +35,6 @@ public BasicServletTestCaseAdapter(String name) super(name); } - @After public void tearDown() throws Exception { servletTestModule = null; @@ -49,7 +45,6 @@ public void tearDown() throws Exception * Creates the {@link com.mockrunner.servlet.ServletTestModule}. If you * overwrite this method, you must call super.setUp(). */ - @Before public void setUp() throws Exception { servletTestModule = createServletTestModule(getWebMockObjectFactory()); diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java similarity index 84% rename from mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java rename to mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java index 46e03043a..9138a0966 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/ImageButtonFilterTest.java @@ -5,26 +5,24 @@ import javax.servlet.http.HttpServletRequest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.servlet.BasicServletTestCaseAdapter; /** * Example test for the {@link ImageButtonFilter}. * Demonstrates the usage of the filter test features in - * {@link com.mockrunner.servlet.ServletTestModule} + * {@link com.mockrunner.servlet.ServletTestModule} * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter}. */ public class ImageButtonFilterTest extends BasicServletTestCaseAdapter { - private ImageButtonFilter filter; - - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); - filter = createFilter(ImageButtonFilter.class); + createFilter(ImageButtonFilter.class); } @Test diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/LogoutServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java similarity index 92% rename from mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/LogoutServletTest.java rename to mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java index f567422d1..7326721d3 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/LogoutServletTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/LogoutServletTest.java @@ -7,35 +7,35 @@ import javax.servlet.http.HttpServletRequest; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.servlet.BasicServletTestCaseAdapter; /** * Example test for {@link LogoutServlet}. - * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} + * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter} * with and without a filter. */ public class LogoutServletTest extends BasicServletTestCaseAdapter { - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); createServlet(LogoutServlet.class); } - - @Test + + @Test public void testDoLogout() throws Exception { addRequestParameter("logout", "true"); doPost(); assertFalse(getWebMockObjectFactory().getMockSession().isValid()); } - - @Test + + @Test public void testDoLogoutWithFilteredImageButton() throws Exception { addRequestParameter("logout.x", "11"); diff --git a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java similarity index 92% rename from mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java rename to mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java index 2589ee6dd..1e6b88fc8 100644 --- a/mockrunner-servlet/src/main/java/com/mockrunner/example/servlet/RedirectServletTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/example/servlet/RedirectServletTest.java @@ -4,30 +4,30 @@ import java.io.BufferedReader; -import org.jdom.Element; -import org.junit.Before; -import org.junit.Test; +import org.jdom2.Element; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.servlet.BasicServletTestCaseAdapter; /** * Example test for {@link RedirectServlet}. - * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} + * Demonstrates the usage of {@link com.mockrunner.servlet.ServletTestModule} * and {@link com.mockrunner.servlet.BasicServletTestCaseAdapter}. * Demonstrates the testing of output data as string as well as parsed * HTML data (testServletOutputAsXML). - * + * */ public class RedirectServletTest extends BasicServletTestCaseAdapter { - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); createServlet(RedirectServlet.class); } - - @Test + + @Test public void testServletOutput() throws Exception { addRequestParameter("redirecturl", "http://www.mockrunner.com"); @@ -43,8 +43,8 @@ public void testServletOutput() throws Exception assertEquals("", reader.readLine().trim()); verifyOutputContains("URL=http://www.mockrunner.com"); } - - @Test + + @Test public void testServletOutputAsXML() throws Exception { addRequestParameter("redirecturl", "http://www.mockrunner.com"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java index 8e473fe64..5b4c6b9bc 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/ExceptionTestTag.java @@ -4,16 +4,17 @@ public class ExceptionTestTag extends TestBodyTag implements TryCatchFinally { + private static final long serialVersionUID = -5883246210258932478L; private boolean doCatchCalled = false; private boolean doFinallyCalled = false; private Throwable caughtException = null; private Throwable throwException = null; - + public ExceptionTestTag() { throwException = null; } - + public ExceptionTestTag(Throwable throwException) { this.throwException = throwException; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java index 55b292ab7..d9e784caa 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/JasperJspFactoryTest.java @@ -1,6 +1,6 @@ package com.mockrunner.test.web; -import java.util.Arrays; +import static org.assertj.core.api.Assertions.assertThat; import javax.el.ELResolver; import javax.el.MethodExpression; @@ -11,43 +11,46 @@ import org.apache.jasper.el.ELContextImpl; import org.apache.jasper.runtime.JspApplicationContextImpl; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.JasperJspFactory; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.WebMockObjectFactory; -import junit.framework.TestCase; - -public class JasperJspFactoryTest extends TestCase +class JasperJspFactoryTest { private WebMockObjectFactory mockFactory; private JasperJspFactory jasperFactory; - + + @BeforeEach protected void setUp() throws Exception { - super.setUp(); mockFactory = new WebMockObjectFactory(); jasperFactory = new JasperJspFactory(); } - - public void testConfigure() + + @Test + void testConfigure() { - assertSame(jasperFactory, jasperFactory.configure(mockFactory)); - assertTrue(jasperFactory.getJspApplicationContext(null) instanceof JspApplicationContextImpl); - assertSame(jasperFactory.getJspApplicationContext(null), mockFactory.getMockServletContext().getAttribute(JspApplicationContextImpl.class.getName())); - assertSame(jasperFactory.getPageContext(null, null, null, null, true, 1, true), mockFactory.getMockPageContext()); - assertTrue(mockFactory.getMockPageContext().getELContext() instanceof ELContextImpl); + assertThat(jasperFactory).isSameAs(jasperFactory.configure(mockFactory)); + assertThat(jasperFactory.getJspApplicationContext(null)).isInstanceOf(JspApplicationContextImpl.class); + assertThat(jasperFactory.getJspApplicationContext(null)).isSameAs(mockFactory.getMockServletContext().getAttribute(JspApplicationContextImpl.class.getName())); + assertThat(jasperFactory.getPageContext(null, null, null, null, true, 1, true)).isSameAs(mockFactory.getMockPageContext()); + assertThat(mockFactory.getMockPageContext().getELContext()).isInstanceOf(ELContextImpl.class); } - - public void testResolveVariable() + + @Test + void testResolveVariable() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); mockFactory.getMockSession().setAttribute("test", "value"); ELResolver resolver = mockFactory.getMockPageContext().getELContext().getELResolver(); - assertEquals("value", resolver.getValue(mockFactory.getMockPageContext().getELContext(), null, "test")); + assertThat(resolver.getValue(mockFactory.getMockPageContext().getELContext(), null, "test")).isEqualTo("value"); } - - public void testValueExpressionGetAndSet() + + @Test + void testValueExpressionGetAndSet() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -55,12 +58,13 @@ public void testValueExpressionGetAndSet() mockFactory.getMockSession().setAttribute("test", testObject); JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), "${test.testProperty}", String.class); - assertEquals("value", valueExpression.getValue(mockFactory.getMockPageContext().getELContext())); + assertThat(valueExpression.getValue(mockFactory.getMockPageContext().getELContext())).isEqualTo("value"); valueExpression.setValue(mockFactory.getMockPageContext().getELContext(), "anotherValue"); - assertEquals("anotherValue", testObject.getTestProperty()); + assertThat(testObject.getTestProperty()).isEqualTo("anotherValue"); } - - public void testValueExpressionAttributes() + + @Test + void testValueExpressionAttributes() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -68,26 +72,28 @@ public void testValueExpressionAttributes() mockFactory.getMockSession().setAttribute("test", testObject); JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), "${test.testProperty}", String.class); - assertEquals(String.class, valueExpression.getExpectedType()); - assertEquals(String.class, valueExpression.getType(mockFactory.getMockPageContext().getELContext())); - assertFalse(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())); - assertEquals("${test.testProperty}", valueExpression.getExpressionString()); + assertThat(valueExpression.getExpectedType()).isEqualTo(String.class); + assertThat(valueExpression.getType(mockFactory.getMockPageContext().getELContext())).isEqualTo(String.class); + assertThat(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())).isFalse(); + assertThat(valueExpression.getExpressionString()).isEqualTo("${test.testProperty}"); valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), "${test.testReadOnlyProperty}", Integer.class); - assertEquals(Integer.class, valueExpression.getExpectedType()); - assertEquals(Integer.class, valueExpression.getType(mockFactory.getMockPageContext().getELContext())); - assertTrue(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())); - assertEquals("${test.testReadOnlyProperty}", valueExpression.getExpressionString()); + assertThat(valueExpression.getExpectedType()).isEqualTo(Integer.class); + assertThat(valueExpression.getType(mockFactory.getMockPageContext().getELContext())).isEqualTo(Integer.class); + assertThat(valueExpression.isReadOnly(mockFactory.getMockPageContext().getELContext())).isTrue(); + assertThat(valueExpression.getExpressionString()).isEqualTo("${test.testReadOnlyProperty}"); } - - public void testArithmeticValueExpression() + + @Test + void testArithmeticValueExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); mockFactory.getMockRequest().setAttribute("test", testObject); assertExpressionEquals("${(test['testReadOnlyProperty'] + test.testArrayProperty[0]) == 26}", "true"); } - - public void testDeferredValueExpression() + + @Test + void testDeferredValueExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); @@ -97,23 +103,25 @@ public void testDeferredValueExpression() mockFactory.getMockSession().setAttribute("test", "xyz"); assertExpressionEquals("#{sessionScope.test}", "xyz"); } - - public void testDeferredMethodExpression() + + @Test + void testDeferredMethodExpression() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); TestObject testObject = new TestObject(); mockFactory.getMockServletContext().setAttribute("test", testObject); JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); MethodExpression methodExpression = applicationContext.getExpressionFactory().createMethodExpression(mockFactory.getMockPageContext().getELContext(), "#{test.testMethod}", String.class, new Class[] {String.class,}); - assertEquals("Hello World", methodExpression.invoke(mockFactory.getMockPageContext().getELContext(), new String[] {"Hello World"})); + assertThat(methodExpression.invoke(mockFactory.getMockPageContext().getELContext(), new String[] {"Hello World"})).isEqualTo("Hello World"); MethodInfo methodInfo = methodExpression.getMethodInfo(mockFactory.getMockPageContext().getELContext()); - assertEquals("testMethod", methodInfo.getName()); - assertEquals(String.class, methodInfo.getReturnType()); - assertTrue(Arrays.equals(new Class[] {String.class}, methodInfo.getParamTypes())); - assertEquals("#{test.testMethod}", methodExpression.getExpressionString()); + assertThat(methodInfo.getName()).isEqualTo("testMethod"); + assertThat(methodInfo.getReturnType()).isEqualTo(String.class); + assertThat(methodInfo.getParamTypes()).isEqualTo(new Class[] {String.class}); + assertThat(methodExpression.getExpressionString()).isEqualTo("#{test.testMethod}"); } - - public void testExpressionScopes() + + @Test + void testExpressionScopes() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); mockFactory.getMockRequest().setAttribute("requesttest", "requestvalue"); @@ -129,8 +137,9 @@ public void testExpressionScopes() assertExpressionEquals("${applicationScope.requesttest}", ""); assertExpressionEquals("${sessionScope.requesttest}", ""); } - - public void testImplicitObjects() + + @Test + void testImplicitObjects() { mockFactory.setDefaultJspFactory(jasperFactory.configure(mockFactory)); MockHttpServletRequest request = mockFactory.getMockRequest(); @@ -149,41 +158,41 @@ public void testImplicitObjects() assertExpressionEquals("${headerValues.header[1]}", "value2"); assertExpressionEquals("${header.header}", "value1"); } - + private void assertExpressionEquals(String expression, String value) { JspApplicationContext applicationContext = JspFactory.getDefaultFactory().getJspApplicationContext(mockFactory.getMockPageContext().getServletContext()); ValueExpression valueExpression = applicationContext.getExpressionFactory().createValueExpression(mockFactory.getMockPageContext().getELContext(), expression, String.class); - assertEquals(value, valueExpression.getValue(mockFactory.getMockPageContext().getELContext())); + assertThat(valueExpression.getValue(mockFactory.getMockPageContext().getELContext())).isEqualTo(value); } - + public static class TestObject { - private String testProperty; - - public String getTestProperty() - { - return testProperty; - } - - public void setTestProperty(String testProperty) - { - this.testProperty = testProperty; - } - - public String[] getTestArrayProperty() - { - return new String[] {"1"}; - } - - public Integer getTestReadOnlyProperty() - { - return 25; - } - - public String testMethod(String test) - { - return test; - } + private String testProperty; + + public String getTestProperty() + { + return testProperty; + } + + public void setTestProperty(String testProperty) + { + this.testProperty = testProperty; + } + + public String[] getTestArrayProperty() + { + return new String[] {"1"}; + } + + public Integer getTestReadOnlyProperty() + { + return 25; + } + + public String testMethod(String test) + { + return test; + } } } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java index f75eafdd5..a131843de 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockExpressionEvaluatorTest.java @@ -1,25 +1,31 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import javax.servlet.jsp.el.ELException; import javax.servlet.jsp.el.Expression; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockExpressionEvaluator; import com.mockrunner.mock.web.MockFunctionMapper; import com.mockrunner.mock.web.MockVariableResolver; -public class MockExpressionEvaluatorTest extends TestCase +@SuppressWarnings("deprecation") +class MockExpressionEvaluatorTest { private MockExpressionEvaluator evaluator; + @BeforeEach protected void setUp() throws Exception { - super.setUp(); evaluator = new MockExpressionEvaluator(); } - public void testEvaluateFailure() throws Exception + @Test + void testEvaluateFailure() throws Exception { try { @@ -41,8 +47,9 @@ public void testEvaluateFailure() throws Exception //should throw exception } } - - public void testEvaluateOk() throws Exception + + @Test + void testEvaluateOk() throws Exception { evaluator.addObject("myexp", 3); assertEquals(3, evaluator.evaluate("myexp", Integer.class, null, null)); @@ -50,8 +57,9 @@ public void testEvaluateOk() throws Exception evaluator.addObject("myexp", object); assertEquals(object, evaluator.evaluate("myexp", Object.class, null, null)); } - - public void testExpression() throws Exception + + @Test + void testExpression() throws Exception { Expression expression = evaluator.parseExpression("myexp", String.class, null); try @@ -76,6 +84,6 @@ public void testExpression() throws Exception //should throw exception } } - - public void testDummy(){} + + void testDummy(){} } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java index b089f932b..8e627179f 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterChainTest.java @@ -1,5 +1,12 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import javax.servlet.Filter; @@ -10,23 +17,23 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; +import org.junit.jupiter.api.BeforeEach; + import com.mockrunner.mock.web.MockFilterChain; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpServletResponse; -import junit.framework.TestCase; - -public class MockFilterChainTest extends TestCase +class MockFilterChainTest { private MockFilterChain chain; - + + @BeforeEach protected void setUp() throws Exception { - super.setUp(); chain = new MockFilterChain(); } - - public void testNoServlet() throws Exception + + void testNoServlet() throws Exception { chain.doFilter(null, null); TestServlet servlet = new TestServlet(); @@ -38,22 +45,22 @@ public void testNoServlet() throws Exception chain.doFilter(null, null); assertFalse(servlet.wasServiceCalled()); } - - public void testFilterInstance() throws Exception + + void testFilterInstance() throws Exception { try { chain.addFilter(String.class); fail(); - } + } catch(IllegalArgumentException exc) { //should throw exception } chain.addFilter(TestFilter.class); } - - public void testDoFilter() throws Exception + + void testDoFilter() throws Exception { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -76,8 +83,8 @@ public void testDoFilter() throws Exception assertNull(chain.getLastRequest()); assertNull(chain.getLastResponse()); } - - public void testRequestAndResponseList() throws Exception + + void testRequestAndResponseList() throws Exception { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -107,8 +114,8 @@ public void testRequestAndResponseList() throws Exception assertSame(response2, chain.getResponseList().get(3)); assertSame(response2, chain.getLastResponse()); } - - public void testLastRequestAndResponse() throws Exception + + void testLastRequestAndResponse() throws Exception { TestFilter filter1 = new TestFilter(); TestFilter filter2 = new TestFilter(); @@ -122,8 +129,8 @@ public void testLastRequestAndResponse() throws Exception assertSame(request, chain.getLastRequest()); assertSame(response, chain.getLastResponse()); } - - public void testReset() throws Exception + + void testReset() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); @@ -137,102 +144,103 @@ public void testReset() throws Exception chain.doFilter(request, response); assertFalse(filter2.wasDoFilterCalled()); } - + public static class SkipTestFilter implements Filter { - public void init(FilterConfig config) throws ServletException - { + public void init(FilterConfig config) throws ServletException + { - } + } - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - { - - } + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException + { - public void destroy() - { - - } + } + + public void destroy() + { + + } } - + public static class TestFilter implements Filter { - private boolean doFilterCalled = false; - private boolean doChain = true; - private ServletRequest request; - private ServletResponse response; + private boolean doFilterCalled = false; + private boolean doChain = true; + private ServletRequest request; + private ServletResponse response; - public void init(FilterConfig config) throws ServletException - { + public void init(FilterConfig config) throws ServletException + { - } + } - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException - { - doFilterCalled = true; - if(doChain) + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - if(null != this.request) + doFilterCalled = true; + if(doChain) { - request = this.request; + if(null != this.request) + { + request = this.request; + } + if(null != this.response) + { + response = this.response; + } + chain.doFilter(request, response); } - if(null != this.response) - { - response = this.response; - } - chain.doFilter(request, response); } - } - public void destroy() - { - - } + public void destroy() + { - public void setDoChain(boolean doChain) - { - this.doChain = doChain; - } - - public void setRequest(ServletRequest request) - { - this.request = request; - } - - public void setResponse(ServletResponse response) - { - this.response = response; - } - - public boolean wasDoFilterCalled() - { - return doFilterCalled; - } + } - public void reset() - { - doFilterCalled = false; - } + public void setDoChain(boolean doChain) + { + this.doChain = doChain; + } + + public void setRequest(ServletRequest request) + { + this.request = request; + } + + public void setResponse(ServletResponse response) + { + this.response = response; + } + + public boolean wasDoFilterCalled() + { + return doFilterCalled; + } + + public void reset() + { + doFilterCalled = false; + } } - + public static class TestServlet extends HttpServlet { - private boolean serviceCalled = false; - - public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException - { - serviceCalled = true; - } - - public void reset() - { - serviceCalled = false; - } - - public boolean wasServiceCalled() - { - return serviceCalled; - } + private static final long serialVersionUID = -395159716150268037L; + private boolean serviceCalled = false; + + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException + { + serviceCalled = true; + } + + public void reset() + { + serviceCalled = false; + } + + public boolean wasServiceCalled() + { + return serviceCalled; + } } } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java index 2463c05e6..82e4faea6 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFilterConfigTest.java @@ -1,17 +1,24 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockFilterConfig; -public class MockFilterConfigTest extends TestCase +public class MockFilterConfigTest { + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test public void testInitParameters() { MockFilterConfig config = new MockFilterConfig(); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java index 73ac090a2..42a0e9a5a 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockFunctionMapperTest.java @@ -1,27 +1,32 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.lang.reflect.Method; -import com.mockrunner.mock.web.MockFunctionMapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import com.mockrunner.mock.web.MockFunctionMapper; -public class MockFunctionMapperTest extends TestCase +public class MockFunctionMapperTest { private MockFunctionMapper mapper; private Method method1; private Method method2; private Method method3; - + + @BeforeEach protected void setUp() throws Exception { - super.setUp(); mapper = new MockFunctionMapper(); method1 = this.getClass().getMethod("method1", null); method2 = this.getClass().getMethod("method2", null); - method3 = this.getClass().getMethod("method3", null); + method3 = this.getClass().getMethod("method3", null); } + @Test public void testAddFuntion() { mapper.addFunction(null, "method1", method1); @@ -33,21 +38,21 @@ public void testAddFuntion() assertNull(mapper.resolveFunction(null, "method2")); assertNull(mapper.resolveFunction("myPrefix", "method3")); } - + public void method1() { - + } - + public void method2() { } - + public void method3() { } - + public void testDummy(){} } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java index d0cca377b..0c3733819 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletRequestTest.java @@ -1,14 +1,23 @@ package com.mockrunner.test.web; +import static java.util.Collections.list; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.BufferedReader; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.security.Principal; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.Locale; @@ -22,40 +31,45 @@ import javax.servlet.ServletResponse; import javax.servlet.http.Cookie; -import org.apache.tools.ant.types.selectors.SelectorUtils; - -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpSession; import com.mockrunner.mock.web.MockRequestDispatcher; -public class MockHttpServletRequestTest extends TestCase +class MockHttpServletRequestTest { private MockHttpServletRequest request; + + @BeforeEach protected void setUp() { request = new MockHttpServletRequest(); } + @AfterEach protected void tearDown() { request = null; } - public void testResetAll() throws Exception + @Test + void testResetAll() throws Exception { request .addAttribute("key", "value") .addHeader("header", "headervalue") .setContentLength(5) .resetAll(); - assertNull(request.getAttribute("key")); - assertNull(request.getHeader("header")); - assertEquals(-1, request.getContentLength()); + assertThat(request.getAttribute("key")).isNull();; + assertThat(request.getHeader("header")).isNull(); + assertThat(request.getContentLength()).isEqualTo(-1); } - public void testAttributeListenerCalled() + @Test + void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); TestAttributeListener listener2 = new TestAttributeListener(); @@ -65,59 +79,59 @@ public void testAttributeListenerCalled() .addAttributeListener(listener2) .addAttributeListener(listener3) .addAttribute("key", "value"); - assertTrue(listener1.wasAttributeAddedCalled()); - assertTrue(listener2.wasAttributeAddedCalled()); - assertTrue(listener3.wasAttributeAddedCalled()); - assertFalse(listener1.wasAttributeReplacedCalled()); - assertFalse(listener2.wasAttributeReplacedCalled()); - assertFalse(listener3.wasAttributeReplacedCalled()); + assertThat(listener1.wasAttributeAddedCalled()).isTrue(); + assertThat(listener2.wasAttributeAddedCalled()).isTrue(); + assertThat(listener3.wasAttributeAddedCalled()).isTrue(); + assertThat(listener1.wasAttributeReplacedCalled()).isFalse(); + assertThat(listener2.wasAttributeReplacedCalled()).isFalse(); + assertThat(listener3.wasAttributeReplacedCalled()).isFalse(); listener1.reset(); listener2.reset(); listener3.reset(); request.setAttribute("key", "value1"); - assertFalse(listener1.wasAttributeAddedCalled()); - assertFalse(listener2.wasAttributeAddedCalled()); - assertFalse(listener3.wasAttributeAddedCalled()); - assertTrue(listener1.wasAttributeReplacedCalled()); - assertTrue(listener2.wasAttributeReplacedCalled()); - assertTrue(listener3.wasAttributeReplacedCalled()); + assertThat(listener1.wasAttributeAddedCalled()).isFalse(); + assertThat(listener2.wasAttributeAddedCalled()).isFalse(); + assertThat(listener3.wasAttributeAddedCalled()).isFalse(); + assertThat(listener1.wasAttributeReplacedCalled()).isTrue(); + assertThat(listener2.wasAttributeReplacedCalled()).isTrue(); + assertThat(listener3.wasAttributeReplacedCalled()).isTrue(); request.removeAttribute("key"); - assertTrue(listener1.wasAttributeRemovedCalled()); - assertTrue(listener2.wasAttributeRemovedCalled()); - assertTrue(listener3.wasAttributeRemovedCalled()); + assertThat(listener1.wasAttributeRemovedCalled()).isTrue(); + assertThat(listener2.wasAttributeRemovedCalled()).isTrue(); + assertThat(listener3.wasAttributeRemovedCalled()).isTrue(); } - @SuppressWarnings("rawtypes") - public void testFluentApi() throws Exception { + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testFluentApi() throws Exception { request .setupAddParameter("param1", "value1") .clearParameters() .setupAddParameter("param2", "value2") .setupAddParameter("param3", "value3"); - assertEquals(2, request.getParameterMap().size()); + assertThat(request.getParameterMap().size()).isEqualTo(2); request .addAttribute("attribute1", "avalue1") .clearAttributes() .addAttribute("attribute2", "avalue2") .addAttribute("attribute3", "avalue3"); Enumeration attributeNames = request.getAttributeNames(); - int attributeNamesSize = getEnumerationSize(attributeNames); - assertEquals(2, attributeNamesSize); + assertThat(list(attributeNames)).hasSize(2); Locale defaultLocale = request.getLocale(); - assertNotNull(defaultLocale); - assertEquals("Expect an empty locales list", 0, getEnumerationSize(request.getLocales())); + assertThat(defaultLocale).isNotNull(); + assertThat(Collections.list(request.getLocales())).isEmpty(); Locale nbNo = Locale.forLanguageTag("nb-NO"); request.addLocale(nbNo); // Verify default locale has changed and that getLocales() is non-empty assertNotEquals(defaultLocale, request.getLocale()); assertEquals(nbNo, request.getLocale()); - assertEquals(1, getEnumerationSize(request.getLocales())); + assertThat(list(request.getLocales())).hasSize(1); Locale nnNo = Locale.forLanguageTag("nn-NO"); request.addLocales(Arrays.asList(nnNo, Locale.CANADA_FRENCH)); // Verify that default locale hasn't changed and that the list of locales is changed by two assertEquals(nbNo, request.getLocale()); - assertEquals(3, getEnumerationSize(request.getLocales())); + assertThat(Collections.list(request.getLocales())).hasSize(3); String basicAuth = "Basic"; String post = "POST"; @@ -149,11 +163,11 @@ public void testFluentApi() throws Exception { assertEquals(servletPath, request.getServletPath()); Principal principal = new Principal() { - @Override - public String getName() { - return "jad"; - } - }; + @Override + public String getName() { + return "jad"; + } + }; String remoteUser = "jad"; String utf8 = "UTF-8"; String contentType = "application/json"; @@ -187,7 +201,8 @@ public String getName() { assertEquals(remoteHost, request.getRemoteHost()); } - public void testFluentCreators() { + @Test + void testFluentCreators() { final String url = "http://localhost:8181/myapp/servlet/argument?arg1=value"; MockHttpServletRequest getRequest = MockHttpServletRequest.getRequest(URI.create(url)); assertEquals(url, getRequest.getRequestURL().toString()); @@ -197,7 +212,8 @@ public void testFluentCreators() { assertEquals("POST", postJsonRequest.getMethod()); } - public void testAttributeListenerValues() + @Test + void testAttributeListenerValues() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); request @@ -213,7 +229,8 @@ public void testAttributeListenerValues() assertEquals("anotherValue", listener.getRemovedEventValue()); } - public void testAttributeListenerNullValue() + @Test + void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); request @@ -233,13 +250,15 @@ public void testAttributeListenerNullValue() assertFalse(listener.wasAttributeRemovedCalled()); } - public void testGetAttributeNames() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testGetAttributeNames() { Enumeration enumeration = request.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(enumeration.hasMoreElements()).isFalse(); request.setAttribute("key", null); enumeration = request.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(enumeration.hasMoreElements()).isFalse(); request .addAttribute("key1", "value1") .addAttribute("key2", "value2"); @@ -249,23 +268,24 @@ public void testGetAttributeNames() List testList = new ArrayList(); testList.add(enumeration.nextElement()); testList.add(enumeration.nextElement()); - assertFalse(enumeration.hasMoreElements()); - assertTrue(testList.contains("key1")); - assertTrue(testList.contains("key2")); + assertThat(enumeration.hasMoreElements()).isFalse(); + assertThat(testList.contains("key1")).isTrue(); + assertThat(testList.contains("key2")).isTrue(); request.setAttribute("key2", null); - assertNull(request.getAttribute("key2")); + assertThat(request.getAttribute("key2")).isNull();; enumeration = request.getAttributeNames(); testList = new ArrayList(); testList.add(enumeration.nextElement()); - assertFalse(enumeration.hasMoreElements()); - assertTrue(testList.contains("key1")); + assertThat(enumeration.hasMoreElements()).isFalse(); + assertThat(testList).contains("key1"); request.setAttribute("key1", null); - assertNull(request.getAttribute("key1")); + assertThat(request.getAttribute("key1")).isNull();; enumeration = request.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(enumeration.hasMoreElements()).isFalse(); } - public void testAddRequestParameter() throws Exception + @Test + void testAddRequestParameter() throws Exception { request.setupAddParameter("abc", "abc"); assertEquals("abc", request.getParameter("abc")); @@ -279,7 +299,9 @@ public void testAddRequestParameter() throws Exception assertEquals("456", request.getParameterValues("abc")[1]); } - public void testHeaders() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testHeaders() { request .addHeader("testHeader", "xyz") @@ -333,7 +355,9 @@ public void testHeaders() assertFalse(request.getHeaders("doesnotexist").hasMoreElements()); } - public void testHeadersCaseInsensitive() + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testHeadersCaseInsensitive() { request .addHeader("testHeader", "xyz") @@ -362,7 +386,8 @@ public void testHeadersCaseInsensitive() assertTrue(headerNames.contains("myHeader2")); } - public void testCookies() + @Test + void testCookies() { assertNull(request.getCookies()); request @@ -379,7 +404,8 @@ public void testCookies() assertEquals("value3", cookies[2].getValue()); } - public void testBodyContent() throws Exception + @Test + void testBodyContent() throws Exception { request.setBodyContent("test\nanothertest???"); BufferedReader reader = request.getReader(); @@ -395,7 +421,8 @@ public void testBodyContent() throws Exception assertEquals(55, stream.read()); } - public void testRequestDispatcher() throws Exception + @Test + void testRequestDispatcher() throws Exception { final String rdPath1 = "rdPathOne"; final String rdPath2 = "rdPathTwo"; @@ -437,7 +464,8 @@ public void testRequestDispatcher() throws Exception assertEquals(0, request.getRequestDispatcherMap().size()); } - public void testSessionCreation() throws Exception + @Test + void testSessionCreation() throws Exception { request.setSession(null); assertNull(request.getSession(false)); @@ -458,7 +486,8 @@ public void testSessionCreation() throws Exception assertNotNull(request.getSession(false)); } - public void testSessionInvalidate() throws Exception + @Test + void testSessionInvalidate() throws Exception { request.setSession(new MockHttpSession()); request.getSession().invalidate(); @@ -466,7 +495,8 @@ public void testSessionInvalidate() throws Exception assertTrue(((MockHttpSession)request.getSession(true)).isValid()); } - public void testIsUserInRole() + @Test + void testIsUserInRole() { request .setUserInRole("role1", true) @@ -476,18 +506,7 @@ public void testIsUserInRole() assertFalse(request.isUserInRole("role3")); } - private int getEnumerationSize(Enumeration enumeration) { - int size = 0; - while(enumeration.hasMoreElements()) { - ++size; - enumeration.nextElement(); - } - - return size; - } - - private class TestAttributeListener implements ServletRequestAttributeListener - { + private class TestAttributeListener implements ServletRequestAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; private boolean wasAttributeRemovedCalled = false; @@ -530,8 +549,7 @@ public boolean wasAttributeReplacedCalled() } } - private class TestAttributeOrderListener implements ServletRequestAttributeListener - { + private class TestAttributeOrderListener implements ServletRequestAttributeListener { private String addedEventKey; private Object addedEventValue; private String replacedEventKey; @@ -588,8 +606,7 @@ public Object getReplacedEventValue() } } - private class TestRequestDispatcher implements RequestDispatcher - { + private class TestRequestDispatcher implements RequestDispatcher { public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java index 1a8d45d78..88588d9e2 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpServletResponseTest.java @@ -1,27 +1,33 @@ package com.mockrunner.test.web; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.IOException; import java.io.PrintWriter; -import java.util.Collection; - import javax.servlet.http.HttpServletResponse; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockHttpServletResponse; import com.mockrunner.mock.web.MockServletOutputStream; -public class MockHttpServletResponseTest extends TestCase +class MockHttpServletResponseTest { private MockHttpServletResponse response; - + + @BeforeEach protected void setUp() throws Exception { - super.setUp(); response = new MockHttpServletResponse(); } - - public void testResetAll() throws Exception + + @Test + void testResetAll() throws Exception { response.addHeader("header", "headervalue"); response.sendError(HttpServletResponse.SC_BAD_REQUEST); @@ -31,8 +37,10 @@ public void testResetAll() throws Exception assertEquals(8192, response.getBufferSize()); assertFalse(response.wasErrorSent()); } - - public void testHeaders() + + @SuppressWarnings("unchecked") + @Test + void testHeaders() { response.addHeader("testHeader", "xyz"); response.addHeader("testHeader", "abc"); @@ -51,35 +59,40 @@ public void testHeaders() response.addIntHeader("intHeader", 0); assertEquals("0", response.getHeader("intHeader")); response.clearHeaders(); - Collection headers = response.getHeaderNames(); - assertTrue(headers.isEmpty()); + assertThat(response.getHeaderNames()).isEmpty(); } - - public void testGetHeaderNames() + + @SuppressWarnings("unchecked") + @Test + void testGetHeaderNames() { response.addHeader("testHeader1", "xyz1"); response.addHeader("testHeader1", "abc"); response.addHeader("testHeader2", "xyz2"); response.addHeader("testHeader3", "xyz3"); - Collection headerNames= response.getHeaderNames(); - assertEquals(3, headerNames.size()); - assertTrue(headerNames.contains("testHeader1")); - assertTrue(headerNames.contains("testHeader2")); - assertTrue(headerNames.contains("testHeader3")); + assertThat(response.getHeaderNames()) + .hasSize(3) + .contains("testHeader1") + .contains("testHeader2") + .contains("testHeader3"); } - - public void testGetHeaders() + + @SuppressWarnings("unchecked") + @Test + void testGetHeaders() { response.addHeader("testHeader1", "xyz1"); response.addHeader("testHeader1", "abc"); response.addHeader("testHeader2", "xyz2"); - Collection headers = response.getHeaders("testHeader1"); - assertEquals(2, headers.size()); - assertTrue(headers.contains("xyz1")); - assertTrue(headers.contains("abc")); + assertThat(response.getHeaders("testHeader1")) + .hasSize(2) + .contains("xyz1") + .contains("abc"); } - - public void testHeadersCaseInsensitive() + + @SuppressWarnings("unchecked") + @Test + void testHeadersCaseInsensitive() { response.addHeader("testHeader", "xyz"); response.addHeader("TESTHeader", "abc"); @@ -87,14 +100,15 @@ public void testHeadersCaseInsensitive() response.addHeader("myHeader2", "abc"); assertEquals("xyz", response.getHeader("myheader1")); assertEquals("abc", response.getHeader("MYHEADER2")); - Collection headerNames = response.getHeaderNames(); - assertEquals(3, headerNames.size()); - assertTrue(headerNames.contains("testHeader")); - assertTrue(headerNames.contains("MYHEADER1")); - assertTrue(headerNames.contains("myHeader2")); + assertThat(response.getHeaderNames()) + .hasSize(3) + .contains("testHeader") + .contains("MYHEADER1") + .contains("myHeader2"); } - - public void testOutputStreams() throws IOException + + @Test + void testOutputStreams() throws IOException { response.getOutputStream().print("test"); response.getWriter().print(true); @@ -103,22 +117,25 @@ public void testOutputStreams() throws IOException assertEquals("testtruetest", response.getOutputStreamContent()); assertEquals("testtruetest".getBytes().length, response.getOutputStreamBinaryContent().length); } - - public void testGetSetContentType() throws IOException + + @Test + void testGetSetContentType() throws IOException { assertNull(response.getContentType()); response.setContentType("myType"); assertEquals("myType", response.getContentType()); } - - public void testFlush() throws IOException + + @Test + void testFlush() throws IOException { response.getOutputStream().write('a'); response.flushBuffer(); assertEquals("a", ((MockServletOutputStream)response.getOutputStream()).getContent()); } - - public void testReset() throws IOException + + @Test + void testReset() throws IOException { response.addHeader("testHeader", "xyz"); assertTrue(response.getHeaderList("testHeader").size() == 1); @@ -130,8 +147,9 @@ public void testReset() throws IOException response.reset(); assertNull(response.getHeaderList("testHeader")); } - - public void testSetCharacterEncoding() throws IOException + + @Test + void testSetCharacterEncoding() throws IOException { response.setCharacterEncoding("ISO-8859-1"); response.getWriter().write("?"); @@ -142,30 +160,33 @@ public void testSetCharacterEncoding() throws IOException response.setCharacterEncoding("ISO-8859-1"); assertTrue(response.getOutputStreamContent().startsWith("??")); response.resetAll(); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); String input = "\u00F8"; - PrintWriter writer = response.getWriter(); + PrintWriter writer = response.getWriter(); writer.write(input); - response.flushBuffer(); + response.flushBuffer(); String output = response.getOutputStreamContent(); assertTrue(output.equals(input)); } - public void testRedirect() throws IOException + @Test + void testRedirect() throws IOException { response.sendRedirect("/some-location"); assertEquals("/some-location", response.getHeader("Location")); assertEquals(HttpServletResponse.SC_FOUND, response.getStatusCode()); } - public void testEncodeRedirectURL() throws IOException { + @Test + void testEncodeRedirectURL() throws IOException { final String encoded1 = response.encodeRedirectURL("page#/some-location?a=b&c=d"); assertEquals("page%23%2Fsome-location%3Fa%3Db%26c%3Dd", encoded1); final String encoded2 = response.encodeRedirectURL("page"); assertEquals("page", encoded2); } - public void testEncodeRedirectUrl() throws IOException { + @Test + void testEncodeRedirectUrl() throws IOException { final String encoded = response.encodeRedirectUrl("page#/some-location?a=b&c=d"); assertEquals("page%23%2Fsome-location%3Fa%3Db%26c%3Dd", encoded); final String encoded2 = response.encodeRedirectUrl("page"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java index 46d19ab29..040d4bd45 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockHttpSessionTest.java @@ -1,5 +1,13 @@ package com.mockrunner.test.web; +import static java.util.Collections.list; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.ArrayList; import java.util.Enumeration; import java.util.List; @@ -9,25 +17,30 @@ import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingListener; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockHttpSession; -public class MockHttpSessionTest extends TestCase +class MockHttpSessionTest { private MockHttpSession session; - protected void setUp() + @BeforeEach + void setUp() { session = new MockHttpSession(); } - protected void tearDown() + @AfterEach + void tearDown() { session = null; } - public void testResetAll() throws Exception + @Test + void testResetAll() throws Exception { session.setAttribute("key", "value"); session.setMaxInactiveInterval(3); @@ -35,8 +48,9 @@ public void testResetAll() throws Exception assertNull(session.getAttribute("key")); assertEquals(-1, session.getMaxInactiveInterval()); } - - public void testBindingListenerInvalidate() + + @Test + void testBindingListenerInvalidate() { TestSessionListener listener1 = new TestSessionListener(); TestSessionListener listener2 = new TestSessionListener(); @@ -57,14 +71,15 @@ public void testBindingListenerInvalidate() { session.invalidate(); fail(); - } + } catch(IllegalStateException exc) { //should throw exception } } - - public void testBindingListenerOverwriteAttribute() + + @Test + void testBindingListenerOverwriteAttribute() { TestSessionListener listener1 = new TestSessionListener(); TestSessionListener listener2 = new TestSessionListener(); @@ -74,8 +89,9 @@ public void testBindingListenerOverwriteAttribute() assertTrue(listener2.wasValueBoundCalled()); assertFalse(listener2.wasValueUnboundCalled()); } - - public void testBindingListenerOverwriteSameAttribute() + + @Test + void testBindingListenerOverwriteSameAttribute() { TestSessionListener listener = new TestSessionListener(); session.setAttribute("key", listener); @@ -85,8 +101,9 @@ public void testBindingListenerOverwriteSameAttribute() assertTrue(listener.wasValueBoundCalled()); assertTrue(listener.wasValueUnboundBeforeBoundCalled()); } - - public void testBindingListenerCorrectOrder() + + @Test + void testBindingListenerCorrectOrder() { session.setAttribute("key", "test"); TestSessionOrderListener listener = new TestSessionOrderListener(); @@ -107,8 +124,9 @@ public void testBindingListenerCorrectOrder() assertEquals(listener, listener.getUnboundEventValue()); assertEquals(null, listener.getUnboundSessionValue()); } - - public void testAttributeListenerCalled() + + @Test + void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); TestAttributeListener listener2 = new TestAttributeListener(); @@ -138,8 +156,9 @@ public void testAttributeListenerCalled() assertTrue(listener2.wasAttributeRemovedCalled()); assertTrue(listener3.wasAttributeRemovedCalled()); } - - public void testAttributeListenerOrder() + + @Test + void testAttributeListenerOrder() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); session.addAttributeListener(listener); @@ -154,10 +173,11 @@ public void testAttributeListenerOrder() session.removeAttribute("key"); assertEquals("key", listener.getRemovedEventKey()); assertEquals("anotherValue", listener.getRemovedEventValue()); - assertNull("", listener.getRemovedSessionValue()); + assertNull(listener.getRemovedSessionValue()); } - - public void testAttributeListenerNullValue() + + @Test + void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); session.addAttributeListener(listener); @@ -175,25 +195,25 @@ public void testAttributeListenerNullValue() session.removeAttribute("myKey"); assertFalse(listener.wasAttributeRemovedCalled()); } - - public void testGetAttributeNames() + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testGetAttributeNames() { - Enumeration enumeration = session.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(list(session.getAttributeNames())).isEmpty(); session.setAttribute("key", null); - enumeration = session.getAttributeNames(); - assertFalse(enumeration.hasMoreElements()); + assertThat(list(session.getAttributeNames())).isEmpty(); session.setAttribute("key1", "value1"); session.setAttribute("key2", "value2"); assertEquals("value1", session.getAttribute("key1")); assertEquals("value2", session.getAttribute("key2")); - enumeration = session.getAttributeNames(); + Enumeration enumeration = session.getAttributeNames(); List testList = new ArrayList(); testList.add(enumeration.nextElement()); testList.add(enumeration.nextElement()); assertFalse(enumeration.hasMoreElements()); - assertTrue(testList.contains("key1")); - assertTrue(testList.contains("key2")); + assertThat(testList).contains("key1"); + assertThat(testList).contains("key2"); session.setAttribute("key2", null); assertNull(session.getAttribute("key2")); enumeration = session.getAttributeNames(); @@ -206,20 +226,19 @@ public void testGetAttributeNames() enumeration = session.getAttributeNames(); assertFalse(enumeration.hasMoreElements()); } - - private static class TestSessionListener implements HttpSessionBindingListener - { + + private static class TestSessionListener implements HttpSessionBindingListener { private boolean valueBoundCalled = false; private boolean valueUnboundCalled = false; private boolean valueUnboundBeforeBoundCalled = false; - + public void reset() { valueBoundCalled = false; valueUnboundCalled = false; valueUnboundBeforeBoundCalled = false; } - + public void valueBound(HttpSessionBindingEvent event) { valueBoundCalled = true; @@ -233,7 +252,7 @@ public void valueUnbound(HttpSessionBindingEvent event) valueUnboundBeforeBoundCalled = true; } } - + public boolean wasValueBoundCalled() { return valueBoundCalled; @@ -243,22 +262,21 @@ public boolean wasValueUnboundCalled() { return valueUnboundCalled; } - + public boolean wasValueUnboundBeforeBoundCalled() { return valueUnboundBeforeBoundCalled; } } - - private static class TestSessionOrderListener implements HttpSessionBindingListener - { + + private static class TestSessionOrderListener implements HttpSessionBindingListener { private String boundEventKey; private Object boundEventValue; private Object boundSessionValue; private String unboundEventKey; private Object unboundEventValue; private Object unboundSessionValue; - + public void valueBound(HttpSessionBindingEvent event) { boundEventKey = event.getName(); @@ -272,7 +290,7 @@ public void valueUnbound(HttpSessionBindingEvent event) unboundEventValue = event.getValue(); unboundSessionValue = event.getSession().getAttribute(unboundEventKey); } - + public String getBoundEventKey() { return boundEventKey; @@ -303,14 +321,13 @@ public Object getUnboundSessionValue() return unboundSessionValue; } } - - private static class InvalidateAttributeListener implements HttpSessionAttributeListener - { + + private static class InvalidateAttributeListener implements HttpSessionAttributeListener { private boolean didThrowIllegalStateException = false; - + public void attributeAdded(HttpSessionBindingEvent event) { - + } public void attributeRemoved(HttpSessionBindingEvent event) @@ -320,7 +337,7 @@ public void attributeRemoved(HttpSessionBindingEvent event) try { session.getAttribute(event.getName()); - } + } catch(IllegalStateException exc) { didThrowIllegalStateException = true; @@ -329,7 +346,7 @@ public void attributeRemoved(HttpSessionBindingEvent event) public void attributeReplaced(HttpSessionBindingEvent event) { - + } public boolean getDidThrowIllegalStateException() @@ -337,13 +354,12 @@ public boolean getDidThrowIllegalStateException() return didThrowIllegalStateException; } } - - private static class TestAttributeListener implements HttpSessionAttributeListener - { + + private static class TestAttributeListener implements HttpSessionAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; private boolean wasAttributeRemovedCalled = false; - + public void attributeAdded(HttpSessionBindingEvent event) { wasAttributeAddedCalled = true; @@ -358,14 +374,14 @@ public void attributeReplaced(HttpSessionBindingEvent event) { wasAttributeReplacedCalled = true; } - + public void reset() { wasAttributeAddedCalled = false; wasAttributeReplacedCalled = false; wasAttributeRemovedCalled = false; } - + public boolean wasAttributeAddedCalled() { return wasAttributeAddedCalled; @@ -381,9 +397,8 @@ public boolean wasAttributeReplacedCalled() return wasAttributeReplacedCalled; } } - - private static class TestAttributeOrderListener implements HttpSessionAttributeListener - { + + private static class TestAttributeOrderListener implements HttpSessionAttributeListener { private String addedEventKey; private Object addedEventValue; private Object addedSessionValue; @@ -393,7 +408,7 @@ private static class TestAttributeOrderListener implements HttpSessionAttributeL private String removedEventKey; private Object removedEventValue; private Object removedSessionValue; - + public void attributeAdded(HttpSessionBindingEvent event) { addedEventKey = event.getName(); @@ -414,7 +429,7 @@ public void attributeReplaced(HttpSessionBindingEvent event) replacedEventValue = event.getValue(); replacedSessionValue = event.getSession().getAttribute(replacedEventKey); } - + public String getAddedEventKey() { return addedEventKey; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java index dc3fd7a2b..60961eb60 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspPropertyGroupDescriptorTest.java @@ -1,26 +1,34 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Iterator; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockJspPropertyGroupDescriptor; -public class MockJspPropertyGroupDescriptorTest extends TestCase +class MockJspPropertyGroupDescriptorTest { private MockJspPropertyGroupDescriptor descriptor; - - protected void setUp() throws Exception + + @BeforeEach + void setUp() throws Exception { descriptor = new MockJspPropertyGroupDescriptor(); } - protected void tearDown() throws Exception + @AfterEach + void tearDown() throws Exception { descriptor = null; } - public void testReset() + @Test + void testReset() { descriptor.addIncludeCoda("coda"); descriptor.addIncludePrelude("prelude"); @@ -60,8 +68,9 @@ public void testReset() assertEquals("false", descriptor.getScriptingInvalid()); assertEquals("false", descriptor.getTrimDirectiveWhitespaces()); } - - public void testIncludeAndURLPatterns() + + @Test + void testIncludeAndURLPatterns() { assertTrue(descriptor.getIncludeCodas().isEmpty()); assertTrue(descriptor.getIncludePreludes().isEmpty()); @@ -82,8 +91,10 @@ public void testIncludeAndURLPatterns() assertTrue(descriptor.getIncludePreludes().isEmpty()); assertTrue(descriptor.getUrlPatterns().isEmpty()); } - - public void testIncludeAndURLPatternsListChange() + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + void testIncludeAndURLPatternsListChange() { descriptor.addIncludeCoda("coda1"); descriptor.addIncludePrelude("prelude1"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java index 2885fafbd..209089591 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockJspWriterTest.java @@ -1,64 +1,73 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.io.StringWriter; +import org.junit.jupiter.api.Test; + import com.mockrunner.mock.web.MockHttpServletResponse; import com.mockrunner.mock.web.MockJspWriter; -import junit.framework.TestCase; - -public class MockJspWriterTest extends TestCase +class MockJspWriterTest { - public void testWithDefaultWriter() throws Exception + @Test + void testWithDefaultWriter() throws Exception { - MockJspWriter writer = new MockJspWriter(); - writer.print("test1"); - writer.clear(); - writer.print("test2"); - writer.clearBuffer(); - writer.print("test3"); - assertEquals("test3", writer.getOutputAsString()); + try (MockJspWriter writer = new MockJspWriter()) { + writer.print("test1"); + writer.clear(); + writer.print("test2"); + writer.clearBuffer(); + writer.print("test3"); + assertEquals("test3", writer.getOutputAsString()); + } } - - public void testWithProvidedWriter() throws Exception + + @Test + void testWithProvidedWriter() throws Exception { StringWriter providedWriter = new StringWriter(); - MockJspWriter writer = new MockJspWriter(providedWriter); - writer.print("test1"); - try - { - writer.clear(); - fail(); - } - catch(IOException exc) - { - //should throw exception + try (MockJspWriter writer = new MockJspWriter(providedWriter)) { + writer.print("test1"); + try + { + writer.clear(); + fail(); + } + catch(IOException exc) + { + //should throw exception + } + writer.print("test2"); + writer.clearBuffer(); + writer.print("test3"); + assertEquals("", writer.getOutputAsString()); + writer.flush(); } - writer.print("test2"); - writer.clearBuffer(); - writer.print("test3"); - assertEquals("", writer.getOutputAsString()); - writer.flush(); assertEquals("test1test2test3", providedWriter.toString()); } - - public void testWithProvidedResponse() throws Exception + + @Test + void testWithProvidedResponse() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); - MockJspWriter writer = new MockJspWriter(response); - writer.print("test1"); - assertEquals("test1", writer.getOutputAsString()); - assertEquals("test1", response.getOutputStreamContent()); - response.getWriter().print("test2"); - assertEquals("test1test2", writer.getOutputAsString()); - assertEquals("test1test2", response.getOutputStreamContent()); - writer.clear(); - assertEquals("", writer.getOutputAsString()); - assertEquals("", response.getOutputStreamContent()); - writer.print("test1"); - writer.clearBuffer(); - assertEquals("", writer.getOutputAsString()); + try (MockJspWriter writer = new MockJspWriter(response)) { + writer.print("test1"); + assertEquals("test1", writer.getOutputAsString()); + assertEquals("test1", response.getOutputStreamContent()); + response.getWriter().print("test2"); + assertEquals("test1test2", writer.getOutputAsString()); + assertEquals("test1test2", response.getOutputStreamContent()); + writer.clear(); + assertEquals("", writer.getOutputAsString()); + assertEquals("", response.getOutputStreamContent()); + writer.print("test1"); + writer.clearBuffer(); + assertEquals("", writer.getOutputAsString()); + } assertEquals("", response.getOutputStreamContent()); } } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java index 034410f65..cccc28a21 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletConfigTest.java @@ -1,18 +1,25 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockServletConfig; -public class MockServletConfigTest extends TestCase +class MockServletConfigTest { - public void testInitParameters() + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testInitParameters() { MockServletConfig config = new MockServletConfig(); config.setInitParameter("key1", "value1"); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java index ef9ff8354..6d6574b4c 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockServletContextTest.java @@ -1,5 +1,11 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -19,27 +25,33 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.mockrunner.mock.web.MockRequestDispatcher; import com.mockrunner.mock.web.MockServletContext; import com.mockrunner.util.common.StreamUtil; -public class MockServletContextTest extends TestCase +class MockServletContextTest { private MockServletContext context; - protected void setUp() + @BeforeEach + void setUp() { context = new MockServletContext(); } - protected void tearDown() + @AfterEach + void tearDown() { context = null; } - - public void testResetAll() throws Exception + + @SuppressWarnings({ "rawtypes", "deprecation" }) + @Test + void testResetAll() throws Exception { context.setAttribute("key", "value"); context.addResourcePaths("path", new ArrayList()); @@ -49,8 +61,10 @@ public void testResetAll() throws Exception assertNull(context.getResourcePaths("path")); assertNull(context.getResource("path")); } - - public void testResources() throws Exception + + @SuppressWarnings({ "deprecation", "rawtypes", "unchecked" }) + @Test + void testResources() throws Exception { context.setResource("testPath", new URL("http://test")); assertEquals(new URL("http://test"), context.getResource("testPath")); @@ -79,8 +93,9 @@ public void testResources() throws Exception assertEquals(3, stream.read()); assertEquals(-1, stream.read()); } - - public void testAttributeListenerCalled() + + @Test + void testAttributeListenerCalled() { TestAttributeListener listener1 = new TestAttributeListener(); TestAttributeListener listener2 = new TestAttributeListener(); @@ -111,7 +126,8 @@ public void testAttributeListenerCalled() assertTrue(listener3.wasAttributeRemovedCalled()); } - public void testAttributeListenerValues() + @Test + void testAttributeListenerValues() { TestAttributeOrderListener listener = new TestAttributeOrderListener(); context.addAttributeListener(listener); @@ -126,7 +142,8 @@ public void testAttributeListenerValues() assertEquals("anotherValue", listener.getRemovedEventValue()); } - public void testAttributeListenerNullValue() + @Test + void testAttributeListenerNullValue() { TestAttributeListener listener = new TestAttributeListener(); context.addAttributeListener(listener); @@ -144,8 +161,10 @@ public void testAttributeListenerNullValue() context.removeAttribute("myKey"); assertFalse(listener.wasAttributeRemovedCalled()); } - - public void testGetAttributeNames() + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testGetAttributeNames() { Enumeration enumeration = context.getAttributeNames(); assertFalse(enumeration.hasMoreElements()); @@ -175,24 +194,25 @@ public void testGetAttributeNames() enumeration = context.getAttributeNames(); assertFalse(enumeration.hasMoreElements()); } - - public void testRequestDispatcher() throws Exception + + @Test + void testRequestDispatcher() throws Exception { final String rdPath1 = "rdPathOne"; final String rdPath2 = "rdPathTwo"; final String rdPath3 = "rdPathThree"; - + assertEquals(0, context.getRequestDispatcherMap().size()); MockRequestDispatcher rd1 = (MockRequestDispatcher)context.getRequestDispatcher(rdPath1); assertEquals(rdPath1, rd1.getPath()); assertNull(rd1.getForwardedRequest()); assertNull(rd1.getIncludedRequest()); - + assertEquals(1, context.getRequestDispatcherMap().size()); assertTrue(context.getRequestDispatcherMap().containsKey(rdPath1)); assertSame(rd1, context.getRequestDispatcherMap().get(rdPath1)); - + MockRequestDispatcher actualRd2 = new MockRequestDispatcher(); context.setRequestDispatcher(rdPath2, actualRd2); MockRequestDispatcher rd2 = (MockRequestDispatcher)context.getRequestDispatcher(rdPath2); @@ -200,32 +220,33 @@ public void testRequestDispatcher() throws Exception assertSame(actualRd2, rd2); assertNull(rd1.getForwardedRequest()); assertNull(rd1.getIncludedRequest()); - + rd2 = (MockRequestDispatcher)context.getNamedDispatcher(rdPath2); assertEquals(rdPath2, rd2.getPath()); assertSame(actualRd2, rd2); - + assertEquals(2, context.getRequestDispatcherMap().size()); assertTrue(context.getRequestDispatcherMap().containsKey(rdPath2)); assertSame(rd2, context.getRequestDispatcherMap().get(rdPath2)); - + RequestDispatcher actualRd3 = new TestRequestDispatcher(); context.setRequestDispatcher(rdPath3, actualRd3); RequestDispatcher rd3 = context.getRequestDispatcher(rdPath3); assertSame(actualRd3, rd3); - + rd3 = context.getNamedDispatcher(rdPath3); assertSame(actualRd3, rd3); - + assertEquals(3, context.getRequestDispatcherMap().size()); assertTrue(context.getRequestDispatcherMap().containsKey(rdPath3)); assertSame(rd3, context.getRequestDispatcherMap().get(rdPath3)); - + context.clearRequestDispatcherMap(); assertEquals(0, context.getRequestDispatcherMap().size()); } - - public void testSetResourceAsStream() throws Exception + + @Test + void testSetResourceAsStream() throws Exception { byte[] input = {1, 2, 3, 4}; context.setResourceAsStream("testpath1", input); @@ -235,8 +256,9 @@ public void testSetResourceAsStream() throws Exception result = context.getResourceAsStream("testpath2"); assertTrue(StreamUtil.compareStreams(new ByteArrayInputStream(input), result)); } - - public void testGetContext() throws Exception + + @Test + void testGetContext() throws Exception { assertNull(context.getContext("abc")); context.setContext("abc", context); @@ -245,8 +267,10 @@ public void testGetContext() throws Exception context.setContext("xyz", anotherContext); assertSame(anotherContext, context.getContext("xyz")); } - - public void testInitParameters() + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testInitParameters() { context.setInitParameter("key1", "value1"); Map parameters = new HashMap(); @@ -270,8 +294,10 @@ public void testInitParameters() params = context.getInitParameterNames(); assertFalse(params.hasMoreElements()); } - - public void testInitParametersOverwrite() + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + void testInitParametersOverwrite() { assertTrue(context.setInitParameter("key1", "value1")); assertEquals("value1", context.getInitParameter("key1")); @@ -282,21 +308,21 @@ public void testInitParametersOverwrite() context.setInitParameters(parameters); assertEquals("value2", context.getInitParameter("key1")); } - - public void testVersion() + + @Test + void testVersion() { context.setMajorVersion(5); context.setMinorVersion(1); assertEquals(5, context.getMajorVersion()); assertEquals(1, context.getMinorVersion()); } - - private class TestAttributeListener implements ServletContextAttributeListener - { + + private class TestAttributeListener implements ServletContextAttributeListener { private boolean wasAttributeAddedCalled = false; private boolean wasAttributeReplacedCalled = false; private boolean wasAttributeRemovedCalled = false; - + public void attributeAdded(ServletContextAttributeEvent event) { wasAttributeAddedCalled = true; @@ -311,14 +337,14 @@ public void attributeReplaced(ServletContextAttributeEvent event) { wasAttributeReplacedCalled = true; } - + public void reset() { wasAttributeAddedCalled = false; wasAttributeReplacedCalled = false; wasAttributeRemovedCalled = false; } - + public boolean wasAttributeAddedCalled() { return wasAttributeAddedCalled; @@ -335,15 +361,14 @@ public boolean wasAttributeReplacedCalled() } } - private class TestAttributeOrderListener implements ServletContextAttributeListener - { + private class TestAttributeOrderListener implements ServletContextAttributeListener { private String addedEventKey; private Object addedEventValue; private String replacedEventKey; private Object replacedEventValue; private String removedEventKey; private Object removedEventValue; - + public void attributeAdded(ServletContextAttributeEvent event) { addedEventKey = event.getName(); @@ -361,7 +386,7 @@ public void attributeReplaced(ServletContextAttributeEvent event) replacedEventKey = event.getName(); replacedEventValue = event.getValue(); } - + public String getAddedEventKey() { return addedEventKey; @@ -392,15 +417,14 @@ public Object getReplacedEventValue() return replacedEventValue; } } - - private class TestRequestDispatcher implements RequestDispatcher - { - + + private class TestRequestDispatcher implements RequestDispatcher { + public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException { } - + public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException { diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java index adc71794f..37aeb0445 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/MockVariableResolverTest.java @@ -1,24 +1,32 @@ package com.mockrunner.test.web; -import com.mockrunner.mock.web.MockVariableResolver; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import com.mockrunner.mock.web.MockVariableResolver; -public class MockVariableResolverTest extends TestCase +class MockVariableResolverTest { private MockVariableResolver resolver; - protected void setUp() throws Exception + @BeforeEach + void setUp() throws Exception { resolver = new MockVariableResolver(); } - protected void tearDown() throws Exception + @AfterEach + void tearDown() throws Exception { resolver = null; } - - public void testResolve() throws Exception + + @Test + void testResolve() throws Exception { assertNull(resolver.resolveVariable("test")); resolver.addVariable("test", 3); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java index e8766f47b..5d7a2f953 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestBodyTag.java @@ -10,6 +10,7 @@ public class TestBodyTag extends BodyTagSupport { + private static final long serialVersionUID = 6856704428326055577L; private String testString; private Integer testInteger; private double testDouble; @@ -24,7 +25,7 @@ public class TestBodyTag extends BodyTagSupport private boolean doEndTagCalled = false; private boolean doAfterBodyCalled = false; private boolean doInitBodyCalled = false; - + public void setDoAfterBodyReturnValue(int doAfterBodyReturnValue) { this.doAfterBodyReturnValue = doAfterBodyReturnValue; @@ -53,7 +54,7 @@ public int doStartTag() throws JspException } return doStartTagReturnValue; } - + public void doInitBody() throws JspException { doInitBodyCalled = true; @@ -66,7 +67,7 @@ public int doAfterBody() throws JspException int returnValue = doAfterBodyReturnValue; if(BodyTagSupport.EVAL_BODY_AGAIN == doAfterBodyReturnValue) { - doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; + doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; } return returnValue; } @@ -106,7 +107,7 @@ public void setTestString(String testString) { this.testString = testString; } - + public void setPageContext(PageContext context) { super.setPageContext(context); @@ -117,12 +118,12 @@ public PageContext getPageContext() { return context; } - + public JspWriter getBufferedOut() { return bufferedOut; } - + public void release() { if(wasDoStartTagCalled() && wasDoEndTagCalled()) @@ -131,17 +132,17 @@ public void release() } releaseCalled = true; } - + public boolean wasReleaseCalled() { return releaseCalled; } - + public boolean wasReleaseCallLastMethodCall() { return releaseLastCall; } - + public boolean wasDoInitBodyCalled() { return doInitBodyCalled; diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java index 12ce4ed66..d36efa5c1 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestFragmentTag.java @@ -9,6 +9,7 @@ public class TestFragmentTag extends TagSupport { + private static final long serialVersionUID = -423825397076113310L; private JspFragment testFragment; public void setTestFragment(JspFragment testFragment) @@ -30,6 +31,6 @@ public int doStartTag() throws JspException } return EVAL_BODY_INCLUDE; } - - + + } diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java index c67c8b555..7019f0aad 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/TestTag.java @@ -9,6 +9,7 @@ public class TestTag extends TagSupport { + private static final long serialVersionUID = -6184401531349252629L; private String testString; private Integer testInteger; private double testDouble; @@ -21,7 +22,7 @@ public class TestTag extends TagSupport private boolean doStartTagCalled = false; private boolean doEndTagCalled = false; private boolean doAfterBodyCalled = false; - + public void setDoAfterBodyReturnValue(int doAfterBodyReturnValue) { this.doAfterBodyReturnValue = doAfterBodyReturnValue; @@ -50,14 +51,14 @@ public int doStartTag() throws JspException } return doStartTagReturnValue; } - + public int doAfterBody() throws JspException { doAfterBodyCalled = true; int returnValue = doAfterBodyReturnValue; if(BodyTagSupport.EVAL_BODY_AGAIN == doAfterBodyReturnValue) { - doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; + doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY; } return returnValue; } @@ -67,7 +68,7 @@ public int doEndTag() throws JspException doEndTagCalled = true; return doEndTagReturnValue; } - + public double getTestDouble() { return testDouble; @@ -111,12 +112,12 @@ public boolean wasReleaseCalled() { return releaseCalled; } - + public boolean wasReleaseCallLastMethodCall() { return releaseLastCall; } - + public boolean wasDoAfterBodyCalled() { return doAfterBodyCalled; @@ -131,7 +132,7 @@ public boolean wasDoStartTagCalled() { return doStartTagCalled; } - + public void setPageContext(PageContext context) { super.setPageContext(context); diff --git a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java index b758de0a8..b9963daa2 100644 --- a/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java +++ b/mockrunner-servlet/src/test/java/com/mockrunner/test/web/WebMockObjectFactoryTest.java @@ -1,5 +1,11 @@ package com.mockrunner.test.web; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletRequest; @@ -13,6 +19,8 @@ import javax.servlet.jsp.JspFactory; import javax.servlet.jsp.PageContext; +import org.junit.jupiter.api.Test; + import com.mockrunner.mock.web.MockFilterChain; import com.mockrunner.mock.web.MockFilterConfig; import com.mockrunner.mock.web.MockHttpServletRequest; @@ -24,11 +32,10 @@ import com.mockrunner.mock.web.MockServletContext; import com.mockrunner.mock.web.WebMockObjectFactory; -import junit.framework.TestCase; - -public class WebMockObjectFactoryTest extends TestCase +class WebMockObjectFactoryTest { - public void testDifferentMockObjects() + @Test + void testDifferentMockObjects() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); WebMockObjectFactory factory2 = new WebMockObjectFactory(); @@ -38,8 +45,9 @@ public void testDifferentMockObjects() assertNotSame(factory1.getMockServletConfig(), factory2.getMockServletConfig()); assertNotSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - - public void testMockObjectsWithSameContext() + + @Test + void testMockObjectsWithSameContext() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); WebMockObjectFactory factory2 = new WebMockObjectFactory(factory1); @@ -49,8 +57,9 @@ public void testMockObjectsWithSameContext() assertNotSame(factory1.getMockServletConfig(), factory2.getMockServletConfig()); assertSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - - public void testMockObjectsWithSameSessionAndContext() + + @Test + void testMockObjectsWithSameSessionAndContext() { WebMockObjectFactory factory1 = new WebMockObjectFactory(); WebMockObjectFactory factory2 = new WebMockObjectFactory(factory1, false); @@ -66,8 +75,9 @@ public void testMockObjectsWithSameSessionAndContext() assertNotSame(factory1.getMockServletConfig(), factory2.getMockServletConfig()); assertSame(factory1.getMockServletContext(), factory2.getMockServletContext()); } - - public void testSetDefaultJspFactory() + + @Test + void testSetDefaultJspFactory() { WebMockObjectFactory factory = new WebMockObjectFactory(); assertSame(factory.getMockJspFactory(), JspFactory.getDefaultFactory()); @@ -88,8 +98,9 @@ public void testSetDefaultJspFactory() assertNull(factory.getMockJspFactory()); assertNull(factory.getJspFactory()); } - - public void testAddRequestWrapper() + + @Test + void testAddRequestWrapper() { WebMockObjectFactory factory = new WebMockObjectFactory(); factory.getMockRequest().setupAddParameter("test", "test"); @@ -100,8 +111,9 @@ public void testAddRequestWrapper() HttpServletRequestWrapper requestWrapper = (HttpServletRequestWrapper)factory.getWrappedRequest(); assertSame(factory.getMockRequest(), requestWrapper.getRequest()); } - - public void testAddResponseWrapper() throws Exception + + @Test + void testAddResponseWrapper() throws Exception { WebMockObjectFactory factory = new WebMockObjectFactory(); factory.addResponseWrapper(HttpServletResponseWrapper.class); @@ -109,12 +121,13 @@ public void testAddResponseWrapper() throws Exception assertTrue(response instanceof HttpServletResponseWrapper); response.getWriter().print("test"); response.getWriter().flush(); - assertEquals("test", factory.getMockResponse().getOutputStreamContent()); + assertEquals("test", factory.getMockResponse().getOutputStreamContent()); HttpServletResponseWrapper responseWrapper = (HttpServletResponseWrapper)factory.getWrappedResponse(); assertSame(factory.getMockResponse(), responseWrapper.getResponse()); } - - public void testAddRequestAndResponseWrapperClasses() + + @Test + void testAddRequestAndResponseWrapperClasses() { WebMockObjectFactory factory = new WebMockObjectFactory(); factory.addRequestWrapper(TestRequestWrapper.class); @@ -124,8 +137,9 @@ public void testAddRequestAndResponseWrapperClasses() assertTrue(factory.getWrappedResponse() instanceof TestResponseWrapper); assertSame(factory.getMockResponse(), ((TestResponseWrapper)factory.getWrappedResponse()).getResponse()); } - - public void testRefresh() throws Exception + + @Test + void testRefresh() throws Exception { WebMockObjectFactory factory = new WebMockObjectFactory(); HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(factory.getMockRequest()); @@ -141,8 +155,9 @@ public void testRefresh() throws Exception assertSame(responseWrapper, pageContext.getResponse()); assertSame(pageContext, factory.getMockJspFactory().getPageContext()); } - - public void testOverrideCreate() + + @Test + void testOverrideCreate() { WebMockObjectFactory factory = new TestWebMockObjectFactory(); assertNotSame(factory.getMockRequest().getClass(), MockHttpServletRequest.class); @@ -154,39 +169,36 @@ public void testOverrideCreate() assertNotSame(factory.getMockServletContext().getClass(), MockServletContext.class); assertNotSame(factory.getMockSession().getClass(), MockHttpSession.class); } - - public static class TestRequestWrapper extends MockHttpServletRequest - { + + public static class TestRequestWrapper extends MockHttpServletRequest { private HttpServletRequest request; - + public TestRequestWrapper(HttpServletRequest request) { this.request = request; } - + public HttpServletRequest getRequest() { return request; } } - - public static class TestResponseWrapper extends MockHttpServletResponse - { + + public static class TestResponseWrapper extends MockHttpServletResponse { private HttpServletResponse response; - + public TestResponseWrapper(HttpServletResponse response) { this.response = response; } - + public HttpServletResponse getResponse() { return response; } } - - public static class TestWebMockObjectFactory extends WebMockObjectFactory - { + + public static class TestWebMockObjectFactory extends WebMockObjectFactory { public MockFilterChain createMockFilterChain() { return new MockFilterChain() {}; @@ -196,7 +208,7 @@ public MockFilterConfig createMockFilterConfig() { return new MockFilterConfig() {}; } - + public MockPageContext createMockPageContext() { return new MockPageContext() {}; @@ -204,7 +216,7 @@ public MockPageContext createMockPageContext() public MockHttpServletRequest createMockRequest() { - + return new MockHttpServletRequest() {}; } @@ -228,9 +240,8 @@ public MockHttpSession createMockSession() return new MockHttpSession() {}; } } - - public static class TestJspFactory extends JspFactory - { + + public static class TestJspFactory extends JspFactory { public JspEngineInfo getEngineInfo() { return null; @@ -248,7 +259,7 @@ public PageContext getPageContext(Servlet servlet, ServletRequest request, Servl public void releasePageContext(PageContext pageContext) { - - } + + } } } diff --git a/mockrunner-struts/pom.xml b/mockrunner-struts/pom.xml index f867618be..92ceb4019 100644 --- a/mockrunner-struts/pom.xml +++ b/mockrunner-struts/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT .. diff --git a/mockrunner-tag/pom.xml b/mockrunner-tag/pom.xml index 3eed1af44..949e26509 100644 --- a/mockrunner-tag/pom.xml +++ b/mockrunner-tag/pom.xml @@ -5,8 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT - .. + 2.0.8-SNAPSHOT mockrunner-tag diff --git a/pom.xml b/pom.xml index a97d38b6a..bc7f19ca4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.mockrunner mockrunner - 2.0.7-SNAPSHOT + 2.0.8-SNAPSHOT pom MockRunner http://mockrunner.github.io @@ -32,7 +32,7 @@ Europe/Berlin - + Steinar Bang @@ -119,7 +119,7 @@ commons-beanutils commons-beanutils - 1.9.2 + 1.9.4 commons-digester @@ -141,21 +141,43 @@ jboss-j2ee 4.2.2.GA + + org.jboss.spec.javax.rmi + jboss-rmi-api_1.0_spec + 1.0.6.Final + oro oro 2.0.8 - jdom - jdom - 1.0 + org.jdom + jdom2 + 2.0.6.1 junit junit 4.12 + + org.junit + junit-bom + 6.1.0 + pom + import + + + org.assertj + assertj-core + 3.27.7 + + + org.mockito + mockito-core + 5.23.0 + org.mockejb mockejb @@ -177,9 +199,9 @@ 1.3.04 - org.apache.tomcat - servlet-api - 6.0.37 + javax.servlet + javax.servlet-api + 4.0.1 org.apache.tomcat @@ -316,7 +338,7 @@ org.apache.karaf.tooling karaf-maven-plugin - 4.1.7 + 4.4.6 true 80 @@ -347,7 +369,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.17 + 3.2.5 false @@ -426,10 +448,15 @@ true + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.5 + - + @@ -493,7 +520,7 @@ - /usr/bin/javadoc + ${env.JAVA_HOME}/bin/javadoc @@ -505,7 +532,7 @@ - /usr/bin/javadoc + ${env.JAVA_HOME}/bin/javadoc @@ -572,7 +599,7 @@ mockrunner-core -