Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/1066#discussion_r46172837
  
    --- 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");
    --- End diff --
    
    I'd include in error as much context as possible (as long as it doesn't 
risk logging security info) - e.g. `key.getDescription() + " of " + entity + " 
must be map or list of maps, but is " + (config == null ? null : 
config.getClass().getName())`


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to