Package javax.validation

Examples of javax.validation.MessageInterpolator


    /**
     * {@inheritDoc}
     */
    public ValidatorContext messageInterpolator(MessageInterpolator messageInterpolator)
    {
        MessageInterpolator messageInterpolatorWrapper = new InvalidValueAwareMessageInterpolator(messageInterpolator);
        CodiUtils.injectFields(messageInterpolatorWrapper, false);
        return this.wrapped.messageInterpolator(messageInterpolatorWrapper);
    }
View Full Code Here


  }

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

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

  }

  @Test
  @SpecAssertion(section = "5.3.1.2", id = "a")
  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 = "5.3.1.2", id = "b")
  public void testIfNoLocaleIsSpecifiedTheDefaultLocaleIsAssumed() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    String messageTemplate = (String) descriptor.getAttributes().get( "message" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String messageInterpolatedWithNoLocale = interpolator.interpolate( messageTemplate, context );
    String messageInterpolatedWithDefaultLocale = interpolator.interpolate(
        messageTemplate, context, Locale.getDefault()
    );

    assertEquals( messageInterpolatedWithNoLocale, messageInterpolatedWithDefaultLocale, "Wrong substitution" );
  }
View Full Code Here

      @SpecAssertion(section = "10.3.2", id = "a"),
      @SpecAssertion(section = "10.3", id = "a")
  })
  public void testMessageInterpolatorIsSubjectToDependencyInjection() {
    assertNotNull( defaultValidatorFactory );
    MessageInterpolator messageInterpolator = defaultValidatorFactory.getMessageInterpolator();

    assertEquals( messageInterpolator.interpolate( null, null ), Greeter.MESSAGE );
  }
View Full Code Here

      @SpecAssertion(section = "5.3.1", id = "a"),
      @SpecAssertion(section = "5.3.2", id = "f"),
      @SpecAssertion(section = "5.5.3", 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 = "5.3.1.1", id = "a"),
      @SpecAssertion(section = "5.3.2", id = "f"),
      @SpecAssertion(section = "5.5.3", 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 = "5.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 = "5.3.1", id = "g"),
      @SpecAssertion(section = "5.3.1", id = "h"),
      @SpecAssertion(section = "5.3.1", id = "i")
  })
  public void testEscapedCharactersAreConsideredAsLiterals() {
    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" );

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

  }

  @Test
  @SpecAssertion(section = "5.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.