You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/12/16 22:07:57 UTC
svn commit: r487884 -
/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/
Author: elecharny
Date: Sat Dec 16 13:07:56 2006
New Revision: 487884
URL: http://svn.apache.org/viewvc?view=rev&rev=487884
Log:
Applied Stefan Seelmann Patch 2/2 (TESTS)
Added:
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleDescriptionSyntaxCheckerTest.java
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleUseDescriptionSyntaxCheckerTest.java
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleDescriptionTest.java
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleUseDescriptionTest.java
directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserTestUtils.java
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleDescriptionSyntaxCheckerTest.java?view=auto&rev=487884
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleDescriptionSyntaxCheckerTest.java Sat Dec 16 13:07:56 2006
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test cases for MatchingRuleDescriptionSyntaxChecker.
+ *
+ * There are also many test cases in SchemaParserMatchingRuleDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MatchingRuleDescriptionSyntaxCheckerTest extends TestCase
+{
+ private MatchingRuleDescriptionSyntaxChecker checker = new MatchingRuleDescriptionSyntaxChecker();
+
+ public void testValid()
+ {
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.5 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.5 NAME 'caseExactMatch' DESC 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.5 NAME 'caseExactMatch' DESC 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ABC-DEF 'test' )" ) ) );
+
+ // spaces
+ assertTrue( checker.isValidSyntax( "(2.5.13.5 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15)" ) );
+ assertTrue( checker.isValidSyntax( "( 2.5.13.5 NAME 'caseExactMatch' DESC 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ABC-DEF 'test')" ) );
+ }
+
+
+ public void testInvalid()
+ {
+ // null
+ assertFalse( checker.isValidSyntax( null ) );
+
+ // empty
+ assertFalse( checker.isValidSyntax( "" ) );
+
+ // missing/invalid OID
+ assertFalse( checker.isValidSyntax( "()" ) );
+ assertFalse( checker.isValidSyntax( "( )" ) );
+ assertFalse( checker.isValidSyntax( "( . )" ) );
+ assertFalse( checker.isValidSyntax( "( 1 )" ) );
+ assertFalse( checker.isValidSyntax( "( 1. )" ) );
+ assertFalse( checker.isValidSyntax( "( 1.2. )" ) );
+ assertFalse( checker.isValidSyntax( "( 1.A )" ) );
+ assertFalse( checker.isValidSyntax( "( A.B )" ) );
+
+ // missing right parenthesis
+ assertFalse( checker.isValidSyntax( "( 2.5.13.5 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 " ) );
+
+ // missing quotes
+ assertFalse( checker.isValidSyntax( "( 2.5.13.5 DESC Description SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )" ) );
+
+ // lowercase DESC
+ assertFalse( checker.isValidSyntax( "( 2.5.13.5 desc 'Directory String' )" ) );
+
+ // invalid extension
+ assertFalse( checker.isValidSyntax( "( 2.5.13.5 DESC 'Description' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ABC-DEF )" ) );
+ assertFalse( checker.isValidSyntax( "( 2.5.13.5 DESC 'Description' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ABC-123 'test' )" ) );
+
+ // SYNTAX is required
+ assertFalse( checker.isValidSyntax( "( 2.5.13.5 NAME 'caseExactMatch' )" ) );
+
+ }
+
+}
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleUseDescriptionSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleUseDescriptionSyntaxCheckerTest.java?view=auto&rev=487884
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleUseDescriptionSyntaxCheckerTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MatchingRuleUseDescriptionSyntaxCheckerTest.java Sat Dec 16 13:07:56 2006
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test cases for MatchingRuleUseDescriptionSyntaxChecker.
+ *
+ * There are also many test cases in SchemaParserMatchingRuleUseDescriptionTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MatchingRuleUseDescriptionSyntaxCheckerTest extends TestCase
+{
+ private MatchingRuleUseDescriptionSyntaxChecker checker = new MatchingRuleUseDescriptionSyntaxChecker();
+
+
+ public void testValid()
+ {
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.17 APPLIES userPassword )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.17 APPLIES ( javaSerializedData $ userPassword ) )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.17 NAME 'octetStringMatch' APPLIES ( javaSerializedData $ userPassword ) )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.17 NAME 'octetStringMatch' DESC 'octetStringMatch' APPLIES ( javaSerializedData $ userPassword ) )" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.17 NAME 'octetStringMatch' DESC 'octetStringMatch' APPLIES ( javaSerializedData $ userPassword ) X-ABC-DEF 'test' )" ) ) );
+
+ // spaces
+ assertTrue( checker.isValidSyntax( ( "(2.5.13.17 APPLIES userPassword)" ) ) );
+ assertTrue( checker.isValidSyntax( ( "( 2.5.13.17 NAME 'octetStringMatch' DESC 'octetStringMatch' APPLIES (javaSerializedData $ userPassword) X-ABC-DEF 'test' )" ) ) );
+ }
+
+
+ public void testInvalid()
+ {
+ // null
+ assertFalse( checker.isValidSyntax( null ) );
+
+ // empty
+ assertFalse( checker.isValidSyntax( "" ) );
+
+ // missing/invalid OID
+ assertFalse( checker.isValidSyntax( "()" ) );
+ assertFalse( checker.isValidSyntax( "( )" ) );
+ assertFalse( checker.isValidSyntax( "( . )" ) );
+ assertFalse( checker.isValidSyntax( "( 1 )" ) );
+ assertFalse( checker.isValidSyntax( "( 1. )" ) );
+ assertFalse( checker.isValidSyntax( "( 1.2. )" ) );
+ assertFalse( checker.isValidSyntax( "( 1.A )" ) );
+ assertFalse( checker.isValidSyntax( "( A.B )" ) );
+
+ // missing right parenthesis
+ assertFalse( checker.isValidSyntax( "( 2.5.13.17 APPLIES userPassword " ) );
+
+ // missing quotes
+ assertFalse( checker.isValidSyntax( "( 2.5.13.17 DESC Directory String APPLIES userPassword )" ) );
+
+ // lowercase DESC
+ assertFalse( checker.isValidSyntax( "( 2.5.13.17 desc 'Directory String' APPLIES userPassword )" ) );
+
+ // invalid extension
+ assertFalse( checker.isValidSyntax( "( 2.5.13.17 APPLIES userPassword X-ABC-DEF )" ) );
+ assertFalse( checker.isValidSyntax( "( 2.5.13.17 APPLIES userPassword X-ABC-123 'test' )" ) );
+
+ // APPLIES is required
+ assertFalse( checker.isValidSyntax( ( "( 2.5.13.17 NAME 'octetStringMatch' )" ) ) );
+ }
+
+}
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleDescriptionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleDescriptionTest.java?view=auto&rev=487884
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleDescriptionTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleDescriptionTest.java Sat Dec 16 13:07:56 2006
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import java.text.ParseException;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleDescriptionSchemaParser;
+
+
+/**
+ * Tests the MatchingRuleDescriptionSchemaParser class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaParserMatchingRuleDescriptionTest extends TestCase
+{
+ /** the parser instance */
+ private MatchingRuleDescriptionSchemaParser parser;
+
+ protected void setUp() throws Exception
+ {
+ parser = new MatchingRuleDescriptionSchemaParser();
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ parser = null;
+ }
+
+
+ public void testNumericOid() throws Exception
+ {
+ SchemaParserTestUtils.testNumericOid( parser );
+ }
+
+
+ public void testNames() throws Exception
+ {
+ SchemaParserTestUtils.testNames( parser );
+ }
+
+
+ public void testDescription() throws ParseException
+ {
+ SchemaParserTestUtils.testDescription( parser );
+ }
+
+
+ public void testObsolete() throws ParseException
+ {
+ SchemaParserTestUtils.testObsolete( parser );
+ }
+
+
+ public void testSyntax() throws ParseException
+ {
+
+ String value = null;
+ MatchingRuleDescription mrd = null;
+
+ // simple
+ value = "( 1.1 SYNTAX 0.1.2.3.4.5.6.7.8.9 )";
+ mrd = parser.parseMatchingRuleDescription( value );
+ assertEquals( "0.1.2.3.4.5.6.7.8.9", mrd.getSyntax() );
+
+ // simple
+ value = "( 1.1 SYNTAX 123.456.789.0 )";
+ mrd = parser.parseMatchingRuleDescription( value );
+ assertEquals( "123.456.789.0", mrd.getSyntax() );
+
+ // simple with spaces
+ value = "( 1.1 SYNTAX 0.1.2.3.4.5.6.7.8.9 )";
+ mrd = parser.parseMatchingRuleDescription( value );
+ assertEquals( "0.1.2.3.4.5.6.7.8.9", mrd.getSyntax() );
+
+ // non-numeric not allowed
+ value = "( test )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid SYNTAX test" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ }
+
+
+ public void testExtensions() throws ParseException
+ {
+ SchemaParserTestUtils.testExtensions( parser );
+ }
+
+
+ public void testFull() throws ParseException
+ {
+ String value = null;
+ MatchingRuleDescription mrd = null;
+
+ value = "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüà é¨é·' OBSOLETE SYNTAX 0.1.2.3.4.5.6.7.8.9 X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
+ mrd = parser.parseMatchingRuleDescription( value );
+
+ assertEquals( "1.2.3.4.5.6.7.8.9.0", mrd.getNumericOid() );
+ assertEquals( 2, mrd.getNames().size() );
+ assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", mrd.getNames().get( 0 ) );
+ assertEquals( "test", mrd.getNames().get( 1 ) );
+ assertEquals( "Descripton äöüà é¨é·", mrd.getDescription() );
+ assertTrue( mrd.isObsolete() );
+ assertEquals( "0.1.2.3.4.5.6.7.8.9", mrd.getSyntax() );
+ assertEquals( 2, mrd.getExtensions().size() );
+ assertNotNull( mrd.getExtensions().get( "X-TEST-a" ) );
+ assertEquals( 2, mrd.getExtensions().get( "X-TEST-a" ).size() );
+ assertEquals( "test1-1", mrd.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+ assertEquals( "test1-2", mrd.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+ assertNotNull( mrd.getExtensions().get( "X-TEST-b" ) );
+ assertEquals( 2, mrd.getExtensions().get( "X-TEST-b" ).size() );
+ assertEquals( "test2-1", mrd.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+ assertEquals( "test2-2", mrd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+ }
+
+
+ ////////////////////////////////////////////////////////////////
+ // Some real-world matching rule descriptons //
+ ////////////////////////////////////////////////////////////////
+
+ public void testRfc1() throws ParseException
+ {
+ String value = "( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )";
+ MatchingRuleDescription mrd = parser.parseMatchingRuleDescription( value );
+
+ assertEquals( "2.5.13.5", mrd.getNumericOid() );
+ assertEquals( 1, mrd.getNames().size() );
+ assertEquals( "caseExactMatch", mrd.getNames().get( 0 ) );
+ assertEquals( "", mrd.getDescription() );
+ assertFalse( mrd.isObsolete() );
+ assertEquals( "1.3.6.1.4.1.1466.115.121.1.15", mrd.getSyntax() );
+ assertEquals( 0, mrd.getExtensions().size() );
+ }
+
+
+ public void testSun1() throws ParseException
+ {
+ String value = "( 2.5.13.5 NAME 'caseExactMatch' DESC 'Case Exact Matching on Directory String [defined in X.520]' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )";
+ MatchingRuleDescription mrd = parser.parseMatchingRuleDescription( value );
+
+ assertEquals( "2.5.13.5", mrd.getNumericOid() );
+ assertEquals( 1, mrd.getNames().size() );
+ assertEquals( "caseExactMatch", mrd.getNames().get( 0 ) );
+ assertEquals( "Case Exact Matching on Directory String [defined in X.520]", mrd.getDescription() );
+ assertFalse( mrd.isObsolete() );
+ assertEquals( "1.3.6.1.4.1.1466.115.121.1.15", mrd.getSyntax() );
+ assertEquals( 0, mrd.getExtensions().size() );
+ }
+
+
+ /**
+ * This is a real matching rule from Sun Directory 5.2. It has an invalid
+ * syntax, no DOTs allowed in NAME value.
+ */
+ public void testSun2() throws ParseException
+ {
+ String value = "( 1.3.6.1.4.1.42.2.27.9.4.34.3.6 NAME 'caseExactSubstringMatch-2.16.840.1.113730.3.3.2.11.3' DESC 'en' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )";
+ try
+ {
+ parser.parseMatchingRuleDescription( value );
+ TestCase
+ .fail( "Exception expected, invalid NAME value 'caseExactSubstringMatch-2.16.840.1.113730.3.3.2.11.3' (contains DOTs)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+ }
+
+
+ /**
+ * Tests the multithreaded use of a single parser.
+ */
+ public void testMultiThreaded() throws Exception
+ {
+ String[] testValues = new String[]
+ {
+ "( 1.1 )",
+ "( 2.5.13.5 NAME 'caseExactMatch' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
+ "( 2.5.13.5 NAME 'caseExactMatch' DESC 'Case Exact Matching on Directory String [defined in X.520]' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )",
+ "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüà é¨é·' OBSOLETE SYNTAX 0.1.2.3.4.5.6.7.8.9 X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )" };
+ SchemaParserTestUtils.testMultiThreaded( parser, testValues );
+ }
+
+}
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleUseDescriptionTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleUseDescriptionTest.java?view=auto&rev=487884
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleUseDescriptionTest.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserMatchingRuleUseDescriptionTest.java Sat Dec 16 13:07:56 2006
@@ -0,0 +1,297 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import java.text.ParseException;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.shared.ldap.schema.syntax.parser.MatchingRuleUseDescriptionSchemaParser;
+
+
+/**
+ * Tests the MatchingRuleUseDescriptionSchemaParser class.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SchemaParserMatchingRuleUseDescriptionTest extends TestCase
+{
+ /** the parser instance */
+ private MatchingRuleUseDescriptionSchemaParser parser;
+
+
+ protected void setUp() throws Exception
+ {
+ parser = new MatchingRuleUseDescriptionSchemaParser();
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ parser = null;
+ }
+
+
+ public void testNumericOid() throws Exception
+ {
+ SchemaParserTestUtils.testNumericOid( parser );
+ }
+
+
+ public void testNames() throws Exception
+ {
+ SchemaParserTestUtils.testNames( parser );
+ }
+
+
+ public void testDescription() throws ParseException
+ {
+ SchemaParserTestUtils.testDescription( parser );
+ }
+
+
+ public void testObsolete() throws ParseException
+ {
+ SchemaParserTestUtils.testObsolete( parser );
+ }
+
+
+ public void testApplies() throws ParseException
+ {
+
+ String value = null;
+ MatchingRuleUseDescription mrud = null;
+
+ // no APPLIES
+ value = "( 1.1 )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 0, mrud.getApplicableAttributes().size() );
+
+ // APPLIES simple numericoid
+ value = "( 1.1 APPLIES 1.2.3.4.5.6.7.8.9.0 )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 1, mrud.getApplicableAttributes().size() );
+ assertEquals( "1.2.3.4.5.6.7.8.9.0", mrud.getApplicableAttributes().get( 0 ) );
+
+ // SUP simple descr
+ value = "( 1.1 APPLIES abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 1, mrud.getApplicableAttributes().size() );
+ assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", mrud
+ .getApplicableAttributes().get( 0 ) );
+
+ // APPLIES single numericoid
+ value = "( 1.1 APPLIES ( 123.4567.890 ) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 1, mrud.getApplicableAttributes().size() );
+ assertEquals( "123.4567.890", mrud.getApplicableAttributes().get( 0 ) );
+
+ // APPLIES single descr
+ value = "( 1.1 APPLIES ( a-z-A-Z-0-9 ) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 1, mrud.getApplicableAttributes().size() );
+ assertEquals( "a-z-A-Z-0-9", mrud.getApplicableAttributes().get( 0 ) );
+
+ // APPLIES multi numericoid
+ value = "( 1.1 APPLIES ( 1.2.3 $ 4.5.6 $ 7.8.90 ) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 3, mrud.getApplicableAttributes().size() );
+ assertEquals( "1.2.3", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "4.5.6", mrud.getApplicableAttributes().get( 1 ) );
+ assertEquals( "7.8.90", mrud.getApplicableAttributes().get( 2 ) );
+
+ // APPLIES multi descr
+ value = "( 1.1 APPLIES ( test1 $ test2 ) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 2, mrud.getApplicableAttributes().size() );
+ assertEquals( "test1", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "test2", mrud.getApplicableAttributes().get( 1 ) );
+
+ // APPLIES multi mixed
+ value = "( 1.1 APPLIES ( test1 $ 1.2.3.4 $ test2 ) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 3, mrud.getApplicableAttributes().size() );
+ assertEquals( "test1", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "1.2.3.4", mrud.getApplicableAttributes().get( 1 ) );
+ assertEquals( "test2", mrud.getApplicableAttributes().get( 2 ) );
+
+ // APPLIES multi mixed no space
+ value = "( 1.1 APPLIES (TEST-1$1.2.3.4$TEST-2) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 3, mrud.getApplicableAttributes().size() );
+ assertEquals( "TEST-1", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "1.2.3.4", mrud.getApplicableAttributes().get( 1 ) );
+ assertEquals( "TEST-2", mrud.getApplicableAttributes().get( 2 ) );
+
+ // APPLIES multi mixed many spaces
+ value = "( 1.1 APPLIES ( test1 $ 1.2.3.4$test2 ) )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ assertEquals( 3, mrud.getApplicableAttributes().size() );
+ assertEquals( "test1", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "1.2.3.4", mrud.getApplicableAttributes().get( 1 ) );
+ assertEquals( "test2", mrud.getApplicableAttributes().get( 2 ) );
+
+ // no quote allowed
+ value = "( 1.1 APPLIES 'test' )";
+ try
+ {
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ fail( "Exception expected, invalid APPLIES 'test' (quoted)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // no quote allowed
+ value = "( 1.1 APPLIES '1.2.3.4' )";
+ try
+ {
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ fail( "Exception expected, invalid APPLIES '1.2.3.4' (quoted)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // invalid character
+ value = "( 1.1 APPLIES 1.2.3.4.A )";
+ try
+ {
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ fail( "Exception expected, invalid APPLIES '1.2.3.4.A' (invalid character)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // invalid start
+ value = "( 1.1 APPLIES ( test1 $ -test2 ) )";
+ try
+ {
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ fail( "Exception expected, invalid APPLIES '-test' (starts with hypen)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // invalid separator
+ value = "( 1.1 APPLIES ( test1 test2 ) )";
+ try
+ {
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ fail( "Exception expected, invalid separator (no DOLLAR)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // empty APPLIES
+ value = "( 1.1 APPLIES )";
+ try
+ {
+ mrud = parser.parseMatchingRuleUseDescription( value );
+ fail( "Exception expected, no APPLIES value" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+ }
+
+
+ public void testExtensions() throws ParseException
+ {
+ SchemaParserTestUtils.testExtensions( parser );
+ }
+
+
+ public void testFull() throws ParseException
+ {
+ String value = null;
+ MatchingRuleUseDescription mrud = null;
+
+ value = "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüà é¨é·' OBSOLETE APPLIES ( 0.1.2.3.4.5.6.7.8.9 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )";
+ mrud = parser.parseMatchingRuleUseDescription( value );
+
+ assertEquals( "1.2.3.4.5.6.7.8.9.0", mrud.getNumericOid() );
+ assertEquals( 2, mrud.getNames().size() );
+ assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", mrud.getNames().get( 0 ) );
+ assertEquals( "test", mrud.getNames().get( 1 ) );
+ assertEquals( "Descripton äöüà é¨é·", mrud.getDescription() );
+ assertTrue( mrud.isObsolete() );
+ assertEquals( 2, mrud.getApplicableAttributes().size() );
+ assertEquals( "0.1.2.3.4.5.6.7.8.9", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", mrud
+ .getApplicableAttributes().get( 1 ) );
+ assertEquals( 2, mrud.getExtensions().size() );
+ assertNotNull( mrud.getExtensions().get( "X-TEST-a" ) );
+ assertEquals( 2, mrud.getExtensions().get( "X-TEST-a" ).size() );
+ assertEquals( "test1-1", mrud.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+ assertEquals( "test1-2", mrud.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+ assertNotNull( mrud.getExtensions().get( "X-TEST-b" ) );
+ assertEquals( 2, mrud.getExtensions().get( "X-TEST-b" ).size() );
+ assertEquals( "test2-1", mrud.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+ assertEquals( "test2-2", mrud.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+ }
+
+
+ ////////////////////////////////////////////////////////////////
+ // Some real-world matching rule use descriptons //
+ ////////////////////////////////////////////////////////////////
+
+ public void testOpenldap1() throws ParseException
+ {
+ String value = "( 2.5.13.17 NAME 'octetStringMatch' APPLIES ( javaSerializedData $ userPassword ) )";
+ MatchingRuleUseDescription mrud = parser.parseMatchingRuleUseDescription( value );
+
+ assertEquals( "2.5.13.17", mrud.getNumericOid() );
+ assertEquals( 1, mrud.getNames().size() );
+ assertEquals( "octetStringMatch", mrud.getNames().get( 0 ) );
+ assertEquals( "", mrud.getDescription() );
+ assertFalse( mrud.isObsolete() );
+ assertEquals( 2, mrud.getApplicableAttributes().size() );
+ assertEquals( "javaSerializedData", mrud.getApplicableAttributes().get( 0 ) );
+ assertEquals( "userPassword", mrud.getApplicableAttributes().get( 1 ) );
+ assertEquals( 0, mrud.getExtensions().size() );
+ }
+
+
+ /**
+ * Tests the multithreaded use of a single parser.
+ */
+ public void testMultiThreaded() throws Exception
+ {
+ String[] testValues = new String[]
+ {
+ "( 1.1 )",
+ "( 2.5.13.17 NAME 'octetStringMatch' APPLIES ( javaSerializedData $ userPassword ) )",
+ "( 2.5.13.1 NAME 'distinguishedNameMatch' APPLIES ( memberOf $ dITRedirect $ associatedName $ secretary $ documentAuthor $ manager $ seeAlso $ roleOccupant $ owner $ member $ distinguishedName $ aliasedObjectName $ namingContexts $ subschemaSubentry $ modifiersName $ creatorsName ) )",
+ "( 1.2.3.4.5.6.7.8.9.0 NAME ( 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' 'test' ) DESC 'Descripton äöüà é¨é·' OBSOLETE APPLIES ( 0.1.2.3.4.5.6.7.8.9 $ abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 ) X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2') )" };
+ SchemaParserTestUtils.testMultiThreaded( parser, testValues );
+ }
+
+}
Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserTestUtils.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserTestUtils.java?view=auto&rev=487884
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserTestUtils.java (added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/SchemaParserTestUtils.java Sat Dec 16 13:07:56 2006
@@ -0,0 +1,531 @@
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.directory.shared.ldap.schema.syntax.parser.AbstractSchemaParser;
+
+
+public abstract class SchemaParserTestUtils
+{
+
+ /**
+ * Test numericoid
+ *
+ * @throws ParseException
+ */
+ public static void testNumericOid( AbstractSchemaParser parser ) throws ParseException
+ {
+ String value = null;
+ AbstractSchemaDescription asd = null;
+
+ // null test
+ value = null;
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, null" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // no oid
+ value = "( )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, no NUMERICOID" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // simple
+ value = "( 0.1.2.3.4.5.6.7.8.9 )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
+
+ // simple
+ value = "( 123.4567.890 )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( "123.4567.890", asd.getNumericOid() );
+
+ // simple with spaces
+ value = "( 0.1.2.3.4.5.6.7.8.9 )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( "0.1.2.3.4.5.6.7.8.9", asd.getNumericOid() );
+
+ // non-numeric not allowed
+ value = "( test )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID test" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // to short
+ value = "( 1 )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID 1" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // dot only
+ value = "( . )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID ." );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // ends with dot
+ value = "( 1.1. )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID 1.1." );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // quotes not allowed
+ value = "( '1.1' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID '1.1' (quoted)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // leading 0 not allowed
+ value = "( 01.1 )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID 01.1 (leading zero)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // alpha not allowed
+ value = "( 1.2.a.4 )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NUMERICOID 1.2.a.4 (alpha not allowed)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ }
+
+ /**
+ * Tests NAME and its values
+ *
+ * @throws ParseException
+ */
+ public static void testNames( AbstractSchemaParser parser ) throws ParseException
+ {
+ String value = null;
+ AbstractSchemaDescription asd = null;
+
+ // alpha
+ value = "( 1.1 NAME 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 1, asd.getNames().size() );
+ TestCase.assertEquals( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", asd.getNames().get( 0 ) );
+
+ // alpha-num-hypen
+ value = "( 1.1 NAME 'abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789' )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 1, asd.getNames().size() );
+ TestCase.assertEquals( "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", asd.getNames().get( 0 ) );
+
+ // with parentheses
+ value = "( 1.1 NAME ( 'a-z-0-9' ) )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 1, asd.getNames().size() );
+ TestCase.assertEquals( "a-z-0-9", asd.getNames().get( 0 ) );
+
+ // with parentheses, without space
+ value = "( 1.1 NAME ('a-z-0-9') )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 1, asd.getNames().size() );
+ TestCase.assertEquals( "a-z-0-9", asd.getNames().get( 0 ) );
+
+ // multi with space
+ value = "( 1.1 NAME ( 'test1' 'test2' ) )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 2, asd.getNames().size() );
+ TestCase.assertEquals( "test1", asd.getNames().get( 0 ) );
+ TestCase.assertEquals( "test2", asd.getNames().get( 1 ) );
+
+ // multi without space
+ value = "( 1.1 NAME ('test1' 'test2' 'test3') )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 3, asd.getNames().size() );
+ TestCase.assertEquals( "test1", asd.getNames().get( 0 ) );
+ TestCase.assertEquals( "test2", asd.getNames().get( 1 ) );
+ TestCase.assertEquals( "test3", asd.getNames().get( 2 ) );
+
+ // multi with many spaces
+ value = "( 1.1 NAME ( 'test1' 'test2' 'test3' ) )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 3, asd.getNames().size() );
+ TestCase.assertEquals( "test1", asd.getNames().get( 0 ) );
+ TestCase.assertEquals( "test2", asd.getNames().get( 1 ) );
+ TestCase.assertEquals( "test3", asd.getNames().get( 2 ) );
+
+ // lowercase
+ value = "( 1.1 name 'test' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, NAME is lowercase" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // unquoted
+ value = "( 1.1 NAME test )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NAME test (unquoted)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // start with number
+ value = "( 1.1 NAME '1test' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NAME 1test (starts with number)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // start with hypen
+ value = "( 1.1 NAME '-test' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NAME -test (starts with hypen)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // invalid character
+ value = "( 1.1 NAME 'te_st' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NAME te_st (contains invalid character)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // NAM unknown
+ value = "( 1.1 NAM 'test' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid token NAM" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // one valid, one invalid
+ value = "( 1.1 NAME ( 'test' 'te_st' ) )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NAME te_st (contains invalid character)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // no space between values
+ value = "( 1.1 NAME ( 'test1''test2' ) )";
+ try
+ {
+ asd = parser.parse( value );
+ TestCase.fail( "Exception expected, invalid NAME values (no space between values)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+ }
+
+
+ /**
+ * Tests DESC
+ *
+ * @throws ParseException
+ */
+ public static void testDescription( AbstractSchemaParser parser ) throws ParseException
+ {
+ String value = null;
+ AbstractSchemaDescription asd = null;
+
+ // simple
+ value = "(1.1 DESC 'Descripton')";
+ asd = parser.parse( value );
+ TestCase.assertEquals( "Descripton", asd.getDescription() );
+
+ // unicode
+ value = "( 1.1 DESC 'Descripton äöüà é¨é·' )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( "Descripton äöüà é¨é·", asd.getDescription() );
+
+ // lowercase
+ value = "( 1.1 desc 'Descripton' )";
+ try
+ {
+ parser.parse( value );
+ TestCase.fail( "Exception expected, DESC is lowercase" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ }
+
+
+ /**
+ * Test extensions.
+ *
+ * @throws ParseException
+ */
+ public static void testExtensions( AbstractSchemaParser parser ) throws ParseException
+ {
+ String value = null;
+ AbstractSchemaDescription asd = null;
+
+ // no extension
+ value = "( 1.1 )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 0, asd.getExtensions().size() );
+
+ // single extension with one value
+ value = "( 1.1 X-TEST 'test' )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 1, asd.getExtensions().size() );
+ TestCase.assertNotNull( asd.getExtensions().get( "X-TEST" ) );
+ TestCase.assertEquals( 1, asd.getExtensions().get( "X-TEST" ).size() );
+ TestCase.assertEquals( "test", asd.getExtensions().get( "X-TEST" ).get( 0 ) );
+
+ // single extension with multiple values
+ value = "( 1.1 X-TEST-ABC ('test1' 'test äöüÃ' 'test é¨é·' ) )";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 1, asd.getExtensions().size() );
+ TestCase.assertNotNull( asd.getExtensions().get( "X-TEST-ABC" ) );
+ TestCase.assertEquals( 3, asd.getExtensions().get( "X-TEST-ABC" ).size() );
+ TestCase.assertEquals( "test1", asd.getExtensions().get( "X-TEST-ABC" ).get( 0 ) );
+ TestCase.assertEquals( "test äöüÃ", asd.getExtensions().get( "X-TEST-ABC" ).get( 1 ) );
+ TestCase.assertEquals( "test é¨é·", asd.getExtensions().get( "X-TEST-ABC" ).get( 2 ) );
+
+ // multiple extensions
+ value = "(1.1 X-TEST-a ('test1-1' 'test1-2') X-TEST-b ('test2-1' 'test2-2'))";
+ asd = parser.parse( value );
+ TestCase.assertEquals( 2, asd.getExtensions().size() );
+ TestCase.assertNotNull( asd.getExtensions().get( "X-TEST-a" ) );
+ TestCase.assertEquals( 2, asd.getExtensions().get( "X-TEST-a" ).size() );
+ TestCase.assertEquals( "test1-1", asd.getExtensions().get( "X-TEST-a" ).get( 0 ) );
+ TestCase.assertEquals( "test1-2", asd.getExtensions().get( "X-TEST-a" ).get( 1 ) );
+ TestCase.assertNotNull( asd.getExtensions().get( "X-TEST-b" ) );
+ TestCase.assertEquals( 2, asd.getExtensions().get( "X-TEST-b" ).size() );
+ TestCase.assertEquals( "test2-1", asd.getExtensions().get( "X-TEST-b" ).get( 0 ) );
+ TestCase.assertEquals( "test2-2", asd.getExtensions().get( "X-TEST-b" ).get( 1 ) );
+
+ // invalid extension, no number allowed
+ value = "( 1.1 X-TEST1 'test' )";
+ try
+ {
+ asd = parser.parse( value );
+ TestCase.fail( "Exception expected, invalid extension X-TEST1 (no number allowed)" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ }
+
+
+ /**
+ * Tests OBSOLETE
+ *
+ * @throws ParseException
+ */
+ public static void testObsolete( AbstractSchemaParser parser ) throws ParseException
+ {
+ String value = null;
+ AbstractSchemaDescription asd = null;
+
+ // not obsolete
+ value = "( 1.1 )";
+ asd = parser.parse( value );
+ TestCase.assertFalse( asd.isObsolete() );
+
+ // not obsolete
+ value = "( 1.1 NAME 'test' DESC 'Descripton' )";
+ asd = parser.parse( value );
+ TestCase.assertFalse( asd.isObsolete() );
+
+ // obsolete
+ value = "(1.1 NAME 'test' DESC 'Descripton' OBSOLETE)";
+ asd = parser.parse( value );
+ TestCase.assertTrue( asd.isObsolete() );
+
+ // obsolete
+ value = "(1.1 OBSOLETE)";
+ asd = parser.parse( value );
+ TestCase.assertTrue( asd.isObsolete() );
+
+ // ivalid
+ value = "(1.1 NAME 'test' DESC 'Descripton' OBSOLET )";
+ try
+ {
+ asd = parser.parse( value );
+ TestCase.fail( "Exception expected, invalid OBSOLETE value" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ // trailing value not allowed
+ value = "(1.1 NAME 'test' DESC 'Descripton' OBSOLETE 'true' )";
+ try
+ {
+ asd = parser.parse( value );
+ TestCase.fail( "Exception expected, trailing value ('true') now allowed" );
+ }
+ catch ( ParseException pe )
+ {
+ // expected
+ }
+
+ }
+
+
+
+ /**
+ * Tests the multithreaded use of a single parser.
+ */
+ public static void testMultiThreaded( AbstractSchemaParser parser, String[] testValues ) throws ParseException
+ {
+ final boolean[] isSuccessMultithreaded = new boolean[1];
+ isSuccessMultithreaded[0] = true;
+
+ // start up and track all threads (40 threads)
+ List<Thread> threads = new ArrayList<Thread>();
+ for ( int ii = 0; ii < 10; ii++ )
+ {
+ for ( int i = 0; i < testValues.length; i++ )
+ {
+ Thread t = new Thread( new ParseSpecification( parser, testValues[i], isSuccessMultithreaded ) );
+ threads.add( t );
+ t.start();
+ }
+ }
+
+ // wait until all threads have died
+ boolean hasLiveThreads = false;
+ do
+ {
+ hasLiveThreads = false;
+
+ for ( int ii = 0; ii < threads.size(); ii++ )
+ {
+ Thread t = ( Thread ) threads.get( ii );
+ hasLiveThreads = hasLiveThreads || t.isAlive();
+ }
+ }
+ while ( hasLiveThreads );
+
+ // check that no one thread failed to parse and generate a SS object
+ TestCase.assertTrue( isSuccessMultithreaded[0] );
+
+ }
+
+ static class ParseSpecification implements Runnable
+ {
+ private final AbstractSchemaParser parser;
+ private final String value;
+ private final boolean[] isSuccessMultithreaded;
+
+ private AbstractSchemaDescription result;
+
+ public ParseSpecification( AbstractSchemaParser parser, String value, boolean[] isSuccessMultithreaded )
+ {
+ this.parser = parser;
+ this.value = value;
+ this.isSuccessMultithreaded = isSuccessMultithreaded;
+ }
+
+
+ public void run()
+ {
+ try
+ {
+ result = parser.parse( value );
+ }
+ catch ( ParseException e )
+ {
+ e.printStackTrace();
+ }
+
+ isSuccessMultithreaded[0] = isSuccessMultithreaded[0] && ( result != null );
+ }
+ }
+
+
+}