Giter Club home page Giter Club logo

mockrunner's Introduction

Mockrunner - mock classes for enterprise application testing

FYI: Older 1.1.x branch with support for Java 6 has been moved to "Best Effort" support. If you need support on a feature with that version, feel free to open an issue and we will try to address it as time allows.

Documentation

Maven site (http://mockrunner.github.io/mockrunner/)

Building

Must be build using Java 8

mockrunner's People

Contributors

cemartins avatar davidkarlsen avatar devensungard avatar greyfairer avatar infosec812 avatar justinpitts avatar kz282 avatar mthmulders avatar rvansa avatar steinarb avatar the-alchemist avatar vulkman avatar wborn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mockrunner's Issues

Need config example for mockrunner-jms

Hello! I am newbie in Java and struggle with mockrunner-jms setup. The example in the project doesn't contain config files, so I'm getting the following exception when launching PrintMessageServletTest, failing block:
protected void setUp() throws Exception
{
super.setUp();
ejbModule = createEJBTestModule();
ejbModule.bindToContext("java:ConnectionFactory",
getJMSMockObjectFactory().getMockQueueConnectionFactory());
queue = getDestinationManager().createQueue("testQueue");
ejbModule.bindToContext("queue/testQueue", queue);
servletModule = createServletTestModule();
servletModule.createServlet(PrintMessageServlet.class);
}
As far as I understand, I need to put some sonfig in my classpath. Please, help me to get mockrunner-jms example running. If you want, I then can create a little maven project with this example and help other people to onboard this more rapidly...

"C:\Program Files\Java\jdk1.8.0_121\bin\java" -ea -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.4\lib\idea_rt.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.3.4\plugins\junit\lib\junit-rt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Users\Maria\IdeaProjects\jeta\jeta-master\target\test-classes;C:\Users\Maria\IdeaProjects\jeta\jeta-master\target\classes;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-java\3.2.0\selenium-java-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\3.2.0\selenium-chrome-driver-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\3.2.0\selenium-remote-driver-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-api\3.2.0\selenium-api-3.2.0.jar;C:\Users\Maria.m2\repository\cglib\cglib-nodep\3.2.4\cglib-nodep-3.2.4.jar;C:\Users\Maria.m2\repository\org\apache\commons\commons-exec\1.3\commons-exec-1.3.jar;C:\Users\Maria.m2\repository\org\apache\httpcomponents\httpclient\4.5.2\httpclient-4.5.2.jar;C:\Users\Maria.m2\repository\org\apache\httpcomponents\httpcore\4.4.4\httpcore-4.4.4.jar;C:\Users\Maria.m2\repository\net\java\dev\jna\jna-platform\4.1.0\jna-platform-4.1.0.jar;C:\Users\Maria.m2\repository\net\java\dev\jna\jna\4.1.0\jna-4.1.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-edge-driver\3.2.0\selenium-edge-driver-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\3.2.0\selenium-firefox-driver-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\3.2.0\selenium-ie-driver-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-opera-driver\3.2.0\selenium-opera-driver-3.2.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-safari-driver\3.2.0\selenium-safari-driver-3.2.0.jar;C:\Users\Maria.m2\repository\com\codeborne\phantomjsdriver\1.4.0\phantomjsdriver-1.4.0.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\htmlunit-driver\2.24\htmlunit-driver-2.24.jar;C:\Users\Maria.m2\repository\org\seleniumhq\selenium\selenium-support\3.2.0\selenium-support-3.2.0.jar;C:\Users\Maria.m2\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;C:\Users\Maria.m2\repository\net\sourceforge\htmlunit\htmlunit\2.24\htmlunit-2.24.jar;C:\Users\Maria.m2\repository\org\apache\httpcomponents\httpmime\4.5.2\httpmime-4.5.2.jar;C:\Users\Maria.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.23\htmlunit-core-js-2.23.jar;C:\Users\Maria.m2\repository\net\sourceforge\htmlunit\neko-htmlunit\2.24\neko-htmlunit-2.24.jar;C:\Users\Maria.m2\repository\net\sourceforge\cssparser\cssparser\0.9.21\cssparser-0.9.21.jar;C:\Users\Maria.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar;C:\Users\Maria.m2\repository\org\eclipse\jetty\websocket\websocket-client\9.2.20.v20161216\websocket-client-9.2.20.v20161216.jar;C:\Users\Maria.m2\repository\org\eclipse\jetty\jetty-util\9.2.20.v20161216\jetty-util-9.2.20.v20161216.jar;C:\Users\Maria.m2\repository\org\eclipse\jetty\jetty-io\9.2.20.v20161216\jetty-io-9.2.20.v20161216.jar;C:\Users\Maria.m2\repository\org\eclipse\jetty\websocket\websocket-common\9.2.20.v20161216\websocket-common-9.2.20.v20161216.jar;C:\Users\Maria.m2\repository\org\eclipse\jetty\websocket\websocket-api\9.2.20.v20161216\websocket-api-9.2.20.v20161216.jar;C:\Users\Maria.m2\repository\junit\junit\4.12\junit-4.12.jar;C:\Users\Maria.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Maria.m2\repository\info\cukes\cucumber-junit\1.2.5\cucumber-junit-1.2.5.jar;C:\Users\Maria.m2\repository\info\cukes\cucumber-core\1.2.5\cucumber-core-1.2.5.jar;C:\Users\Maria.m2\repository\info\cukes\cucumber-html\0.2.3\cucumber-html-0.2.3.jar;C:\Users\Maria.m2\repository\info\cukes\cucumber-java\1.2.5\cucumber-java-1.2.5.jar;C:\Users\Maria.m2\repository\info\cukes\cucumber-picocontainer\1.2.5\cucumber-picocontainer-1.2.5.jar;C:\Users\Maria.m2\repository\info\cukes\cucumber-jvm-deps\1.0.5\cucumber-jvm-deps-1.0.5.jar;C:\Users\Maria.m2\repository\info\cukes\gherkin\2.12.2\gherkin-2.12.2.jar;C:\Users\Maria.m2\repository\org\picocontainer\picocontainer\2.15\picocontainer-2.15.jar;C:\Users\Maria.m2\repository\com\sun\jersey\jersey-client\1.8\jersey-client-1.8.jar;C:\Users\Maria.m2\repository\com\sun\jersey\jersey-core\1.8\jersey-core-1.8.jar;C:\Users\Maria.m2\repository\com\sun\jersey\jersey-json\1.17\jersey-json-1.17.jar;C:\Users\Maria.m2\repository\org\codehaus\jettison\jettison\1.1\jettison-1.1.jar;C:\Users\Maria.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar;C:\Users\Maria.m2\repository\javax\xml\bind\jaxb-api\2.2.2\jaxb-api-2.2.2.jar;C:\Users\Maria.m2\repository\javax\xml\stream\stax-api\1.0-2\stax-api-1.0-2.jar;C:\Users\Maria.m2\repository\javax\activation\activation\1.1\activation-1.1.jar;C:\Users\Maria.m2\repository\org\codehaus\jackson\jackson-core-asl\1.9.2\jackson-core-asl-1.9.2.jar;C:\Users\Maria.m2\repository\org\codehaus\jackson\jackson-mapper-asl\1.9.2\jackson-mapper-asl-1.9.2.jar;C:\Users\Maria.m2\repository\org\codehaus\jackson\jackson-jaxrs\1.9.2\jackson-jaxrs-1.9.2.jar;C:\Users\Maria.m2\repository\org\codehaus\jackson\jackson-xc\1.9.2\jackson-xc-1.9.2.jar;C:\Users\Maria.m2\repository\log4j\log4j\1.2.17\log4j-1.2.17.jar;C:\Users\Maria.m2\repository\io\github\bonigarcia\webdrivermanager\1.6.0\webdrivermanager-1.6.0.jar;C:\Users\Maria.m2\repository\org\slf4j\slf4j-api\1.7.12\slf4j-api-1.7.12.jar;C:\Users\Maria.m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar;C:\Users\Maria.m2\repository\com\google\code\gson\gson\2.3.1\gson-2.3.1.jar;C:\Users\Maria.m2\repository\com\typesafe\config\1.2.1\config-1.2.1.jar;C:\Users\Maria.m2\repository\org\apache\commons\commons-lang3\3.4\commons-lang3-3.4.jar;C:\Users\Maria.m2\repository\org\rauschig\jarchivelib\0.7.1\jarchivelib-0.7.1.jar;C:\Users\Maria.m2\repository\org\apache\commons\commons-compress\1.9\commons-compress-1.9.jar;C:\Users\Maria.m2\repository\org\jsoup\jsoup\1.9.2\jsoup-1.9.2.jar;C:\Users\Maria.m2\repository\commons-codec\commons-codec\1.10\commons-codec-1.10.jar;C:\Users\Maria.m2\repository\com\google\guava\guava\21.0\guava-21.0.jar;C:\Users\Maria.m2\repository\com\mockrunner\mockrunner-ejb\1.1.2\mockrunner-ejb-1.1.2.jar;C:\Users\Maria.m2\repository\com\mockrunner\mockrunner-core\1.1.2\mockrunner-core-1.1.2.jar;C:\Users\Maria.m2\repository\com\kirkk\jaranalyzer\1.2\jaranalyzer-1.2.jar;C:\Users\Maria.m2\repository\bcel\bcel\5.1\bcel-5.1.jar;C:\Users\Maria.m2\repository\regexp\regexp\1.2\regexp-1.2.jar;C:\Users\Maria.m2\repository\jakarta-regexp\jakarta-regexp\1.4\jakarta-regexp-1.4.jar;C:\Users\Maria.m2\repository\ant\ant\1.6.5\ant-1.6.5.jar;C:\Users\Maria.m2\repository\commons-beanutils\commons-beanutils\1.9.2\commons-beanutils-1.9.2.jar;C:\Users\Maria.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\Maria.m2\repository\org\mockejb\mockejb\0.6-beta2\mockejb-0.6-beta2.jar;C:\Users\Maria.m2\repository\cglib\cglib-full\2.0.2\cglib-full-2.0.2.jar;C:\Users\Maria.m2\repository\com\mockrunner\mockrunner-jdk1.5-j2ee1.3\0.4\mockrunner-jdk1.5-j2ee1.3-0.4.jar;C:\Users\Maria.m2\repository\commons-digester\commons-digester\1.8\commons-digester-1.8.jar;C:\Users\Maria.m2\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar;C:\Users\Maria.m2\repository\commons-validator\commons-validator\1.3.1\commons-validator-1.3.1.jar;C:\Users\Maria.m2\repository\oro\oro\2.0.8\oro-2.0.8.jar;C:\Users\Maria.m2\repository\jdom\jdom\1.0\jdom-1.0.jar;C:\Users\Maria.m2\repository\nekohtml\nekohtml\0.9.5\nekohtml-0.9.5.jar;C:\Users\Maria.m2\repository\javax\servlet\servlet-api\2.3\servlet-api-2.3.jar;C:\Users\Maria.m2\repository\struts\struts\1.2.9\struts-1.2.9.jar;C:\Users\Maria.m2\repository\commons-fileupload\commons-fileupload\1.0\commons-fileupload-1.0.jar;C:\Users\Maria.m2\repository\antlr\antlr\2.7.2\antlr-2.7.2.jar;C:\Users\Maria.m2\repository\xalan\xalan\2.5.1\xalan-2.5.1.jar;C:\Users\Maria.m2\repository\xerces\xercesImpl\2.9.0\xercesImpl-2.9.0.jar;C:\Users\Maria.m2\repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar;C:\Users\Maria.m2\repository\javax\jms\jms\1.1\jms-1.1.jar;C:\Users\Maria.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\Maria.m2\repository\javax\transaction\javax.transaction-api\1.2\javax.transaction-api-1.2.jar;C:\Users\Maria.m2\repository\org\glassfish\main\ejb\javax.ejb\3.1.2\javax.ejb-3.1.2.jar;C:\Users\Maria.m2\repository\org\glassfish\main\transaction\javax.transaction\3.1.2\javax.transaction-3.1.2.jar;C:\Users\Maria.m2\repository\org\glassfish\main\javaee-api\javax.annotation\3.1.2\javax.annotation-3.1.2.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.jetamocks.jms.PrintMessageServletTest
javax.naming.NameNotFoundException: Name java:/ConnectionFactory not found.
at org.mockejb.jndi.MockContext.lookup(MockContext.java:543)
at org.mockejb.jndi.MockContext$$FastClassByCGLIB$$8f78c5.invoke()
at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:57)
at org.mockejb.interceptor.InterceptorInvoker$CglibMethodInvoker.intercept(InterceptorInvoker.java:95)
at org.mockejb.interceptor.InvocationContext.proceed(InvocationContext.java:177)
at org.mockejb.interceptor.InterceptorInvoker.invoke(InterceptorInvoker.java:53)
at org.mockejb.interceptor.InterceptableProxy.intercept(InterceptableProxy.java:58)
at $javax.naming.Context$$EnhancerByCGLIB$$f6e73895.lookup()
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.jetamocks.jms.PrintMessageServlet.init(PrintMessageServlet.java:36)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.mockrunner.servlet.ServletTestModule.setServlet(ServletTestModule.java:85)
at com.mockrunner.servlet.ServletTestModule.createServlet(ServletTestModule.java:51)
at com.jetamocks.jms.PrintMessageServletTest.setUp(PrintMessageServletTest.java:32)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

