brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Updates to Test framework asserti...
Date Mon, 30 Nov 2015 17:19:09 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1066#discussion_r46173056
  
    --- Diff: usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
---
    @@ -39,122 +42,216 @@
      * @author m4rkmckenna on 11/11/2015.
      */
     public class TestFrameworkAssertions {
    -    private static final Logger LOG = LoggerFactory.getLogger(TestFrameworkAssertions.class);
    +
    +    public static final String IS_NULL = "isNull";
    +    public static final String NOT_NULL = "notNull";
    +    public static final String IS_EQUAL_TO = "isEqualTo";
    +    public static final String EQUAL_TO = "equalTo";
    +    public static final String EQUALS = "equals";
    +    public static final String MATCHES = "matches";
    +    public static final String CONTAINS = "contains";
    +    public static final String IS_EMPTY = "isEmpty";
    +    public static final String NOT_EMPTY = "notEmpty";
    +    public static final String HAS_TRUTH_VALUE = "hasTruthValue";
    +    public static final String UNKNOWN_CONDITION = "unknown condition";
    +
     
         private TestFrameworkAssertions() {
         }
     
    +
         /**
    -     * Evaluates all assertions against dataSupplier
    +     *  Get assertions tolerantly from a configuration key.
    +     *  This supports either a simple map of assertions, such as
          *
    -     * @param dataSupplier
    -     * @param flags
    -     * @param assertions
    -     */
    -    public static void checkAssertions(final Supplier<String> dataSupplier, final
Map flags, final List<Map<String, Object>> assertions) {
    -        //Iterate through assert array
    -        for (final Map<String, Object> assertionsMap : assertions) {
    -            checkAssertions(dataSupplier, flags, assertionsMap);
    -        }
    +     <pre>
    +     assertOut:
    +       contains: 2 users
    +       matches: .*[\d]* days.*
    +     </pre>
    +     * or a list of such maps, (which allows you to repeat keys):
    +     <pre>
    +     assertOut:
    +     - contains: 2 users
    +     - contains: 2 days
    +     </pre>
    +     or
    +    private static List<Map<String,Object>> getAssertions(ConfigKey<Object>
key) {
         }
    +    */
    +    public static List<Map<String, Object>> getAssertions(Entity entity,
ConfigKey<Object> key) {
    +        Object config = entity.getConfig(key);
    +        Maybe<Map<String, Object>> maybeMap = TypeCoercions.tryCoerce(config,
new TypeToken<Map<String, Object>>() {});
    +        if (maybeMap.isPresent()) {
    +            return Collections.singletonList(maybeMap.get());
    +        }
     
    -    /**
    -     * Evaluates all assertions against dataSupplier
    -     *
    -     * @param dataSupplier
    -     * @param flags
    -     * @param assertionsMap
    -     */
    -    public static void checkAssertions(final Supplier<String> dataSupplier, final
Map flags, final Map<String, Object> assertionsMap) {
    -        for (final Map.Entry<String, Object> assertion : assertionsMap.entrySet())
{
    -            final Maybe<Predicate<String>> optionalPredicate = getPredicate(assertion.getKey(),
assertion.getValue());
    -            Asserts.succeedsEventually(flags, new PredicateChecker(dataSupplier, optionalPredicate.get()));
    +        Maybe<List<Map<String, Object>>> maybeList = TypeCoercions.tryCoerce(config,
    +            new TypeToken<List<Map<String, Object>>>() {});
    +        if (maybeList.isPresent()) {
    +            return maybeList.get();
             }
    +
    +        throw new FatalConfigurationRuntimeException(key.getDescription() + " is not
a map or list of maps");
         }
     
    -    /**
    -     * Returns the predicate associated with the predicateKey if one exists
    -     *
    -     * @param predicateKey
    -     * @param predicateTarget
    -     * @return {@link Maybe} of {@Link Predicate}
    -     */
    -    public static Maybe<Predicate<String>> getPredicate(final String predicateKey,
final Object predicateTarget) {
    -        if (StringUtils.equalsIgnoreCase("isNull", predicateKey)) {
    -            return Maybe.of(Predicates.<String>isNull());
    -        } else if (StringUtils.equalsIgnoreCase("notNull", predicateKey)) {
    -            return Maybe.of(Predicates.<String>notNull());
    -        } else if (StringUtils.equalsIgnoreCase("isEqualTo", predicateKey)
    -                || StringUtils.equalsIgnoreCase("equalTo", predicateKey)
    -                || StringUtils.equalsIgnoreCase("equals", predicateKey)) {
    -            return Maybe.of(Predicates.equalTo(TypeCoercions.coerce(predicateTarget.toString(),
String.class)));
    -        } else if (StringUtils.equalsIgnoreCase("matches", predicateKey)) {
    -            return Maybe.of(buildMatchesPredicate(TypeCoercions.coerce(predicateTarget,
String.class)));
    -        } else if (StringUtils.equalsIgnoreCase("contains", predicateKey)) {
    -            return Maybe.of(buildContainsPredicate(TypeCoercions.coerce(predicateTarget,
String.class)));
    +
    +    public static <T> void checkAssertions(Map<String,?> flags,
    +                                           Map<String, Object> assertions,
    +                                           String target,
    +                                           final Supplier<T> actualSupplier) {
    +
    +        AssertionSupport support = new AssertionSupport();
    --- End diff --
    
    Minor: perhaps just call `checkAssertions(flags, ImmutableList.of(assertions), target,
actualSupplier)`


---
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