Package javax.validation

Examples of javax.validation.MessageInterpolator


  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "a")
  public void testUnkownTokenInterpolation() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "{bar}"// unkown token {}
    String actual = interpolator.interpolate( "{bar}", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here


  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "c")
  public void testParametersAreExtractedFromBeanValidationProviderBundle() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( Person.class, "birthday" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String key = "{javax.validation.constraints.Past.message}"; // Past is a builtin constraint so the provider must provide a default message
    String actual = interpolator.interpolate( key, context );
    assertFalse(
        key.equals( actual ),
        "There should have been a message interpolation from the bean validator provider bundle."
    );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "g")
  public void testConstraintAttributeValuesAreInterpolated() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "bar" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "size must be between 5 and 10";
    String actual = interpolator.interpolate( ( String ) descriptor.getAttributes().get( "message" ), context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "h")
  public void testMessageInterpolationWithLocale() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "kann nicht null sein";
    String actual = interpolator.interpolate(
        ( String ) descriptor.getAttributes().get( "message" ), context, Locale.GERMAN
    );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "i")
  public void testFallbackToDefaultLocale() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "may not be null";
    String actual = interpolator.interpolate( ( String ) descriptor.getAttributes().get( "message" ), context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "may not be null";
    actual = interpolator.interpolate(
        ( String ) descriptor.getAttributes().get( "message" ), context, Locale.JAPAN
    );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

public class MessageInterpolationTest extends AbstractTest {

  @Test
  @SpecAssertion(section = "4.3.1", id = "a")
  public void testDefaultMessageInterpolatorIsNotNull() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    assertNotNull( interpolator, "Each bean validation provider must provide a default message interpolator." );
  }
View Full Code Here

      @SpecAssertion(section = "4.3.1", id = "e"),
      @SpecAssertion(section = "4.3.1.1", id = "a")
  })
  public void testSuccessfulInterpolationOfValidationMessagesValue() {

    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "replacement worked";
    String actual = interpolator.interpolate( "{foo}", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "replacement worked replacement worked";
    actual = interpolator.interpolate( "{foo} {foo}", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "This replacement worked just fine";
    actual = interpolator.interpolate( "This {foo} just fine", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "{} replacement worked {unknown}";
    actual = interpolator.interpolate( "{} {foo} {unknown}", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "b")
  public void testRecursiveMessageInterpolation() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "fubar" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "recursion worked";
    String actual = interpolator.interpolate( ( String ) descriptor.getAttributes().get( "message" ), context );
    assertEquals(
        expected, actual, "Expansion should be recursive"
    );
  }
View Full Code Here

      @SpecAssertion(section = "4.3.1", id = "g"),
      @SpecAssertion(section = "4.3.1", id = "h")
  })
  public void testLiteralCurlyBraces() {

    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "{";
    String actual = interpolator.interpolate( "\\{", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "}";
    actual = interpolator.interpolate( "\\}", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "\\";
    actual = interpolator.interpolate( "\\", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "a")
  public void testUnSuccessfulInterpolation() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "foo"// missing {}
    String actual = interpolator.interpolate( "foo", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "#{foo  {}";
    actual = interpolator.interpolate( "#{foo  {}", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

TOP

Related Classes of javax.validation.MessageInterpolator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.