com.mockrunner.base.VerifyFailedException: actual output: Error sending print request for 1 does not match expected output

at com.mockrunner.base.HTMLOutputModule.verifyOutputContains(HTMLOutputModule.java:129)
at com.jetamocks.jms.PrintMessageServletTest.testServletResponse(PrintMessageServletTest.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

javax.naming.NameNotFoundException: Name java:/ConnectionFactory not found.
at org.mockejb.jndi.MockContext.lookup(MockContext.java:543)
at org.mockejb.jndi.MockContext$$FastClassByCGLIB$$8f78c5.invoke()
at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:57)
at org.mockejb.interceptor.InterceptorInvoker$CglibMethodInvoker.intercept(InterceptorInvoker.java:95)
at org.mockejb.interceptor.InvocationContext.proceed(InvocationContext.java:177)
at org.mockejb.interceptor.InterceptorInvoker.invoke(InterceptorInvoker.java:53)
at org.mockejb.interceptor.InterceptableProxy.intercept(InterceptableProxy.java:58)
at $javax.naming.Context$$EnhancerByCGLIB$$f6e73895.lookup()
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.jetamocks.jms.PrintMessageServlet.init(PrintMessageServlet.java:36)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.mockrunner.servlet.ServletTestModule.setServlet(ServletTestModule.java:85)
at com.mockrunner.servlet.ServletTestModule.createServlet(ServletTestModule.java:51)
at com.jetamocks.jms.PrintMessageServletTest.setUp(PrintMessageServletTest.java:32)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

