{"action":"created","comment":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/comments/69830111","id":69830111,"diff_hunk":"@@ -0,0 +1,125 @@\n+/*\n+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com\n+ * The software in this package is published under the terms of the CPAL v1.0\n+ * license, a copy of which has been included with this distribution in the\n+ * LICENSE.txt file.\n+ */\n+package org.mule.functional.junit4.runners;\n+\n+import static java.util.Collections.emptyList;\n+import static org.mule.runtime.core.util.ClassUtils.withContextClassLoader;\n+import org.mule.runtime.module.artifact.classloader.ArtifactClassLoader;\n+\n+import java.lang.annotation.Annotation;\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+import org.junit.runner.Description;\n+import org.junit.runner.Runner;\n+import org.junit.runner.notification.RunNotifier;\n+import org.junit.runners.BlockJUnit4ClassRunner;\n+import org.junit.runners.Suite;\n+import org.junit.runners.model.FrameworkMethod;\n+import org.junit.runners.model.InitializationError;\n+import org.junit.runners.model.TestClass;\n+\n+/**\n+ * Runner that does the testing of the class using a different {@link ClassLoader} from the one that launched the test.\n+ *\n+ * @since 4.0\n+ */\n+public class ArtifactClassloaderTestRunner extends Suite\n+{\n+    private static final List<Runner> NO_RUNNERS = emptyList();\n+    private final ArrayList<Runner> runners = new ArrayList<>();\n+\n+    /**\n+     * Creates a Runner to run {@code klass}\n+     *\n+     * @param klass\n+     * @throws InitializationError if the test class is malformed.\n+     */\n+    public ArtifactClassloaderTestRunner(final Class<?> klass) throws Throwable\n+    {\n+        super(createTestClassUsingClassLoader(klass), NO_RUNNERS);\n+        Class<? extends Runner> runnerClass = BlockJUnit4ClassRunner.class;\n+        RunnerDelegateTo runnerDelegateTo = klass.getAnnotation(RunnerDelegateTo.class);\n+        if (runnerDelegateTo != null)\n+        {\n+            runnerClass = runnerDelegateTo.value();\n+        }\n+        runners.add(runnerClass.cast(runnerClass.getConstructor(Class.class).newInstance(getTestClass().getJavaClass())));\n+    }\n+\n+    @Override\n+    protected List<Runner> getChildren() {\n+        return runners;\n+    }\n+\n+    @Override\n+    public Description getDescription() {\n+        // Just to avoid having duplicated name in IDEA/Eclipse JUnit panel view due to this is a Suite, we always have only one delegate/child runner.\n+        return runners.get(0).getDescription();\n+    }\n+\n+\n+    protected void runChild(final Runner runner, final RunNotifier notifier) {\n+        withContextClassLoader(getTestClass().getJavaClass().getClassLoader(), () -> runner.run(notifier));\n+    }\n+\n+    /**\n+     * @param klass\n+     * @return the {@link ClassLoader} that would be used to run the test. This way the test will be isolated and it will behave\n+     * similar as an application running in a Mule standalone container.\n+     * @throws Throwable\n+     */\n+    private static Class<?> createTestClassUsingClassLoader(Class<?> klass) throws Throwable\n+    {\n+        // Initializes utility classes\n+        ClassPathURLsProvider classPathURLsProvider = new DefaultClassPathURLsProvider();\n+        MavenDependenciesResolver mavenDependenciesResolver = new DependencyGraphMavenDependenciesResolver();\n+        MavenMultiModuleArtifactMapping mavenMultiModuleArtifactMapping = new MuleMavenMultiModuleArtifactMapping();\n+        ClassLoaderRunnerFactory classLoaderRunnerFactory = new MuleClassLoaderRunnerFactory();\n+        ClassPathClassifier classPathClassifier = new MuleClassPathClassifier();\n+\n+        // Does the classification and creation of the isolated ClassLoader\n+        ArtifactUrlClassification artifactUrlClassification = classPathClassifier.classify(new DefaultClassPathClassifierContext(klass, classPathURLsProvider.getURLs(),\n+                                                                                           mavenDependenciesResolver.buildDependencies(), mavenMultiModuleArtifactMapping));\n+        ClassLoaderTestRunner classLoaderTestRunner = classLoaderRunnerFactory.createClassLoader(klass, artifactUrlClassification);","path":"tests/functional/src/main/java/org/mule/functional/junit4/runners/ArtifactClassloaderTestRunner.java","position":88,"original_position":88,"commit_id":"36cf4aaec51b40210b3ba4499311604d8e9af264","original_commit_id":"36cf4aaec51b40210b3ba4499311604d8e9af264","user":{"login":"pablokraan","id":561399,"avatar_url":"https://avatars.githubusercontent.com/u/561399?v=3","gravatar_id":"","url":"https://api.github.com/users/pablokraan","html_url":"https://github.com/pablokraan","followers_url":"https://api.github.com/users/pablokraan/followers","following_url":"https://api.github.com/users/pablokraan/following{/other_user}","gists_url":"https://api.github.com/users/pablokraan/gists{/gist_id}","starred_url":"https://api.github.com/users/pablokraan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pablokraan/subscriptions","organizations_url":"https://api.github.com/users/pablokraan/orgs","repos_url":"https://api.github.com/users/pablokraan/repos","events_url":"https://api.github.com/users/pablokraan/events{/privacy}","received_events_url":"https://api.github.com/users/pablokraan/received_events","type":"User","site_admin":false},"body":"Not for this PR, but create a issue in order to improve the runer to avoid the need of having to create a new classLoader on every test. All the tests in a given module will have the same classLoader, so it seems non performant to create a new one every time.","created_at":"2016-07-06T23:30:29Z","updated_at":"2016-07-06T23:30:29Z","html_url":"https://github.com/mulesoft/mule/pull/2930#discussion_r69830111","pull_request_url":"https://api.github.com/repos/mulesoft/mule/pulls/2930","_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments/69830111"},"html":{"href":"https://github.com/mulesoft/mule/pull/2930#discussion_r69830111"},"pull_request":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2930"}}},"pull_request":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/2930","id":76481166,"html_url":"https://github.com/mulesoft/mule/pull/2930","diff_url":"https://github.com/mulesoft/mule/pull/2930.diff","patch_url":"https://github.com/mulesoft/mule/pull/2930.patch","issue_url":"https://api.github.com/repos/mulesoft/mule/issues/2930","number":2930,"state":"open","locked":false,"title":"DO NOT MERGE - FOR REVIEW ONLY - MULE-9738 Improve functional test case to work with extensions","user":{"login":"gsfernandes","id":7305769,"avatar_url":"https://avatars.githubusercontent.com/u/7305769?v=3","gravatar_id":"","url":"https://api.github.com/users/gsfernandes","html_url":"https://github.com/gsfernandes","followers_url":"https://api.github.com/users/gsfernandes/followers","following_url":"https://api.github.com/users/gsfernandes/following{/other_user}","gists_url":"https://api.github.com/users/gsfernandes/gists{/gist_id}","starred_url":"https://api.github.com/users/gsfernandes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsfernandes/subscriptions","organizations_url":"https://api.github.com/users/gsfernandes/orgs","repos_url":"https://api.github.com/users/gsfernandes/repos","events_url":"https://api.github.com/users/gsfernandes/events{/privacy}","received_events_url":"https://api.github.com/users/gsfernandes/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-06T18:43:20Z","updated_at":"2016-07-06T23:30:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7bda207d8cc346a7d1f34077f835b76c11a54f22","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mulesoft/mule/pulls/2930/commits","review_comments_url":"https://api.github.com/repos/mulesoft/mule/pulls/2930/comments","review_comment_url":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mulesoft/mule/issues/2930/comments","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/36cf4aaec51b40210b3ba4499311604d8e9af264","head":{"label":"mulesoft:MULE-9738-runner-support","ref":"MULE-9738-runner-support","sha":"36cf4aaec51b40210b3ba4499311604d8e9af264","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","deployments_url":"https://api.github.com/repos/mulesoft/mule/deployments","created_at":"2012-12-07T19:23:06Z","updated_at":"2016-07-06T17:22:56Z","pushed_at":"2016-07-06T23:25:38Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":244431,"stargazers_count":347,"watchers_count":347,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":359,"mirror_url":null,"open_issues_count":19,"forks":359,"open_issues":19,"watchers":347,"default_branch":"mule-4.x"}},"base":{"label":"mulesoft:mule-4.x","ref":"mule-4.x","sha":"b1409c837517c0673da0c8168509b3d90db80c0c","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","deployments_url":"https://api.github.com/repos/mulesoft/mule/deployments","created_at":"2012-12-07T19:23:06Z","updated_at":"2016-07-06T17:22:56Z","pushed_at":"2016-07-06T23:25:38Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":244431,"stargazers_count":347,"watchers_count":347,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":359,"mirror_url":null,"open_issues_count":19,"forks":359,"open_issues":19,"watchers":347,"default_branch":"mule-4.x"}},"_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2930"},"html":{"href":"https://github.com/mulesoft/mule/pull/2930"},"issue":{"href":"https://api.github.com/repos/mulesoft/mule/issues/2930"},"comments":{"href":"https://api.github.com/repos/mulesoft/mule/issues/2930/comments"},"review_comments":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2930/comments"},"review_comment":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2930/commits"},"statuses":{"href":"https://api.github.com/repos/mulesoft/mule/statuses/36cf4aaec51b40210b3ba4499311604d8e9af264"}}}}
{"actor":{"display_login":"pablokraan"}}