| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2014 ForgeRock AS. |
| | | * Portions copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.schema; |
| | | |
| | | import static org.testng.Assert.fail; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Syntax tests. |
| | | */ |
| | | /** Syntax tests. */ |
| | | @SuppressWarnings("javadoc") |
| | | public abstract class AbstractSyntaxTestCase extends AbstractSchemaTestCase { |
| | | /** |
| | |
| | | @DataProvider(name = "acceptableValues") |
| | | public abstract Object[][] createAcceptableValues(); |
| | | |
| | | /** |
| | | * Test the normalization and the approximate comparison. |
| | | */ |
| | | /** Test the normalization and the approximate comparison. */ |
| | | @Test(dataProvider = "acceptableValues") |
| | | public void testAcceptableValues(final String value, final Boolean result) throws Exception { |
| | | // Make sure that the specified class can be instantiated as a task. |
| | | final Syntax syntax = getRule(); |
| | | |
| | | final LocalizableMessageBuilder reason = new LocalizableMessageBuilder(); |
| | | // test the valueIsAcceptable method |
| | | final Boolean liveResult = syntax.valueIsAcceptable(ByteString.valueOf(value), reason); |
| | | |
| | | if (!liveResult.equals(result)) { |
| | | fail(syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason); |
| | | } |
| | | assertEquals(liveResult, result, |
| | | syntax + ".valueIsAcceptable gave bad result for " + value + "reason : " + reason); |
| | | } |
| | | |
| | | /** |
| | | * Get an instance of the attribute syntax that muste be tested. |
| | | * Get an instance of the attribute syntax that must be tested. |
| | | * |
| | | * @return An instance of the attribute syntax that muste be tested. |
| | | * @return An instance of the attribute syntax that must be tested. |
| | | */ |
| | | protected abstract Syntax getRule() throws SchemaException, DecodeException; |
| | | } |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Bit string syntax tests. |
| | | */ |
| | | /** Bit string syntax tests. */ |
| | | @Test |
| | | public class BitStringSyntaxTest extends AbstractSyntaxTestCase { |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | @DataProvider(name = "acceptableValues") |
| | | public Object[][] createAcceptableValues() { |
| | | return new Object[][] { { "'0101'B", true }, { "'1'B", true }, { "'0'B", true }, { "invalid", false }, |
| | | { "1", false }, { "'010100000111111010101000'B", true }, }; |
| | | return new Object[][] { |
| | | { "'0101'B", true }, |
| | | { "'1'B", true }, |
| | | { "'0'B", true }, |
| | | { "invalid", false }, |
| | | { "1", false }, |
| | | { "'010100000111111010101000'B", true }, |
| | | }; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAABlBMVEX/JgAAAAAP" |
| | | + "IsinAAAACklEQVQImWNgAAAAAgAB9HFkpgAAAABJRU5ErkJggg=="; |
| | | |
| | | try { |
| | | return new Object[][] { |
| | | { ByteString.valueOfBase64(nonImage), false }, |
| | | { ByteString.valueOfBase64(jfifImage), true }, |
| | | { ByteString.valueOfBase64(exifImage), true }, |
| | | { ByteString.valueOfBase64(pngImage), false } }; |
| | | } catch (Exception e) { |
| | | return new Object[][] {}; |
| | | } |
| | | return new Object[][] { |
| | | { ByteString.valueOfBase64(nonImage), false }, |
| | | { ByteString.valueOfBase64(jfifImage), true }, |
| | | { ByteString.valueOfBase64(exifImage), true }, |
| | | { ByteString.valueOfBase64(pngImage), false } |
| | | }; |
| | | } |
| | | |
| | | /** Test acceptable values for this syntax when not allowing malformed JPEG photos. */ |
| | |
| | | |
| | | // directoryOperation can't inherit from userApplications |
| | | scBuild.addAttributeType("(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE SUP cn " |
| | | + " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch" + " SUBSTR caseIgnoreSubstringsMatch" |
| | | + " EQUALITY caseIgnoreMatch ORDERING caseIgnoreOrderingMatch" |
| | | + " SUBSTR caseIgnoreSubstringsMatch" |
| | | + " SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE" |
| | | + " NO-USER-MODIFICATION USAGE directoryOperation )", true); |
| | | scBuild.addSchema(Schema.getCoreSchema(), false); |