コード例 #1
0
  /** Test the normalization and the middle substring match. */
  @Test(dataProvider = "substringMiddleMatchData")
  public void middleMatchingRules(
      final String value, final String[] middleSubs, final ConditionResult result)
      throws Exception {
    final MatchingRule rule = getRule();

    // normalize the 2 provided values and check that they are equals
    final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOf(value));

    final StringBuilder printableMiddleSubs = new StringBuilder();
    final List<ByteSequence> middleList = new ArrayList<>(middleSubs.length);
    printableMiddleSubs.append("*");
    for (final String middleSub : middleSubs) {
      printableMiddleSubs.append(middleSub);
      printableMiddleSubs.append("*");
      middleList.add(ByteString.valueOf(middleSub));
    }

    final ConditionResult substringAssertionMatches =
        rule.getSubstringAssertion(null, middleList, null).matches(normalizedValue);
    final ConditionResult assertionMatches =
        rule.getAssertion(ByteString.valueOf(printableMiddleSubs)).matches(normalizedValue);
    final String message = getMessage("middle", rule, value, printableMiddleSubs.toString());
    assertEquals(substringAssertionMatches, result, message);
    assertEquals(assertionMatches, result, message);
  }
コード例 #2
0
  /** Test that invalid values are rejected. */
  @Test(
      expectedExceptions = DecodeException.class,
      dataProvider = "substringInvalidAttributeValues")
  public void substringInvalidAttributeValues(final String value) throws Exception {
    // Get the instance of the rule to be tested.
    final MatchingRule rule = getRule();

    rule.normalizeAttributeValue(ByteString.valueOf(value));
  }
コード例 #3
0
  /** Test the normalization and the final substring match. */
  @Test(dataProvider = "substringFinalMatchData")
  public void finalMatchingRules(
      final String value, final String finalValue, final ConditionResult result) throws Exception {
    final MatchingRule rule = getRule();

    // normalize the 2 provided values and check that they are equals
    final ByteString normalizedValue = rule.normalizeAttributeValue(ByteString.valueOf(value));

    final ConditionResult substringAssertionMatches =
        rule.getSubstringAssertion(null, null, ByteString.valueOf(finalValue))
            .matches(normalizedValue);
    final ConditionResult assertionMatches =
        rule.getAssertion(ByteString.valueOf("*" + finalValue)).matches(normalizedValue);
    final String message = getMessage("final", rule, value, finalValue);
    assertEquals(substringAssertionMatches, result, message);
    assertEquals(assertionMatches, result, message);
  }