com.mockrunner.base.VerifyFailedException: Expected 3 messages received by queue testQueue, received 0 messages

at com.mockrunner.jms.JMSTestModule.verifyNumberOfReceivedQueueMessages(JMSTestModule.java:2450)
at com.mockrunner.jms.JMSTestCaseAdapter.verifyNumberOfReceivedQueueMessages(JMSTestCaseAdapter.java:1179)
at com.jetamocks.jms.PrintMessageServletTest.testSendAndReceive(PrintMessageServletTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

javax.naming.NameNotFoundException: Name java:/ConnectionFactory not found.
at org.mockejb.jndi.MockContext.lookup(MockContext.java:543)
at org.mockejb.jndi.MockContext$$FastClassByCGLIB$$8f78c5.invoke()
at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:57)
at org.mockejb.interceptor.InterceptorInvoker$CglibMethodInvoker.intercept(InterceptorInvoker.java:95)
at org.mockejb.interceptor.InvocationContext.proceed(InvocationContext.java:177)
at org.mockejb.interceptor.InterceptorInvoker.invoke(InterceptorInvoker.java:53)
at org.mockejb.interceptor.InterceptableProxy.intercept(InterceptableProxy.java:58)
at $javax.naming.Context$$EnhancerByCGLIB$$f6e73895.lookup()
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.jetamocks.jms.PrintMessageServlet.init(PrintMessageServlet.java:36)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at com.mockrunner.servlet.ServletTestModule.setServlet(ServletTestModule.java:85)
at com.mockrunner.servlet.ServletTestModule.createServlet(ServletTestModule.java:51)
at com.jetamocks.jms.PrintMessageServletTest.setUp(PrintMessageServletTest.java:32)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

com.mockrunner.base.VerifyFailedException: No QueueConnection present.

at com.mockrunner.jms.JMSTestModule.verifyQueueConnectionStarted(JMSTestModule.java:769)
at com.mockrunner.jms.JMSTestCaseAdapter.verifyQueueConnectionStarted(JMSTestCaseAdapter.java:451)
at com.jetamocks.jms.PrintMessageServletTest.testInitPrintMessageReceiver(PrintMessageServletTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:176)
at junit.framework.TestCase.runBare(TestCase.java:141)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:252)
at junit.framework.TestSuite.run(TestSuite.java:247)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code -1

Generics for servlet creation

Hi,

I would like to use generics for the com.mockrunner.servlet.ServletTestModule.createServlet(Class) method and then on the corresponding com.mockrunner.servlet.BasicServletTestCaseAdapter.createServlet(Class)

That is, I would like to have the source changed into the following code:

    public <T extends HttpServlet> T createServlet(Class<T> servletClass)
    {
        if(!HttpServlet.class.isAssignableFrom(servletClass))
        {
            throw new RuntimeException("servletClass must be an instance of javax.servlet.http.HttpServlet");
        }
        try
        {
            T theServlet = servletClass.newInstance();
            setServlet(theServlet, true);
            return theServlet;
        }
        catch(Exception exc)
        {
            throw new NestedApplicationException(exc);
        }
    }

and

  protected <T extends HttpServlet> T createServlet(Class<T> servletClass)
  {
      return servletTestModule.createServlet(servletClass);
  }

Benefits:
no need to cast the return type to my servlet in tests:
MyServlet servlet = (MyServlet) createServlet(MyServlet.class);
becomes
MyServlet servlet = createServlet(MyServlet.class);

also, the method become type safe, any invocation will be with a class that is subclass of HttpServlet, so the check if(!HttpServlet.class.isAssignableFrom(servletClass)) becomes quite reduntant

Support the particial mock jdbc DataSource

When I use the mockrunner-jdbc for my enterprise application, just want to mock some sql in the special codes. And the other parts of the application uses the real datasource. But mockrunner-jdbc overide the low level jdbc driver, this causes the real useful datasource invalid. So i want to just the mockdatasource for my application, when i want to test some code without the mock, i just use the real datasource.

Unable to use columnType

My application needs to use the ResultSetMetaData.getColumnType(), but it returns 1111 (SQL type "other") for any column type. This would be a nice addition if it could be done.

MockResultSet rs = new MockResultSet("myMock");
rs.addColumn("columnA", new Integer[]{1});
rs.getMetaData.getColumnType(1) // returns 1111

Make it possible to use MockHttpServletRequest and MockHttpServletResponse from pax exam test

I am trying to write a pax exam test for a servlet OSGi service intended to be picked up by the pax web whiteboard extender

The integration test is basically to call Servlet.service() and check that the servlet returns a 200 OK and some data (it tests that everything starts and initializes properly).

I first tried to use mockito to mock the request and response, but that failed miserably because of PAXEXAM-274 (which was reported in 2011 and is still open).

So I tried using the mockrunner-servlet classes, but that failed because the mockrunner-servlet JAR isn't an OSGi bundle.

So what's needed is to make the mockrunner-servlet JAR be an OSGi bundle.

It would also be nice to have a mockrunner-servlet karaf feature.

mockrunner-core depends on struts and tomcat

I believe struts and tomcat related code should be moved out of the core module.

Currently, the core module depends on lots of stuff that IMHO should be moved to the struts module

