cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jburwell <...@git.apache.org>
Subject [GitHub] cloudstack pull request: CLOUDSTACK-8562: Dynamic Role-Based API C...
Date Thu, 14 Apr 2016 22:14:29 GMT
Github user jburwell commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1489#discussion_r59800993
  
    --- Diff: api/test/org/apache/cloudstack/acl/RuleTest.java ---
    @@ -0,0 +1,39 @@
    +package org.apache.cloudstack.acl;
    +
    +import com.cloud.exception.InvalidParameterValueException;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.Arrays;
    +
    +public class RuleTest {
    +
    +    @Test
    +    public void testToString() throws Exception {
    +        Rule rule = new Rule("someString");
    +        Assert.assertEquals(rule.toString(), "someString");
    +    }
    +
    +    @Test
    +    public void testValidateRuleWithValidData() throws Exception {
    +        for (String rule : Arrays.asList("a", "1", "someApi", "someApi321", "123SomeApi",
    +                "prefix*", "*middle*", "*Suffix",
    +                "*", "**", "f***", "m0nk3yMa**g1c*")) {
    +            Assert.assertTrue(Rule.validate(rule));
    +            Assert.assertEquals(new Rule(rule).toString(), rule);
    +        }
    +    }
    +
    +    @Test
    +    public void testValidateRuleWithInvalidData() throws Exception {
    +        for (String rule : Arrays.asList(null, "", " ", "  ", "\n", "\t", "\r", "\"",
"\'",
    +                "^someApi$", "^someApi", "some$", "some-Api;", "some,Api",
    +                "^", "$", "^$", ".*", "\\w+", "r**l3rd0@Kr3", "j@s1n|+|0ȷ",
    +                "[a-z0-9-]+", "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"))
{
    +            try {
    +                new Rule(rule);
    +                Assert.fail("Invalid rule, exception was expected");
    +            } catch (InvalidParameterValueException ignored) {}
    +        }
    --- End diff --
    
    This method can be simplified by removing the try-catch and added ``expected=InvalidParameterValueException.class``
to the ``@Test`` annotation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message