You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Juan Pedro López Sáez <jp...@altiria.com> on 2004/01/22 11:22:55 UTC

Strange problem

Hello everybody.

I am experiencing a quite strange problem.

I'm testing a servlet using: 

Cactus-13-1.5
Tomcat 4.1.27
J2SE 1.4.2_01
J2EE 1.3.1
Ant 1.5.1

I use the cactus ant tasks and everything seems to be properly
configured. My Cactus Test class extends the ServletTestCase class.

If I run my tests in a windows platform, everything is ok.
If I run my tests in a Linux Debian platform, there are no errors the
very first time at a day, but next executions show me the same error. I
guess it has something to do with the inactivity period at night. The
first test in my test suite (I just have one) throws the following
exception:

[cactus] Testcase:
testMultdestOk(com.altiria.wasp.push.gateway.TestPushWebappGateway):      Caused an ERROR
   [cactus] Failed to get the test results at
[http://localhost:8081/api/ServletRedirector]
   [cactus] org.apache.cactus.util.ChainedRuntimeException: Failed to
get the test results at [http://localhost:8081/api/ServletRedirector]
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:131)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:222)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runWebTest(WebClientTestCaseDelegate.java:333)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runGenericTest(WebClientTestCaseDelegate.java:281)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runTest(WebClientTestCaseDelegate.java:257)
   [cactus]     at
org.apache.cactus.ServletTestCase.runCactusTest(ServletTestCase.java:300)
   [cactus]     at
org.apache.cactus.ServletTestCase.runBare(ServletTestCase.java:263)
   [cactus] org.apache.cactus.client.ParsingException: Not a valid
response [500 Error Interno del Servidor]
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.callGetResult(DefaultHttpClient.java:249)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody0(DefaultHttpClient.java:126)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest_aroundBody1$advice(DefaultHttpClient.java:222)
   [cactus]     at
org.apache.cactus.client.connector.http.DefaultHttpClient.doTest(DefaultHttpClient.java)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runWebTest(WebClientTestCaseDelegate.java:333)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runGenericTest(WebClientTestCaseDelegate.java:281)
   [cactus]     at
org.apache.cactus.internal.client.WebClientTestCaseDelegate.runTest(WebClientTestCaseDelegate.java:257)
   [cactus]     at
org.apache.cactus.ServletTestCase.runCactusTest(ServletTestCase.java:300)
   [cactus]     at
org.apache.cactus.ServletTestCase.runBare(ServletTestCase.java:263)


No matters what the first test is. It is the same situation if I change
the test execution order in the test suite. 

The rest of the test suite is correcly executed.

Every test has the same structure:

  public void beginMyTest(WebRequest theRequest)
    {

log.debug("Enter beginMyTest");

        theRequest.addHeader("Content-type",
"application/x-www-form-urlencoded; charset=UTF-8");
        theRequest.addParameter("cmd",
"sendsms",WebRequest.POST_METHOD);
        
    }

   public void testMyTest() throws Exception{
log.debug("Enter testMyTest");

try{ 
MyServletToTest servlet = new MyServletToTest();
servlet.init(config);

// Call method to test
servlet.doPost(request,response);
}catch(Exception e){
log.fatal("Exception in test",e);
} 
}


    public void endMyTest(WebResponse theResponse)
        throws Exception
    {
log.debug("Enter endMyTest");

        String expected = "expected response";
        
        String result = theResponse.getText();

database = System.getProperty("myDatabasePath");
log.info("database to test results: "+database);

        assertEquals(expected, result);
        // Fetch database data after executing your code
        IDataSet databaseDataSet = getConnection().createDataSet();
        ITable actualTable = databaseDataSet.getTable("TABLE_TO_TEST");
        
        // Load expected data from an XML dataset
        IDataSet expectedDataSet = new FlatXmlDataSet(new
InputStreamReader(getClass().getResourceAsStream("/expectedTablesxml")));

        ITable expectedTable =
expectedDataSet.getTable("TABLE_TO_TEST");
        

        // Assert actual database table match expected table

        Assertion.assertEquals(expectedTable,new
CompositeTable(expectedTable.getTableMetaData(), actualTable));
        
    }

