# HG changeset patch # User Andrew Azores # Date 1506105198 14400 # Node ID 57a4676a934301da74f5ec7790e708753cdc8226 # Parent 0e10eacbeeb717ee0a823bb58956b073f433822a Use JVM mainClass in byteman rule template Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025159.html diff -r 0e10eacbeeb7 -r 57a4676a9343 src/app/components/jvm-info/byteman/byteman.controller.js --- a/src/app/components/jvm-info/byteman/byteman.controller.js Fri Sep 22 07:51:59 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.controller.js Fri Sep 22 14:33:18 2017 -0400 @@ -85,8 +85,11 @@ } generateTemplate () { - return this._translate('byteman.RULE_TEMPLATE') - .then(res => this.ruleText = res); + return this._svc.getJvmMainClass(this.systemId, this.jvmId) + .then(mainClass => { + return this._translate('byteman.RULE_TEMPLATE', { mainClass: mainClass }) + .then(res => this.ruleText = res); + }); } } diff -r 0e10eacbeeb7 -r 57a4676a9343 src/app/components/jvm-info/byteman/byteman.controller.spec.js --- a/src/app/components/jvm-info/byteman/byteman.controller.spec.js Fri Sep 22 07:51:59 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.controller.spec.js Fri Sep 22 14:33:18 2017 -0400 @@ -45,7 +45,8 @@ svc = { getLoadedRules: sinon.stub(), loadRule: sinon.stub(), - unloadRules: sinon.stub() + unloadRules: sinon.stub(), + getJvmMainClass: sinon.stub() }; angular.mock.inject($controller => { @@ -173,9 +174,14 @@ }); describe('generateTemplate ()', () => { - it('should set rule text from translate service', () => { + it('should set rule text to template', () => { + svc.getJvmMainClass.returns({ + then: sinon.stub().yields('com.example.FooClass') + }); translate.then.yields('rule template'); ctrl.generateTemplate(); + translate.should.be.calledOnce(); + translate.should.be.calledWith('byteman.RULE_TEMPLATE', { mainClass: 'com.example.FooClass' }); ctrl.ruleText.should.equal('rule template'); }); }); diff -r 0e10eacbeeb7 -r 57a4676a9343 src/app/components/jvm-info/byteman/byteman.service.js --- a/src/app/components/jvm-info/byteman/byteman.service.js Fri Sep 22 07:51:59 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.service.js Fri Sep 22 14:33:18 2017 -0400 @@ -60,6 +60,10 @@ return this._sendCmdChanRequest(systemId, jvmId, UNLOAD_RULE_ACTION); } + getJvmMainClass (systemId, jvmId) { + return this._getJvmInfo(systemId, jvmId).then(res => res.mainClass); + } + _sendCmdChanRequest (systemId, jvmId, action, rule) { let defer = this._q.defer(); diff -r 0e10eacbeeb7 -r 57a4676a9343 src/app/components/jvm-info/byteman/byteman.service.spec.js --- a/src/app/components/jvm-info/byteman/byteman.service.spec.js Fri Sep 22 07:51:59 2017 -0400 +++ b/src/app/components/jvm-info/byteman/byteman.service.spec.js Fri Sep 22 14:33:18 2017 -0400 @@ -244,5 +244,26 @@ }); }); + describe('getJvmMainClass (systemId, jvmId)', () => { + it('should resolve mock data', done => { + let response = { + response: [ + { + mainClass: 'com.example.FooClass' + } + ] + }; + httpBackend.when('GET', 'http://example.com:1234/jvms/0.0.1/systems/foo-systemId/jvms/foo-jvmId') + .respond(response); + svc.getJvmMainClass('foo-systemId', 'foo-jvmId').then(res => { + res.should.equal(response.response[0].mainClass); + done(); + }); + httpBackend.expectGET('http://example.com:1234/jvms/0.0.1/systems/foo-systemId/jvms/foo-jvmId'); + httpBackend.flush(); + scope.$apply(); + }); + }); + }); diff -r 0e10eacbeeb7 -r 57a4676a9343 src/app/components/jvm-info/byteman/en.locale.yaml --- a/src/app/components/jvm-info/byteman/en.locale.yaml Fri Sep 22 07:51:59 2017 -0400 +++ b/src/app/components/jvm-info/byteman/en.locale.yaml Fri Sep 22 14:33:18 2017 -0400 @@ -7,12 +7,12 @@ UNLOAD_BTN_LABEL: Unload Rule GENERATE_RULE_BTN_LABEL: Generate Rule Template RULE_TEMPLATE: | - RULE Thermostat byteman template rule for com.redhat.thermostat.main.Thermostat - CLASS com.redhat.thermostat.main.Thermostat + RULE Thermostat byteman template rule for {{mainClass}} + CLASS {{mainClass}} METHOD main HELPER org.jboss.byteman.thermostat.helper.ThermostatHelper AT ENTRY IF true DO - send("foo-marker", "action", "com.redhat.thermostat.main.Thermostat.main() called"); + send("foo-marker", "action", "{{mainClass}}.main() called"); ENDRULE