1

I need to write unit test cases for endeca application,i started writing using junit and mocking using Mockito, but while mocking HttpEneConnection,ENEQueryResults, i am getting following exception. Please tell me how to mock without giving mdex hostname and port.

com.endeca.navigation.ENEConnectionException: Hostname or port not specified.
    at com.endeca.navigation.HttpENEConnection.query(Unknown Source)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
bated
  • 960
  • 2
  • 15
  • 29
Srinivas
  • 11
  • 1
  • first line of the stacktrace *com.endeca.navigation.ENEConnectionException: Hostname or port not specified.* states your problem. – Blip Dec 09 '15 at 06:40
  • could you provide the mocking code snippet? – KrishPrabakar Dec 09 '15 at 07:33
  • @Before public void setUp() throws ENEQueryException{ HttpENEConnection enecon = new HttpENEConnection(); ENEQuery eneQuery=new UrlENEQuery(); ENEQueryResults eneQueryResults=enecon.query(eneQuery); Mockito.when(mdexService.getConnection()).thenReturn(enecon); Mockito.when(enecon.query(eneQuery)).thenReturn(eneQueryResults); Mockito.when(envProperties.getProperty("maxRecordsFromMdex")) .thenReturn("20000"); } – Srinivas Dec 10 '15 at 06:39
  • By providing hostname name and port its works fine, but test case should run independently without using mdex server results, so i am facing problem to mock the mdex connection and results. – Srinivas Dec 10 '15 at 06:43
  • Use a mock set of results. – Rivasa Dec 17 '15 at 15:48
  • Try using another form of constructor of HttpENEConnection. Something like `= new HttpENEConnection(String hostName, String port);` – KrishPrabakar Dec 22 '15 at 06:55

0 Answers0