This is an automated email from the ASF dual-hosted git repository. billyliu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 56e73333dc6f4b7e074826070c806209d0bdab79 Author: Jiatao Tao <245915...@qq.com> AuthorDate: Sun Feb 11 16:36:43 2018 +0800 minor, add ut for ValidateUtilTest. --- .../apache/kylin/rest/util/ValidateUtilTest.java | 36 ------ .../apache/kylin/rest/util/ValidateUtilTest.java | 134 +++++++++++++++++++++ 2 files changed, 134 insertions(+), 36 deletions(-) diff --git a/server-base/src/test/java/org/apache/kylin/rest/util/ValidateUtilTest.java b/server-base/src/test/java/org/apache/kylin/rest/util/ValidateUtilTest.java deleted file mode 100644 index 8f3b14c..0000000 --- a/server-base/src/test/java/org/apache/kylin/rest/util/ValidateUtilTest.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.kylin.rest.util; - -import org.junit.Assert; -import org.junit.Test; - -public class ValidateUtilTest { - - @Test - public void testIsAlphanumericUnderscore() { - Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("a")); - Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("123")); - Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("abc123")); - Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("abc123_")); - Assert.assertFalse(ValidateUtil.isAlphanumericUnderscore("abc@")); - Assert.assertFalse(ValidateUtil.isAlphanumericUnderscore("")); - Assert.assertFalse(ValidateUtil.isAlphanumericUnderscore(null)); - } -} diff --git a/server/src/test/java/org/apache/kylin/rest/util/ValidateUtilTest.java b/server/src/test/java/org/apache/kylin/rest/util/ValidateUtilTest.java new file mode 100644 index 0000000..62bd203 --- /dev/null +++ b/server/src/test/java/org/apache/kylin/rest/util/ValidateUtilTest.java @@ -0,0 +1,134 @@ +/* + * 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.kylin.rest.util; + +import static org.apache.kylin.metadata.MetadataConstants.TYPE_GROUP; +import static org.apache.kylin.metadata.MetadataConstants.TYPE_USER; + +import java.io.IOException; + +import org.apache.kylin.common.persistence.RootPersistentEntity; +import org.apache.kylin.rest.security.AclPermission; +import org.apache.kylin.rest.service.AccessService; +import org.apache.kylin.rest.service.ServiceTestBase; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import com.google.common.collect.Lists; + +public class ValidateUtilTest extends ServiceTestBase { + private final String PROJECT = "default"; + private final String NOT_EXISTS = "not_exists"; + private final String TABLE = "DEFAULT.TEST_KYLIN_FACT"; + + @Autowired + @Qualifier("validateUtil") + private ValidateUtil validateUtil; + + @Autowired + @Qualifier("accessService") + private AccessService accessService; + + @Test + public void testCheckIdentifiersExists() throws IOException { + validateUtil.checkIdentifiersExists("ADMIN", true); + validateUtil.checkIdentifiersExists("ROLE_ADMIN", false); + + try { + validateUtil.checkIdentifiersExists(NOT_EXISTS, true); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals("Operation failed, user:not_exists not exists, please add first.", e.getMessage()); + } + + try { + validateUtil.checkIdentifiersExists(NOT_EXISTS, false); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals("Operation failed, group:not_exists not exists, please add first.", e.getMessage()); + } + } + + @Test + public void testGetAndValidateIdentifiers() throws IOException { + RootPersistentEntity ae = accessService.getAclEntity("ProjectInstance", "1eaca32a-a33e-4b69-83dd-0bb8b1f8c91b"); + accessService.init(ae, AclPermission.ADMINISTRATION); + accessService.grant(ae, AclPermission.ADMINISTRATION, accessService.getSid("u1", true)); + accessService.grant(ae, AclPermission.ADMINISTRATION, accessService.getSid("g1", false)); + + Assert.assertEquals(Lists.newArrayList("ADMIN", "u1"), + Lists.newArrayList(validateUtil.getAllIdentifiersInPrj(PROJECT, TYPE_USER))); + Assert.assertEquals(Lists.newArrayList("g1"), + Lists.newArrayList(validateUtil.getAllIdentifiersInPrj(PROJECT, TYPE_GROUP))); + + validateUtil.validateIdentifiers(PROJECT, "u1", TYPE_USER); + try { + validateUtil.validateIdentifiers(PROJECT, NOT_EXISTS, TYPE_USER); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals("Operation failed, user:not_exists not exists in project.", e.getMessage()); + } + } + + @Test + public void testValidateTable() throws IOException { + validateUtil.validateTable(PROJECT, TABLE); + try { + validateUtil.validateTable(PROJECT, NOT_EXISTS); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals("Operation failed, table:not_exists not exists", e.getMessage()); + } + } + + @Test + public void testValidateColumns() throws IOException { + validateUtil.validateColumn(PROJECT, TABLE, Lists.newArrayList("TRANS_ID")); + try { + validateUtil.validateColumn(PROJECT, TABLE, Lists.newArrayList(NOT_EXISTS)); + Assert.fail(); + } catch (Exception e) { + Assert.assertEquals("Operation failed, column:not_exists not exists", e.getMessage()); + } + } + + @Test + public void testValidateArgs() { + validateUtil.validateArgs(PROJECT); + try { + validateUtil.validateArgs(""); + Assert.fail(); + } catch (Exception e) { + Assert.assertTrue(e instanceof IllegalStateException); + } + } + + @Test + public void testIsAlphanumericUnderscore() { + Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("a")); + Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("123")); + Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("abc123")); + Assert.assertTrue(ValidateUtil.isAlphanumericUnderscore("abc123_")); + Assert.assertFalse(ValidateUtil.isAlphanumericUnderscore("abc@")); + Assert.assertFalse(ValidateUtil.isAlphanumericUnderscore("")); + Assert.assertFalse(ValidateUtil.isAlphanumericUnderscore(null)); + } +} -- To stop receiving notification emails like this one, please contact billy...@apache.org.