[INFO] +- com.mockrunner:mockrunner-jdbc:jar:0.4.6:test
[INFO] | - com.mockrunner:mockrunner-core:jar:0.4.6:test
[INFO] | +- jdom:jdom:jar:1.0:test
[INFO] | +- org.apache.tomcat:jasper:jar:6.0.37:test
[INFO] | | +- org.apache.tomcat:servlet-api:jar:6.0.37:test
[INFO] | | +- org.apache.tomcat:juli:jar:6.0.37:test
[INFO] | | +- org.apache.tomcat:jsp-api:jar:6.0.37:test
[INFO] | | +- org.apache.tomcat:catalina:jar:6.0.37:test
[INFO] | | | - org.apache.tomcat:annotations-api:jar:6.0.37:test
[INFO] | | +- org.apache.tomcat:el-api:jar:6.0.37:test
[INFO] | | +- org.eclipse.jdt.core.compiler:ecj:jar:4.2.2:test
[INFO] | | - org.apache.tomcat:jasper-el:jar:6.0.37:test
[INFO] | +- org.apache.struts:struts-extras:jar:1.3.10:test
[INFO] | | - org.apache.struts:struts-core:jar:1.3.10:test
[INFO] | | +- commons-chain:commons-chain:jar:1.2:test
[INFO] | | +- commons-digester:commons-digester:jar:1.8:test
[INFO] | | +- commons-validator:commons-validator:jar:1.3.1:test
[INFO] | | - oro:oro:jar:2.0.8:test
[INFO] | +- jboss:jboss-j2ee:jar:4.2.0.GA:test
[INFO] | +- com.kirkk:jaranalyzer:jar:1.2:test
[INFO] | | +- bcel:bcel:jar:5.1:test
[INFO] | | +- jakarta-regexp:jakarta-regexp:jar:1.4:test
[INFO] | | - ant:ant:jar:1.6.5:test
[INFO] | - nekohtml:nekohtml:jar:0.9.5:test

The MockPreparedStatement's batch is not cleared after executeBatch

Hello Carlos!

I have been testing batch inserts with Mockrunner-JDBC and encountered an issue: after I add parameter sets to a MockPreparedStatements batch via addBatch and then execute the batch via executeBatch the MockPreparedStatements batch is not cleared, so I must execute clearBatch manually before adding more parametersets to the batch.

This question describes the issue properly: http://stackoverflow.com/questions/9192541/are-the-parameter-values-automatically-cleared-after-executing-a-batch-of-sql-co , and this answer links to the specification: http://stackoverflow.com/a/22005160

According to the 15.1.2 of the JDBC 3.0 specification I advise calling clearBatch() in the finally block of MockPreparedStatement like this:

--- origin/master (8cfeb9d)
+++ Modified In Working Tree
@@ -286,6 +286,8 @@

     protected int[] executeBatch(List<MockParameterMap> batchParams) throws SQLException
     {
+        try
+        {
         int[] results = new int[batchParams.size()];
         SQLException exception = null;
         for(int ii = 0; ii < results.length; ii++)
@@ -317,6 +319,11 @@
         }
         return results;
     }
