@Test
public void testApplies() throws ParseException
{
String value = null;
MatchingRuleUse matchingRuleUse = null;
// APPLIES simple numericoid
value = "( 1.1 APPLIES 1.2.3.4.5.6.7.8.9.0 )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 1, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "1.2.3.4.5.6.7.8.9.0", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
// SUP simple descr
value = "( 1.1 APPLIES abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 1, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", matchingRuleUse
.getApplicableAttributeOids().get( 0 ) );
// APPLIES single numericoid
value = "( 1.1 APPLIES ( 123.4567.890 ) )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 1, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "123.4567.890", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
// APPLIES single descr
value = "(1.1 APPLIES(a-z-A-Z-0-9))";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 1, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "a-z-A-Z-0-9", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
// APPLIES multi numericoid
value = "( 1.1 APPLIES ( 1.2.3 $ 4.5.6 $ 7.8.90 ) )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 3, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "1.2.3", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
assertEquals( "4.5.6", matchingRuleUse.getApplicableAttributeOids().get( 1 ) );
assertEquals( "7.8.90", matchingRuleUse.getApplicableAttributeOids().get( 2 ) );
// APPLIES multi descr
value = "( 1.1 APPLIES ( test1 $ test2 ) )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 2, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "test1", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
assertEquals( "test2", matchingRuleUse.getApplicableAttributeOids().get( 1 ) );
// APPLIES multi mixed, tabs
value = "\t(\t1.1\tAPPLIES\t(\ttest1\t$\t1.2.3.4\t$\ttest2\t)\t)\t";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 3, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "test1", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
assertEquals( "1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get( 1 ) );
assertEquals( "test2", matchingRuleUse.getApplicableAttributeOids().get( 2 ) );
// APPLIES multi mixed no space
value = "(1.1 APPLIES(TEST-1$1.2.3.4$TEST-2))";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 3, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "TEST-1", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
assertEquals( "1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get( 1 ) );
assertEquals( "TEST-2", matchingRuleUse.getApplicableAttributeOids().get( 2 ) );
// APPLIES multi mixed many spaces
value = "( 1.1 APPLIES ( test1 $ 1.2.3.4$test2 ) )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 3, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "test1", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
assertEquals( "1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get( 1 ) );
assertEquals( "test2", matchingRuleUse.getApplicableAttributeOids().get( 2 ) );
// quoted value
value = "( 1.1 APPLIES 'test' )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 1, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "test", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
// quoted value
value = "( 1.1 APPLIES '1.2.3.4' )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 1, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "1.2.3.4", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
// no $ separator
value = "( 1.1 APPLIES ( test1 test2 ) )";
matchingRuleUse = parser.parseMatchingRuleUseDescription( value );
assertEquals( 2, matchingRuleUse.getApplicableAttributeOids().size() );
assertEquals( "test1", matchingRuleUse.getApplicableAttributeOids().get( 0 ) );
assertEquals( "test2", matchingRuleUse.getApplicableAttributeOids().get( 1 ) );
// invalid character
value = "( 1.1 APPLIES 1.2.3.4.A )";
try
{