DmrModel extends DmrModelValue implements Model { @Override public ModelString set(String value) { if (value == null) return asValue(ModelString.class); return (ModelString) asValue(this.value.set(value)); } DmrModel(ModelNode value); @Override ModelString set(String value); @Override ModelNumber set(int value); @Override ModelNumber set(long value); @Override ModelNumber set(double value); @Override ModelNumber set(BigInteger value); @Override ModelNumber set(BigDecimal value); @Override ModelBoolean set(boolean value); @Override ModelObject setEmptyObject(); @Override ModelList setEmptyList(); @Override ModelReference set(PathAddress value);  }
@Test public void testString() { assertTrue(newModel().set("foo").isDefined()); assertEquals(ModelValue.ModelValueType.STRING, newModel().set("foo").getValueType()); assertEquals("foo", newModel().set("foo").getValue()); }
@Test public void testNullString() { assertFalse(newModel().set((String) null).isDefined()); assertNull(newModel().set((String) null).getValue()); }
@Test public void testNumber() { assertTrue(newModel().set(3).isDefined()); assertEquals(ModelValue.ModelValueType.NUMBER, newModel().set(3).getValueType()); assertEquals(ModelNumber.ModelNumberType.INT, newModel().set(3).getNumberType()); assertEquals(3, newModel().set(3).getInt()); assertTrue(newModel().set(3L).isDefined()); assertEquals(ModelValue.ModelValueType.NUMBER, newModel().set(3L).getValueType()); assertEquals(ModelNumber.ModelNumberType.LONG, newModel().set(3L).getNumberType()); assertEquals(3L, newModel().set(3L).getInt()); assertTrue(newModel().set(Math.PI).isDefined()); assertEquals(ModelValue.ModelValueType.NUMBER, newModel().set(Math.PI).getValueType()); assertEquals(ModelNumber.ModelNumberType.DOUBLE, newModel().set(Math.PI).getNumberType()); assertEquals(Math.PI, newModel().set(Math.PI).getDouble(), 0); BigInteger bi = new BigInteger("3"); assertTrue(newModel().set(bi).isDefined()); assertEquals(ModelValue.ModelValueType.NUMBER, newModel().set(bi).getValueType()); assertEquals(ModelNumber.ModelNumberType.BIG_INTEGER, newModel().set(bi).getNumberType()); assertEquals(BigInteger.valueOf(3), newModel().set(bi).getBigInteger()); BigDecimal bd = new BigDecimal(String.valueOf(Math.PI)); assertTrue(newModel().set(bd).isDefined()); assertEquals(ModelValue.ModelValueType.NUMBER, newModel().set(bd).getValueType()); assertEquals(ModelNumber.ModelNumberType.BIG_DECIMAL, newModel().set(bd).getNumberType()); assertEquals(BigDecimal.valueOf(Math.PI), newModel().set(bd).getBigDecimal()); }
@Test public void testNullNumber() { assertFalse(newModel().set((BigInteger) null).isDefined()); assertNull(newModel().set((BigInteger) null).getBigInteger()); assertFalse(newModel().set((BigDecimal) null).isDefined()); assertNull(newModel().set((BigDecimal) null).getBigDecimal()); }
@Test public void testBoolean() { assertTrue(newModel().set(true).isDefined()); assertEquals(ModelValue.ModelValueType.BOOLEAN, newModel().set(true).getValueType()); assertTrue(newModel().set(true).getValue()); assertFalse(newModel().set(false).getValue()); }
@Test public void testReference() { assertTrue(newModel().set(PathAddress.pathAddress("foo", "bar")).isDefined()); assertEquals(ModelValue.ModelValueType.REFERENCE, newModel().set(PathAddress.pathAddress("foo", "bar")).getValueType()); }