use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class ViewNameMethodReturnValueHandlerTests method returnViewNameRedirect.
@Test
public void returnViewNameRedirect() throws Exception {
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
assertThat(this.mavContainer.getViewName()).isEqualTo("redirect:testView");
assertThat(this.mavContainer.getModel()).isSameAs(redirectModel);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class RedirectAttributesMethodArgumentResolver method resolveArgument.
@Override
public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception {
Assert.state(mavContainer != null, "RedirectAttributes argument only supported on regular handler methods");
ModelMap redirectAttributes;
if (binderFactory != null) {
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, DataBinder.DEFAULT_OBJECT_NAME);
redirectAttributes = new RedirectAttributesModelMap(dataBinder);
} else {
redirectAttributes = new RedirectAttributesModelMap();
}
mavContainer.setRedirectModel(redirectAttributes);
return redirectAttributes;
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class ModelAndViewMethodReturnValueHandlerTests method handleRedirectAttributesWithoutRedirect.
@Test
public void handleRedirectAttributesWithoutRedirect() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView();
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertThat(mavContainer.getView()).isEqualTo(null);
assertThat(mavContainer.getModel().isEmpty()).isTrue();
assertThat(model).as("RedirectAttributes should not be used if controller doesn't redirect").isNotSameAs(redirectAttributes);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project Sermant by huaweicloud.
the class FileEntryControllerTest method testSaveAndGet.
@SuppressWarnings("unchecked")
@Test
public void testSaveAndGet() {
ModelMap model = new ModelMap();
String path = "test1-path";
scriptController.addFolder(getTestUser(), "", path, model);
// create
scriptController.createForm(getTestUser(), path, "test.com", "new_file.py", "jython", false, null, new RedirectAttributesModelMap(), model);
FileEntry script = (FileEntry) model.get("file");
script.setContent(script.getContent() + "#test comment");
scriptController.save(getTestUser(), script, null, "", false, model);
scriptController.validate(getTestUser(), script, "test.com");
// save and get
model.clear();
scriptController.getOne(getTestUser(), script.getPath(), -1L, model);
FileEntry newScript = (FileEntry) model.get("file");
assertThat(newScript.getFileName(), is(script.getFileName()));
assertThat(newScript.getContent(), is(script.getContent()));
// List<Long> versionList = newScript.getRevisions();
// reversion list is not implemented yet.
// assertThat(versionList.size(), is(2));
model.clear();
scriptController.search(getTestUser(), "test", model);
model.clear();
scriptController.delete(getTestUser(), path, "new_file.py");
scriptController.getAll(getTestUser(), path, model);
List<FileEntry> scriptList = (List<FileEntry>) model.get("files");
assertThat(scriptList.size(), is(0));
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.
the class SamplesControllerTest method testRemoveGenomeAssemblyFromSample.
@Test
public void testRemoveGenomeAssemblyFromSample() {
Long sampleId = 1L;
Long assemblyId = 2L;
GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
Sample sample = new Sample();
when(sampleService.read(sampleId)).thenReturn(sample);
when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
HttpServletRequest request = new MockHttpServletRequest();
controller.removeGenomeAssemblyFromSample(attributes, sampleId, assemblyId, request, Locale.US);
verify(sampleService).removeGenomeAssemblyFromSample(sample, assemblyId);
}
Aggregations