{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments/44515581","id":44515581,"diff_hunk":"@@ -0,0 +1,107 @@\n+package org.apache.brooklyn.test.framework;\n+\n+import com.google.api.client.util.Objects;\n+import com.google.common.collect.ImmutableMap;\n+import com.google.common.collect.Lists;\n+import org.apache.brooklyn.api.location.Location;\n+import org.apache.brooklyn.core.entity.AbstractEntity;\n+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;\n+import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;\n+import org.apache.brooklyn.util.core.flags.TypeCoercions;\n+import org.apache.brooklyn.util.exceptions.Exceptions;\n+import org.apache.brooklyn.util.time.Duration;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.Collection;\n+import java.util.Map;\n+\n+import static org.apache.brooklyn.util.http.HttpAsserts.assertContentEventuallyContainsText;\n+import static org.apache.brooklyn.util.http.HttpAsserts.assertContentEventuallyMatches;\n+import static org.apache.brooklyn.util.http.HttpAsserts.assertHttpStatusCodeEventuallyEquals;\n+\n+/**\n+ * {@inheritDoc}\n+ */\n+public class TestHttpCallImpl extends AbstractEntity implements TestHttpCall {\n+\n+    private static final Logger LOG = LoggerFactory.getLogger(TestHttpCallImpl.class);\n+\n+    /**\n+     * {@inheritDoc}\n+     */\n+    public void start(Collection<? extends Location> locations) {\n+        ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);\n+        final String url = getConfig(TARGET_URL);\n+        final Map assertions = getConfig(ASSERTIONS);\n+        final Duration timeout = getConfig(TIMEOUT);\n+        try {\n+            checkAssertions(url.toString(), ImmutableMap.of(\"timeout\", timeout), assertions);\n+            sensors().set(SERVICE_UP, true);\n+            ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING);\n+        } catch (Throwable t) {\n+            LOG.info(\"Url [{}] test failed\", url);\n+            sensors().set(SERVICE_UP, false);\n+            ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE);\n+            throw Exceptions.propagate(t);\n+        }\n+    }\n+\n+    /**\n+     * Tests HTTP Request reponse matches assertions\n+     * <p>\n+     * Supported keys in the <code>assertions</code> {@link Map} include:\n+     * <ul>\n+     * <li>string - simple string match\n+     * <li>regex - uses {@link java.lang.String#matches(String)}, if the url returns a multi-line response you should\n+     * use the embedded dotall flag expression <code>(?s)</code> in your regex.\n+     * <li>status - HTTP status code\n+     * </ul>\n+     * Wraps the {@link org.apache.brooklyn.util.http.HttpAsserts} immediate assertion methods.\n+     * <p>\n+     * See the test/resources directory for examples.\n+     *\n+     * @param url        The target URL to be tested\n+     * @param flags      Passed to {@link org.apache.brooklyn.util.http.HttpAsserts#assertContentEventuallyContainsText(Map, String, String, String...)},\n+     *                   {@link org.apache.brooklyn.util.http.HttpAsserts#assertContentEventuallyMatches(Map, String, String)},\n+     *                   {@link org.apache.brooklyn.util.http.HttpAsserts#assertHttpStatusCodeEventuallyEquals(Map, String, int)}\n+     *\n+     * @param assertions The map of assertions\n+     */\n+    private void checkAssertions(final String url, final Map<String,?> flags, final Map<?, ?> assertions) {\n+\n+        for (final Map.Entry<?, ?> entry : assertions.entrySet()) {","path":"usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestHttpCallImpl.java","position":73,"original_position":73,"commit_id":"eaacdf0a5656d3a6b10c9c7d8fad374382710c0c","original_commit_id":"eaacdf0a5656d3a6b10c9c7d8fad374382710c0c","user":{"login":"ahgittin","id":496540,"avatar_url":"https://avatars.githubusercontent.com/u/496540?v=3","gravatar_id":"","url":"https://api.github.com/users/ahgittin","html_url":"https://github.com/ahgittin","followers_url":"https://api.github.com/users/ahgittin/followers","following_url":"https://api.github.com/users/ahgittin/following{/other_user}","gists_url":"https://api.github.com/users/ahgittin/gists{/gist_id}","starred_url":"https://api.github.com/users/ahgittin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahgittin/subscriptions","organizations_url":"https://api.github.com/users/ahgittin/orgs","repos_url":"https://api.github.com/users/ahgittin/repos","events_url":"https://api.github.com/users/ahgittin/events{/privacy}","received_events_url":"https://api.github.com/users/ahgittin/received_events","type":"User","site_admin":false},"body":"this kind of map feels like the wrong syntax as it prevents multiple tests of the same type (e.g. multiple `regex` checks)\r\n\r\ni think we should take a list of maps, where the maps should be single-entry.  (if a map is provided we could support the current implementation but with a warning.)  this would also allow us to define more complex assertions which might require multiple settings (e.g. `ignoreCase` for `string` (aka `contains`)","created_at":"2015-11-11T09:38:44Z","updated_at":"2015-11-11T09:38:44Z","html_url":"https://github.com/apache/incubator-brooklyn/pull/999#discussion_r44515581","pull_request_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments/44515581"},"html":{"href":"https://github.com/apache/incubator-brooklyn/pull/999#discussion_r44515581"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999","id":49469971,"html_url":"https://github.com/apache/incubator-brooklyn/pull/999","diff_url":"https://github.com/apache/incubator-brooklyn/pull/999.diff","patch_url":"https://github.com/apache/incubator-brooklyn/pull/999.patch","issue_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/999","number":999,"state":"open","locked":false,"title":"Implementation of proposed Test Entities to allow testing directly from blueprints","user":{"login":"m4rkmckenna","id":207962,"avatar_url":"https://avatars.githubusercontent.com/u/207962?v=3","gravatar_id":"","url":"https://api.github.com/users/m4rkmckenna","html_url":"https://github.com/m4rkmckenna","followers_url":"https://api.github.com/users/m4rkmckenna/followers","following_url":"https://api.github.com/users/m4rkmckenna/following{/other_user}","gists_url":"https://api.github.com/users/m4rkmckenna/gists{/gist_id}","starred_url":"https://api.github.com/users/m4rkmckenna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m4rkmckenna/subscriptions","organizations_url":"https://api.github.com/users/m4rkmckenna/orgs","repos_url":"https://api.github.com/users/m4rkmckenna/repos","events_url":"https://api.github.com/users/m4rkmckenna/events{/privacy}","received_events_url":"https://api.github.com/users/m4rkmckenna/received_events","type":"User","site_admin":false},"body":"**Proposal**\r\nhttp://mail-archives.apache.org/mod_mbox/incubator-brooklyn-dev/201510.mbox/%3CE185CA37-E693-4733-8DE1-208872BC1978%40cloudsoftcorp.com%3E\r\n\r\nThis PR relies on #994  ","created_at":"2015-11-02T18:52:18Z","updated_at":"2015-11-11T09:38:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b2b862029afe0dc752485a23aaf5802c7653dd45","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/999/comments","statuses_url":"https://api.github.com/repos/apache/incubator-brooklyn/statuses/eaacdf0a5656d3a6b10c9c7d8fad374382710c0c","head":{"label":"m4rkmckenna:test-framework","ref":"test-framework","sha":"eaacdf0a5656d3a6b10c9c7d8fad374382710c0c","user":{"login":"m4rkmckenna","id":207962,"avatar_url":"https://avatars.githubusercontent.com/u/207962?v=3","gravatar_id":"","url":"https://api.github.com/users/m4rkmckenna","html_url":"https://github.com/m4rkmckenna","followers_url":"https://api.github.com/users/m4rkmckenna/followers","following_url":"https://api.github.com/users/m4rkmckenna/following{/other_user}","gists_url":"https://api.github.com/users/m4rkmckenna/gists{/gist_id}","starred_url":"https://api.github.com/users/m4rkmckenna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m4rkmckenna/subscriptions","organizations_url":"https://api.github.com/users/m4rkmckenna/orgs","repos_url":"https://api.github.com/users/m4rkmckenna/repos","events_url":"https://api.github.com/users/m4rkmckenna/events{/privacy}","received_events_url":"https://api.github.com/users/m4rkmckenna/received_events","type":"User","site_admin":false},"repo":{"id":45178718,"name":"incubator-brooklyn","full_name":"m4rkmckenna/incubator-brooklyn","owner":{"login":"m4rkmckenna","id":207962,"avatar_url":"https://avatars.githubusercontent.com/u/207962?v=3","gravatar_id":"","url":"https://api.github.com/users/m4rkmckenna","html_url":"https://github.com/m4rkmckenna","followers_url":"https://api.github.com/users/m4rkmckenna/followers","following_url":"https://api.github.com/users/m4rkmckenna/following{/other_user}","gists_url":"https://api.github.com/users/m4rkmckenna/gists{/gist_id}","starred_url":"https://api.github.com/users/m4rkmckenna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m4rkmckenna/subscriptions","organizations_url":"https://api.github.com/users/m4rkmckenna/orgs","repos_url":"https://api.github.com/users/m4rkmckenna/repos","events_url":"https://api.github.com/users/m4rkmckenna/events{/privacy}","received_events_url":"https://api.github.com/users/m4rkmckenna/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/m4rkmckenna/incubator-brooklyn","description":"Mirror of Apache Brooklyn","fork":true,"url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn","forks_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/forks","keys_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/teams","hooks_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/hooks","issue_events_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/issues/events{/number}","events_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/events","assignees_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/assignees{/user}","branches_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/branches{/branch}","tags_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/tags","blobs_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/statuses/{sha}","languages_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/languages","stargazers_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/stargazers","contributors_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/contributors","subscribers_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/subscribers","subscription_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/subscription","commits_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/contents/{+path}","compare_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/merges","archive_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/downloads","issues_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/issues{/number}","pulls_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/pulls{/number}","milestones_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/milestones{/number}","notifications_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/labels{/name}","releases_url":"https://api.github.com/repos/m4rkmckenna/incubator-brooklyn/releases{/id}","created_at":"2015-10-29T11:24:03Z","updated_at":"2015-10-29T11:24:23Z","pushed_at":"2015-11-09T21:57:50Z","git_url":"git://github.com/m4rkmckenna/incubator-brooklyn.git","ssh_url":"git@github.com:m4rkmckenna/incubator-brooklyn.git","clone_url":"https://github.com/m4rkmckenna/incubator-brooklyn.git","svn_url":"https://github.com/m4rkmckenna/incubator-brooklyn","homepage":null,"size":253865,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"6c4b5170d8dbd4ff4a26deffa2580c65cf4ee357","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":19368221,"name":"incubator-brooklyn","full_name":"apache/incubator-brooklyn","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-brooklyn","description":"Mirror of Apache Brooklyn","fork":false,"url":"https://api.github.com/repos/apache/incubator-brooklyn","forks_url":"https://api.github.com/repos/apache/incubator-brooklyn/forks","keys_url":"https://api.github.com/repos/apache/incubator-brooklyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-brooklyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-brooklyn/teams","hooks_url":"https://api.github.com/repos/apache/incubator-brooklyn/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-brooklyn/events","assignees_url":"https://api.github.com/repos/apache/incubator-brooklyn/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-brooklyn/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-brooklyn/tags","blobs_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-brooklyn/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-brooklyn/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-brooklyn/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-brooklyn/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-brooklyn/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-brooklyn/subscription","commits_url":"https://api.github.com/repos/apache/incubator-brooklyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-brooklyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-brooklyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-brooklyn/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-brooklyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-brooklyn/merges","archive_url":"https://api.github.com/repos/apache/incubator-brooklyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-brooklyn/downloads","issues_url":"https://api.github.com/repos/apache/incubator-brooklyn/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-brooklyn/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-brooklyn/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-brooklyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-brooklyn/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-brooklyn/releases{/id}","created_at":"2014-05-02T07:00:07Z","updated_at":"2015-11-10T06:27:40Z","pushed_at":"2015-11-11T03:35:41Z","git_url":"git://github.com/apache/incubator-brooklyn.git","ssh_url":"git@github.com:apache/incubator-brooklyn.git","clone_url":"https://github.com/apache/incubator-brooklyn.git","svn_url":"https://github.com/apache/incubator-brooklyn","homepage":null,"size":265932,"stargazers_count":123,"watchers_count":123,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":97,"mirror_url":"git://git.apache.org/incubator-brooklyn.git","open_issues_count":14,"forks":97,"open_issues":14,"watchers":123,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999"},"html":{"href":"https://github.com/apache/incubator-brooklyn/pull/999"},"issue":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/issues/999"},"comments":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/issues/999/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/pulls/999/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-brooklyn/statuses/eaacdf0a5656d3a6b10c9c7d8fad374382710c0c"}}}}