-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added UI support for numbers and boolean plus tests.
- Loading branch information
Showing
7 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/org/jminix/console/resource/AttributeResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.jminix.console.resource; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import java.util.Map; | ||
|
||
import javax.management.MBeanServer; | ||
import javax.management.ObjectName; | ||
|
||
import org.jminix.console.JMiniXStuff; | ||
import org.jminix.server.DefaultLocalServerConnectionProvider; | ||
import org.jminix.type.AttributeFilter; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.restlet.Context; | ||
import org.restlet.Request; | ||
import org.restlet.Response; | ||
import org.restlet.resource.Resource; | ||
|
||
public class AttributeResourceTest { | ||
private MBeanServer mbs; | ||
private ObjectName mbeanName; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
mbs = ManagementFactory.getPlatformMBeanServer(); | ||
mbeanName = new ObjectName("org.jminix.console:type=JMiniXStuff"); | ||
mbs.registerMBean(new JMiniXStuff(), mbeanName); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception { | ||
mbs.unregisterMBean(mbeanName); | ||
} | ||
|
||
@Test | ||
public void testPrimitiveAttribute() { | ||
AttributeResource res = new AttributeResource(); | ||
init(res); | ||
Request req = res.getRequest(); | ||
req.getAttributes().put("attribute", "SimpleString"); | ||
Map<String,Object> model = res.getModel(); | ||
assertEquals(JMiniXStuff.SIMPLE_STRING_VALUE, model.get(AbstractTemplateResource.VALUE_MODEL_ATTRIBUTE)); | ||
} | ||
|
||
@Test | ||
public void testArrayAttribute() { | ||
AttributeResource res = new AttributeResource(); | ||
init(res); | ||
Request req = res.getRequest(); | ||
req.getAttributes().put("attribute", "StringArray"); | ||
Map<String,Object> model = res.getModel(); | ||
assertEquals(JMiniXStuff.STRING_ARRAY_VALUE, model.get(AbstractTemplateResource.ITEMS_MODEL_ATTRIBUTE)); | ||
} | ||
|
||
@Test | ||
public void testArrayFilter() { | ||
AttributeResource res = new AttributeResource(); | ||
init(res, new AttributeFilter() { | ||
@Override | ||
public Object filter(Object object) { | ||
return String.join(" ", (String[])object); | ||
} | ||
}); | ||
Request req = res.getRequest(); | ||
req.getAttributes().put("attribute", "StringArray"); | ||
Map<String,Object> model = res.getModel(); | ||
assertEquals(JMiniXStuff.SIMPLE_STRING_VALUE, model.get(AbstractTemplateResource.VALUE_MODEL_ATTRIBUTE)); | ||
} | ||
|
||
private void init(Resource res) { | ||
init(res, null); | ||
} | ||
|
||
private void init(Resource res, AttributeFilter attributeFilter) { | ||
Context ctx = new Context(); | ||
ctx.getAttributes().put("serverProvider", new DefaultLocalServerConnectionProvider()); | ||
if (attributeFilter != null) { | ||
ctx.getAttributes().put("attributeFilter", attributeFilter); | ||
} | ||
Request req = new Request(); | ||
req.getAttributes().put("domain", "org.jminix.console"); | ||
req.getAttributes().put("mbean", "type=JMiniXStuff"); | ||
req.getAttributes().put("server", "0"); | ||
Response resp = new Response(req); | ||
res.init(ctx, req, resp); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../org/jminix/resource/ValueParserTest.java → ...nix/console/resource/ValueParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package org.jminix.resource; | ||
package org.jminix.console.resource; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
|