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));
}
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));
}
Aggregations