Java 类org.springframework.validation.support.BindingAwareModelMap 实例源码

项目:dawg    文件:ParkControllerTest.java   
@SuppressWarnings("unchecked")
@Test(dataProvider="testUserFrontWithInvalidTokenData")
public void testUserFrontWithInvalidToken(String token,String tags, String q, String[] sort, String[] otherTagsExp) {
    ParkController controller = new ParkController();
    Integer page = Integer.valueOf(1);
    Integer size = Integer.valueOf(1);
    Boolean asc = Boolean.TRUE;
    try {
        Model model = new BindingAwareModelMap();
        MockHttpSession session = new MockHttpSession();
        ReflectionTestUtils.setField(controller, "serverUtils", utils);
        Assert.assertEquals("login", controller.userFront(token, q,tags, page, size, asc, sort, model, session));
    }catch (CerealException e) {
        Assert.fail(e.getMessage());
    }
}
项目:alf.io    文件:ReservationFlowIntegrationTest.java   
private String reserveTicket(String eventName) {
    ReservationForm reservationForm = new ReservationForm();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("POST");
    ServletWebRequest servletWebRequest = new ServletWebRequest(request);
    BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation");
    Model model = new BindingAwareModelMap();
    RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
    TicketReservationModification ticketReservation = new TicketReservationModification();
    ticketReservation.setAmount(1);
    ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new));
    reservationForm.setReservation(Collections.singletonList(ticketReservation));


    return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH);
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@EventListener
public void simulateUsersClicking(ApplicationReadyEvent event) {
    Flux
        .interval(Duration.ofMillis(500))
        .flatMap(tick ->
            Mono.defer(() ->
                homeController.index(new BindingAwareModelMap())))
        .subscribe();
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@EventListener
public void simulateUsersClicking(ApplicationReadyEvent event) {
    Flux
        .interval(Duration.ofMillis(500))
        .flatMap(tick ->
            Mono.defer(() ->
                homeController.index(new BindingAwareModelMap())))
        .subscribe();
}
项目:spring4-understanding    文件:AnnotationMethodHandlerAdapter.java   
protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    ServletHandlerMethodResolver methodResolver = getMethodResolver(handler);
    Method handlerMethod = methodResolver.resolveHandlerMethod(request);
    ServletHandlerMethodInvoker methodInvoker = new ServletHandlerMethodInvoker(methodResolver);
    ServletWebRequest webRequest = new ServletWebRequest(request, response);
    ExtendedModelMap implicitModel = new BindingAwareModelMap();

    Object result = methodInvoker.invokeHandlerMethod(handlerMethod, handler, webRequest, implicitModel);
    ModelAndView mav =
            methodInvoker.getModelAndView(handlerMethod, handler.getClass(), result, implicitModel, webRequest);
    methodInvoker.updateModelAttributes(handler, (mav != null ? mav.getModel() : null), implicitModel, webRequest);
    return mav;
}
项目:eMonocot    文件:SearchControllerTest.java   
@Before
public void setUp() throws Exception {
    searchController = new SearchController();
    facets = new ArrayList<FacetRequest>();
    model = new BindingAwareModelMap();
    searchableObjectService = EasyMock.createMock(SearchableObjectService.class);
    searchController.setSearchableObjectService(searchableObjectService);
    page = new DefaultPageImpl<SearchableObject>(0, 0, 20, new ArrayList<SearchableObject>(),null);
    facetNames = new String[] {"base.class_s", "taxon.family_ss", "taxon.distribution_TDWG_0_ss", "taxon.measurement_or_fact_threatStatus_txt", "taxon.measurement_or_fact_Lifeform_txt", "taxon.measurement_or_fact_Habitat_txt", "taxon.taxon_rank_s", "taxon.taxonomic_status_s", "searchable.sources_ss" };
}
项目:dawg    文件:PopulateControllerTest.java   
@SuppressWarnings("unchecked")
@Test
public void testPopulateWithModel() {
    PopulateController controller = new PopulateController();
    ParkService mockParkService = new MockParkService();
    ChimpsToken myToken = new ChimpsToken("mytoken");
    mockParkService.saveToken(myToken);
    ReflectionTestUtils.setField(controller, "parkService", mockParkService);
    Model model = new BindingAwareModelMap();
    Assert.assertEquals(controller.populate(model), "populate");
    List<ChimpsToken> tokens = (List<ChimpsToken>) model.asMap().get("population");
    Assert.assertNotNull(tokens);
    Assert.assertTrue(tokens.contains(myToken));
}
项目:dawg    文件:PopulateControllerTest.java   
@Test
public void testPopulateTable() {
    PopulateController controller = new PopulateController();
    ParkService mockParkService = new MockParkService();
    ReflectionTestUtils.setField(controller, "parkService", mockParkService);

    Model model = new BindingAwareModelMap();
    Assert.assertEquals(controller.populateTable(model), "populateTable");
    Assert.assertNotNull(model.asMap().get("population"));
}
项目:class-guard    文件:AnnotationMethodHandlerAdapter.java   
protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {

    ServletHandlerMethodResolver methodResolver = getMethodResolver(handler);
    Method handlerMethod = methodResolver.resolveHandlerMethod(request);
    ServletHandlerMethodInvoker methodInvoker = new ServletHandlerMethodInvoker(methodResolver);
    ServletWebRequest webRequest = new ServletWebRequest(request, response);
    ExtendedModelMap implicitModel = new BindingAwareModelMap();

    Object result = methodInvoker.invokeHandlerMethod(handlerMethod, handler, webRequest, implicitModel);
    ModelAndView mav =
            methodInvoker.getModelAndView(handlerMethod, handler.getClass(), result, implicitModel, webRequest);
    methodInvoker.updateModelAttributes(handler, (mav != null ? mav.getModel() : null), implicitModel, webRequest);
    return mav;
}
项目:jresplus    文件:ExtendableAnnotationMethodHandlerAdapter.java   
protected ModelAndView invokeHandlerMethod(HttpServletRequest request,
        HttpServletResponse response, Object handler) throws Exception {

    ServletHandlerMethodResolver methodResolver = getMethodResolver(handler);
    Method handlerMethod = methodResolver.resolveHandlerMethod(request);
    ServletHandlerMethodInvoker methodInvoker = new ServletHandlerMethodInvoker(
            methodResolver);
    ServletWebRequest webRequest = new ServletWebRequest(request, response);
    ExtendedModelMap implicitModel = new BindingAwareModelMap();

    if (this.methodInvokeInterceptors != null
            && !this.methodInvokeInterceptors.isEmpty()) {
        for (AnnotationMethodHandlerInterceptor interceptor : this.methodInvokeInterceptors) {
            interceptor.preInvoke(handlerMethod, handler, webRequest);
        }
    }

    Object result = methodInvoker.invokeHandlerMethod(handlerMethod,
            handler, webRequest, implicitModel);

    ModelAndView mav = methodInvoker.getModelAndView(handlerMethod,
            handler.getClass(), result, implicitModel, webRequest);
    if (this.methodInvokeInterceptors != null
            && !this.methodInvokeInterceptors.isEmpty()) {
        for (int i = this.methodInvokeInterceptors.size() - 1; i >= 0; i--) {
            this.methodInvokeInterceptors.get(i).postInvoke(handlerMethod,
                    handler, webRequest, mav);
        }
    }

    methodInvoker.updateModelAttributes(handler,
            (mav != null ? mav.getModel() : null), implicitModel,
            webRequest);
    return mav;
}
项目:alf.io    文件:ReservationFlowIntegrationTest.java   
private TicketDecorator checkReservationComplete(String eventName, String reservationIdentifier) {
    Model confirmationPageModel = new BindingAwareModelMap();
    String confirmationPageSuccess = reservationController.showConfirmationPage(eventName, reservationIdentifier, false, false, confirmationPageModel, Locale.ENGLISH, new MockHttpServletRequest());
    assertEquals("/event/reservation-page-complete", confirmationPageSuccess);
    @SuppressWarnings("unchecked")
    List<Pair<?, List<TicketDecorator>>> tickets = (List<Pair<?, List<TicketDecorator>>>) confirmationPageModel.asMap().get("ticketsByCategory");
    assertEquals(1, tickets.size());
    assertEquals(1, tickets.get(0).getRight().size());
    return tickets.get(0).getRight().get(0);
}
项目:alf.io    文件:ReservationFlowIntegrationTest.java   
private void validatePayment(String eventName, String reservationIdentifier) {
    Principal principal = Mockito.mock(Principal.class);
    Mockito.when(principal.getName()).thenReturn(user);
    assertEquals(1, eventApiController.getPendingPayments(eventName, principal).size());
    assertEquals("OK", eventApiController.confirmPayment(eventName, reservationIdentifier, principal, new BindingAwareModelMap(), new MockHttpServletRequest()));
    assertEquals(0, eventApiController.getPendingPayments(eventName, principal).size());
}
项目:spring-mvc-params    文件:ResourceParamControllerTest.java   
/**
 * RequestMappingHandlerAdapter's default ordering puts MapMethodProcessor ahead of custom Argument Resolvers.
 * So we can't actually inject Maps from the context. :(
 */
