/src/test/resources/examples/MapAsInterfaceTests.groovy
Groovy | 64 lines | 50 code | 14 blank | 0 comment | 2 complexity | e7463d2a67002403f2eaafbf716e9dc8 MD5 | raw file
- import com.atlassian.core.action.ActionUtils
- import com.atlassian.core.ofbiz.CoreFactory
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.action.ActionNames
- import com.atlassian.jira.event.ListenerManager
- import com.atlassian.jira.event.listeners.DebugListener
- import org.apache.log4j.Category
- import webwork.dispatcher.ActionResult
- import com.atlassian.jira.event.issue.IssueEventListener
- import org.netbeans.lib.cvsclient.commandLine.command.log
- import com.atlassian.jira.event.issue.IssueEvent
-
- Category log = Category.getInstance("com.onresolve.jira.groovy.Scratch")
-
- ComponentManager componentManager = ComponentManager.getInstance()
-
- class AwesomePostFunction {
- Category log = Category.getInstance("com.acme.AwesomePostFunction")
- void doStuff() {
- log.fatal("doStuff")
- log.fatal(this.class.getName())
- }
- }
-
- log.debug("Script name: ${this.class.getName()}")
- (new AwesomePostFunction()).doStuff()
- return
-
- IssueEventListener getMapAsInterface() {
- def map = [:]
-
- IssueEventListener.class.methods.each() { method ->
- map."$method.name" = { Object[] args ->
- println "Called method ${method.name} with ${args}"
- }
- }
- map.toString = {-> "dynamic interface impl "}
-
- return map.asType(IssueEventListener.class) as IssueEventListener
- }
-
- IssueEventListener issueEventListener = getMapAsInterface()
- log.debug(this.class.getName())
- log.debug(issueEventListener.class.getName())
- return
-
- issueEventListener.metaClass.constructor = {println "EMC Ctor"}
-
-
- log.debug "InstallListener running"
-
- String LISTENER_NAME = "Debug ListenerX";
-
- ListenerManager listenerManager = (ListenerManager) ComponentManager.getInstance().getContainer().getComponentInstance(ListenerManager.class)
-
- if (!listenerManager.getListeners().containsKey(LISTENER_NAME)) {
- ActionResult aResult = CoreFactory.getActionDispatcher().execute(ActionNames.LISTENER_CREATE,
- ["name": LISTENER_NAME, "clazz": issueEventListener.class.getName()])
- ActionUtils.checkForErrors(aResult);
- log.info "Installed listener $LISTENER_NAME"
- }
- else {
- log.debug "Listener $LISTENER_NAME already installed"
- }