+        finally
+        {
+            clearBatch();
+        }
+    }

     private void setGeneratedKeysResultSet(String sql, MockParameterMap params)
     {

Kind regards,
Zoltan

Contribution: XMLResultSetFactory for Oracle SQL Developer export format

I just paste in the source file. It allows you export query results from your database with oracle sql developer tool (https://www.oracle.com/tools/downloads/sqldev-downloads.html). We use it to get test data from our real world databases. Thx for the great project!
Achim


package com.mockrunner.jdbc;

import java.io.File;
import java.util.Iterator;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

import com.mockrunner.base.NestedApplicationException;
import com.mockrunner.mock.jdbc.MockResultSet;

/**

  • Adds support for the XML export format that Oracle SQLDeveloper (at least version 17.2.0.188) creates.

  • See https://www.oracle.com/tools/downloads/sqldev-downloads.html

  • Example format:

  • <COLUMN NAME="CONNECTION_NO"><![CDATA[2517308732]]></COLUMN>
    
  • <COLUMN NAME="VAR"><![CDATA[chatservice.platformid]]></COLUMN>
    
  • <COLUMN NAME="VALUE"><![CDATA[QDE]]></COLUMN>
    
  • <COLUMN NAME="VALID_FROM"><![CDATA[08-NOV-18 05.00.34.298260000 PM]]></COLUMN>
    
  • <COLUMN NAME="EXPERT_NO"><![CDATA[758750]]></COLUMN>
    
  • <COLUMN NAME="MANDATOR_NO"><![CDATA[100]]></COLUMN>
    
  • <COLUMN NAME="CONNECTION_NO"><![CDATA[2517308732]]></COLUMN>
    
  • <COLUMN NAME="VAR"><![CDATA[member_login_time]]></COLUMN>
    
  • <COLUMN NAME="VALUE"><![CDATA[20181108164224]]></COLUMN>
    
  • <COLUMN NAME="VALID_FROM"><![CDATA[08-NOV-18 05.00.34.352730000 PM]]></COLUMN>
    
  • <COLUMN NAME="EXPERT_NO"><![CDATA[758750]]></COLUMN>
    
  • <COLUMN NAME="MANDATOR_NO"><![CDATA[100]]></COLUMN>
    
  • Obtain data files via Oracle SQLDeveloper:

    1. Execute Query, e.g.: "SELECT * FROM PERSON PARAM WHERE ROWNUM < 4;"
    2. Right click "Query Result" Window.
    3. Select "Export"
    4. Choose "Format -> XML"
    5. Choose "Save As -> Clipboard"
    6. Create a file somewhere in your (resources) classpath.
    7. Paste the clipboard () into the file.
    8. In case Oracle SQL Developer created a header with " encoding='UTF8'" correct that to "encoding='UTF-8'" (else you get an exception).
  • @author [email protected]
    /
    public class XMLResultSetFactorySQLDeveloperSupport extends XMLResultSetFactory
    {
    /
    * ID of the "dialect" the XML export feature of Oracle SQLDeveloper creates. */
    public final static int ORACLE_SQLDEVELOPER_DIALECT = 2;

    /** A copy from superclass. Field is needed for output, but private and I did not want to touch original. */
    protected String copyFileName;

    public XMLResultSetFactorySQLDeveloperSupport(final File file)
    {
    super(file);
    this.copyFileName = file.getAbsolutePath();
    }

    public XMLResultSetFactorySQLDeveloperSupport(final String fileName)
    {
    super(fileName);
    this.copyFileName = fileName;
    }

    /**

    • Compared to {@link XMLResultSetFactory#create(String)} this adds support for
    • {@link #ORACLE_SQLDEVELOPER_DIALECT} and dispatches to super when
    • that {@link #getDialect()} is not matched.
    • @see #setDialect(int)
      */
      @OverRide
      public MockResultSet create(String id)
      {
      MockResultSet mockResultSet;
      switch(this.getDialect())
      {
      case ORACLE_SQLDEVELOPER_DIALECT :{
      mockResultSet = createSQLDeveloperResultSet(id);
      break;
      }
      default :
      {
      mockResultSet = super.create(id);
      }
      }
      return mockResultSet;
      }

    /**

    • Return a MockResultSet with proper column names and rows based on the XML Document.

    • Basically this is the same "dialect" as {@link XMLResultSetFactory#SYBASE_DIALECT} with the following changes:

      • Nodes for rows are not "row" but "ROW" (uppercase).
      • Column nodes have the column name in the attribute value of attribute "NAME" (v.s. the column node name is the database column name): -->
    • Example format:

    • <COLUMN NAME="CONNECTION_NO"><![CDATA[2517308732]]></COLUMN>
      
    • <COLUMN NAME="VAR"><![CDATA[chatservice.platformid]]></COLUMN>
      
    • <COLUMN NAME="VALUE"><![CDATA[QDE]]></COLUMN>
      
    • <COLUMN NAME="VALID_FROM"><![CDATA[08-NOV-18 05.00.34.298260000 PM]]></COLUMN>
      
    • <COLUMN NAME="EXPERT_NO"><![CDATA[758750]]></COLUMN>
      
    • <COLUMN NAME="MANDATOR_NO"><![CDATA[100]]></COLUMN>
      
    • <COLUMN NAME="CONNECTION_NO"><![CDATA[2517308732]]></COLUMN>
      
    • <COLUMN NAME="VAR"><![CDATA[member_login_time]]></COLUMN>
      
    • <COLUMN NAME="VALUE"><![CDATA[20181108164224]]></COLUMN>
      
    • <COLUMN NAME="VALID_FROM"><![CDATA[08-NOV-18 05.00.34.352730000 PM]]></COLUMN>
      
    • <COLUMN NAME="EXPERT_NO"><![CDATA[758750]]></COLUMN>
      
    • <COLUMN NAME="MANDATOR_NO"><![CDATA[100]]></COLUMN>
      
    • @return MockResultSet Results read from XML Document in the format Oracle SQL Developer creates.
      */
      public MockResultSet createSQLDeveloperResultSet(String id)
      {
      MockResultSet resultSet = new MockResultSet(id);
      SAXBuilder builder = new SAXBuilder();
      Document doc = null;
      File fileToParse = getXMLFile();
      if (null == fileToParse)
      {
      throw new RuntimeException("File " + this.copyFileName + " not found.");
      }
      try
      {
      doc = builder.build(fileToParse);
      Element root = doc.getRootElement();
      List rows = root.getChildren("ROW");
      Iterator ri = rows.iterator();
      boolean firstIteration = true;
      // - iteration START
      while (ri.hasNext())
      {
      // 1 ROW START
      Element cRow = (Element) ri.next();
      List cRowChildren = cRow.getChildren();
      Iterator cri = cRowChildren.iterator();
      String[] cRowValues = new String[cRowChildren.size()];
      int curCol = 0;

       	while (cri.hasNext())
       	{
       		// 1 CELL START
       		Element crValue = cri.next();
       		// 1st row: Get column names: 
       		if (firstIteration)
       		{
       			resultSet.addColumn(crValue.getAttributeValue("NAME"));
       		}
       		
       		String value = this.getTrim() ? crValue.getTextTrim() : crValue.getText();
       		cRowValues[curCol] = value;
       		curCol++;
       		// 1 CELL END
       	}
       	resultSet.addRow(cRowValues);
       	firstIteration = false;
       	// 1 ROW END
       	
       }
       // <ROW> - iteration END
      

      }
      catch (Exception exc)
      {
      throw new NestedApplicationException("Failure while reading from XML file", exc);
      }
      return resultSet;
      }

}

JMS Test Module should create Queues/Topics automatically

In activeMQ, JMS Queues and Topics are created automatically when first used.

Mockrunner JMS does not do this, so when you use it in a test, you need to explicitly create all the queues and topics you are going to use.

A simple lazy initialization like creating the topic on the first call of DestinationManager.getTopic() could solve a lot of overhead for tests.

MockPreparedStatement.executeQuery() returning null

I have played around with the bookstore example to use PreparedStatements. I have the following code ing the try-catch block:

            connection.setAutoCommit(false);
            String stmt = "select isbn, quantity from books where isbn = ?";
            PreparedStatement pStmt = connection.prepareStatement(stmt);
            for (int c = 0; c < isbnNumbers.size(); c++) {
                pStmt.setString(1, (String) isbnNumbers.get(c));
                result = pStmt.executeQuery();
                System.out.println(result);
                while (result.next()) {
                    int quantity = result.getInt("quantity");
                    System.out.println(quantity);
                    if (quantity > 0) {
                        result.updateInt("quantity", quantity - 1);
                        result.updateRow();
                        resultList.add(result.getString("isbn"));
                    }
                }
            }
            connection.commit();

the result of executeQuery() is null, causing the call of result.next() to fail
according to the secification of the preparedStatement intereface, executeQuery should never return null, so I think this is a bug

reduce mockrunner-core transitive dependency set

Was attempting to use mockrunner-jdbc for a commercial entity - which implies legal OSS licensing issues. The dependency tree was rather large. We found that (at least for our use) we could exclude all transitive dependencies aside from mockrunner-core. Large dependency trees complicates both your licensing and many entities use of your library.

I believe that the majority of these dependencies should be reduced to test scope so that they are not exposed as transitive dependencies. See the relevant section from the Maven book:
http://books.sonatype.com/mvnref-book/reference/pom-relationships-sect-project-dependencies.html#table-transitive-dep-and-scope

Dependency Tree:

[INFO] \- com.mockrunner:mockrunner-jdbc:jar:1.0.4:test
[INFO]    \- com.mockrunner:mockrunner-core:jar:1.0.4:test
[INFO]       +- junit:junit:jar:4.11:test
[INFO]       |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]       +- commons-logging:commons-logging:jar:1.0.4:test
[INFO]       +- jdom:jdom:jar:1.0:test
[INFO]       +- oro:oro:jar:2.0.8:test
[INFO]       +- com.kirkk:jaranalyzer:jar:1.2:test
[INFO]       |  +- bcel:bcel:jar:5.1:test
[INFO]       |  |  \- regexp:regexp:jar:1.2:test
[INFO]       |  +- jakarta-regexp:jakarta-regexp:jar:1.4:test
[INFO]       |  \- ant:ant:jar:1.6.5:test
[INFO]       \- nekohtml:nekohtml:jar:0.9.5:test
[INFO]          \- xerces:xercesImpl:jar:2.4.0:test
[INFO] ------------------------------------------------------------------------

Regards
~rmp

100% CPU in mockrunner JMS module