@Test
public void testRequestMap() throws Exception {
    MvcResult result1 = this.mockMvc.perform(get("/requestMap").param("param", "test"))
            //.andDo(print())
            .andExpect(status().isOk())
            .andExpect(model().attribute("param", "test"))
            .andExpect(model().attributeExists("map"))
            .andReturn();

    BindingAwareModelMap map1 = (BindingAwareModelMap) result1.getModelAndView().getModel().get("map");
    assertThat((String)map1.get("param"), equalTo("test"));
}
项目:spring-mvc-params    文件:AutowiredParamControllerTest.java   
/**
 * RequestMappingHandlerAdapter's default ordering puts MapMethodProcessor ahead of custom Argument Resolvers.
 * So we can't actually inject Maps from the context. :(
 */
@Test
public void testRequestMap() throws Exception {
    MvcResult result1 = this.mockMvc.perform(get("/requestMap").param("param", "test"))
            //.andDo(print())
            .andExpect(status().isOk())
            .andExpect(model().attribute("param", "test"))
            .andExpect(model().attributeExists("map"))
            .andReturn();

    BindingAwareModelMap map1 = (BindingAwareModelMap) result1.getModelAndView().getModel().get("map");
    assertThat((String)map1.get("param"), equalTo("test"));
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
    homeController.index(
        new BindingAwareModelMap(),
        null);
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
    homeController.index(
        new BindingAwareModelMap());
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
    homeController.index(
        new BindingAwareModelMap());
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
    homeController.index(
        new BindingAwareModelMap());
}
项目:Learning-Spring-Boot-2.0-Second-Edition    文件:CommentSimulator.java   
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
    homeController.index(
        new BindingAwareModelMap(),
        null);
}
项目:springboot-scala-withswagger    文件:ThymeleafTextTemplatesController.java   
@PostMapping("/form")
public String postForm(@ModelAttribute Form form) {

    Model model = new BindingAwareModelMap();

    Context context = new Context();
    context.setVariable("name", form.getName());
    context.setVariable("url", form.getUrl());
    context.setVariable("tags", form.getTags().split(" "));

    String text = templateEngine.process("text-template", context);

    model.addAttribute("text", text);

    return "th-form";
}
项目:dawg    文件:ParkControllerTest.java   
@SuppressWarnings("unchecked")
@Test(dataProvider="testUserFrontWithValidTokenData")
public void testUserFrontWithValidToken(String token, String tag,String q, String[] sort, String[] otherTagsExp) {
    ParkController controller = new ParkController();
    Map<String, Object>[] filteredStbs = new HashMap[1];
    Map<String, Object>[] allStbs = new HashMap[2];
    Map<String, Object> stb1 = new HashMap<String, Object>();
    stb1.put(MetaStb.ID, "sample");
    stb1.put(MetaStb.TAGS, Arrays.asList("tag1"));
    stb1.put(MetaStb.MACADDRESS, "00:00:00:00:00");

    Map<String, Object> stb2 = new HashMap<String, Object>();
    stb2.put(MetaStb.ID, "otherDevice");
    stb2.put(MetaStb.TAGS, Arrays.asList("tag2", "tag3"));
    stb2.put(MetaStb.MACADDRESS, "00:00:00:00:01");

    filteredStbs[0] = stb1;
    allStbs[0] = stb1;
    allStbs[1] = stb2;

    ReflectionTestUtils.setField(controller, "serverUtils", utils);

    ParkService mockService = EasyMock.createMock(ParkService.class);
    if (q == null) {
        EasyMock.expect(mockService.findAll((Pageable) EasyMock.anyObject())).andReturn(allStbs);
    } else {
        EasyMock.expect(mockService.findByKeys((String[]) EasyMock.anyObject(), (Pageable) EasyMock.anyObject())).andReturn(
                filteredStbs);
        EasyMock.expect(mockService.findAll()).andReturn(allStbs);
    }
    if (tag != null) {
        EasyMock.expect(
                mockService.findByCriteria(
                    (Criteria) EasyMock.anyObject(),
                    (Pageable) EasyMock.anyObject())).andReturn(
                filteredStbs);
    }
    EasyMock.replay(mockService);
    ReflectionTestUtils.setField(controller, "service", mockService);
    ReflectionTestUtils.setField(controller, "config", createConfig());

    Integer page = Integer.valueOf(1);
    Integer size = Integer.valueOf(1);
    Boolean asc = Boolean.TRUE;

    try {
        Model model = new BindingAwareModelMap();
        MockHttpSession session = new MockHttpSession();
        Assert.assertEquals("index",
                controller.userFront(token, tag,q, page, size, asc, sort, model, session));
        Assert.assertEquals(model.asMap().get("search"), q == null ? "" : q);
        String otherTagsJson = (String) model.asMap().get("otherTags");
        String deviceTagsJson = (String) model.asMap().get("deviceTags");
        JsonCerealEngine engine = new JsonCerealEngine();
        List<String> otherTags = engine.readFromString(otherTagsJson, List.class);
        Map<String, List<String>> deviceTags = engine.readFromString(deviceTagsJson, Map.class);

        Assert.assertEquals(otherTags.size(), otherTagsExp.length);
        for (String tags : otherTagsExp) {
            Assert.assertTrue(otherTags.contains(tags));
        }
        Assert.assertEquals(deviceTags.size(), q != null ? 1 : 2);
        Assert.assertTrue(deviceTags.containsKey("sample"));
        Assert.assertTrue(deviceTags.get("sample").contains("tag1"));
    } catch (CerealException e) {

        Assert.fail(e.getMessage());
    }
}