Skip to content

Commit

Permalink
TRUNK-3949: Backported WebTestHelper changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Apr 2, 2013
1 parent b1fd753 commit a354ea1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -25,6 +25,7 @@
import org.openmrs.web.test.WebTestHelper.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.annotation.NotTransactional;


/**`
Expand All @@ -40,6 +41,7 @@ public UserService getUS() {
}

@Test
@NotTransactional
public void shouldUpdateRoleWithParent() throws Exception {
Role parent = new Role("parent", "parent");
getUS().saveRole(parent);
Expand All @@ -61,6 +63,8 @@ public void shouldUpdateRoleWithParent() throws Exception {
wth.handle(requestPOST);

Assert.assertEquals("updated child", getUS().getRole("child").getDescription());

deleteAllData();
}

}
14 changes: 10 additions & 4 deletions test/web/org/openmrs/web/test/WebTestHelper.java
Expand Up @@ -24,6 +24,8 @@
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerMapping;
Expand Down Expand Up @@ -133,10 +135,6 @@ public Response handle(final HttpServletRequest request) throws Exception {

Assert.assertTrue("The requested URI has no handlers: " + request.getRequestURI(), supported);

//Complete the request by flushing and clearing the Hibernate session
Context.flushSession();
Context.clearSession();

return new Response(response, request.getSession(), modelAndView);
}

Expand All @@ -153,5 +151,13 @@ public Response(MockHttpServletResponse http, HttpSession session, ModelAndView
this.session = session;
this.modelAndView = modelAndView;
}

public Errors getErrors(String model) {
return (Errors) modelAndView.getModel().get(BindException.MODEL_KEY_PREFIX + model);
}

public Errors getErrors() {
return getErrors("command");
}
}
}

0 comments on commit a354ea1

Please sign in to comment.