Hello,
I've noticed a strange behavior while developing a testing module for my application.
I'm using Spring JMS support.
When I start the application I have the CPU at 100%, and looks like I have an infinite loop on Session.commit() (by raising the debug level to DEBUG I can see the trace left here

public void commit() throws JMSException
{
     connection.throwJMSException();
     numberCommits++;
     if(logger.isDebugEnabled())
         logger.debug("Mock session commit");
}

Am I doing something wrong here?

Setting up complete mockrunner project

Hi,

Is there an easy way to set up mockrunner so I can run the tests within eclipse? I am not used to maven. But if it helps me get all dependencies to run the test, that would be nice.

Joe

Introducing Java 5 Generics

Hello Guys!

Thanks for maintaining this project, I found it very-very useful in my work.

One day I was trying to change the ResultSet of a Prepared statement, and I failed. I created the Prepared Statement like this:

    PreparedStatementResultSetHandler preparedStatementResultSetHandler = 
        conn.getPreparedStatementResultSetHandler();

    MockResultSet resultSet = preparedStatementResultSetHandler.createResultSet();
    for(String columnName : columnNames){
        resultSet.addColumn(columnName);
    }
    for(Object[] row : rows){
        resultSet.addRow(row);
    }
    preparedStatementResultSetHandler.prepareResultSet(query, resultSet, new Object[0]);

And I tried to remove the ResultSet as follows:

    PreparedStatementResultSetHandler preparedStatementResultSetHandler = 
        conn.getPreparedStatementResultSetHandler();
    preparedStatementResultSetHandler.removeResultSet(query);

I found out that the PreparedStatementResultSetHandler.removeResultSet(String sql) does not remove the result set. Debugging further it seems that AbstractParameterResultSetHandler and AbstractResultSetHandler have some private fields with the same name and the removeResultSet(String sql) operates on the AbstractResultSetHandler.resultSetsForStatement, but not on AbstractParameterResultSetHandler.resultSetsForStatement. Those Maps have different value types too.

The simple solution would be adding overriding methods to AbstractParameterResultSetHandler, but that's still an error-prone solution. The fields that have the same name in AbstractParameterResultSetHandler and AbstractResultSetHandler are to be fixed. I was thinking to introduce Java 5 style Generics to the source to make sure that Maps and Lists are handled properly. I think that #11 would be resolved by this too.

But before starting that I would like to ask if someone has started that work before. Is there anyone still using Java 1.4?

Kind regards,
KZ

[REQ] Support Jakarta EE 9

With the upgrade to Spring Boot 3 and the adoption of Jakarta EE9, Jakarta EE 9 a new top-level jakarta package, replacing EE 8’s javax top-level package.

For example, the current com.mockrunner.mock.jms.MockSession class is using the javax.jms. packages instead of jakarta.jms..

Is there provision for a release using Jakarta EE9?

MockHttpServletResponse.sendError(int, String) drops message

The MockHttpServletResponse.sendError(int, String) method uses the status code, but doesn't use the message argument.

If I'm interpreting the javadoc correctly, a better behaviour would be to set the content type to "text/html" and return the message as the response body (potentially inside a trivial HTML file, but that's not really important for testing purposes).

Bug: verifySQLStatementParameter does not respect null parameter

JDBCTestModule.verifySQLStatementParameter(String sql, int indexOfParameterSet, MockParameterMap parameterMap)

does not take into account null parameters.
The following null-check

if(null == nextActualParameter)
{
       throw new VerifyFailedException("No parameter " + key + " found.");
}

should be replaced by

 if(!actualParameterMap.containsKey(key))
{
      throw new VerifyFailedException("No parameter " + key + " found.");
}
  • The parameter-size check is ok
  • The method ParameterUtil.compareParameter compares null == null as equal
  • The overloaded methods for 1 parameter do not have this null-check, we should add it there too (with additional contains-methods checking for index/name)
    i.e.
verifySQLStatementParameter(String sql, int indexOfParameterSet, int indexOfParameter, Object expectedParameter)

Calling MockDatabaseMetaData.getColumns twice returns the same ResultSet object

Hi,

I have a test case where lots of DatabaseMetaData info are queried. I have found that querying the same column info twice makes the second query fail.

I have narrowed it to a test case:

    /**
     * Looks like MockDatabaseMetaData.getColumns method returns the same ResultSet if called twice.
     * They should only have the same content but with different cursor and other internals. 
     * 
     * Moving the cursor before the first row makes this test case pass, but returning clones of the result sets fixes this issue in real.
     * @throws SQLException 
     */
    public void testColumns2() throws SQLException
    {
        MockDatabaseMetaData metaData = new MockDatabaseMetaData();
        MockResultSet testResult = new MockResultSet("id");
        testResult.addColumn("COLUMN_NAME", new Object[]{"mycolumn"});
        testResult.addColumn("DATA_TYPE", new Object[]{java.sql.Types.INTEGER});
        metaData.setColumns(null, "public", "mytable", "mycolumn", testResult);
        
        ResultSet columns1 = metaData.getColumns(null, "public", "mytable", "mycolumn");
        columns1.next();
        assertEquals(columns1.getInt("DATA_TYPE"), java.sql.Types.INTEGER);
        columns1.close();
//        Makes this test case pass
//        columns1.beforeFirst();

        ResultSet columns2 = metaData.getColumns(null, "public", "mytable", "mycolumn");
//        Makes this test case pass too
//        columns2.beforeFirst(); 
        columns2.next();
        assertEquals(columns2.getInt("DATA_TYPE"), java.sql.Types.INTEGER);
        columns2.close();
    }

This test case fails:

Running com.mockrunner.test.jdbc.MockDatabaseMetaDataTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.188 sec <<< FAILURE! - in com.mockrunner.test.jdbc.MockDatabaseMetaDataTest
testColumns2(com.mockrunner.test.jdbc.MockDatabaseMetaDataTest)  Time elapsed: 0.069 sec  <<< ERROR!
java.sql.SQLException: Current row invalid
	at com.mockrunner.mock.jdbc.MockResultSet.checkRowBounds(MockResultSet.java:2225)
	at com.mockrunner.mock.jdbc.MockResultSet.getObject(MockResultSet.java:797)
	at com.mockrunner.mock.jdbc.MockResultSet.getInt(MockResultSet.java:937)
	at com.mockrunner.test.jdbc.MockDatabaseMetaDataTest.testColumns2(MockDatabaseMetaDataTest.java:1359)

As the method MockPreparedStatement.executeQuery returns a clone of the resultsets, so the DatabaseMetaData.findMatchingDatabaseIdentifier should return a clone as well.

Tests failing when building with maven on openjdk

This is how "mvn clean install" fails on debian 9.6 "stretch", amd64, openjdk-8-jdk:amd64 8u181-b13-2~deb9u1:

INFO] Reactor Summary:
[INFO] 
[INFO] MockRunner ......................................... SUCCESS [  0.316 s]
[INFO] MockRunner-Core .................................... SUCCESS [  6.659 s]
[INFO] MockRunner-JMS ..................................... FAILURE [  2.535 s]
[INFO] MockRunner-EJB ..................................... SKIPPED
[INFO] MockRunner-JDBC .................................... SKIPPED
[INFO] MockRunner-JCA ..................................... SKIPPED
[INFO] MockRunner-Servlet ................................. SKIPPED
[INFO] MockRunner-TAG ..................................... SKIPPED
[INFO] MockRunner-Struts .................................. SKIPPED
[INFO] MockRunner-ALL ..................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.998 s
[INFO] Finished at: 2018-12-15T17:20:21+01:00
[INFO] Final Memory: 34M/506M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project mockrunner-jms: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/sb/workspaces/mockrunner/mockrunner/mockrunner-jms && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar /home/sb/workspaces/mockrunner/mockrunner/mockrunner-jms/target/surefire/surefirebooter5979724891049919537.jar /home/sb/workspaces/mockrunner/mockrunner/mockrunner-jms/target/surefire/surefire5036894430562333897tmp /home/sb/workspaces/mockrunner/mockrunner/mockrunner-jms/target/surefire/surefire_04181330382505179197tmp
[ERROR] -> [Help 1]

Java 1.6 compatibility

Could you recompile the library to support java 1.6 too ? I believe it is a matter of setting target level in the pom.xml in compiler maven plugin configuration.

