EntityParser { public <PK extends Serializable, T extends DomainObject<PK, ?>> List<T> parse(Class<T> clazz, JoinTables joinTables, ParseSession status) throws IllegalAccessException, InstantiationException, XMLStreamException, ImportException { FieldMap fieldMap = FieldMapFactory.buildFieldMapForEntity(clazz); this.status = status; return parseDomainObjects(clazz, fieldMap, joinTables, status); } EntityParser(XMLEventReader reader, EntityParserDao parserDao, PrimaryKeyCache keyCache, BackupConfig backupConfig); List<T> parse(Class<T> clazz, JoinTables joinTables, ParseSession status);  }
@Test public void shouldParseTwoTimesheetEntries() throws XMLStreamException, InstantiationException, IllegalAccessException, ImportException { EntityParser parser = createParser("<TIMESHEET_ENTRIES CLASS=\"net.rrm.ehour.domain.TimesheetEntry\">\n<TIMESHEET_ENTRY>\n<ASSIGNMENT_ID>1</ASSIGNMENT_ID>\n<ENTRY_DATE>2007-03-26</ENTRY_DATE>\n<HOURS>8.0</HOURS>\n <COMMENT>jaja</COMMENT>\n </TIMESHEET_ENTRY>\n <TIMESHEET_ENTRY>\n <ASSIGNMENT_ID>2</ASSIGNMENT_ID>\n <ENTRY_DATE>2007-03-26</ENTRY_DATE>\n <HOURS>0.0</HOURS>\n </TIMESHEET_ENTRY>\n </TIMESHEET_ENTRIES>\n", ProjectAssignmentObjectMother.createProjectAssignment(1), 1); keyCache.putKey(ProjectAssignment.class, 1, 1); keyCache.putKey(ProjectAssignment.class, 2, 2); List<TimesheetEntry> result = parser.parse(TimesheetEntry.class, new JoinTables(), status); assertEquals(2, result.size()); assertNotNull(result.get(0).getEntryId().getEntryDate()); assertNotNull(result.get(0).getEntryId().getProjectAssignment()); assertEquals(8.0, result.get(0).getHours(), 0); assertEquals("jaja", result.get(0).getComment()); assertEquals(2, daoValidator.getTotalPersistCount()); }
@Test public void shouldParseEnum() throws IllegalAccessException, XMLStreamException, InstantiationException, ImportException { EntityParser parser = createParser(" <AUDITS CLASS=\"net.rrm.ehour.domain.Audit\"><AUDIT>\n <AUDIT_ID>173</AUDIT_ID>\n <USER_ID>2</USER_ID>\n <USER_FULLNAME>Edeling, Thies</USER_FULLNAME>\n <AUDIT_DATE>2010-01-12 16:20:51.0</AUDIT_DATE>\n <SUCCESS>Y</SUCCESS>\n <AUDIT_ACTION_TYPE>LOGIN</AUDIT_ACTION_TYPE>\n </AUDIT></AUDITS>\n", UserObjectMother.createUser(), 2); when(backupConfig.entityForClass(Audit.class)).thenReturn(mock(BackupEntityType.class)); List<Audit> result = parser.parse(Audit.class, new JoinTables(), status); assertEquals(1, result.size()); assertEquals(AuditActionType.LOGIN, result.get(0).getAuditActionType()); }
@Test public void shouldRetrieveManyToOne() throws IllegalAccessException, XMLStreamException, InstantiationException, ImportException { User user = UserObjectMother.createUser(); EntityParser parser = createParser("<AUDITS CLASS=\"net.rrm.ehour.domain.Audit\"><AUDIT>\n <AUDIT_ID>173</AUDIT_ID>\n <USER_ID>2</USER_ID>\n <USER_FULLNAME>Edeling, Thies</USER_FULLNAME>\n <AUDIT_DATE>2010-01-12 16:20:51.0</AUDIT_DATE>\n <SUCCESS>Y</SUCCESS>\n <AUDIT_ACTION_TYPE>LOGIN</AUDIT_ACTION_TYPE>\n </AUDIT></AUDITS>\n", user, 2); when(backupConfig.entityForClass(Audit.class)).thenReturn(mock(BackupEntityType.class)); keyCache.putKey(User.class, 2, 2); List<Audit> result = parser.parse(Audit.class, new JoinTables(), status); assertEquals(1, result.size()); assertEquals(AuditActionType.LOGIN, result.get(0).getAuditActionType()); assertEquals(1, daoValidator.getTotalPersistCount()); assertEquals(user, result.get(0).getUser()); }
@Test @Ignore public void shouldImportManyToMany() throws XMLStreamException, InstantiationException, IllegalAccessException, ImportException { UserDepartment department = UserDepartmentObjectMother.createUserDepartment(); EntityParser parser = createParser("<USERLIST>\n <USERS>\n <USER_ID>1</USER_ID>\n <USERNAME>admin</USERNAME>\n <PASSWORD>1d798ca9dba7df61bf399a02695f9f50034bad66</PASSWORD>\n <FIRST_NAME>eHour</FIRST_NAME>\n <LAST_NAME>Admin</LAST_NAME>\n <EMAIL>t@t.net</EMAIL>\n <ACTIVE>Y</ACTIVE>\n </USERS>\n <USERS>\n <USER_ID>3</USER_ID>\n <USERNAME>thies</USERNAME>\n <PASSWORD>e2e90187007d55ae40678e11e0c9581cb7bb9928</PASSWORD>\n <FIRST_NAME>Thies</FIRST_NAME>\n <LAST_NAME>Edeling</LAST_NAME>\n <EMAIL>thies@te-con.nl</EMAIL>\n <ACTIVE>Y</ACTIVE>\n <SALT>6367</SALT>\n </USERS>\n </USERLIST>\n", department, 1); JoinTables joinTables = new JoinTables(); joinTables.put("USER_TO_DEPARTMENT", "1", "2"); joinTables.put("USER_TO_USERROLE", "1", "ADMIN"); List<User> result = parser.parse(User.class, joinTables, status); User user = result.get(0); assertEquals(1, user.getUserRoles().size()); }