directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [4/4] directory-kerby git commit: DIRKRB-519 Check all the tests to use the NameTest format.
Date Thu, 31 Dec 2015 03:12:43 GMT
DIRKRB-519 Check all the tests to use the NameTest format.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/d06becfd
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/d06becfd
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/d06becfd

Branch: refs/heads/trunk
Commit: d06becfd72909a224c065197cf947f8f87917d2d
Parents: e0ce27d
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Thu Dec 31 11:19:34 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Thu Dec 31 11:19:34 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/asn1/Asn1BooleanTest.java  |  70 +++++++
 .../apache/kerby/asn1/Asn1CollectionTest.java   |  60 ++++++
 .../asn1/Asn1ConstructedOctetStringTest.java    |  36 ++++
 .../org/apache/kerby/asn1/Asn1DumpTest.java     |  95 +++++++++
 .../org/apache/kerby/asn1/Asn1FlagsTest.java    | 158 ++++++++++++++
 .../org/apache/kerby/asn1/Asn1IntegerTest.java  |  72 +++++++
 .../kerby/asn1/Asn1ObjectIdentifierTest.java    |  66 ++++++
 .../org/apache/kerby/asn1/Asn1UtcTimeTest.java  |  72 +++++++
 .../java/org/apache/kerby/asn1/DataTest.java    | 127 ++++++++++++
 .../apache/kerby/asn1/PersonnelRecordTest.java  | 121 +++++++++++
 .../apache/kerby/asn1/TaggingEncodingTest.java  | 205 +++++++++++++++++++
 .../org/apache/kerby/asn1/TestAsn1Boolean.java  |  70 -------
 .../apache/kerby/asn1/TestAsn1Collection.java   |  60 ------
 .../asn1/TestAsn1ConstructedOctetString.java    |  36 ----
 .../org/apache/kerby/asn1/TestAsn1Dump.java     |  95 ---------
 .../org/apache/kerby/asn1/TestAsn1Flags.java    | 158 --------------
 .../org/apache/kerby/asn1/TestAsn1Integer.java  |  72 -------
 .../kerby/asn1/TestAsn1ObjectIdentifier.java    |  66 ------
 .../org/apache/kerby/asn1/TestAsn1UtcTime.java  |  72 -------
 .../java/org/apache/kerby/asn1/TestData.java    | 127 ------------
 .../apache/kerby/asn1/TestPersonnelRecord.java  | 121 -----------
 .../apache/kerby/asn1/TestTaggingEncoding.java  | 205 -------------------
 .../kerb/client/KrbClientSettingTest.java       |   2 +-
 .../client/KrbConfigLoadForSpecialsTest.java    |  51 +++++
 .../kerberos/kerb/client/KrbConfigLoadTest.java |  65 ++++++
 .../kerberos/kerb/client/TestKrbConfigLoad.java |  65 ------
 .../client/TestKrbConfigLoadForSpecials.java    |  51 -----
 .../kerberos/kerb/codec/AsRepCodecTest.java     |  72 +++++++
 .../kerberos/kerb/codec/AsReqCodecTest.java     | 104 ++++++++++
 .../kerberos/kerb/codec/PaPkAsRepTest.java      |  45 ++++
 .../codec/PkinitAnonymousAsRepCodecTest.java    | 123 +++++++++++
 .../codec/PkinitAnonymousAsReqCodecTest.java    | 151 ++++++++++++++
 .../kerb/codec/PkinitRsaAsRepCodecTest.java     |  68 ++++++
 .../kerb/codec/PkinitRsaAsReqCodecTest.java     | 112 ++++++++++
 .../kerberos/kerb/codec/TestAsRepCodec.java     |  72 -------
 .../kerberos/kerb/codec/TestAsReqCodec.java     | 104 ----------
 .../kerberos/kerb/codec/TestPaPkAsRep.java      |  45 ----
 .../codec/TestPkinitAnonymousAsRepCodec.java    | 123 -----------
 .../codec/TestPkinitAnonymousAsReqCodec.java    | 151 --------------
 .../kerb/codec/TestPkinitRsaAsRepCodec.java     |  68 ------
 .../kerb/codec/TestPkinitRsaAsReqCodec.java     | 112 ----------
 .../kerberos/kerb/codec/TestTgsRepCodec.java    |  68 ------
 .../kerberos/kerb/codec/TestTgsReqCodec.java    |  92 ---------
 .../kerberos/kerb/codec/TgsRepCodecTest.java    |  68 ++++++
 .../kerberos/kerb/codec/TgsReqCodecTest.java    |  92 +++++++++
 .../kerberos/kerb/server/KdcConfigLoadTest.java |  73 +++++++
 .../kerberos/kerb/server/TestKdcConfigLoad.java |  73 -------
 .../apache/commons/ssl/CertificatesTest.java    |  84 ++++++++
 .../org/apache/commons/ssl/KeyMaterialTest.java |  77 +++++++
 .../org/apache/commons/ssl/OpenSSLTest.java     | 166 +++++++++++++++
 .../org/apache/commons/ssl/PKCS8KeyTest.java    |  61 ++++++
 .../apache/commons/ssl/TestCertificates.java    |  84 --------
 .../org/apache/commons/ssl/TestKeyMaterial.java |  77 -------
 .../org/apache/commons/ssl/TestOpenSSL.java     | 166 ---------------
 .../org/apache/commons/ssl/TestPKCS8Key.java    |  61 ------
 .../apache/commons/ssl/TestTrustMaterial.java   |  67 ------
 .../apache/commons/ssl/TrustMaterialTest.java   |  67 ++++++
 .../org/apache/kerby/cms/CertificateTest.java   |  76 +++++++
 .../apache/kerby/cms/CompressedDataTest.java    |  49 +++++
 .../org/apache/kerby/cms/EnvelopedDataTest.java |  86 ++++++++
 .../org/apache/kerby/cms/ExtensionTest.java     |  54 +++++
 .../org/apache/kerby/cms/GeneralNameTest.java   |  50 +++++
 .../org/apache/kerby/cms/SignedDataTest.java    | 111 ++++++++++
 .../org/apache/kerby/cms/TestCertificate.java   |  76 -------
 .../apache/kerby/cms/TestCompressedData.java    |  49 -----
 .../org/apache/kerby/cms/TestEnvelopedData.java |  86 --------
 .../org/apache/kerby/cms/TestExtension.java     |  54 -----
 .../org/apache/kerby/cms/TestGeneralName.java   |  50 -----
 .../org/apache/kerby/cms/TestSignedData.java    | 111 ----------
 .../java/org/apache/kerby/util/Base64Test.java  |  90 ++++++++
 .../apache/kerby/util/IPAddressParserTest.java  |  80 ++++++++
 .../java/org/apache/kerby/util/TestBase64.java  |  90 --------
 .../apache/kerby/util/TestIPAddressParser.java  |  80 --------
 73 files changed, 3158 insertions(+), 3158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java
