@Test public void testPropertyValueTypeConverter() { ModelNode description = createDescription(ModelType.PROPERTY, ModelType.INT); TypeConverter converter = getConverter(description); ModelNode node = new ModelNode(); node.set("name", 1); node.protect(); Assert.assertEquals(SimpleType.STRING, converter.getOpenType()); String dmr = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(node, ModelNode.fromString(dmr)); Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(node))); assertToArray(converter, dmr); }
@Test public void testPropertyValueTypeExpressionConverter() throws Exception { ModelNode description = createDescription(ModelType.PROPERTY, ModelType.INT); TypeConverter converter = getConverter(description); ModelNode node = new ModelNode(); node.set("name", "${this.should.not.exist.!!!!!:1}"); node.protect(); ModelNode expected = node.clone().resolve(); Assert.assertEquals(SimpleType.STRING, converter.getOpenType()); String dmr = assertCast(String.class, converter.fromModelNode(node)); Assert.assertEquals(expected, ModelNode.fromString(dmr)); Assert.assertEquals(dmr, assertCast(String.class, converter.fromModelNode(expected))); assertToArray(converter, dmr); }
/** * Handles DMR strings in the configuration * * @param node the node to create. * @param name the name for the node. * @param value the value for the node. */ private void handleDmrString(final ModelNode node, final String name, final String value) { final String realValue = value.substring(2); node.get(name).set(ModelNode.fromString(realValue)); }