| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2014 Manuel Gaupp |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.protocols.asn1; |
| | | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import org.opends.server.protocols.asn1.GSERParser; |
| | | import org.opends.server.protocols.asn1.GSERException; |
| | | import org.opends.server.DirectoryServerTestCase; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * This class tests the GSERParser. |
| | | */ |
| | | /** This class tests the GSERParser. */ |
| | | public class GSERParserTestCase extends DirectoryServerTestCase |
| | | { |
| | | |
| | | /** |
| | | * Try to create a GSER Parser with <CODE>null</CODE> as parameter. |
| | | */ |
| | | @Test(expectedExceptions = { NullPointerException.class }) |
| | | /** Try to create a GSER Parser with <CODE>null</CODE> as parameter. */ |
| | | @Test(expectedExceptions = NullPointerException.class) |
| | | public void testGSERParserInitWithNull () throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(null); |
| | | new GSERParser(null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the <CODE>hasNext</CODE> method. |
| | | */ |
| | | /** Test the <CODE>hasNext</CODE> method. */ |
| | | @Test |
| | | public void testHasNext() throws Exception |
| | | { |
| | |
| | | assertFalse(parser.hasNext()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the <CODE>skipSP</CODE> method. |
| | | */ |
| | | /** Test the <CODE>skipSP</CODE> method. */ |
| | | @Test |
| | | public void testSkipSP() throws Exception |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the <CODE>skipMSP</CODE> method. |
| | | */ |
| | | /** Test the <CODE>skipMSP</CODE> method. */ |
| | | @Test |
| | | public void testSkipMSP() throws Exception |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Verify that <CODE>skipMSP</CODE> requires at least one space. |
| | | */ |
| | | @Test(expectedExceptions = { GSERException.class }) |
| | | /** Verify that <CODE>skipMSP</CODE> requires at least one space. */ |
| | | @Test(expectedExceptions = GSERException.class) |
| | | public void testSkipMSPwithZeroSpaces() throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser("42"); |
| | | parser.skipMSP(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the <CODE>testSequence</CODE> test case. |
| | | */ |
| | | /** Create data for the <CODE>testSequence</CODE> test case. */ |
| | | @DataProvider(name="sequenceValues") |
| | | public Object[][] createSequenceValues() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test sequence parsing. |
| | | */ |
| | | /** Test sequence parsing. */ |
| | | @Test(dataProvider="sequenceValues") |
| | | public void testSequence(String value, boolean expectedResult) throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(value); |
| | | boolean result = true; |
| | | try |
| | | try |
| | | { |
| | | parser.readStartSequence(); |
| | | parser.nextInteger(); |
| | |
| | | assertEquals(expectedResult,result); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the <CODE>testString</CODE> test case. |
| | | */ |
| | | /** Create data for the <CODE>testString</CODE> test case. */ |
| | | @DataProvider(name="stringValues") |
| | | public Object[][] createStringValues() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the parsing of String values. |
| | | */ |
| | | /** Test the parsing of String values. */ |
| | | @Test(dataProvider="stringValues") |
| | | public void testString(String value, boolean expectedResult) throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(value); |
| | | boolean result = true; |
| | | try |
| | | try |
| | | { |
| | | assertNotNull(parser.nextString()); |
| | | if (parser.hasNext()) |
| | |
| | | assertEquals(expectedResult,result); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the <CODE>testInteger</CODE> test case. |
| | | */ |
| | | /** Create data for the <CODE>testInteger</CODE> test case. */ |
| | | @DataProvider(name="integerValues") |
| | | public Object[][] createIntegerValues() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the <CODE>testBigInteger</CODE> test case. |
| | | */ |
| | | /** Create data for the <CODE>testBigInteger</CODE> test case. */ |
| | | @DataProvider(name="bigIntegerValues") |
| | | public Object[][] createBigIntegerValues() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the parsing of Integer values. |
| | | */ |
| | | /** Test the parsing of Integer values. */ |
| | | @Test(dataProvider="integerValues") |
| | | public void testInteger(String value, boolean expectedResult) throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(value); |
| | | boolean result = true; |
| | | try |
| | | try |
| | | { |
| | | parser.nextInteger(); |
| | | if (parser.hasNext()) |
| | |
| | | assertEquals(expectedResult,result); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the parsing of BigInteger values. |
| | | */ |
| | | /** Test the parsing of BigInteger values. */ |
| | | @Test(dataProvider="bigIntegerValues") |
| | | public void testBigInteger(String value, boolean expectedResult) throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(value); |
| | | boolean result = true; |
| | | try |
| | | try |
| | | { |
| | | parser.nextBigInteger(); |
| | | if (parser.hasNext()) |
| | |
| | | assertEquals(expectedResult,result); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the <CODE>testNamedValueIdentifier</CODE> test case. |
| | | */ |
| | | /** Create data for the <CODE>testNamedValueIdentifier</CODE> test case. */ |
| | | @DataProvider(name="namedValueIdentifierValues") |
| | | public Object[][] createNamedValueIdentifierValues() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the parsing of NamedValue identifiers. |
| | | */ |
| | | /** Test the parsing of NamedValue identifiers. */ |
| | | @Test(dataProvider="namedValueIdentifierValues") |
| | | public void testNamedValueIdentifier(String value, boolean expectedResult) throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(value); |
| | | boolean result = true; |
| | | try |
| | | try |
| | | { |
| | | assertNotNull(parser.nextNamedValueIdentifier()); |
| | | if (parser.hasNext()) |
| | |
| | | assertEquals(expectedResult,result); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the <CODE>testIdentifiedChoiceIdentifier</CODE> test case. |
| | | */ |
| | | /** Create data for the <CODE>testIdentifiedChoiceIdentifier</CODE> test case. */ |
| | | @DataProvider(name="identifiedChoicdeIdentifierValues") |
| | | public Object[][] createIdentifiedChoicdeIdentifierValues() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test the parsing of IdentifiedChoice identifiers. |
| | | */ |
| | | /** Test the parsing of IdentifiedChoice identifiers. */ |
| | | @Test(dataProvider="identifiedChoicdeIdentifierValues") |
| | | public void testIdentifiedChoicdeIdentifier(String value, boolean expectedResult) throws Exception |
| | | { |
| | | GSERParser parser = new GSERParser(value); |
| | | boolean result = true; |
| | | try |
| | | try |
| | | { |
| | | assertNotNull(parser.nextChoiceValueIdentifier()); |
| | | if (parser.hasNext()) |