use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class JsonSerializableUtilityTest method testWriterListLength.
@Test
public void testWriterListLength() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonException, IOException {
List<Object> writerList1 = new ArrayList<>();
writerList1.add(new Integer(1));
writerList1.add(new Integer(2));
List<Object> writerList2 = new ArrayList<>();
writerList2.add(new Integer(1));
writerList2.add(new Integer(2));
JsonSerializableTestObject o1 = new JsonSerializableTestObject();
o1.setWriterList(writerList1);
JsonSerializableTestObject o2 = new JsonSerializableTestObject();
o2.setWriterList(writerList2);
JsonSerializableUtility util = new JsonSerializableUtility();
Map<String, Object> changes = util.findChanges(o1, o2);
// No Changes
if (changes.size() != 0)
Assert.fail("List should not have changed");
// Modify the List
writerList2.remove(1);
changes = util.findChanges(o1, o2);
if (changes.size() != 1)
Assert.fail("List should have changed");
@SuppressWarnings("unchecked") List<Object> changedList = (List<Object>) changes.get("writerList");
Assert.assertNotNull("List should have changed", changedList);
Assert.assertEquals((int) 1, changedList.size());
Assert.assertEquals((int) 1, changedList.get(0));
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class JsonSerializableUtilityTest method testRollupEnum.
@Test
public void testRollupEnum() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonException, IOException {
JsonSerializableTestObject o1 = new JsonSerializableTestObject();
JsonSerializableTestObject o2 = new JsonSerializableTestObject();
JsonSerializableUtility util = new JsonSerializableUtility();
Map<String, Object> changes = util.findChanges(o1, o2);
if (changes.size() != 0)
Assert.fail("Day Of Week should not have changed");
o2.setDayOfWeekEnum(DayOfWeek.FRIDAY);
changes = util.findChanges(o1, o2);
if (changes.size() != 1)
Assert.fail("Day Of Week should have changed");
DayOfWeek dow = (DayOfWeek) changes.get("dayOfWeekEnum");
Assert.assertEquals(DayOfWeek.FRIDAY, dow);
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseDeletedEvent.
public static void raiseDeletedEvent(String auditEventType, AbstractVO<?> o) {
Map<String, Object> context = new HashMap<String, Object>();
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findValues(o);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_DELETE, auditEventType, o, "event.audit.extended.deleted", context);
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseAddedEvent.
public static void raiseAddedEvent(String auditEventType, AbstractVO<?> o) {
Map<String, Object> context = new HashMap<String, Object>();
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findValues(o);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_CREATE, auditEventType, o, "event.audit.extended.added", context);
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class JsonSerializableUtilityTest method testIntArray.
@Test
public void testIntArray() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonException, IOException {
JsonSerializableTestObject o1 = new JsonSerializableTestObject();
JsonSerializableTestObject o2 = new JsonSerializableTestObject();
JsonSerializableUtility util = new JsonSerializableUtility();
Map<String, Object> changes = util.findChanges(o1, o2);
if (changes.size() != 0)
Assert.fail("Int array should not have changed");
o2.setIntArray(new int[] { 1, 2, 3 });
changes = util.findChanges(o1, o2);
if (changes.size() != 1)
Assert.fail("Int array should have changed");
int[] changed = (int[]) changes.get("intArray");
Assert.assertNotNull("Int array should have changed", changed);
Assert.assertEquals((int) 3, changed.length);
Assert.assertEquals(1, changed[0]);
Assert.assertEquals(2, changed[1]);
Assert.assertEquals(3, changed[2]);
}
Aggregations