MR-jdbc does not return subsequent resultsets for a query

Hello!

I am testing an app where I would like to return different resultsets for subsequent calls of the same query. I am experimenting with MockPreparedStatements.prepareResultSets(String sql, MockResultSet[] resultSets), but after executing the query I'm always receiving the first MockResultSet. Why is it possible to configure multiple resultsets then?

I think I have a clue about this:

    private MockResultSet cloneAndSetMultipleResultSets(MockResultSet[] results, MockParameterMap params)
    {
        results = cloneResultSets(results);
        if(null != results)
        {
            resultSetHandler.addReturnedResultSets(results);
        }
        setResultSets(results);
        setGeneratedKeysResultSet(sql, params);
        if(null != results && results.length > 0)
        {
            return results[0];
        }
        return null;
    }

Are there any reasons, why results[0] is returned every time, or is this a bug?

I think if there are multiple resultsets for a given query and parametermap, the first resultset is to be returned for the first execution, the second for the second etc. If there are more executions than resultsets, then the last resultset is to be returned multiple times. This usage is consistent with the "same resultset every time the query is executed with a parameter map" use case as well.

Working with sessions from MockHttpServletRequest

As I was writing some tests involving HttpServlet and HttpSession, I noticed the following:

  1. When you invoke MockHttpServletRequest#getSession(false) after having set a MockHttpSession, it will still return null.
  2. When you invoke MockHttpServletRequest#getSession(true) (without further interaction with that HttpServletRequest) it will return null.

I would like to suggest the following changes:

  1. When you invoke MockHttpServletRequest#getSession(false) after having set a MockHttpSession, it will return the previously set MockHttpSession.
  2. When you invoke MockHttpServletRequest#getSession(true) (without further interaction with that HttpServletRequest) it will return a new instance of MockHttpSession, unless there already is an instance of MockHttpSession.

These changes would make the MockHttpServletRequest a bit more conformant to the Servlet spec.
How would you feel about such changes? I can contribute a PR if the above suggestions would be approved.

executeQuery() and prepareGlobalResultSet()

Hi,

First of all, thanks for creating mockrunner. I have used it for a few days and already I like it a lot.
Issue #8 was closed, ignoring the issue @frab3 raised. I experience the same misbehaviour, so here is the new issue.
I get an empty result set, but expect a result set with ID and USERNAME. Here is a working example with a workaround:

import java.sql.*;
import java.util.HashMap;
import org.junit.Test;
import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter;
import com.mockrunner.jdbc.PreparedStatementResultSetHandler;
import com.mockrunner.mock.jdbc.MockResultSet;
public class ExtractDataTest extends BasicJDBCTestCaseAdapter {
    @Test
    public void test() throws Exception {
        PreparedStatementResultSetHandler statementHandler = getJDBCMockObjectFactory()
                .getMockConnection().getPreparedStatementResultSetHandler();
        MockResultSet resultMock = statementHandler.createResultSet();
        resultMock.addColumn("ID", new Object[]{"1"});
        resultMock.addColumn("USERNAME", new Object[]{"foobar"});
        statementHandler.prepareGlobalResultSet(resultMock);
        // statementHandler.prepareResultSet("SELECT * FROM DUAL", resultMock, new HashMap()); // WORKAROUND
        Connection con = DriverManager.getConnection( "a", "b", "c");
        System.out.println(con); //com.mockrunner.mock.jdbc.MockConnection@29d8a2c5
        PreparedStatement stmtObjects = con.prepareStatement(
                  "SELECT * FROM DUAL WHERE 1=?"); //SELECT * FROM DUAL would work, too.
        ResultSet rs = stmtObjects.executeQuery();
        System.out.println(rs);
        System.out.println(this.getPreparedStatements());
    }
}

I first raised the issue on stackoverflow, so it would be great if you could write a comment there if you fix the bug.
http://stackoverflow.com/questions/28676123/mockrunner-jdbc-no-columns-rows-in-result-set/28691264#28691264

Licenses

Can you please move the licenses to the individual projects / headers of the projects. By dumping all of the licenses in the root folder you have made it extremely difficult to tell which code (and snippet) is under which license.

Thanks

JMSCorrelationID does not work in JMS module

Maybe it is not implemented by Mockrunner JMS but even if so, I'd expect it to be ignored (and especially not hang the whole test as in 1.0.8)

It seems, JMSCorrelationID does not work in the JMS module.

Code like

qrec = session.createReceiver(queue);
Message m = qrec.receive();

works assuming a message was sent to the queue first.

Trying

String filter = "JMSCorrelationID = 'myId'";
qrec = session.createReceiver(queue, filter);
Message m = qrec.receive();

gives a null message, even if JMSCorrelationID had been set to the message first like

msg.setJMSCorrelationID("myId");

At least in Mockrunner 1.0.4 it you get null. After upgrading to 1.0.8 the receiver test simply hangs up completely. I suspect it could be related to #13 but not sure.

MockResultSet: need a better way to add rows

I'm testing a legacy application and have to mock a ResultSet that's quite wide for which adding rows by creating List<Object> is unreadable. Is there anyway to create aMap<String,Object> row for something like mockResultSet.addRow(row); where the keys are the column names and the Object is the column's contests?

BasicServletTestCaseAdapter and JUnit 4

Hey,

are there plans to move from the JUnit3-styled test layout (extends TestCase) to JUnit4-styled layout (without extending this class)?

Since one of the super classes of BasicServletTestCaseAdapter extends the TestCase class, annotations like @Test or @BeforeClass do not work within the own test classes; see: http://stackoverflow.com/a/1151384

For now, a workaround would be to use the com.mockrunner.servlet.ServletTestModule class directly without extending the BasicServletTestCaseAdapter class. However, this is a little bit less comfortable, since then we must always call e.g. servletTestModule.doGet() instead of just doGet().

MockHttpServletRequest.getSession(true) does not create a session

When invoking MockHttpServletRequest#getSession(true), there is no session created. There is even a unit test that explicitly verifies this, so I guess it is somehow intended.

However, the Servlet API JavaDoc states

Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.

I am curious why MockRunner is in contradiction of the JavaDoc here?

If this is perceived as a mistake, I'll be more than happy to supply a patch that addresses this deviation.

JDBC - missmatch in UpdateCount, MoreResults and ResultSet

When you open javadoc of java.sql.Statement#getMoreResults() you can see the following

Moves to this Statement object's next result, returns true if it is a ResultSet object, and implicitly closes any current ResultSet object(s) obtained with the method getResultSet.
There are no more results when the following is true:
          // stmt is a Statement object
          ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))

Therefore we have an old legacy logic in our code base which looks like this:

