Search in sources :

Example 1 with EvoServletConfig

use of org.evosuite.runtime.javaee.javax.servlet.EvoServletConfig in project evosuite by EvoSuite.

the class HttpServletTest method testInitServlet.

@Test
public void testInitServlet() throws Exception {
    final String delegate = "/result.jsp";
    Assert.assertFalse(TestDataJavaEE.getInstance().getViewOfDispatchers().contains(delegate));
    HttpServlet servlet = new HttpServlet() {

        @Override
        public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(delegate);
            dispatcher.forward(req, resp);
        }
    };
    EvoHttpServletRequest req = new EvoHttpServletRequest();
    EvoHttpServletResponse resp = new EvoHttpServletResponse();
    try {
        servlet.service(req, resp);
        Assert.fail();
    } catch (IllegalStateException e) {
    // expected
    }
    EvoServletConfig conf = new EvoServletConfig();
    servlet.init(conf);
    try {
        servlet.service(req, resp);
        Assert.fail();
    } catch (NullPointerException e) {
    // expected
    }
    conf.createDispatcher(delegate);
    servlet.init(conf);
    servlet.service(req, resp);
    String body = resp.getBody();
    Assert.assertNotEquals(EvoHttpServletResponse.WARN_NO_COMMITTED, body);
    Assert.assertTrue(body.length() > 0);
    // the name of the delegate should appear in the response
    Assert.assertTrue(body.contains(delegate));
    Assert.assertTrue(TestDataJavaEE.getInstance().getViewOfDispatchers().contains(delegate));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) EvoServletConfig(org.evosuite.runtime.javaee.javax.servlet.EvoServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestDispatcher(javax.servlet.RequestDispatcher) Test(org.junit.Test)

Example 2 with EvoServletConfig

use of org.evosuite.runtime.javaee.javax.servlet.EvoServletConfig in project evosuite by EvoSuite.

the class ConstraintVerifierTest method testEvoSuiteClassExclude.

@Test
public void testEvoSuiteClassExclude() throws Exception {
    TestChromosome tc = new TestChromosome();
    TestFactory factory = TestFactory.getInstance();
    // shouldn't be able to instantiate EvoServletConfig directly
    factory.addConstructor(tc.getTestCase(), new GenericConstructor(EvoServletConfig.class.getConstructor(), EvoServletConfig.class), 0, 0);
    Assert.assertEquals(1, tc.size());
    Assert.assertFalse(ConstraintVerifier.verifyTest(tc));
}
Also used : EvoServletConfig(org.evosuite.runtime.javaee.javax.servlet.EvoServletConfig) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) Test(org.junit.Test)

Aggregations

EvoServletConfig (org.evosuite.runtime.javaee.javax.servlet.EvoServletConfig)2 Test (org.junit.Test)2 RequestDispatcher (javax.servlet.RequestDispatcher)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)1