Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Deleted unnecessary getId method
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfpeterbacklund committed Mar 29, 2010
1 parent b35321f commit 8e0513a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
Expand Up @@ -9,8 +9,6 @@
import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;

import java.lang.reflect.Field;

public abstract class AbstractRepositoryTest extends AbstractTransactionalDataSourceSpringContextTests {

SessionFactory sessionFactory;
Expand All @@ -26,14 +24,8 @@ public void setHandlingEventRepository(HandlingEventRepository handlingEventRepo
this.handlingEventRepository = handlingEventRepository;
}

/*protected AbstractRepositoryTest() {
setAutowireMode(AUTOWIRE_BY_NAME);
setDependencyCheck(false);
}*/

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
//transactionManager = new HibernateTransactionManager(sessionFactory);
}

public SessionFactory getSessionFactory() {
Expand All @@ -55,26 +47,13 @@ protected String[] getConfigLocations() {
@Override
protected void onSetUpInTransaction() throws Exception {
// TODO store Sample* and object instances here instead of handwritten SQL
SampleDataGenerator.loadSampleData(jdbcTemplate, new TransactionTemplate(transactionManager));
//SampleDataGenerator.loadSampleData(jdbcTemplate, new TransactionTemplate(transactionManager));
SampleDataGenerator.loadHibernateData(new TransactionTemplate(transactionManager), sessionFactory, handlingEventFactory, handlingEventRepository);
sjt = new SimpleJdbcTemplate(jdbcTemplate);
}

protected Session getSession() {
return sessionFactory.getCurrentSession();
}

// Instead of exposing a getId() on persistent classes
protected Long getLongId(Object o) {
if (getSession().contains(o)) {
return (Long) getSession().getIdentifier(o);
} else {
try {
Field id = o.getClass().getDeclaredField("id");
id.setAccessible(true);
return (Long) id.get(o);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
Expand Up @@ -123,10 +123,10 @@ public void testSave() {

assertEquals("AAA", map.get("TRACKING_ID"));

Long originId = getLongId(origin);
Long originId = (Long) getSession().getIdentifier(cargo);
assertEquals(originId, map.get("SPEC_ORIGIN_ID"));

Long destinationId = getLongId(destination);
Long destinationId = (Long) getSession().getIdentifier(cargo);
assertEquals(destinationId, map.get("SPEC_DESTINATION_ID"));

getSession().clear();
Expand All @@ -137,7 +137,7 @@ public void testSave() {

public void testReplaceItinerary() {
Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
Long cargoId = getLongId(cargo);
Long cargoId = (Long) getSession().getIdentifier(cargo);
assertEquals(3, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));

Location legFrom = locationRepository.find(new UnLocode("DEHAM"));
Expand Down

0 comments on commit 8e0513a

Please sign in to comment.