new file mode 100644
index 0000000..5557975
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1BooleanTest.java
@@ -0,0 +1,70 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Boolean;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1BooleanTest {
+
+    @Test
+    public void testEncoding() throws IOException {
+        testEncodingWith(true, "0x01 01 FF", true);
+        testEncodingWith(false, "0x01 01 00", true);
+    }
+
+    private void testEncodingWith(Boolean value, String expectedEncoding,
+                                  boolean isDer) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1Boolean aValue = new Asn1Boolean(value);
+        if (isDer) {
+            aValue.useDER();
+        } else {
+            aValue.useBER();
+        }
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws IOException {
+        testDecodingWith(true, "0x01 01 FF", true);
+        testDecodingWith(false, "0x01 01 7F", true);
+        testDecodingWith(true, "0x01 01 7F", false);
+        testDecodingWith(false, "0x01 01 00", true);
+    }
+
+    private void testDecodingWith(Boolean expectedValue, String content,
+                                  boolean isDer) throws IOException {
+        Asn1Boolean decoded = new Asn1Boolean();
+        if (isDer) {
+            decoded.useDER();
+        } else {
+            decoded.useBER();
+        }
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java
new file mode 100644
index 0000000..50d51af
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1CollectionTest.java
@@ -0,0 +1,60 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Boolean;
+import org.apache.kerby.asn1.type.Asn1IA5String;
+import org.apache.kerby.asn1.type.Asn1Sequence;
+import org.apache.kerby.asn1.type.Asn1String;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1CollectionTest {
+    static final String TEST_STR = "Jones";
+    static final Boolean TEST_BOOL = true;
+    static final byte[] EXPECTED_BYTES = new byte[] {(byte) 0x30, (byte) 0x0A,
+            (byte) 0x16, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73, (byte) 0x01, (byte) 0x01, (byte) 0xFF
+    };
+
+    @Test
+    public void testSequenceEncoding() throws IOException {
+        Asn1Sequence seq = new Asn1Sequence();
+        seq.addItem(new Asn1IA5String(TEST_STR));
+        seq.addItem(new Asn1Boolean(TEST_BOOL));
+
+        assertThat(seq.encode()).isEqualTo(EXPECTED_BYTES);
+    }
+
+    @Test
+    public void testSequenceDecoding() throws IOException {
+        Asn1Sequence seq = new Asn1Sequence();
+        seq.decode(EXPECTED_BYTES);
+        Asn1String field =
+            (Asn1String) seq.getValue().get(0);
+        assertThat(field.getValue()).isEqualTo(TEST_STR);
+
+        Asn1Boolean field2 = (Asn1Boolean) seq.getValue().get(1);
+        assertThat(field2.getValue()).isEqualTo(TEST_BOOL);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java
new file mode 100644
index 0000000..7b110a9
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ConstructedOctetStringTest.java
@@ -0,0 +1,36 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1OctetString;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class Asn1ConstructedOctetStringTest {
+
+    @Test
+    public void testDecoding() throws IOException {
+        byte[] data = TestUtil.readBytesFromTxtFile("/constructed-octet-string.txt");
+        Asn1OctetString octetString = new Asn1OctetString();
+        octetString.decode(data);
+        Asn1.dump(octetString);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java
new file mode 100644
index 0000000..fb83fc0
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1DumpTest.java
@@ -0,0 +1,95 @@
+/**
+ *  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.kerby.asn1;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+
+public class Asn1DumpTest {
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithPersonnelRecord() throws IOException {
+        try {
+            PersonnelRecord pr = DataTest.createSamplePersonnel();
+            Asn1.dump(pr);
+
+            byte[] data = DataTest.createSammplePersonnelEncodingData();
+            Asn1.parseAndDump(data);
+            Asn1.decodeAndDump(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithCompressedData() throws IOException {
+        String hexStr = TestUtil.readStringFromTxtFile("/compressed-data.txt");
+        try {
+            Asn1.parseAndDump(hexStr);
+            Asn1.decodeAndDump(hexStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithSignedData() throws IOException {
+        String hexStr = TestUtil.readStringFromTxtFile("/signed-data.txt");
+        try {
+            Asn1.parseAndDump(hexStr);
+            Asn1.decodeAndDump(hexStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    @org.junit.Ignore
+    public void testDumpWithDerData() throws IOException {
+        byte[] data = TestUtil.readBytesFromBinFile("/der-data.dat");
+        try {
+            Asn1.parseAndDump(data);
+            Asn1.decodeAndDump(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+
+    @Test
+    public void testDumpWithEmptyContainer() throws IOException {
+        byte[] data = TestUtil.readBytesFromTxtFile("/empty-container.txt");
+        try {
+            Asn1.parseAndDump(data);
+            Asn1.decodeAndDump(data);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Assert.fail();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java
new file mode 100644
index 0000000..3182811
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1FlagsTest.java
@@ -0,0 +1,158 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Flags;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class Asn1FlagsTest {
+  
+  public static final int FLAG_0 = 0b00000000000000000000000000000001;
+  public static final int FLAG_1 = 0b00000000000000000000000000000010;
+  public static final int FLAG_2 = 0x00000004;
+  public static final int FLAG_3 = 0x00000008;
+  public static final int FLAG_4 = 16;
+  public static final int FLAG_5 = 32;
+  
+  public enum TestEnum implements EnumType {
+    FLAG_0(0x00000001),
+    FLAG_1(0x00000002),
+    FLAG_2(0x00000004),
+    FLAG_3(0x00000008),
+    FLAG_4(0x00000010),
+    FLAG_5(0x00000020);
+    
+    private int value;
+    
+    private TestEnum(int value) {
+      this.value = value;
+    }
+
+    @Override
+    public int getValue() {
+      return value;
+    }
+
+
+    @Override
+    public String getName() {
+      return name();
+    }
+  }
+  
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+  
+  private Asn1Flags flags;
+  
+  @Before
+  public void setUp() {
+    flags = new Asn1Flags(FLAG_5 | FLAG_3 | FLAG_1);
+  }
+
+  @Test
+  public void testToValue() throws IOException {
+    byte[] value = {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
+    flags.setValue(value);
+    assertEquals(0b11011110101011011011111011101111, flags.getFlags());
+  }
+
+  @Test
+  public void testFlags() {
+    flags = new Asn1Flags();
+    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
+  }
+
+  @Test
+  public void testFlagsInt() {
+    flags = new Asn1Flags(FLAG_4 | FLAG_2 | FLAG_0);
+    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
+  }
+
+  @Test
+  public void testSetFlags() {
+    flags.setFlags(FLAG_4 | FLAG_2 | FLAG_0);
+    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
+  }
+
+  @Test
+  public void testGetFlags() {
+    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
+  }
+
+  @Test
+  public void testIsFlagSetInt() {
+    assertTrue(flags.isFlagSet(FLAG_5));
+    assertFalse(flags.isFlagSet(FLAG_4));
+  }
+
+  @Test
+  public void testSetFlagInt() {
+    flags.setFlag(FLAG_4);
+    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
+  }
+
+  @Test
+  public void testClearFlagInt() {
+    flags.clearFlag(FLAG_3);
+    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
+  }
+
+  @Test
+  public void testClear() {
+    flags.clear();
+    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
+  }
+
+  @Test
+  public void testIsFlagSetEnum() {
+    assertTrue(flags.isFlagSet(TestEnum.FLAG_5));
+    assertFalse(flags.isFlagSet(TestEnum.FLAG_4));
+  }
+
+  @Test
+  public void testSetFlagEnum() {
+    flags.setFlag(TestEnum.FLAG_4);
+    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
+  }
+
+  @Test
+  public void testSetFlagEnumBoolean() {
+    flags.setFlag(TestEnum.FLAG_4, true);
+    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
+    flags.setFlag(TestEnum.FLAG_4, false);
+    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
+  }
+
+  @Test
+  public void testClearFlagEnum() {
+    flags.clearFlag(TestEnum.FLAG_3);
+    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
+  }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java
new file mode 100644
index 0000000..04bb11f
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1IntegerTest.java
@@ -0,0 +1,72 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Integer;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1IntegerTest {
+
+    @Test
+    public void testEncoding() throws IOException {
+        testEncodingWith(0, "0x02 01 00");
+        testEncodingWith(1, "0x02 01 01");
+        testEncodingWith(2, "0x02 01 02");
+        testEncodingWith(127, "0x02 01 7F");
+        testEncodingWith(128, "0x02 02 00 80");
+        testEncodingWith(-1, "0x02 01 FF");
+        testEncodingWith(-128, "0x02 01 80");
+        testEncodingWith(-32768, "0x02 02 80 00");
+        testEncodingWith(1234567890, "0x02 04 49 96 02 D2");
+    }
+
+    private void testEncodingWith(int value, String expectedEncoding) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1Integer aValue = new Asn1Integer(value);
+        aValue.useDER();
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws IOException {
+        testDecodingWith(0, "0x02 01 00");
+        testDecodingWith(1, "0x02 01 01");
+        testDecodingWith(2, "0x02 01 02");
+        testDecodingWith(127, "0x02 01 7F");
+        testDecodingWith(128, "0x02 02 00 80");
+        testDecodingWith(-1, "0x02 01 FF");
+        testDecodingWith(-128, "0x02 01 80");
+        testDecodingWith(-32768, "0x02 02 80 00");
+        testDecodingWith(1234567890, "0x02 04 49 96 02 D2");
+    }
+
+    private void testDecodingWith(int expectedValue, String content) throws IOException {
+        Asn1Integer decoded = new Asn1Integer();
+        decoded.useDER();
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue().intValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java
new file mode 100644
index 0000000..9106dc7
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1ObjectIdentifierTest.java
@@ -0,0 +1,66 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1ObjectIdentifierTest {
+
+    @Test
+    public void testEncoding() throws Exception {
+        /**
+         * Cryptography for Developers -> ASN.1 UTCTIME Type
+         * Applying this to the MD5 OID, we first transform the dotted decimal form into the
+         * array of words.Thus, 1.2.840.113549.2.5 becomes {42, 840, 113549, 2, 5}, and then further
+         * 404_CRYPTO_02.qxd 10/27/06 3:40 PM Page 36split into seven-bit digits with the proper most significant bits as
+         * {{0x2A}, {0x86, 0x48},{0x86, 0xF7, 0x0D}, {0x02}, {0x05}}.Therefore, the full encoding for MD5 is 0x06 08 2A
+         * 86 48 86 F7 0D 02 05.
+         */
+        testEncodingWith("1.2.840.113549.2.5",
+                "0x06 08 2A 86 48 86 F7 0D 02 05");
+    }
+
+    private void testEncodingWith(String oid, String expectedEncoding) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1ObjectIdentifier aValue = new Asn1ObjectIdentifier(oid);
+        aValue.useDER();
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws Exception {
+        testDecodingWith("1.2.840.113549.2.5",
+                "0x06 08 2A 86 48 86 F7 0D 02 05");
+    }
+
+    private void testDecodingWith(String expectedValue, String content) throws IOException {
+        Asn1ObjectIdentifier decoded = new Asn1ObjectIdentifier();
+        decoded.useDER();
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java
new file mode 100644
index 0000000..271abff
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/Asn1UtcTimeTest.java
@@ -0,0 +1,72 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1UtcTime;
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.SimpleTimeZone;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class Asn1UtcTimeTest {
+
+    @Test
+    public void testEncoding() throws Exception {
+        /**
+         * Cryptography for Developers -> ASN.1 UTCTIME Type
+         * the encoding of July 4, 2003 at 11:33 and 28 seconds would be
+         “030704113328Z” and be encoded as 0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A.
+         */
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
+        String dateInString = "2003-07-04 11:33:28";
+        Date date = sdf.parse(dateInString);
+        testEncodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
+    }
+
+    private void testEncodingWith(Date value, String expectedEncoding) throws IOException {
+        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
+        Asn1UtcTime aValue = new Asn1UtcTime(value);
+        aValue.useDER();
+        byte[] encodingBytes = aValue.encode();
+        assertThat(encodingBytes).isEqualTo(expected);
+    }
+
+    @Test
+    public void testDecoding() throws Exception {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String dateInString = "2003-07-04 11:33:28";
+        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
+        Date date = sdf.parse(dateInString);
+        testDecodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
+    }
+
+    private void testDecodingWith(Date expectedValue, String content) throws IOException {
+        Asn1UtcTime decoded = new Asn1UtcTime();
+        decoded.useDER();
+        decoded.decode(HexUtil.hex2bytesFriendly(content));
+        assertThat(decoded.getValue()).isEqualTo(expectedValue);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java
new file mode 100644
index 0000000..4e5c0a5
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/DataTest.java
@@ -0,0 +1,127 @@
+/**
+ *  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.kerby.asn1;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+
+public class DataTest {
+
+    public static PersonnelRecord createSamplePersonnel() {
+        PersonnelRecord pr = new PersonnelRecord();
+
+        pr.setName(new PersonnelRecord.Name("John", "P", "Smith"));
+
+        pr.setTitle("Director");
+
+        pr.setEmployeeNumber(new PersonnelRecord.EmployeeNumber(51));
+
+        pr.setDateOfHire(new PersonnelRecord.Date("19710917"));
+
+        pr.setNameOfSpouse(new PersonnelRecord.Name("Mary", "T", "Smith"));
+
+        PersonnelRecord.ChildInformation child1 = new PersonnelRecord.ChildInformation();
+        child1.setName(new PersonnelRecord.Name("Ralph", "T", "Smith"));
+        child1.setDateOfBirth(new PersonnelRecord.Date("19571111"));
+
+        PersonnelRecord.ChildInformation child2 = new PersonnelRecord.ChildInformation();
+        child2.setName(new PersonnelRecord.Name("Susan", "B", "Jones"));
+        child2.setDateOfBirth(new PersonnelRecord.Date("19590717"));
+
+        pr.setChildren(new PersonnelRecord.Children(child1, child2));
+
+        return pr;
+    }
+
+    public static byte[] createSammplePersonnelEncodingData() {
+        class BufferOutput {
+            ByteBuffer buffer;
+
+            void put(byte ... bytes) {
+                buffer.put(bytes);
+            }
+
+            void put(String s) {
+                byte[] bytes = s.getBytes(StandardCharsets.US_ASCII);
+                buffer.put(bytes);
+            }
+
+            public byte[] output() {
+                int len = (int) 0x85 + 3;
+                buffer = ByteBuffer.allocate(len);
+
+                // personnel record
+                put((byte) 0x60, (byte) 0x81, (byte) 0x85);
+
+                // -name
+                put((byte) 0x61, (byte) 0x10);
+                put((byte) 0x1A, (byte) 0x04); put("John");
+                put((byte) 0x1A, (byte) 0x01); put("P");
+                put((byte) 0x1A, (byte) 0x05); put("Smith");
+
+                //-title
+                put((byte) 0xA0, (byte) 0x0A);
+                put((byte) 0x1A, (byte) 0x08); put("Director");
+
+                //-employee number
+                put((byte) 0x42, (byte) 0x01, (byte) 0x33);
+
+                //-date of hire
+                put((byte) 0xA1, (byte) 0x0A);
+                put((byte) 0x43, (byte) 0x08); put("19710917");
+
+                //-spouse
+                put((byte) 0xA2, (byte) 0x12);
+                put((byte) 0x61, (byte) 0x10);
+                put((byte) 0x1A, (byte) 0x04); put("Mary");
+                put((byte) 0x1A, (byte) 0x01); put("T");
+                put((byte) 0x1A, (byte) 0x05); put("Smith");
+
+                //-children
+                put((byte) 0xA3, (byte) 0x42);
+                //--child 1
+                put((byte) 0x31, (byte) 0x1F);
+                //---name
+                put((byte) 0x61, (byte) 0x11);
+                put((byte) 0x1A, (byte) 0x05); put("Ralph");
+                put((byte) 0x1A, (byte) 0x01); put("T");
+                put((byte) 0x1A, (byte) 0x05); put("Smith");
+                //-date of birth
+                put((byte) 0xA0, (byte) 0x0A);
+                put((byte) 0x43, (byte) 0x08); put("19571111");
+                //--child 2
+                put((byte) 0x31, (byte) 0x1F);
+                //---name
+                put((byte) 0x61, (byte) 0x11);
+                put((byte) 0x1A, (byte) 0x05); put("Susan");
+                put((byte) 0x1A, (byte) 0x01); put("B");
+                put((byte) 0x1A, (byte) 0x05); put("Jones");
+                //-date of birth
+                put((byte) 0xA0, (byte) 0x0A);
+                put((byte) 0x43, (byte) 0x08); put("19590717");
+
+                return buffer.array();
+            }
+        }
+
+        BufferOutput buffer = new BufferOutput();
+        return buffer.output();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java
new file mode 100644
index 0000000..514b82b
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/PersonnelRecordTest.java
@@ -0,0 +1,121 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.util.HexUtil;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Ref. X.690-0207(http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf),
+ * Annex A, A.1 ASN.1 description of the record structure
+ */
+public class PersonnelRecordTest {
+
+    static boolean verbose = false;
+
+    @Test
+    public void testEncoding() throws IOException {
+        PersonnelRecord pr = DataTest.createSamplePersonnel();
+
+        if (verbose) {
+            System.out.println("Name:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getName().encode()));
+
+            System.out.println("DateOfHire:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getDateOfHire().encode()));
+
+            System.out.println("SpouseName:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getNameOfSpouse().encode()));
+
+            System.out.println("Child1:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(0).encode()));
+
+            System.out.println("Child2:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(1).encode()));
+
+            System.out.println("Children:");
+            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().encode()));
+        }
+
+        byte[] data = DataTest.createSammplePersonnelEncodingData();
+        byte[] encoded = pr.encode();
+
+        if (verbose) {
+            System.out.println("ExpectedData:");
+            System.out.println(HexUtil.bytesToHexFriendly(data));
+
+            System.out.println("Encoded:");
+            System.out.println(HexUtil.bytesToHexFriendly(encoded));
+        }
+
+        assertThat(encoded).isEqualTo(data);
+    }
+
+    @Test
+    public void testDecoding() throws IOException {
+        PersonnelRecord expected = DataTest.createSamplePersonnel();
+        byte[] data = DataTest.createSammplePersonnelEncodingData();
+        Asn1.parseAndDump(data);
+        PersonnelRecord decoded = new PersonnelRecord();
+        decoded.decode(data);
+        Asn1.dump(decoded);
+
+        assertThat(decoded.getName().getGivenName())
+                .isEqualTo(expected.getName().getGivenName());
+        assertThat(decoded.getName().getInitial())
+                .isEqualTo(expected.getName().getInitial());
+        assertThat(decoded.getName().getFamilyName())
+                .isEqualTo(expected.getName().getFamilyName());
+        assertThat(decoded.getDateOfHire().getValue().getValue())
+                .isEqualTo(expected.getDateOfHire().getValue().getValue());
+        assertThat(decoded.getTitle())
+                .isEqualTo(expected.getTitle());
+        assertThat(decoded.getEmployeeNumber().getValue().getValue())
+                .isEqualTo(expected.getEmployeeNumber().getValue().getValue());
+        assertThat(decoded.getNameOfSpouse().getGivenName())
+                .isEqualTo(expected.getNameOfSpouse().getGivenName());
+        assertThat(decoded.getNameOfSpouse().getInitial())
+                .isEqualTo(expected.getNameOfSpouse().getInitial());
+        assertThat(decoded.getNameOfSpouse().getFamilyName())
+                .isEqualTo(expected.getNameOfSpouse().getFamilyName());
+        assertThat(decoded.getChildren().getElements().size())
+            .isEqualTo(expected.getChildren().getElements().size());
+        assertThat(decoded.getChildren().getElements().get(0).getName().getGivenName())
+                .isEqualTo(expected.getChildren().getElements().get(0).getName().getGivenName());
+        assertThat(decoded.getChildren().getElements().get(0).getName().getInitial())
+                .isEqualTo(expected.getChildren().getElements().get(0).getName().getInitial());
+        assertThat(decoded.getChildren().getElements().get(0).getName().getFamilyName())
+                .isEqualTo(expected.getChildren().getElements().get(0).getName().getFamilyName());
+        assertThat(decoded.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue())
+                .isEqualTo(expected.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue());
+        assertThat(decoded.getChildren().getElements().get(1).getName().getGivenName())
+                .isEqualTo(expected.getChildren().getElements().get(1).getName().getGivenName());
+        assertThat(decoded.getChildren().getElements().get(1).getName().getInitial())
+                .isEqualTo(expected.getChildren().getElements().get(1).getName().getInitial());
+        assertThat(decoded.getChildren().getElements().get(1).getName().getFamilyName())
+                .isEqualTo(expected.getChildren().getElements().get(1).getName().getFamilyName());
+        assertThat(decoded.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue())
+                .isEqualTo(expected.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue());
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java
new file mode 100644
index 0000000..ad9be01
--- /dev/null
+++ b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TaggingEncodingTest.java
@@ -0,0 +1,205 @@
+/**
+ *  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.kerby.asn1;
+
+import org.apache.kerby.asn1.type.Asn1Tagging;
+import org.apache.kerby.asn1.type.Asn1VisibleString;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ Ref. X.690-0207 8.14 Encoding of a tagged value
+ EXAMPLE
+ With ASN.1 type definitions (in an explicit tagging environment) of:
+ Type1 ::= VisibleString
+ Type2 ::= [APPLICATION 3] IMPLICIT Type1
+ Type3 ::= [2] Type2
+ Type4 ::= [APPLICATION 7] IMPLICIT Type3
+ Type5 ::= [2] IMPLICIT Type2
+ a value of:
+ "Jones"
+ is encoded as follows:
+ For Type1:
+ VisibleString Length Contents
+ 1A16 0516 4A6F6E657316
+ For Type2:
+ [Application 3] Length Contents
+ 4316 0516 4A6F6E657316
+ For Type3:
+ [2] Length Contents
+ A216 0716
+ [APPLICATION 3] Length Contents
+ 4316 0516 4A6F6E657316
+ For Type4:
+ [Application 7] Length Contents
+ 6716 0716
+ [APPLICATION 3] Length Contents
+ 4316 0516 4A6F6E657316
+ For Type5:
+ [2] Length Contents
+ 8216 0516 4A6F6E657316
+ */
+
+public class TaggingEncodingTest {
+    static final String TEST_STRING = "Jones";
+    static final byte[] TYPE1_EXPECTED_BYTES = new byte[] {(byte) 0x1A, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE2_EXPECTED_BYTES = new byte[] {(byte) 0x43, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE3_EXPECTED_BYTES = new byte[] {(byte) 0xA2, (byte) 0x07,
+            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE4_EXPECTED_BYTES = new byte[] {(byte) 0x67, (byte) 0x07,
+            (byte) 0x43, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
+            (byte) 0x65, (byte) 0x73};
+    static final byte[] TYPE5_EXPECTED_BYTES = new byte[] {(byte) 0x82, (byte) 0x05,
+            (byte) 0x4A, (byte) 0x6F, (byte) 0x6E, (byte) 0x65, (byte) 0x73};
+
+
+    public static class Type1 extends Asn1VisibleString {
+        public Type1(String value) {
+            super(value);
+        }
+        public Type1() {
+            this(null);
+        }
+    }
+
+    public static class Type2 extends Asn1Tagging<Type1> {
+        public Type2(Type1 value) {
+            super(3, value, true, true);
+        }
+        public Type2() {
+            this(null);
+        }
+    }
+
+    public static class Type3 extends Asn1Tagging<Type2> {
+        public Type3(Type2 value) {
+            super(2, value, false, false);
+        }
+        public Type3() {
+            this(null);
+        }
+    }
+
+    public static class Type4 extends Asn1Tagging<Type3> {
+        public Type4(Type3 value) {
+            super(7, value, true, true);
+        }
+        public Type4() {
+            this(null);
+        }
+    }
+
+    public static class Type5 extends Asn1Tagging<Type2> {
+        public Type5(Type2 value) {
+            super(2, value, false, true);
+        }
+        public Type5() {
+            this(null);
+        }
+    }
+
+    @Test
+    public void testAsn1TaggingEncoding() throws IOException {
+        Type1 aType1 = new Type1(TEST_STRING);
+        Type2 aType2 = new Type2(aType1);
+        Type3 aType3 = new Type3(aType2);
+        Type4 aType4 = new Type4(aType3);
+        Type5 aType5 = new Type5(aType2);
+
+        assertThat(aType1.encode()).isEqualTo(TYPE1_EXPECTED_BYTES);
+        assertThat(aType2.encode()).isEqualTo(TYPE2_EXPECTED_BYTES);
+        assertThat(aType3.encode()).isEqualTo(TYPE3_EXPECTED_BYTES);
+        assertThat(aType4.encode()).isEqualTo(TYPE4_EXPECTED_BYTES);
+        assertThat(aType5.encode()).isEqualTo(TYPE5_EXPECTED_BYTES);
+    }
+
+    @Test
+    public void testAsn1TaggingDecoding() throws IOException {
+        Type1 aType1 = new Type1();
+        aType1.decode(TYPE1_EXPECTED_BYTES);
+        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
+
+        Type2 aType2 = new Type2();
+        aType2.decode(TYPE2_EXPECTED_BYTES);
+        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
+
+        Type3 aType3 = new Type3();
+        aType3.decode(TYPE3_EXPECTED_BYTES);
+        assertThat(aType3.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+
+        Type4 aType4 = new Type4();
+        aType4.decode(TYPE4_EXPECTED_BYTES);
+        assertThat(aType4.getValue().getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+
+        Type5 aType5 = new Type5();
+        aType5.decode(TYPE5_EXPECTED_BYTES);
+        assertThat(aType5.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+    }
+
+    @Test
+    public void testTaggingEncodingOption() throws IOException {
+        Type1 aType1 = new Type1(TEST_STRING);
+        Type2 aType2 = new Type2(aType1);
+        Type3 aType3 = new Type3(aType2);
+
+        assertThat(aType1.encode()).isEqualTo(TYPE1_EXPECTED_BYTES);
+        assertThat(TYPE2_EXPECTED_BYTES)
+                .isEqualTo(aType1.taggedEncode(TaggingOption.newImplicitAppSpecific(3))); // for Type2
+        assertThat(TYPE3_EXPECTED_BYTES)
+                .isEqualTo(aType2.taggedEncode(TaggingOption.newExplicitContextSpecific(2))); // for Type3
+        assertThat(TYPE4_EXPECTED_BYTES)
+                .isEqualTo(aType3.taggedEncode(TaggingOption.newImplicitAppSpecific(7))); // for Type4
+        assertThat(TYPE5_EXPECTED_BYTES)
+                .isEqualTo(aType2.taggedEncode(TaggingOption.newImplicitContextSpecific(2))); // for Type5
+    }
+
+    @Test
+    public void testTaggingDecodingOption() throws IOException {
+        Type1 aType1 = new Type1();
+        aType1.decode(TYPE1_EXPECTED_BYTES);
+        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
+
+        // for Type2
+        aType1 = new Type1();
+        aType1.taggedDecode(TYPE2_EXPECTED_BYTES, TaggingOption.newImplicitAppSpecific(3));
+        assertThat(aType1.getValue()).isEqualTo(TEST_STRING);
+
+        // for Type3
+        Type2 aType2 = new Type2();
+        aType2.taggedDecode(TYPE3_EXPECTED_BYTES, TaggingOption.newExplicitContextSpecific(2));
+        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
+
+        // for Type4
+        Type3 aType3 = new Type3();
+        aType3.taggedDecode(TYPE4_EXPECTED_BYTES, TaggingOption.newImplicitAppSpecific(7));
+        assertThat(aType3.getValue().getValue().getValue()).isEqualTo(TEST_STRING);
+
+        // for Type5
+        aType2 = new Type2();
+        aType2.taggedDecode(TYPE5_EXPECTED_BYTES, TaggingOption.newImplicitContextSpecific(2));
+        assertThat(aType2.getValue().getValue()).isEqualTo(TEST_STRING);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
deleted file mode 100644
index 22dd8a0..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Boolean.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Boolean;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1Boolean {
-
-    @Test
-    public void testEncoding() throws IOException {
-        testEncodingWith(true, "0x01 01 FF", true);
-        testEncodingWith(false, "0x01 01 00", true);
-    }
-
-    private void testEncodingWith(Boolean value, String expectedEncoding,
-                                  boolean isDer) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1Boolean aValue = new Asn1Boolean(value);
-        if (isDer) {
-            aValue.useDER();
-        } else {
-            aValue.useBER();
-        }
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws IOException {
-        testDecodingWith(true, "0x01 01 FF", true);
-        testDecodingWith(false, "0x01 01 7F", true);
-        testDecodingWith(true, "0x01 01 7F", false);
-        testDecodingWith(false, "0x01 01 00", true);
-    }
-
-    private void testDecodingWith(Boolean expectedValue, String content,
-                                  boolean isDer) throws IOException {
-        Asn1Boolean decoded = new Asn1Boolean();
-        if (isDer) {
-            decoded.useDER();
-        } else {
-            decoded.useBER();
-        }
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java
deleted file mode 100644
index ffa4a95..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Collection.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Boolean;
-import org.apache.kerby.asn1.type.Asn1IA5String;
-import org.apache.kerby.asn1.type.Asn1Sequence;
-import org.apache.kerby.asn1.type.Asn1String;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1Collection {
-    static final String TEST_STR = "Jones";
-    static final Boolean TEST_BOOL = true;
-    static final byte[] EXPECTED_BYTES = new byte[] {(byte) 0x30, (byte) 0x0A,
-            (byte) 0x16, (byte) 0x05, (byte) 0x4A, (byte) 0x6F, (byte) 0x6E,
-            (byte) 0x65, (byte) 0x73, (byte) 0x01, (byte) 0x01, (byte) 0xFF
-    };
-
-    @Test
-    public void testSequenceEncoding() throws IOException {
-        Asn1Sequence seq = new Asn1Sequence();
-        seq.addItem(new Asn1IA5String(TEST_STR));
-        seq.addItem(new Asn1Boolean(TEST_BOOL));
-
-        assertThat(seq.encode()).isEqualTo(EXPECTED_BYTES);
-    }
-
-    @Test
-    public void testSequenceDecoding() throws IOException {
-        Asn1Sequence seq = new Asn1Sequence();
-        seq.decode(EXPECTED_BYTES);
-        Asn1String field =
-            (Asn1String) seq.getValue().get(0);
-        assertThat(field.getValue()).isEqualTo(TEST_STR);
-
-        Asn1Boolean field2 = (Asn1Boolean) seq.getValue().get(1);
-        assertThat(field2.getValue()).isEqualTo(TEST_BOOL);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java
deleted file mode 100644
index e7b40be..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ConstructedOctetString.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1OctetString;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestAsn1ConstructedOctetString {
-
-    @Test
-    public void testDecoding() throws IOException {
-        byte[] data = TestUtil.readBytesFromTxtFile("/constructed-octet-string.txt");
-        Asn1OctetString octetString = new Asn1OctetString();
-        octetString.decode(data);
-        Asn1.dump(octetString);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java
deleted file mode 100644
index 04c0de3..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Dump.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.io.IOException;
-
-public class TestAsn1Dump {
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithPersonnelRecord() throws IOException {
-        try {
-            PersonnelRecord pr = TestData.createSamplePersonnel();
-            Asn1.dump(pr);
-
-            byte[] data = TestData.createSammplePersonnelEncodingData();
-            Asn1.parseAndDump(data);
-            Asn1.decodeAndDump(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithCompressedData() throws IOException {
-        String hexStr = TestUtil.readStringFromTxtFile("/compressed-data.txt");
-        try {
-            Asn1.parseAndDump(hexStr);
-            Asn1.decodeAndDump(hexStr);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithSignedData() throws IOException {
-        String hexStr = TestUtil.readStringFromTxtFile("/signed-data.txt");
-        try {
-            Asn1.parseAndDump(hexStr);
-            Asn1.decodeAndDump(hexStr);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    @org.junit.Ignore
-    public void testDumpWithDerData() throws IOException {
-        byte[] data = TestUtil.readBytesFromBinFile("/der-data.dat");
-        try {
-            Asn1.parseAndDump(data);
-            Asn1.decodeAndDump(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-
-    @Test
-    public void testDumpWithEmptyContainer() throws IOException {
-        byte[] data = TestUtil.readBytesFromTxtFile("/empty-container.txt");
-        try {
-            Asn1.parseAndDump(data);
-            Asn1.decodeAndDump(data);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Assert.fail();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java
deleted file mode 100644
index 8300f6e..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Flags.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Flags;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class TestAsn1Flags {
-  
-  public static final int FLAG_0 = 0b00000000000000000000000000000001;
-  public static final int FLAG_1 = 0b00000000000000000000000000000010;
-  public static final int FLAG_2 = 0x00000004;
-  public static final int FLAG_3 = 0x00000008;
-  public static final int FLAG_4 = 16;
-  public static final int FLAG_5 = 32;
-  
-  public enum TestEnum implements EnumType {
-    FLAG_0(0x00000001),
-    FLAG_1(0x00000002),
-    FLAG_2(0x00000004),
-    FLAG_3(0x00000008),
-    FLAG_4(0x00000010),
-    FLAG_5(0x00000020);
-    
-    private int value;
-    
-    private TestEnum(int value) {
-      this.value = value;
-    }
-
-    @Override
-    public int getValue() {
-      return value;
-    }
-
-
-    @Override
-    public String getName() {
-      return name();
-    }
-  }
-  
-  @Rule
-  public ExpectedException thrown = ExpectedException.none();
-  
-  private Asn1Flags flags;
-  
-  @Before
-  public void setUp() {
-    flags = new Asn1Flags(FLAG_5 | FLAG_3 | FLAG_1);
-  }
-
-  @Test
-  public void testToValue() throws IOException {
-    byte[] value = {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
-    flags.setValue(value);
-    assertEquals(0b11011110101011011011111011101111, flags.getFlags());
-  }
-
-  @Test
-  public void testFlags() {
-    flags = new Asn1Flags();
-    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
-  }
-
-  @Test
-  public void testFlagsInt() {
-    flags = new Asn1Flags(FLAG_4 | FLAG_2 | FLAG_0);
-    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
-  }
-
-  @Test
-  public void testSetFlags() {
-    flags.setFlags(FLAG_4 | FLAG_2 | FLAG_0);
-    assertEquals(0b00000000000000000000000000010101, flags.getFlags());
-  }
-
-  @Test
-  public void testGetFlags() {
-    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
-  }
-
-  @Test
-  public void testIsFlagSetInt() {
-    assertTrue(flags.isFlagSet(FLAG_5));
-    assertFalse(flags.isFlagSet(FLAG_4));
-  }
-
-  @Test
-  public void testSetFlagInt() {
-    flags.setFlag(FLAG_4);
-    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
-  }
-
-  @Test
-  public void testClearFlagInt() {
-    flags.clearFlag(FLAG_3);
-    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
-  }
-
-  @Test
-  public void testClear() {
-    flags.clear();
-    assertEquals(0b00000000000000000000000000000000, flags.getFlags());
-  }
-
-  @Test
-  public void testIsFlagSetEnum() {
-    assertTrue(flags.isFlagSet(TestEnum.FLAG_5));
-    assertFalse(flags.isFlagSet(TestEnum.FLAG_4));
-  }
-
-  @Test
-  public void testSetFlagEnum() {
-    flags.setFlag(TestEnum.FLAG_4);
-    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
-  }
-
-  @Test
-  public void testSetFlagEnumBoolean() {
-    flags.setFlag(TestEnum.FLAG_4, true);
-    assertEquals(0b00000000000000000000000000111010, flags.getFlags());
-    flags.setFlag(TestEnum.FLAG_4, false);
-    assertEquals(0b00000000000000000000000000101010, flags.getFlags());
-  }
-
-  @Test
-  public void testClearFlagEnum() {
-    flags.clearFlag(TestEnum.FLAG_3);
-    assertEquals(0b00000000000000000000000000100010, flags.getFlags());
-  }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
deleted file mode 100644
index 16b5852..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1Integer.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1Integer;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1Integer {
-
-    @Test
-    public void testEncoding() throws IOException {
-        testEncodingWith(0, "0x02 01 00");
-        testEncodingWith(1, "0x02 01 01");
-        testEncodingWith(2, "0x02 01 02");
-        testEncodingWith(127, "0x02 01 7F");
-        testEncodingWith(128, "0x02 02 00 80");
-        testEncodingWith(-1, "0x02 01 FF");
-        testEncodingWith(-128, "0x02 01 80");
-        testEncodingWith(-32768, "0x02 02 80 00");
-        testEncodingWith(1234567890, "0x02 04 49 96 02 D2");
-    }
-
-    private void testEncodingWith(int value, String expectedEncoding) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1Integer aValue = new Asn1Integer(value);
-        aValue.useDER();
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws IOException {
-        testDecodingWith(0, "0x02 01 00");
-        testDecodingWith(1, "0x02 01 01");
-        testDecodingWith(2, "0x02 01 02");
-        testDecodingWith(127, "0x02 01 7F");
-        testDecodingWith(128, "0x02 02 00 80");
-        testDecodingWith(-1, "0x02 01 FF");
-        testDecodingWith(-128, "0x02 01 80");
-        testDecodingWith(-32768, "0x02 02 80 00");
-        testDecodingWith(1234567890, "0x02 04 49 96 02 D2");
-    }
-
-    private void testDecodingWith(int expectedValue, String content) throws IOException {
-        Asn1Integer decoded = new Asn1Integer();
-        decoded.useDER();
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue().intValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
deleted file mode 100644
index b6b400f..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1ObjectIdentifier.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1ObjectIdentifier {
-
-    @Test
-    public void testEncoding() throws Exception {
-        /**
-         * Cryptography for Developers -> ASN.1 UTCTIME Type
-         * Applying this to the MD5 OID, we first transform the dotted decimal form into the
-         * array of words.Thus, 1.2.840.113549.2.5 becomes {42, 840, 113549, 2, 5}, and then further
-         * 404_CRYPTO_02.qxd 10/27/06 3:40 PM Page 36split into seven-bit digits with the proper most significant bits as
-         * {{0x2A}, {0x86, 0x48},{0x86, 0xF7, 0x0D}, {0x02}, {0x05}}.Therefore, the full encoding for MD5 is 0x06 08 2A
-         * 86 48 86 F7 0D 02 05.
-         */
-        testEncodingWith("1.2.840.113549.2.5",
-                "0x06 08 2A 86 48 86 F7 0D 02 05");
-    }
-
-    private void testEncodingWith(String oid, String expectedEncoding) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1ObjectIdentifier aValue = new Asn1ObjectIdentifier(oid);
-        aValue.useDER();
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws Exception {
-        testDecodingWith("1.2.840.113549.2.5",
-                "0x06 08 2A 86 48 86 F7 0D 02 05");
-    }
-
-    private void testDecodingWith(String expectedValue, String content) throws IOException {
-        Asn1ObjectIdentifier decoded = new Asn1ObjectIdentifier();
-        decoded.useDER();
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
deleted file mode 100644
index 7cfb377..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestAsn1UtcTime.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.type.Asn1UtcTime;
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.SimpleTimeZone;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class TestAsn1UtcTime {
-
-    @Test
-    public void testEncoding() throws Exception {
-        /**
-         * Cryptography for Developers -> ASN.1 UTCTIME Type
-         * the encoding of July 4, 2003 at 11:33 and 28 seconds would be
-         “030704113328Z” and be encoded as 0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A.
-         */
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-        String dateInString = "2003-07-04 11:33:28";
-        Date date = sdf.parse(dateInString);
-        testEncodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
-    }
-
-    private void testEncodingWith(Date value, String expectedEncoding) throws IOException {
-        byte[] expected = HexUtil.hex2bytesFriendly(expectedEncoding);
-        Asn1UtcTime aValue = new Asn1UtcTime(value);
-        aValue.useDER();
-        byte[] encodingBytes = aValue.encode();
-        assertThat(encodingBytes).isEqualTo(expected);
-    }
-
-    @Test
-    public void testDecoding() throws Exception {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        String dateInString = "2003-07-04 11:33:28";
-        sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-        Date date = sdf.parse(dateInString);
-        testDecodingWith(date, "0x17 0D 30 33 30 37 30 34 31 31 33 33 32 38 5A");
-    }
-
-    private void testDecodingWith(Date expectedValue, String content) throws IOException {
-        Asn1UtcTime decoded = new Asn1UtcTime();
-        decoded.useDER();
-        decoded.decode(HexUtil.hex2bytesFriendly(content));
-        assertThat(decoded.getValue()).isEqualTo(expectedValue);
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java
deleted file mode 100644
index 875288a..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestData.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-
-public class TestData {
-
-    public static PersonnelRecord createSamplePersonnel() {
-        PersonnelRecord pr = new PersonnelRecord();
-
-        pr.setName(new PersonnelRecord.Name("John", "P", "Smith"));
-
-        pr.setTitle("Director");
-
-        pr.setEmployeeNumber(new PersonnelRecord.EmployeeNumber(51));
-
-        pr.setDateOfHire(new PersonnelRecord.Date("19710917"));
-
-        pr.setNameOfSpouse(new PersonnelRecord.Name("Mary", "T", "Smith"));
-
-        PersonnelRecord.ChildInformation child1 = new PersonnelRecord.ChildInformation();
-        child1.setName(new PersonnelRecord.Name("Ralph", "T", "Smith"));
-        child1.setDateOfBirth(new PersonnelRecord.Date("19571111"));
-
-        PersonnelRecord.ChildInformation child2 = new PersonnelRecord.ChildInformation();
-        child2.setName(new PersonnelRecord.Name("Susan", "B", "Jones"));
-        child2.setDateOfBirth(new PersonnelRecord.Date("19590717"));
-
-        pr.setChildren(new PersonnelRecord.Children(child1, child2));
-
-        return pr;
-    }
-
-    public static byte[] createSammplePersonnelEncodingData() {
-        class BufferOutput {
-            ByteBuffer buffer;
-
-            void put(byte ... bytes) {
-                buffer.put(bytes);
-            }
-
-            void put(String s) {
-                byte[] bytes = s.getBytes(StandardCharsets.US_ASCII);
-                buffer.put(bytes);
-            }
-
-            public byte[] output() {
-                int len = (int) 0x85 + 3;
-                buffer = ByteBuffer.allocate(len);
-
-                // personnel record
-                put((byte) 0x60, (byte) 0x81, (byte) 0x85);
-
-                // -name
-                put((byte) 0x61, (byte) 0x10);
-                put((byte) 0x1A, (byte) 0x04); put("John");
-                put((byte) 0x1A, (byte) 0x01); put("P");
-                put((byte) 0x1A, (byte) 0x05); put("Smith");
-
-                //-title
-                put((byte) 0xA0, (byte) 0x0A);
-                put((byte) 0x1A, (byte) 0x08); put("Director");
-
-                //-employee number
-                put((byte) 0x42, (byte) 0x01, (byte) 0x33);
-
-                //-date of hire
-                put((byte) 0xA1, (byte) 0x0A);
-                put((byte) 0x43, (byte) 0x08); put("19710917");
-
-                //-spouse
-                put((byte) 0xA2, (byte) 0x12);
-                put((byte) 0x61, (byte) 0x10);
-                put((byte) 0x1A, (byte) 0x04); put("Mary");
-                put((byte) 0x1A, (byte) 0x01); put("T");
-                put((byte) 0x1A, (byte) 0x05); put("Smith");
-
-                //-children
-                put((byte) 0xA3, (byte) 0x42);
-                //--child 1
-                put((byte) 0x31, (byte) 0x1F);
-                //---name
-                put((byte) 0x61, (byte) 0x11);
-                put((byte) 0x1A, (byte) 0x05); put("Ralph");
-                put((byte) 0x1A, (byte) 0x01); put("T");
-                put((byte) 0x1A, (byte) 0x05); put("Smith");
-                //-date of birth
-                put((byte) 0xA0, (byte) 0x0A);
-                put((byte) 0x43, (byte) 0x08); put("19571111");
-                //--child 2
-                put((byte) 0x31, (byte) 0x1F);
-                //---name
-                put((byte) 0x61, (byte) 0x11);
-                put((byte) 0x1A, (byte) 0x05); put("Susan");
-                put((byte) 0x1A, (byte) 0x01); put("B");
-                put((byte) 0x1A, (byte) 0x05); put("Jones");
-                //-date of birth
-                put((byte) 0xA0, (byte) 0x0A);
-                put((byte) 0x43, (byte) 0x08); put("19590717");
-
-                return buffer.array();
-            }
-        }
-
-        BufferOutput buffer = new BufferOutput();
-        return buffer.output();
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d06becfd/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java b/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java
deleted file mode 100644
index 4dcb5be..0000000
--- a/kerby-asn1/src/test/java/org/apache/kerby/asn1/TestPersonnelRecord.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- *  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.kerby.asn1;
-
-import org.apache.kerby.asn1.util.HexUtil;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * Ref. X.690-0207(http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf),
- * Annex A, A.1 ASN.1 description of the record structure
- */
-public class TestPersonnelRecord {
-
-    static boolean verbose = false;
-
-    @Test
-    public void testEncoding() throws IOException {
-        PersonnelRecord pr = TestData.createSamplePersonnel();
-
-        if (verbose) {
-            System.out.println("Name:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getName().encode()));
-
-            System.out.println("DateOfHire:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getDateOfHire().encode()));
-
-            System.out.println("SpouseName:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getNameOfSpouse().encode()));
-
-            System.out.println("Child1:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(0).encode()));
-
-            System.out.println("Child2:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().getElements().get(1).encode()));
-
-            System.out.println("Children:");
-            System.out.println(HexUtil.bytesToHexFriendly(pr.getChildren().encode()));
-        }
-
-        byte[] data = TestData.createSammplePersonnelEncodingData();
-        byte[] encoded = pr.encode();
-
-        if (verbose) {
-            System.out.println("ExpectedData:");
-            System.out.println(HexUtil.bytesToHexFriendly(data));
-
-            System.out.println("Encoded:");
-            System.out.println(HexUtil.bytesToHexFriendly(encoded));
-        }
-
-        assertThat(encoded).isEqualTo(data);
-    }
-
-    @Test
-    public void testDecoding() throws IOException {
-        PersonnelRecord expected = TestData.createSamplePersonnel();
-        byte[] data = TestData.createSammplePersonnelEncodingData();
-        Asn1.parseAndDump(data);
-        PersonnelRecord decoded = new PersonnelRecord();
-        decoded.decode(data);
-        Asn1.dump(decoded);
-
-        assertThat(decoded.getName().getGivenName())
-                .isEqualTo(expected.getName().getGivenName());
-        assertThat(decoded.getName().getInitial())
-                .isEqualTo(expected.getName().getInitial());
-        assertThat(decoded.getName().getFamilyName())
-                .isEqualTo(expected.getName().getFamilyName());
-        assertThat(decoded.getDateOfHire().getValue().getValue())
-                .isEqualTo(expected.getDateOfHire().getValue().getValue());
-        assertThat(decoded.getTitle())
-                .isEqualTo(expected.getTitle());
-        assertThat(decoded.getEmployeeNumber().getValue().getValue())
-                .isEqualTo(expected.getEmployeeNumber().getValue().getValue());
-        assertThat(decoded.getNameOfSpouse().getGivenName())
-                .isEqualTo(expected.getNameOfSpouse().getGivenName());
-        assertThat(decoded.getNameOfSpouse().getInitial())
-                .isEqualTo(expected.getNameOfSpouse().getInitial());
-        assertThat(decoded.getNameOfSpouse().getFamilyName())
-                .isEqualTo(expected.getNameOfSpouse().getFamilyName());
-        assertThat(decoded.getChildren().getElements().size())
-            .isEqualTo(expected.getChildren().getElements().size());
-        assertThat(decoded.getChildren().getElements().get(0).getName().getGivenName())
-                .isEqualTo(expected.getChildren().getElements().get(0).getName().getGivenName());
-        assertThat(decoded.getChildren().getElements().get(0).getName().getInitial())
-                .isEqualTo(expected.getChildren().getElements().get(0).getName().getInitial());
-        assertThat(decoded.getChildren().getElements().get(0).getName().getFamilyName())
-                .isEqualTo(expected.getChildren().getElements().get(0).getName().getFamilyName());
-        assertThat(decoded.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue())
-                .isEqualTo(expected.getChildren().getElements().get(0).getDateOfBirth().getValue().getValue());
-        assertThat(decoded.getChildren().getElements().get(1).getName().getGivenName())
-                .isEqualTo(expected.getChildren().getElements().get(1).getName().getGivenName());
-        assertThat(decoded.getChildren().getElements().get(1).getName().getInitial())
-                .isEqualTo(expected.getChildren().getElements().get(1).getName().getInitial());
-        assertThat(decoded.getChildren().getElements().get(1).getName().getFamilyName())
-                .isEqualTo(expected.getChildren().getElements().get(1).getName().getFamilyName());
-        assertThat(decoded.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue())
-                .isEqualTo(expected.getChildren().getElements().get(1).getDateOfBirth().getValue().getValue());
-    }
-}


Mime
View raw message