private final Model _model = TestModel.getInstance();
public void testAttributePersistence()
{
final String objectName = "testNonPersistAttributes";
TestRootCategory object =
_model.getObjectFactory().create(TestRootCategory.class,
Collections.<String, Object>singletonMap(ConfiguredObject.NAME,
objectName)
);
assertEquals(objectName, object.getName());
assertNull(object.getAutomatedNonPersistedValue());
assertNull(object.getAutomatedPersistedValue());
ConfiguredObjectRecord record = object.asObjectRecord();
assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME));
assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_PERSISTED_VALUE));
assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE));
Map<String, Object> updatedAttributes = new HashMap<>();
final String newValue = "newValue";
updatedAttributes.put(TestRootCategory.AUTOMATED_PERSISTED_VALUE, newValue);
updatedAttributes.put(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE, newValue);
object.setAttributes(updatedAttributes);
assertEquals(newValue, object.getAutomatedPersistedValue());
assertEquals(newValue, object.getAutomatedNonPersistedValue());
record = object.asObjectRecord();
assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME));
assertEquals(newValue, record.getAttributes().get(TestRootCategory.AUTOMATED_PERSISTED_VALUE));
assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE));