gauravpaliwal

testing example

Jul 23rd, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14.  
  15. package org.openmrs.module.feedback.web;
  16.  
  17. import org.springframework.mock.web.MockHttpSession;
  18. import org.springframework.web.servlet.ModelAndView;
  19. import org.openmrs.module.feedback.PredefinedSubject;
  20. import org.springframework.mock.web.MockHttpServletResponse;
  21. import org.springframework.mock.web.MockHttpServletRequest;
  22.  
  23. import javax.servlet.http.HttpServletResponse;
  24.  
  25. import org.openmrs.module.feedback.FeedbackService;
  26. import org.openmrs.web.test.BaseModuleWebContextSensitiveTest ;
  27. import org.openmrs.api.context.Context;
  28.  
  29. import java.util.Map;
  30. import javax.servlet.http.HttpServletRequest;
  31. import junit.framework.Assert;
  32.  
  33. import org.junit.After;
  34. import org.junit.AfterClass;
  35. import org.junit.Before;
  36. import org.junit.BeforeClass;
  37. import org.junit.Test;
  38.  
  39. import static org.junit.Assert.*;
  40.  
  41.  
  42. public class AddPredefinedSubjectFormControllerTest extends BaseModuleWebContextSensitiveTest {
  43.  
  44. private FeedbackService service;
  45. private FeedbackListController controller;
  46. private MockHttpServletRequest request;
  47. private HttpServletResponse response;
  48.  
  49. public AddPredefinedSubjectFormControllerTest() {
  50. }
  51.  
  52. @BeforeClass
  53. public static void setUpClass() throws Exception {
  54. }
  55.  
  56. @AfterClass
  57. public static void tearDownClass() throws Exception {
  58. }
  59.  
  60. @Before
  61. public void setUp() throws Exception {
  62. /*executed before the test is run*/
  63. this.service = Context.getService(FeedbackService.class);
  64. this.controller = new FeedbackListController();
  65. this.request = new MockHttpServletRequest();
  66. this.response = new MockHttpServletResponse();
  67. /*this file is in the same folder of test resources where the hibernate mapping file is located*/
  68. initializeInMemoryDatabase() ;
  69. executeDataSet("PredefinedSubjectDataset.xml");
  70. /*Sample data is loaded into the system*/
  71. authenticate() ;
  72. }
  73.  
  74. @After
  75. public void tearDown() {
  76. }
  77.  
  78. /**
  79. * Test of formBackingObject method, of class AddPredefinedSubjectFormController.
  80. */
  81. @Test
  82. public void testFormBackingObject() throws Exception {
  83. System.out.println("formBackingObject");
  84. PredefinedSubject test = new PredefinedSubject() ;
  85.  
  86. Assert.assertEquals("Test Sucessfull with dataset feedbackSeverityId : 3", service.getPredefinedSubject(3).getSubject() , "to_test_if_it_is_possible_to_enter_exactly_fifty_" ) ;
  87.  
  88. System.out.println(service.getPredefinedSubject(3).getSubject()) ;
  89.  
  90. System.out.println("holla");
  91. HttpServletRequest req = null;
  92. authenticate() ;
  93. AddPredefinedSubjectFormController instance = new AddPredefinedSubjectFormController();
  94. Boolean expResult = null;
  95. Boolean result = instance.formBackingObject(request);
  96. System.out.println("formBackingObject");
  97. ModelAndView mv = new ModelAndView();
  98. instance.setSuccessView("someValue") ;
  99. request.setSession(new MockHttpSession(null));
  100. request.setMethod("POST") ;
  101. request.addParameter("predefinedSubject", "Testing");
  102.  
  103. mv = instance.handleRequest(request, response) ;
  104. FeedbackService hService = (FeedbackService)Context.getService(FeedbackService.class);
  105. System.out.println(hService.getPredefinedSubjects()) ;
  106.  
  107. /*Boolean expResult = null;
  108. assertEquals(expResult, result);*/
  109. }
  110.  
  111. /**
  112. * Test of referenceData method, of class AddPredefinedSubjectFormController.
  113. */
  114. /* @Test
  115. public void testReferenceData() throws Exception {
  116. System.out.println("referenceData");
  117. HttpServletRequest req = null;
  118. AddPredefinedSubjectFormController instance = new AddPredefinedSubjectFormController();
  119. Map expResult = null;
  120. Map result = instance.referenceData(req);
  121. // TODO review the generated test code and remove the default call to fail.
  122. fail("The test case is a prototype.");
  123. }
  124. *
  125. */
  126. }
Advertisement
Add Comment
Please, Sign In to add comment