Search in sources :

Example 1 with EvoHttpServletRequest

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

the class ConstraintVerifierTest method testDeleteAfter.

@Test
public void testDeleteAfter() throws Exception {
    TestChromosome tc = new TestChromosome();
    TestFactory factory = TestFactory.getInstance();
    // get a var for EvoHttpServletRequest
    VariableReference req = factory.addMethod(tc.getTestCase(), new GenericMethod(ConstraintVerifierTest.class.getDeclaredMethod("getNullEvoHttpServletRequest"), ConstraintVerifierTest.class), 0, 0);
    // make it a POST
    factory.addMethod(tc.getTestCase(), new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("asPOST"), EvoHttpServletRequest.class), 1, 0);
    // now add a call to 'asMultipartFormData' which does depend on POST
    factory.addMethod(tc.getTestCase(), new GenericMethod(EvoHttpServletRequest.class.getDeclaredMethod("asMultipartFormData"), EvoHttpServletRequest.class), 2, 0);
    Assert.assertEquals(3, tc.size());
    Assert.assertTrue(ConstraintVerifier.verifyTest(tc));
    // deleting the last one should be fine, but not the POST, as asMultipartFormData has an 'after' dependency on it
    Assert.assertTrue(ConstraintVerifier.canDelete(tc.getTestCase(), 2));
    // should not be able to delete POST directly
    Assert.assertFalse(ConstraintVerifier.canDelete(tc.getTestCase(), 1));
    // what about the first statement where the var is obtained? that should be valid to delete
    Assert.assertTrue(ConstraintVerifier.canDelete(tc.getTestCase(), 0));
    boolean mutated = tc.deleteStatement(factory, 1);
    // should fail to delete POST
    Assert.assertFalse(mutated);
    Assert.assertEquals(3, tc.size());
    mutated = tc.deleteStatement(factory, 0);
    Assert.assertTrue(mutated);
    // should end up deleting everything
    Assert.assertEquals(0, tc.size());
}
Also used : VariableReference(org.evosuite.testcase.variable.VariableReference) EvoHttpServletRequest(org.evosuite.runtime.javaee.javax.servlet.http.EvoHttpServletRequest) GenericMethod(org.evosuite.utils.generic.GenericMethod) Test(org.junit.Test)

Aggregations

EvoHttpServletRequest (org.evosuite.runtime.javaee.javax.servlet.http.EvoHttpServletRequest)1 VariableReference (org.evosuite.testcase.variable.VariableReference)1 GenericMethod (org.evosuite.utils.generic.GenericMethod)1 Test (org.junit.Test)1