Minor code cleanup:
* suppress missing Javadoc warnings in unit tests
* fix minor bugs in OperatingSystem
* renamed methods called "_" to "b" to avoid JDK8 compiler warnings.
| | |
| | | /** |
| | | * Unit tests for the console application class. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public class ConsoleApplicationTestCase extends CliTestCase { |
| | | |
| | | final LocalizableMessage msg = LocalizableMessage.raw("Language is the source of misunderstandings."); |
| | |
| | | /** |
| | | * Unit tests for the SubCommand class. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public final class TestSubCommandArgumentParserTestCase extends CliTestCase { |
| | | |
| | | private SubCommandArgumentParser parser; |
| | |
| | | import static org.testng.Assert.assertFalse; |
| | | import static org.testng.Assert.assertTrue; |
| | | |
| | | @SuppressWarnings("javadoc") |
| | | public class UtilsTestCase extends CliTestCase { |
| | | |
| | | @Test(expectedExceptions = ClientException.class) |
| | |
| | | private boolean isMacOS; |
| | | private boolean isUnixBased; |
| | | |
| | | private static OperatingSystem os; |
| | | static { |
| | | OperatingSystem.getOperatingSystem(); |
| | | } |
| | | private static final OperatingSystem INSTANCE = forName(System.getProperty("INSTANCE.name")); |
| | | |
| | | /** |
| | | * Creates a new operating system value with the provided name. |
| | |
| | | * @return The operating system for the provided name. |
| | | */ |
| | | public static OperatingSystem forName(final String osName) { |
| | | return os = forName2(osName); |
| | | } |
| | | |
| | | private static OperatingSystem forName2(final String osName) { |
| | | if (osName == null) { |
| | | return UNKNOWN; |
| | | } |
| | | |
| | | final String lowerName = osName.toLowerCase(); |
| | | |
| | | if ((lowerName.indexOf("solaris") >= 0) || (lowerName.indexOf("sunos") >= 0)) { |
| | | return SOLARIS; |
| | | } else if (lowerName.indexOf("linux") >= 0) { |
| | |
| | | return WINDOWS; |
| | | } else if ((lowerName.indexOf("freebsd") >= 0) || (lowerName.indexOf("free bsd") >= 0)) { |
| | | return FREEBSD; |
| | | } else if ((lowerName.indexOf("macos x") >= 0) || (lowerName.indexOf("mac os x") >= 0)) { |
| | | } else if ((lowerName.indexOf("macos x") >= 0) || (lowerName.indexOf("mac INSTANCE x") >= 0)) { |
| | | return MACOSX; |
| | | } else if (lowerName.indexOf("z/os") >= 0) { |
| | | } else if (lowerName.indexOf("z/INSTANCE") >= 0) { |
| | | return ZOS; |
| | | } |
| | | return UNKNOWN; |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether the provided operating system is UNIX-based. UNIX-based operating systems include Solaris, |
| | | * Linux, HP-UX, AIX, FreeBSD, and Mac OS X. |
| | | * |
| | | * @param os |
| | | * The operating system for which to make the determination. |
| | | * @return <CODE>true</CODE> if the provided operating system is UNIX-based, or <CODE>false</CODE> if not. |
| | | */ |
| | | public static boolean isUNIXBased(OperatingSystem os) { |
| | | return os.isUnixBased; |
| | | } |
| | | |
| | | /** |
| | | * Returns the operating system on which the JVM is running. |
| | | * |
| | | * @return The operating system on which the JVM is running |
| | | */ |
| | | public static OperatingSystem getOperatingSystem() { |
| | | return OperatingSystem.forName(System.getProperty("os.name")); |
| | | return INSTANCE; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if the underlying operating system is a Windows variant, or {@code false} if not. |
| | | */ |
| | | public static boolean isWindows() { |
| | | return os.isWindows; |
| | | return INSTANCE.isWindows; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if the underlying operating system is Windows Vista, or {@code false} if not. |
| | | */ |
| | | public static boolean isVista() { |
| | | return os == WINDOWS_VISTA; |
| | | return INSTANCE == WINDOWS_VISTA; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if the underlying operating system is Windows 2008, or {@code false} if not. |
| | | */ |
| | | public static boolean isWindows2008() { |
| | | return os == WINDOWS_SERVER_2008; |
| | | return INSTANCE == WINDOWS_SERVER_2008; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if the underlying operating system is Windows 7, or {@code false} if not. |
| | | */ |
| | | public static boolean isWindows7() { |
| | | return os == WINDOWS7; |
| | | return INSTANCE == WINDOWS7; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if we are running under Mac OS and {@code false} otherwise. |
| | | */ |
| | | public static boolean isMacOS() { |
| | | return os == MACOSX; |
| | | return INSTANCE.isMacOS; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if we are running under Unix and {@code false} otherwise. |
| | | */ |
| | | public static boolean isUnix() { |
| | | return os.isUnixBased; |
| | | return INSTANCE.isUnixBased; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if the OS is Unix based. |
| | | */ |
| | | public static boolean isUnixBased() { |
| | | return os.isUnixBased; |
| | | return INSTANCE.isUnixBased; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return {@code true} if the OS is Unknown. |
| | | */ |
| | | public static boolean isUnknown() { |
| | | return os == UNKNOWN; |
| | | return INSTANCE == UNKNOWN; |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * This class tests the model functionality. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public class OperatingSystemTestCase extends UtilTestCase { |
| | | |
| | | // @formatter:off |
| | |
| | | * An abstract base class for all ASN1Reader test cases. |
| | | */ |
| | | @Test(groups = { "precommit", "asn1", "sdk" }) |
| | | @SuppressWarnings("javadoc") |
| | | public abstract class ASN1ReaderTestCase extends ForgeRockTestCase { |
| | | |
| | | /** |
| | |
| | | public class ByteStringBuilderTestCase extends ByteSequenceTestCase { |
| | | |
| | | //@Checkstyle:off |
| | | private static byte _(int i) { |
| | | private static byte b(int i) { |
| | | return (byte) i; |
| | | } |
| | | //@Checkstyle:on |
| | | |
| | | private static final byte[] EIGHT_BYTES = new byte[] { _(0x01), _(0x02), _(0x03), |
| | | _(0x04), _(0x05), _(0x06), _(0x07), _(0x08) }; |
| | | private static final byte[] EIGHT_BYTES = new byte[] { b(0x01), b(0x02), b(0x03), |
| | | b(0x04), b(0x05), b(0x06), b(0x07), b(0x08) }; |
| | | |
| | | /** |
| | | * ByteSequence data provider. |
| | |
| | | System.arraycopy(builders, 0, addlSequences, 0, builders.length); |
| | | addlSequences[builders.length] = |
| | | new Object[] { new ByteStringBuilder().append(EIGHT_BYTES).subSequence(2, 6), |
| | | new byte[] { _(0x03), _(0x04), _(0x05), _(0x06) } }; |
| | | new byte[] { b(0x03), b(0x04), b(0x05), b(0x06) } }; |
| | | |
| | | return addlSequences; |
| | | } |
| | |
| | | public void testAsOutputStream() throws Exception { |
| | | final ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | final OutputStream os = bsb.asOutputStream(); |
| | | os.write(_(0x01)); |
| | | os.write(b(0x01)); |
| | | os.write(2); |
| | | os.write(new byte[] { 2, 3, 4, 5 }, 1, 2); |
| | | os.close(); |
| | |
| | | testBuilderFromStream.append(testStream, 8); |
| | | |
| | | return new Object[][] { |
| | | { new ByteStringBuilder().append(_(0x00)).append(_(0x01)), |
| | | new byte[] { _(0x00), _(0x01) } }, |
| | | { new ByteStringBuilder().append(b(0x00)).append(b(0x01)), |
| | | new byte[] { b(0x00), b(0x01) } }, |
| | | { new ByteStringBuilder(5) |
| | | .append(new byte[] { _(0x01), _(0x02), _(0x03), _(0x04) }) |
| | | .append(new byte[] { _(0x05), _(0x06), _(0x07), _(0x08) }), |
| | | .append(new byte[] { b(0x01), b(0x02), b(0x03), b(0x04) }) |
| | | .append(new byte[] { b(0x05), b(0x06), b(0x07), b(0x08) }), |
| | | EIGHT_BYTES }, |
| | | { new ByteStringBuilder(3).append(EIGHT_BYTES, 0, 3).append(EIGHT_BYTES, 3, 5), |
| | | EIGHT_BYTES }, |
| | |
| | | EIGHT_BYTES }, |
| | | { testBuilderFromStream, EIGHT_BYTES }, |
| | | { new ByteStringBuilder().append(Short.MIN_VALUE).append(Short.MAX_VALUE), |
| | | new byte[] { _(0x80), _(0x00), _(0x7F), _(0xFF) } }, |
| | | new byte[] { b(0x80), b(0x00), b(0x7F), b(0xFF) } }, |
| | | { |
| | | new ByteStringBuilder(5).append(Integer.MIN_VALUE).append(Integer.MAX_VALUE), |
| | | new byte[] { _(0x80), _(0x00), _(0x00), _(0x00), _(0x7F), |
| | | _(0xFF), _(0xFF), _(0xFF) } }, |
| | | new byte[] { b(0x80), b(0x00), b(0x00), b(0x00), b(0x7F), |
| | | b(0xFF), b(0xFF), b(0xFF) } }, |
| | | { |
| | | new ByteStringBuilder().append(Long.MIN_VALUE).append(Long.MAX_VALUE), |
| | | new byte[] { _(0x80), _(0x00), _(0x00), _(0x00), _(0x00), |
| | | _(0x00), _(0x00), _(0x00), _(0x7F), _(0xFF), _(0xFF), |
| | | _(0xFF), _(0xFF), _(0xFF), _(0xFF), _(0xFF) } }, |
| | | new byte[] { b(0x80), b(0x00), b(0x00), b(0x00), b(0x00), |
| | | b(0x00), b(0x00), b(0x00), b(0x7F), b(0xFF), b(0xFF), |
| | | b(0xFF), b(0xFF), b(0xFF), b(0xFF), b(0xFF) } }, |
| | | { new ByteStringBuilder(11).append("this is a").append(" test"), |
| | | "this is a test".getBytes("UTF-8") }, |
| | | { new ByteStringBuilder().append((Object) "this is a").append((Object) " test"), |
| | |
| | | (Object) " test".toCharArray()), "this is a test".getBytes("UTF-8") }, |
| | | { |
| | | new ByteStringBuilder().append((Object) EIGHT_BYTES).append((Object) EIGHT_BYTES), |
| | | new byte[] { _(0x01), _(0x02), _(0x03), _(0x04), _(0x05), |
| | | _(0x06), _(0x07), _(0x08), _(0x01), _(0x02), _(0x03), |
| | | _(0x04), _(0x05), _(0x06), _(0x07), _(0x08) } }, |
| | | new byte[] { b(0x01), b(0x02), b(0x03), b(0x04), b(0x05), |
| | | b(0x06), b(0x07), b(0x08), b(0x01), b(0x02), b(0x03), |
| | | b(0x04), b(0x05), b(0x06), b(0x07), b(0x08) } }, |
| | | { |
| | | new ByteStringBuilder().appendBERLength(0x00000000).appendBERLength(0x00000001) |
| | | .appendBERLength(0x0000000F).appendBERLength(0x00000010).appendBERLength( |
| | |
| | | .appendBERLength(0x00100000).appendBERLength(0x00FFFFFF).appendBERLength( |
| | | 0x01000000).appendBERLength(0x0FFFFFFF).appendBERLength(0x10000000) |
| | | .appendBERLength(0xFFFFFFFF), |
| | | new byte[] { _(0x00), _(0x01), _(0x0F), _(0x10), _(0x7F), |
| | | _(0x81), _(0xFF), _(0x82), _(0x01), _(0x00), _(0x82), |
| | | _(0x0F), _(0xFF), _(0x82), _(0x10), _(0x00), _(0x82), |
| | | _(0xFF), _(0xFF), _(0x83), _(0x01), _(0x00), _(0x00), |
| | | _(0x83), _(0x0F), _(0xFF), _(0xFF), _(0x83), _(0x10), |
| | | _(0x00), _(0x00), _(0x83), _(0xFF), _(0xFF), _(0xFF), |
| | | _(0x84), _(0x01), _(0x00), _(0x00), _(0x00), _(0x84), |
| | | _(0x0F), _(0xFF), _(0xFF), _(0xFF), _(0x84), _(0x10), |
| | | _(0x00), _(0x00), _(0x00), _(0x84), _(0xFF), _(0xFF), |
| | | _(0xFF), _(0xFF) } }, }; |
| | | new byte[] { b(0x00), b(0x01), b(0x0F), b(0x10), b(0x7F), |
| | | b(0x81), b(0xFF), b(0x82), b(0x01), b(0x00), b(0x82), |
| | | b(0x0F), b(0xFF), b(0x82), b(0x10), b(0x00), b(0x82), |
| | | b(0xFF), b(0xFF), b(0x83), b(0x01), b(0x00), b(0x00), |
| | | b(0x83), b(0x0F), b(0xFF), b(0xFF), b(0x83), b(0x10), |
| | | b(0x00), b(0x00), b(0x83), b(0xFF), b(0xFF), b(0xFF), |
| | | b(0x84), b(0x01), b(0x00), b(0x00), b(0x00), b(0x84), |
| | | b(0x0F), b(0xFF), b(0xFF), b(0xFF), b(0x84), b(0x10), |
| | | b(0x00), b(0x00), b(0x00), b(0x84), b(0xFF), b(0xFF), |
| | | b(0xFF), b(0xFF) } }, }; |
| | | } |
| | | |
| | | @Test |
| | |
| | | public void testSetByte() { |
| | | final ByteStringBuilder builder = new ByteStringBuilder(); |
| | | builder.append("this is a ByteString"); |
| | | builder.setByte(2, _('a')); |
| | | builder.setByte(3, _('t')); |
| | | builder.setByte(2, b('a')); |
| | | builder.setByte(3, b('t')); |
| | | Assert.assertEquals(builder.toByteString().toString(), "that is a ByteString"); |
| | | } |
| | | |
| | | @Test(expectedExceptions = { IndexOutOfBoundsException.class }) |
| | | public void testSetByteAtInvalidLowerIndex() { |
| | | final ByteStringBuilder builder = new ByteStringBuilder(); |
| | | builder.setByte(-1, _(0)); |
| | | builder.setByte(-1, b(0)); |
| | | } |
| | | |
| | | @Test(expectedExceptions = { IndexOutOfBoundsException.class }) |
| | | public void testSetByteAtInvalidUpperIndex() { |
| | | final ByteStringBuilder builder = new ByteStringBuilder(); |
| | | builder.setByte(builder.length(), _(0)); |
| | | builder.setByte(builder.length(), b(0)); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * This class tests the GSERParser. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public class GSERParserTestCase extends SdkTestCase { |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Test(expectedExceptions = { NullPointerException.class }) |
| | | public void testGSERParserInitWithNull() throws Exception { |
| | | GSERParser parser = new GSERParser(null); |
| | | new GSERParser(null); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * This class tests the certificateExactMatch matching rule. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public class CertificateExactMatchingRuleImplTest extends SchemaTestCase { |
| | | |
| | | /** |
| | |
| | | public Object[][] nonAsciiStringProvider() throws Exception { |
| | | final String nonAsciiChars = "ëéèêœ"; |
| | | final String nonAsciiCharsReplacement = new String( |
| | | new byte[] { _(0x65), _(0xcc), _(0x88), _(0x65), _(0xcc), |
| | | _(0x81), _(0x65), _(0xcc), _(0x80), _(0x65), _(0xcc), |
| | | _(0x82), _(0xc5), _(0x93), }, "UTF8"); |
| | | new byte[] { b(0x65), b(0xcc), b(0x88), b(0x65), b(0xcc), |
| | | b(0x81), b(0x65), b(0xcc), b(0x80), b(0x65), b(0xcc), |
| | | b(0x82), b(0xc5), b(0x93), }, "UTF8"); |
| | | return new Object[][] { |
| | | { nonAsciiChars, false, false, nonAsciiCharsReplacement }, |
| | | { nonAsciiChars, false, true, nonAsciiCharsReplacement }, |
| | |
| | | } |
| | | |
| | | //@Checkstyle:off |
| | | private byte _(int i) { |
| | | private byte b(int i) { |
| | | return (byte) i; |
| | | } |
| | | //@Checkstyle:on |