Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
"Servletunit" should be used to perform the Unit Testing of the Struts actions also as we need ServletRequest/Response etc., for this.
"MockStrutsTestCase" should be used for this purpose. Please see below for full example.
Step 1 :
Please download "servletunit" jar
Step 2:
Your Test Case should extend "MockStrutsTestCase".
Step 3:
Create your TestCase as follows .
public class EditActionTest extends MockStrutsTestCase {
public EditActionTest(String name) {
super(name);
}
public void tearDown() throws Exception {
closeSession();
}
public void test_update() throws Exception{
addRequestParameter("method",
"update");
addRequestParameter("contactId",
"273016914");
addRequestParameter("reloadContact",
"false");
addRequestParameter("zipCode",
"08053");
addRequestParameter("address1"
, new String[]{"225 Test road", "Apt
6","Test City","Test
State"});
setRequestPathInfo("/contactDetailsEdit");
actionPerform();
verifyForwardPath("/contactDetails.do?contactId=273016914");
verifyNoActionErrors();
assertEquals(request.getAttribute("isAddressVarified"),
true);
}
@Test
public void test_getContactData() throws Exception
{
ContactForm form = new
ContactForm();
HttpServletRequest request =
createMock(HttpServletRequest.class);
BigDecimal oppObjid = new
BigDecimal("273028572");
Contact
opportunity = (Contact) ContactServices
.getOpportunityByObjid(oppObjid);
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.