Skip to content

Commit

Permalink
JavaJmx#setAttribute methods callback and signature parameters logic …
Browse files Browse the repository at this point in the history
…improved
  • Loading branch information
zuazo committed May 13, 2013
1 parent a14608b commit 88fda6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/javaJmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ JavaJmx.prototype.setAttribute = function(mbean, attributeName, value, className
});
java.newInstance.apply(java, newInstanceArgs);
} else {
if (typeof callback === "undefined") {
if (typeof callback === "undefined" && typeof classNameOrCallback === "function") {
callback = classNameOrCallback;
}
setAttribute.call(self, mbean, attributeName, value, callback);
Expand Down
26 changes: 24 additions & 2 deletions test/javaJmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,20 @@ describe("JavaJmx", function() {

describe("#setAttribute", function() {

it("should call MBeanServer.setAttribute with the correct parameters", function(done) {
it("should accept three parameters", function(done) {
javaJmx.mbeanServerConnection.setAttribute = function(objectName, attribute, callback, undef) {
assert.strictEqual(objectName.toString(), "MBean1:type=MBean1");
assert.strictEqual(attribute.getClassSync().getNameSync(), "javax.management.Attribute");
assert.strictEqual(attribute.getNameSync(), "attributeName");
assert.strictEqual(attribute.getValueSync(), "value");
assert.strictEqual(callback, undefined);
assert.strictEqual(undef, undefined);
done();
};
javaJmx.setAttribute("mbean", "attributeName", "value");
});

it("should accept a callback as the third parameter", function(done) {
javaJmx.mbeanServerConnection.setAttribute = function(objectName, attribute, callback, undef) {
assert.strictEqual(objectName.toString(), "MBean1:type=MBean1");
assert.strictEqual(attribute.getClassSync().getNameSync(), "javax.management.Attribute");
Expand All @@ -142,7 +155,7 @@ describe("JavaJmx", function() {
javaJmx.setAttribute("mbean", "attributeName", "value", done);
})

it("should accept the optional className parameter", function(done) {
it("should accept a className as third parameter with a callback", function(done) {
javaJmx.mbeanServerConnection.setAttribute = function(objectName, attribute, callback) {
assert.strictEqual(attribute.getValueSync().getClassSync().getNameSync(), "javax.management.ObjectName");
assert.strictEqual(attribute.getValueSync().getDomainSync(), "domain");
Expand All @@ -151,6 +164,15 @@ describe("JavaJmx", function() {
javaJmx.setAttribute("mbean", "attributeName", [ "domain", "name", "value" ], "javax.management.ObjectName", done);
})

it("should accept a className as third parameter without a callback", function(done) {
javaJmx.mbeanServerConnection.setAttribute = function(objectName, attribute, callback) {
assert.strictEqual(attribute.getValueSync().getClassSync().getNameSync(), "javax.management.ObjectName");
assert.strictEqual(attribute.getValueSync().getDomainSync(), "domain");
done();
};
javaJmx.setAttribute("mbean", "attributeName", [ "domain", "name", "value" ], "javax.management.ObjectName");
})

});

it("#setCredentials", function(done) {
Expand Down

0 comments on commit 88fda6c

Please sign in to comment.