Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D16E18CF5 for ; Thu, 30 Jul 2015 06:24:12 +0000 (UTC) Received: (qmail 77851 invoked by uid 500); 30 Jul 2015 06:24:10 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 77704 invoked by uid 500); 30 Jul 2015 06:24:10 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 76712 invoked by uid 99); 30 Jul 2015 06:24:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jul 2015 06:24:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 68091E683E; Thu, 30 Jul 2015 06:24:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: plusplusjiajia@apache.org To: commits@directory.apache.org Date: Thu, 30 Jul 2015 06:24:45 -0000 Message-Id: In-Reply-To: <4712c8cab9e241bbad3c702a6ba0637e@git.apache.org> References: <4712c8cab9e241bbad3c702a6ba0637e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [38/50] [abbrv] directory-kerby git commit: DIRKRB-384 Refactor backend unit tests in order to share some codes for benchmark tests DIRKRB-384 Refactor backend unit tests in order to share some codes for benchmark tests Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/3f0a6b6c Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/3f0a6b6c Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/3f0a6b6c Branch: refs/heads/pkinit-support Commit: 3f0a6b6cbaa54b97b7e314ae6ae794b1f036f11d Parents: 516cee1 Author: drankye Authored: Wed Jul 22 06:01:26 2015 +0800 Committer: Drankye Committed: Wed Jul 22 06:01:26 2015 +0800 ---------------------------------------------------------------------- kerby-backend/json-backend/pom.xml | 7 - kerby-backend/ldap-backend/pom.xml | 7 - kerby-backend/mavibot-backend/pom.xml | 1 - .../org/apache/kerby/MavibotBackendTest.java | 3 +- kerby-backend/zookeeper-backend/pom.xml | 1 - kerby-kerb/kerb-identity-test/pom.xml | 28 ++- .../kerb/identity/backend/BackendTest.java | 138 ++++++++++++++ .../kerb/identity/backend/BackendTestBase.java | 73 ++++++++ .../kerb/identity/backend/BackendTestUtil.java | 88 +++++++++ .../kerb/identity/backend/BackendTest.java | 183 ------------------- .../kerb/identity/backend/BackendTestBase.java | 73 -------- 11 files changed, 313 insertions(+), 289 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/json-backend/pom.xml ---------------------------------------------------------------------- diff --git a/kerby-backend/json-backend/pom.xml b/kerby-backend/json-backend/pom.xml index d0150e3..92512de 100644 --- a/kerby-backend/json-backend/pom.xml +++ b/kerby-backend/json-backend/pom.xml @@ -41,7 +41,6 @@ org.apache.kerby kerb-identity-test ${project.version} - test-jar test @@ -49,11 +48,5 @@ gson 2.3.1 - - junit - junit - 4.12 - test - http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/ldap-backend/pom.xml ---------------------------------------------------------------------- diff --git a/kerby-backend/ldap-backend/pom.xml b/kerby-backend/ldap-backend/pom.xml index 7346471..b4cbf74 100644 --- a/kerby-backend/ldap-backend/pom.xml +++ b/kerby-backend/ldap-backend/pom.xml @@ -90,13 +90,6 @@ org.apache.kerby kerb-identity-test ${project.version} - test-jar - test - - - junit - junit - 4.12 test http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/mavibot-backend/pom.xml ---------------------------------------------------------------------- diff --git a/kerby-backend/mavibot-backend/pom.xml b/kerby-backend/mavibot-backend/pom.xml index cc5dfa8..c9a1841 100644 --- a/kerby-backend/mavibot-backend/pom.xml +++ b/kerby-backend/mavibot-backend/pom.xml @@ -39,7 +39,6 @@ org.apache.kerby kerb-identity-test ${project.version} - test-jar test http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java ---------------------------------------------------------------------- diff --git a/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java index cd81cf9..6fa17dc 100644 --- a/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java +++ b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java @@ -23,6 +23,7 @@ package org.apache.kerby; import org.apache.kerby.kerberos.kerb.KrbException; import org.apache.kerby.kerberos.kerb.identity.KrbIdentity; import org.apache.kerby.kerberos.kerb.identity.backend.BackendTestBase; +import org.apache.kerby.kerberos.kerb.identity.backend.BackendTestUtil; import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -61,7 +62,7 @@ public class MavibotBackendTest extends BackendTestBase { // overriding this cause MavibotBackend doesn't support range search @Override protected void testGetIdentities(IdentityBackend backend) throws KrbException { - KrbIdentity[] identities = createManyIdentities(); + KrbIdentity[] identities = BackendTestUtil.createManyIdentities(); for (KrbIdentity identity : identities) { backend.addIdentity(identity); http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-backend/zookeeper-backend/pom.xml ---------------------------------------------------------------------- diff --git a/kerby-backend/zookeeper-backend/pom.xml b/kerby-backend/zookeeper-backend/pom.xml index 3a0fb75..e3488b2 100644 --- a/kerby-backend/zookeeper-backend/pom.xml +++ b/kerby-backend/zookeeper-backend/pom.xml @@ -50,7 +50,6 @@ org.apache.kerby kerb-identity-test ${project.version} - test-jar test http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/pom.xml ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-identity-test/pom.xml b/kerby-kerb/kerb-identity-test/pom.xml index a86d027..8224b40 100644 --- a/kerby-kerb/kerb-identity-test/pom.xml +++ b/kerby-kerb/kerb-identity-test/pom.xml @@ -52,21 +52,17 @@ kerb-identity ${project.version} + + + junit + junit + ${junit.version} + + + org.assertj + assertj-core + ${assertj.version} + - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - - - + http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java new file mode 100644 index 0000000..ccb738c --- /dev/null +++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java @@ -0,0 +1,138 @@ +/** + * 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.kerberos.kerb.identity.backend; + +import org.apache.kerby.kerberos.kerb.KrbException; +import org.apache.kerby.kerberos.kerb.identity.KrbIdentity; +import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey; +import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import static org.apache.kerby.kerberos.kerb.identity.backend.BackendTestUtil.TEST_PRINCIPAL; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * A common backend test utility + */ +public abstract class BackendTest { + + protected void testGet(IdentityBackend backend) throws KrbException { + KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL); + backend.addIdentity(kid); + // clear the identity cache. + backend.release(); + + KrbIdentity identity = backend.getIdentity(TEST_PRINCIPAL); + assertThat(identity).isNotNull(); + assertThat(identity.getExpireTime()).isEqualTo(kid.getExpireTime()); + assertThat(identity.isDisabled()).isEqualTo(kid.isDisabled()); + assertThat(identity.getKeyVersion()).isEqualTo(kid.getKeyVersion()); + for (EncryptionKey expectedKey : kid.getKeys().values()) { + EncryptionType actualType = EncryptionType.fromValue(expectedKey.getKeyType().getValue()); + EncryptionKey actualKey = identity.getKey(actualType); + assertThat(actualKey.getKeyType().getValue()).isEqualTo(expectedKey.getKeyType().getValue()); + assertThat(actualKey.getKeyData()).isEqualTo(expectedKey.getKeyData()); + assertThat(actualKey.getKvno()).isEqualTo(expectedKey.getKvno()); + } + + //tearDown + backend.deleteIdentity(TEST_PRINCIPAL); + } + + protected void testStore(IdentityBackend backend) throws KrbException { + KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL); + backend.addIdentity(kid); + // clear the identity cache. + backend.release(); + KrbIdentity kid2 = backend.getIdentity(TEST_PRINCIPAL); + + assertThat(kid).isEqualTo(kid2); + + //tearDown + backend.deleteIdentity(TEST_PRINCIPAL); + } + + protected void testUpdate(IdentityBackend backend) throws KrbException { + KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL); + backend.addIdentity(kid); + + kid.setDisabled(true); + backend.updateIdentity(kid); + + // clear the identity cache. + backend.release(); + assertThat(backend.getIdentity(TEST_PRINCIPAL)).isEqualTo(kid); + + //tearDown + backend.deleteIdentity(TEST_PRINCIPAL); + } + + protected void testDelete(IdentityBackend backend) throws KrbException { + KrbIdentity kid = BackendTestUtil.createOneIdentity(TEST_PRINCIPAL); + backend.addIdentity(kid); + // clear the identity cache. + backend.release(); + + assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNotNull(); + + backend.deleteIdentity(TEST_PRINCIPAL); + assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNull(); + } + + protected void testGetIdentities(IdentityBackend backend) throws KrbException { + KrbIdentity[] identities = BackendTestUtil.createManyIdentities(); + + for (KrbIdentity identity : identities) { + backend.addIdentity(identity); + } + + // clear the identity cache. + backend.release(); + + Iterable principals = backend.getIdentities(); + Iterator iterator = principals.iterator(); + List principalList = new LinkedList<>(); + while (iterator.hasNext()) { + principalList.add(iterator.next()); + } + assertThat(principalList).hasSize(identities.length) + .contains(identities[0].getPrincipalName()) + .contains(identities[1].getPrincipalName()) + .contains(identities[2].getPrincipalName()) + .contains(identities[3].getPrincipalName()) + .contains(identities[4].getPrincipalName()); + + //tearDown + for (KrbIdentity identity : identities) { + backend.deleteIdentity(identity.getPrincipalName()); + } + } + + protected void cleanIdentities(IdentityBackend backend) throws KrbException { + Iterable identities = backend.getIdentities(); + Iterator iterator = identities.iterator(); + while (iterator.hasNext()) { + backend.deleteIdentity(iterator.next()); + } + } +} http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java new file mode 100644 index 0000000..bb542a0 --- /dev/null +++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java @@ -0,0 +1,73 @@ +/** + * 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.kerberos.kerb.identity.backend; + +import org.apache.kerby.kerberos.kerb.KrbException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Json backend test + */ +public abstract class BackendTestBase extends BackendTest { + protected static IdentityBackend backend; + + /** + * Create and prepare an identity backend for the tests. Must override. + */ + @BeforeClass + public static void setup() throws Exception { + //backend = prepareBackend(); + } + + @Test + public void testGet() throws KrbException { + super.testGet(backend); + } + + @Test + public void testStore() throws KrbException { + super.testStore(backend); + } + + @Test + public void testUpdate() throws KrbException { + testUpdate(backend); + } + + @Test + public void testDelete() throws KrbException { + testDelete(backend); + } + + @Test + public void testGetIdentities() throws KrbException { + testGetIdentities(backend); + } + + @AfterClass + public static void tearDown() throws KrbException { + if (backend != null) { + backend.stop(); + backend.release(); + } + } +} http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java new file mode 100644 index 0000000..843e3ee --- /dev/null +++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestUtil.java @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.kerby.kerberos.kerb.identity.backend; + +import org.apache.kerby.kerberos.kerb.KrbException; +import org.apache.kerby.kerberos.kerb.common.EncryptionUtil; +import org.apache.kerby.kerberos.kerb.identity.KrbIdentity; +import org.apache.kerby.kerberos.kerb.spec.KerberosTime; +import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey; +import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * A common backend test utility + */ +public final class BackendTestUtil { + + static final String TEST_PRINCIPAL_PREFIX = "test"; + static final String TEST_REALM = "EXAMPLE.COM"; + + public static final String TEST_PRINCIPAL = TEST_PRINCIPAL_PREFIX + "@" + TEST_REALM; + + static final EncryptionType[] ENC_TYPES = new EncryptionType[]{ + EncryptionType.AES128_CTS, + EncryptionType.DES3_CBC_SHA1_KD + }; + + public static KrbIdentity[] createManyIdentities() throws KrbException { + List results = createManyIdentities(20); + return results.toArray(new KrbIdentity[results.size()]); + } + + public static List createManyIdentities( + int count) throws KrbException { + List results = new ArrayList<>(count); + + for (int i = 0; i < count; ++i) { + String tmp = TEST_PRINCIPAL_PREFIX + i + "@" + TEST_REALM; + results.add(createOneIdentity(tmp)); + } + + return results; + } + + public static KrbIdentity createOneIdentity() throws KrbException { + return createOneIdentity(TEST_PRINCIPAL); + } + + public static KrbIdentity createOneIdentity(String principal) throws KrbException { + KrbIdentity kid = new KrbIdentity(principal); + kid.setCreatedTime(KerberosTime.now()); + kid.setExpireTime(KerberosTime.now()); + kid.setDisabled(false); + kid.setKeyVersion(1); + kid.setLocked(false); + kid.addKeys(generateKeys()); + + return kid; + } + + public static List generateKeys() throws KrbException { + return EncryptionUtil.generateKeys(getEncryptionTypes()); + } + + public static List getEncryptionTypes() { + return Arrays.asList(ENC_TYPES); + } +} http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java b/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java deleted file mode 100644 index dd3c2b6..0000000 --- a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java +++ /dev/null @@ -1,183 +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.kerberos.kerb.identity.backend; - -import org.apache.kerby.kerberos.kerb.KrbException; -import org.apache.kerby.kerberos.kerb.common.EncryptionUtil; -import org.apache.kerby.kerberos.kerb.identity.KrbIdentity; -import org.apache.kerby.kerberos.kerb.spec.KerberosTime; -import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey; -import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * A common backend test utility - */ -public abstract class BackendTest { - - static final String TEST_PRINCIPAL = "test@EXAMPLE.COM"; - - static final EncryptionType[] ENC_TYPES = new EncryptionType[]{ - EncryptionType.AES128_CTS, - EncryptionType.DES3_CBC_SHA1_KD - }; - - protected void testGet(IdentityBackend backend) throws KrbException { - KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL); - backend.addIdentity(kid); - // clear the identity cache. - backend.release(); - - KrbIdentity identity = backend.getIdentity(TEST_PRINCIPAL); - assertThat(identity).isNotNull(); - assertThat(identity.getExpireTime()).isEqualTo(kid.getExpireTime()); - assertThat(identity.isDisabled()).isEqualTo(kid.isDisabled()); - assertThat(identity.getKeyVersion()).isEqualTo(kid.getKeyVersion()); - for (EncryptionKey expectedKey : kid.getKeys().values()) { - EncryptionType actualType = EncryptionType.fromValue(expectedKey.getKeyType().getValue()); - EncryptionKey actualKey = identity.getKey(actualType); - assertThat(actualKey.getKeyType().getValue()).isEqualTo(expectedKey.getKeyType().getValue()); - assertThat(actualKey.getKeyData()).isEqualTo(expectedKey.getKeyData()); - assertThat(actualKey.getKvno()).isEqualTo(expectedKey.getKvno()); - } - - //tearDown - backend.deleteIdentity(TEST_PRINCIPAL); - } - - protected void testStore(IdentityBackend backend) throws KrbException { - KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL); - backend.addIdentity(kid); - // clear the identity cache. - backend.release(); - KrbIdentity kid2 = backend.getIdentity(TEST_PRINCIPAL); - - assertThat(kid).isEqualTo(kid2); - - //tearDown - backend.deleteIdentity(TEST_PRINCIPAL); - } - - protected void testUpdate(IdentityBackend backend) throws KrbException { - KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL); - backend.addIdentity(kid); - - kid.setDisabled(true); - backend.updateIdentity(kid); - - // clear the identity cache. - backend.release(); - assertThat(backend.getIdentity(TEST_PRINCIPAL)).isEqualTo(kid); - - //tearDown - backend.deleteIdentity(TEST_PRINCIPAL); - } - - protected void testDelete(IdentityBackend backend) throws KrbException { - KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL); - backend.addIdentity(kid); - // clear the identity cache. - backend.release(); - - assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNotNull(); - - backend.deleteIdentity(TEST_PRINCIPAL); - assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNull(); - } - - protected void testGetIdentities(IdentityBackend backend) throws KrbException { - KrbIdentity[] identities = createManyIdentities(); - - for (KrbIdentity identity : identities) { - backend.addIdentity(identity); - } - - // clear the identity cache. - backend.release(); - - Iterable principals = backend.getIdentities(); - Iterator iterator = principals.iterator(); - List principalList = new LinkedList<>(); - while (iterator.hasNext()) { - principalList.add(iterator.next()); - } - assertThat(principalList).hasSize(identities.length) - .contains(identities[0].getPrincipalName()) - .contains(identities[1].getPrincipalName()) - .contains(identities[2].getPrincipalName()) - .contains(identities[3].getPrincipalName()) - .contains(identities[4].getPrincipalName()); - - //tearDown - for (KrbIdentity identity : identities) { - backend.deleteIdentity(identity.getPrincipalName()); - } - } - - protected KrbIdentity[] createManyIdentities() { - return new KrbIdentity[] { - createOneIdentity("test1@EXAMPLE.COM"), - createOneIdentity("test2@EXAMPLE.COM"), - createOneIdentity("test3@EXAMPLE.COM"), - createOneIdentity("test4@EXAMPLE.COM"), - createOneIdentity("test5@EXAMPLE.COM"), - createOneIdentity("test6@EXAMPLE.COM"), - }; - } - protected KrbIdentity createOneIdentity(String principal) { - KrbIdentity kid = new KrbIdentity(principal); - kid.setCreatedTime(KerberosTime.now()); - kid.setExpireTime(new KerberosTime(253402300799900L)); - kid.setDisabled(false); - kid.setKeyVersion(1); - kid.setLocked(false); - kid.addKeys(generateKeys(kid.getPrincipalName())); - - return kid; - } - - protected List generateKeys(String principal) { - String passwd = UUID.randomUUID().toString(); - try { - return EncryptionUtil.generateKeys(principal, passwd, getEncryptionTypes()); - } catch (KrbException e) { - throw new RuntimeException("Failed to create keys", e); - } - } - - protected List getEncryptionTypes() { - return Arrays.asList(ENC_TYPES); - } - - protected void cleanIdentities(IdentityBackend backend) throws KrbException { - Iterable identities = backend.getIdentities(); - Iterator iterator = identities.iterator(); - while (iterator.hasNext()) { - backend.deleteIdentity(iterator.next()); - } - } -} http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/3f0a6b6c/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java ---------------------------------------------------------------------- diff --git a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java b/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java deleted file mode 100644 index bb542a0..0000000 --- a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTestBase.java +++ /dev/null @@ -1,73 +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.kerberos.kerb.identity.backend; - -import org.apache.kerby.kerberos.kerb.KrbException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Json backend test - */ -public abstract class BackendTestBase extends BackendTest { - protected static IdentityBackend backend; - - /** - * Create and prepare an identity backend for the tests. Must override. - */ - @BeforeClass - public static void setup() throws Exception { - //backend = prepareBackend(); - } - - @Test - public void testGet() throws KrbException { - super.testGet(backend); - } - - @Test - public void testStore() throws KrbException { - super.testStore(backend); - } - - @Test - public void testUpdate() throws KrbException { - testUpdate(backend); - } - - @Test - public void testDelete() throws KrbException { - testDelete(backend); - } - - @Test - public void testGetIdentities() throws KrbException { - testGetIdentities(backend); - } - - @AfterClass - public static void tearDown() throws KrbException { - if (backend != null) { - backend.stop(); - backend.release(); - } - } -}