...
                       rsExists = theCallableStatement.execute();
                       while (!rsExists && theCallableStatement.getUpdateCount() != -1) {
                           rsExists = theCallableStatement.getMoreResults();
                       }
                       theResultSet = null;
                       while (rsExists) {
                           if (theResultSet != null) {
                               theResultSet.close();
                           }
                           theResultSet = theCallableStatement.getResultSet();
....

It seems, that comparing my testsetup with mock factory and real database (sybase) is working differently.
I don't know how to set up everything correctly. Either it is a bug, or I don't know how to set it up correctly.

statementHandler = getJDBCMockObjectFactory().getMockConnection().getCallableStatementResultSetHandler();


        FileResultSetFactory factory = new FileResultSetFactory(getClass().getResource("/resultsets/myprocedure_213792962.csv").getFile());
        factory.setFirstLineContainsColumnNames(true);

        MockResultSet result = statementHandler.createResultSet("myprocedure_213792962", factory);
        // statementHandler.prepareUpdateCounts("myprocedure", new Integer[]{1,2,3}, ImmutableList.of(213792962L));
        MockParameterMap params = new MockParameterMap();
        params.put(1, 213792962L);
        statementHandler.prepareResultSets("myprocedure", new MockResultSet[] {statementHandler.createResultSet(),statementHandler.createResultSet(), result}, params);

the test looks like this:

 try (Connection connection = connectionForTest();
             CallableStatement callableStatement = connection.prepareCall("myprocedure ?");){


            Long parameter = 213792534L;
            callableStatement.setLong(1, parameter);
            boolean rsExists = callableStatement.execute();

            assertThat(rsExists, is(false));
            assertThat(callableStatement.getUpdateCount(), is(greaterThan(-1)));
            assertThat(callableStatement.getMoreResults(), is(false));
            assertThat(callableStatement.getUpdateCount(), is(greaterThan(-1))); // java.lang.AssertionError: Expected: is a value greater than <-1>     but: <-1> was equal to <-1>
            assertThat(callableStatement.getMoreResults(), is(true));

            ResultSet resultSet = callableStatement.getResultSet();
            assertThat(resultSet, is(notNullValue()));

        } catch (SQLException e) {
            fail(e.getMessage());
        }

The question is, how can I make the updateCount() return an other count and more Results true, if I am not able to use prepareUpdateCounts without delting my resultSets?

I have to admit, it's nice to have such a nice library but it is sometimes a pain to use it. If you don't mind, I would do some ISP (Interface Segregation Principle)....

Make it easier to change test cases between tests in a suite for BasicJDBCTestCaseAdapter

I have a System-Under-Test which requires a number of JDBC interactions which are not easily tested as separate methods. As such, I have to create a number of resultsets and responses for different SQL queries and I use exact matches. When I define the complete set of responses for a successful test it is comprised of over 20 resultsets. In subsequent tests, I just want to modify small parts of the original resultsets, but the current code only allows for adding resultsets (thus creating multiple potential results) or clearing ALL resultsets regardless of the query associated. Ideally, it should be possible that if I define something like:

assuming:

getStatementResultSetHandler().setExactMatch(true);

then:

getStatementResultSetHandler().prepareResultSet(myQuery, mySuccessResult)

Then I should be able to do something like:

getStatementResultSetHandler().replaceResultSet(myNewQuery, myFailureResult)

Or, something like:

getStatementResultSetHandler().removeResultSet(myQuery);
getStatementResultSetHandler().prepareResultSet(myQuery, myFailureResult)

It looks like it could be accomplished by adding some new methods to the AbstractResultSetHandler class which would provide the new functionality. Then, when I needed to change a single result in a defined set of resultsets, I would only need to remove/replace the one I am interested in instead of replacing ALL of the resultsets.

ResultSetIterator not available

I am using mockrunner-jdbc and trying to create a mock test for a Oracle DAO method which uses ResultSetIterator. It comes with sqlj.runtime.ResultSetIterator.

When I try to do following:

MockResultSet result = null;
result.addColumn("col1");
result.addColumn("col2");
result.addColumn("col3");

    List<Object> val = new ArrayList<Object>();

    val.add("1");
    val.add("2");
    val.add(3);

    result.addRow(val);
    result.moveToInsertRow();

ResultSetIterator rsItr = new ResultSetIterImpl((RTResultSet) result);

I get an error that MockResultSet cannot be casted into Runtime ResultSet (RTResultSet).

I think it would be great if mockrunner can provide ResultSetIterator object instead of developer implementing it everytime.

Thanks.

Catching up

I'd like to tackle some of the larger issues I see, especially the ones centered around JMS.

As a means to that end, I'd like to make some passes over the codebase to "catch up" to Java 7, primarily with respect to being precise about type parameters. I'd also like to clean up the usual warnings around serial version uids, the Override annotation, et cetera. My goal would be to get to as close to zero warnings as possible.

Before I get deep in that effort, is there any concern or hesitation about that?

MockHttpServletRequest field setters should store data in headers as well as the actual field

Methods like e.g. MockHttpServletRequest.setContentType() should set a value in MockHttpServletRequest.headers in addition to setting the value returned by the accessor.

The reason for this is that some software (at least Jersey, there may be others), access headers through the HttpServletRequest.getHeaders() method. I.e. it uses request.getHeaders().get("Content-Type") instead of request.getContentType().

Dependency structure when using MockRunner (changed in 2.0.3)

First of all, thanks for making and maintaining MockRunner! It's been valuable to me in the past and I hope it will continue to be.

I have a few projects where I use MockRunner Servlet. Using Maven, I pull in MockRunner Servlet, and that would pull in MockRunner Core. I'm not sure if this is the intended way of using it, but the documentation doesn't really point out how it should be done alternatively.

Starting with MockRunner 2.0.3, this approach is no longer sufficient. I also need to have a dependency on MockRunner Core. I came across this because Dependabot suggested to upgrade and that branch suddenly didn't work anymore. This change has been introduced in #67, where all modules that depend on Core where updated to have <scope>provided</scope>. This requires dependant projects (like mine) to provide for that dependency.

If this is the intended behaviour, it might be nice to have that somewhere on the MockRunner website. I could provide a PR with some documentation suggestion. If it is not intended, I could provide a PR that undoes the <scope>provided</scope>.

Please let me know what approach fits best :-)

Add binary request method to MockHttpServletResponse

It would be nice if MockHttpServletRequest had a method to access the outputstream content as a byte[].

I had to access the stream and cast it to get to the binary content:

    private byte[] getBinaryContent(MockHttpServletResponse response) throws IOException {
        MockServletOutputStream outputstream = (MockServletOutputStream) response.getOutputStream();
        return outputstream.getBinaryContent();
    }

Recieve Timeout / Incompatibility with Spring JmsTemplate.sendAndRecieve

in com.mockrunner.mock.jms.MockMessageConsumer

The following functions return immediately with a null parameter if no messages are in the queue.

Message receive(long timeout)
Message receive()

This is incorrect operation. (Refrerence: http://docs.oracle.com/javaee/6/api/javax/jms/MessageConsumer.html) receive(long timeout) should wait for the timeout period, and receive() should wait forever for a message to be returned. The current implementations act as “RecieveNoWait” should.

This causes the org.springframework.jms.core.JmsTemplate.sendAndReceive family of functions to operate incorrectly, returning a “null” message, before the message can be responded to.

I am developing a quick patch to get my project going and will post shortly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.