The init method of my servlet just gets a reference to a DataSource
pointing to my database:

public void init(ServletConfig config) throws ServletException {
        super.init(config);
       try {
//Context ctx = new InitialContext();
//dataSource = (DataSource)ctx.lookup("java:comp/env/jdbc/MktsmsDb");

    Context init = new InitialContext();
    Context ctx = (Context) init.lookup("java:comp/env");
      dataSource = (DataSource) ctx.lookup("jdbc/myDb");

    if(dataSource == null ) {
log.fatal("Init: dataSource ERROR");
    }
    else {
log.info("Init: dataSource OK");
    }

}
catch (NamingException ex) {
    throw new ServletException("Cannot retrieve
java:/jdbc/MktsmsDb",ex);
}

    }

Sometimes, there are also some random FAILURES in some tests, but of
course those tests shouldn't fail because they have been previously
checked in the windows platform.

Does anybody know what can be happening?

Thank you,

Juan Pedro López.


RE: Strange problem

Posted by Vincent Massol <vm...@pivolis.com>.
Hi,

I do not know what the problem is but you should be able to easily
diagnose the problem by enabling logging.

Re: To test Servlet using tomcat/cactus

Posted by malini <op...@yahoo.co.in>.
Hai all,
I solved it thro the document.I missed the classpaths while compilation
 
malini

malini rajaji <op...@yahoo.co.in> wrote:



Hai all,
I am a new cactus user
i am working in Unix and my cactus&tomcat looks like
/tomcat
/cactus
.I am following the steps given in http://jakarta.apache.org/cactus/integration/howto_tomcat.html
to test a servlet
i placed both sampleservlet.java and itz class in /tomcat/webapps/examples/WEB-INF/classes
Now where to compile the TestSampleServlet.java ??
when i did that in the same dir,it says

TestSampleServlet.java:1: package junit.framework does not exist
import junit.framework.Test;
^
TestSampleServlet.java:2: package junit.framework does not exist
import junit.framework.TestSuite;
^
TestSampleServlet.java:4: package org.apache.cactus does not exist
import org.apache.cactus.ServletTestCase;
^
TestSampleServlet.java:5: package org.apache.cactus does not exist
import org.apache.cactus.WebRequest;
^
TestSampleServlet.java:7: cannot resolve symbol
symbol : class ServletTestCase
location: class TestSampleServlet
public class TestSampleServlet extends ServletTestCase
..
..

Iam using cactus for the first time. I think i have some missing classpaths with cactus

Can anyone help me from this group
regards
malini 



Yahoo! India Mobile: Ringtones, Wallpapers, Picture Messages and more.Download now.
Yahoo! India Mobile: Ringtones, Wallpapers, Picture Messages and more.Download now.

To test Servlet using tomcat/cactus

Posted by malini rajaji <op...@yahoo.co.in>.


Hai all,
I am a new cactus user
i am working in Unix and my cactus&tomcat looks like
<home>/tomcat
<home>/cactus
.I am following the steps given in http://jakarta.apache.org/cactus/integration/howto_tomcat.html
to test a servlet
i placed both sampleservlet.java and itz class in <home>/tomcat/webapps/examples/WEB-INF/classes
Now where to compile the TestSampleServlet.java ??
when i did that in the same dir,it says

TestSampleServlet.java:1: package junit.framework does not exist
import junit.framework.Test;
                       ^
TestSampleServlet.java:2: package junit.framework does not exist
import junit.framework.TestSuite;
                       ^
TestSampleServlet.java:4: package org.apache.cactus does not exist
import org.apache.cactus.ServletTestCase;
                         ^
TestSampleServlet.java:5: package org.apache.cactus does not exist
import org.apache.cactus.WebRequest;
                         ^
TestSampleServlet.java:7: cannot resolve symbol
symbol  : class ServletTestCase
location: class TestSampleServlet
public class TestSampleServlet extends ServletTestCase
..
..

Iam using cactus for the first time. I think i have some missing classpaths with cactus

Can anyone help me from this group
regards
malini                     



Yahoo! India Mobile: Ringtones, Wallpapers, Picture Messages and more.Download now.