use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class JsonSerializableUtilityTest method testNoChange.
@Test
public void testNoChange() 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("Should be no changes.");
}
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class JsonSerializableUtilityTest method testListJsonSerializable.
@Test
public void testListJsonSerializable() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonException, IOException {
List<Object> writerList1 = new ArrayList<>();
writerList1.add(new JsonSerializableTestObject());
writerList1.add(new JsonSerializableTestObject());
List<Object> writerList2 = new ArrayList<>();
writerList2.add(new JsonSerializableTestObject());
writerList2.add(new JsonSerializableTestObject());
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);
if (changes.size() != 0)
Assert.fail("List should not have changed");
((JsonSerializableTestObject) o2.getWriterList().get(0)).setDayOfWeekEnum(DayOfWeek.SUNDAY);
changes = util.findChanges(o1, o2);
if (changes.size() != 1)
Assert.fail("List should have changed");
@SuppressWarnings("unchecked") List<JsonSerializableTestObject> changedList = (List<JsonSerializableTestObject>) changes.get("writerList");
Assert.assertNotNull("List should have changed", changedList);
Assert.assertEquals((int) 2, changedList.size());
Assert.assertEquals(DayOfWeek.SUNDAY, changedList.get(0).getDayOfWeekEnum());
Assert.assertEquals(DayOfWeek.MONDAY, changedList.get(1).getDayOfWeekEnum());
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class JsonSerializableUtilityTest method testAnnotatedListOrder.
@Test
public void testAnnotatedListOrder() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, JsonException, IOException {
List<Object> annotatedList1 = new ArrayList<>();
annotatedList1.add(new Integer(1));
annotatedList1.add(new Integer(2));
List<Object> annotatedList2 = new ArrayList<>();
annotatedList2.add(new Integer(1));
annotatedList2.add(new Integer(2));
JsonSerializableTestObject o1 = new JsonSerializableTestObject();
o1.setAnnotatedList(annotatedList1);
JsonSerializableTestObject o2 = new JsonSerializableTestObject();
o2.setAnnotatedList(annotatedList2);
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
annotatedList2.clear();
annotatedList2.add(new Integer(2));
annotatedList2.add(new Integer(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("annotatedList");
Assert.assertNotNull("List should have changed", changedList);
Assert.assertEquals((int) 2, changedList.size());
Assert.assertEquals((int) 2, changedList.get(0));
Assert.assertEquals((int) 1, changedList.get(1));
}
use of com.serotonin.m2m2.util.JsonSerializableUtility in project ma-core-public by infiniteautomation.
the class AuditEventType method raiseChangedEvent.
public static void raiseChangedEvent(String auditEventType, AbstractVO<?> from, AbstractVO<?> to) {
Map<String, Object> context = new HashMap<String, Object>();
// Find the annotated properties
JsonSerializableUtility scanner = new JsonSerializableUtility();
try {
context = scanner.findChanges(from, to);
if (context.size() == 0)
// If the object wasn't in fact changed, don't raise an event.
return;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | JsonException | IOException e) {
LOG.error(e.getMessage(), e);
}
raiseEvent(AuditEventInstanceVO.CHANGE_TYPE_MODIFY, auditEventType, to, "event.audit.extended.changed", context);
}
Aggregations