* Checks: - Addition of label - That ADD event is issued - Updating of label
* - That UPDATE event is issued - Getting of label
*/
@Test
public void testAddUpdateAndGetLabel() {
final Label initialLabel = (Label) createLabel();
final Label[] updatedLabel = new Label[1];
final boolean[] labelAddedCalled = new boolean[] { false };
final boolean[] labelUpdatedCalled = new boolean[] { false };
LabelListener labelListener = null;
try {
labelListener = new LabelAdapter() {
@Override
public void entitiesAdded(Set<LabelEvent> events) {
for (LabelEvent event : events) {
labelAddedCalled[0] = true;
Label dbLabel = (Label) event.getEntity();
initialLabel.setId(dbLabel.getId());
assertTrue(initialLabel.isIdentical(dbLabel));
}
}
@Override
public void entitiesUpdated(Set<LabelEvent> events) {
LabelEvent event = events.iterator().next();
labelUpdatedCalled[0] = true;
Label dbLabel = (Label) event.getEntity();
assertTrue(updatedLabel[0].isIdentical(dbLabel));
}
};
DynamicDAO.addEntityListener(ILabel.class, labelListener);
long savedLabelId = DynamicDAO.save(initialLabel).getId().longValue();
System.gc();
ILabel dbLabel = DynamicDAO.load(ILabel.class, savedLabelId);
initialLabel.setId(dbLabel.getId());
assertTrue(initialLabel.isIdentical(dbLabel));
dbLabel.setColor("255,255,137");
updatedLabel[0] = (Label) dbLabel;
DynamicDAO.save(dbLabel);
assertTrue(labelAddedCalled[0]);
assertTrue(labelUpdatedCalled[0]);
DynamicDAO.delete(updatedLabel[0]);