@Test
  public void supportedParameters() throws Exception {
    // Only @ModelAttribute arguments
    assertTrue(processor.supportsParameter(paramNamedValidModelAttr));
    assertTrue(processor.supportsParameter(paramModelAttr));

    assertFalse(processor.supportsParameter(paramErrors));
    assertFalse(processor.supportsParameter(paramInt));
    assertFalse(processor.supportsParameter(paramNonSimpleType));
  }
  @Test
  public void supportedParametersInDefaultResolutionMode() throws Exception {
    processor = new ModelAttributeMethodProcessor(true);

    // Only non-simple types, even if not annotated
    assertTrue(processor.supportsParameter(paramNamedValidModelAttr));
    assertTrue(processor.supportsParameter(paramErrors));
    assertTrue(processor.supportsParameter(paramModelAttr));
    assertTrue(processor.supportsParameter(paramNonSimpleType));

    assertFalse(processor.supportsParameter(paramInt));
  }
  @Test
  public void resovleArgumentValidation() throws Exception {
    String name = "attrName";
    Object target = new TestBean();
    mavContainer.addAttribute(name, target);

    StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
    WebDataBinderFactory binderFactory = createMock(WebDataBinderFactory.class);
    expect(binderFactory.createBinder(webRequest, target, name)).andReturn(dataBinder);
    replay(binderFactory);

    processor.resolveArgument(paramNamedValidModelAttr, mavContainer, webRequest, binderFactory);

    assertTrue(dataBinder.isBindInvoked());
    assertTrue(dataBinder.isValidateInvoked());
  }
Пример #4
0
  @Test(timeout = 5000)
  public void testQuery1() {
    ClientMessage cmAdd1 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Hello World")
            .setBody("My first posting!");

    ClientMessage cmAdd2 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("Don Bradman")
            .setSubject("29")
            .setBody("Still the greatest!");

    ClientMessage cmAdd3 =
        new ClientMessage()
            .setType(ClientMessage.Type.CREATE)
            .setAuthor("AdnanAziz1968")
            .setSubject("Random musings")
            .setBody("My second posting!");

    ClientMessage cmQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setAuthor("AdnanAziz1968");

    ServerMessage result = doTxRx(cmAdd1, cmAdd2, cmAdd3, cmQuery);

    assertEquals(result.getPostings().size(), 2);
    for (Posting p : result.getPostings()) {
      assert (p.getAuthor().equals(cmQuery.getAuthor()));
    }

    ClientMessage cmBodyQuery =
        new ClientMessage().setType(ClientMessage.Type.QUERY).setBody("posting My");
    assertEquals(2, result.getPostings().size());
    for (Posting p : result.getPostings()) {
      assertTrue(p.getBody().contains("My"));
      assertTrue(p.getBody().contains("posting"));
    }
    score += 15;
  }
 @Theory
 public void shouldHold(@ForAll @From(Ctor.class) P p) {
   assertTrue(p.box().marked());
   assertTrue(p.box().contents().marked());
   assertEquals(2, p.box().contents().i());
 }
 @Test
 public void bindExceptionRequired() throws Exception {
   assertTrue(processor.isBindExceptionRequired(null, paramNonSimpleType));
 }
 @Test
 public void supportedReturnTypesInDefaultResolutionMode() throws Exception {
   processor = new ModelAttributeMethodProcessor(true);
   assertTrue(processor.supportsReturnType(returnParamNamedModelAttr));
   assertTrue(processor.supportsReturnType(returnParamNonSimpleType));
 }
 @Test
 public void supportedReturnTypes() throws Exception {
   processor = new ModelAttributeMethodProcessor(false);
   assertTrue(processor.supportsReturnType(returnParamNamedModelAttr));
   assertFalse(processor.supportsReturnType(returnParamNonSimpleType));
 }