From: <eri...@us...> - 2009-01-17 20:13:36
|
Revision: 2002 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=2002&view=rev Author: erikvaningen Date: 2009-01-17 20:13:31 +0000 (Sat, 17 Jan 2009) Log Message: ----------- added the entity Image to the ExtrinsicObjectBeDao Modified Paths: -------------- sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/extensionpackage/basicextension/ExtrinsicObjectBeDaoTest.java sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegate.java sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegateTest.java Modified: sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/extensionpackage/basicextension/ExtrinsicObjectBeDaoTest.java =================================================================== --- sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/extensionpackage/basicextension/ExtrinsicObjectBeDaoTest.java 2009-01-17 19:43:48 UTC (rev 2001) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/extensionpackage/basicextension/ExtrinsicObjectBeDaoTest.java 2009-01-17 20:13:31 UTC (rev 2002) @@ -79,8 +79,7 @@ new DaoTestDelegate(extrinsicObjectBeDao).testSave(Image.class); } - // TODO Erik continue here - public void _testMergeImage() { + public void testMergeImage() { new DaoTestDelegate(extrinsicObjectBeDao).testMerge(Image.class, "mimeType"); } @@ -88,9 +87,11 @@ new DaoTestDelegate(extrinsicObjectBeDao).testDelete(Image.class); } - // TODO Erik continue here - public void _testfindImageById() { + public void testfindImageById() { new DaoTestDelegate(extrinsicObjectBeDao).testfindById(Image.class); } + + + } Modified: sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegate.java =================================================================== --- sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegate.java 2009-01-17 19:43:48 UTC (rev 2001) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegate.java 2009-01-17 20:13:31 UTC (rev 2002) @@ -1,6 +1,7 @@ package org.geonetwork.dao.ebrim.provenance; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.InvocationTargetException; @@ -11,8 +12,6 @@ import org.geonetwork.utils.RandomPopulator; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; -import com.sun.corba.se.spi.ior.Identifiable; - /** * DaoTestDelegate can be used test easily a Dao on save, merge, update, findById and findAll. * @@ -253,46 +252,10 @@ String getHibernateIdMethodName = "getHibernateId"; Long foundObject = null; try { - Method methods[] = domainObject.getClass().getDeclaredMethods(); - Method idMethod = null; - for (Method method : methods) { - // When the domain object is not inheriting from Identifiable - if (method.getName().equals(getIdMethodName)) - idMethod = method; - } - - // System.out.println(domainObject.getClass()); - // System.out.println(domainObject.getClass().getSuperclass()); - // System.out.println(domainObject.getClass().getSuperclass().getSuperclass()); - // System.out.println(domainObject.getClass().getSuperclass().getSuperclass().getSuperclass()); - - // When the domain object is inheriting from Identifiable - if (idMethod == null - && domainObject.getClass().getSuperclass().getSimpleName().equals( - Identifiable.class.getSimpleName())) - idMethod = domainObject.getClass().getSuperclass().getDeclaredMethod(getHibernateIdMethodName); - if (idMethod == null - && domainObject.getClass().getSuperclass().getSuperclass().getSimpleName().equals( - Identifiable.class.getSimpleName())) - idMethod = domainObject.getClass().getSuperclass().getSuperclass().getDeclaredMethod( - getHibernateIdMethodName); - - try { - if (idMethod == null - && domainObject.getClass().getSuperclass().getSuperclass().getSuperclass().getSimpleName() - .equals(Identifiable.class.getSimpleName())) - idMethod = domainObject.getClass().getSuperclass().getSuperclass().getSuperclass() - .getDeclaredMethod(getHibernateIdMethodName); - } catch (NullPointerException e) { - // weird to do it like this. I do not find a way however to check whether a class - // has a superclass or not. - } - - // When the domain object is not inheriting from Identifiable but from an abstract class - // which holds the id + Method idMethod = searchMethodUpInTree(domainObject.getClass(), getHibernateIdMethodName); if (idMethod == null) - idMethod = domainObject.getClass().getSuperclass().getDeclaredMethod(getIdMethodName); - + idMethod = searchMethodUpInTree(domainObject.getClass(), getIdMethodName); + assertNotNull(idMethod); foundObject = (Long) idMethod.invoke(domainObject); } catch (SecurityException e) { throw new RuntimeException(e); @@ -302,8 +265,6 @@ throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); } return foundObject; } @@ -325,15 +286,18 @@ // TODO use this method everywhere possible in this class Method searchMethodUpInTree(Class<?> domainClass, String methodName) { Method methodFound = null; + assertNotNull(domainClass); do { - Method methods[] = domainClass.getDeclaredMethods(); - for (Method method : methods) { - if (method.getName().toLowerCase().equals(methodName.toLowerCase())) - methodFound = method; + if (domainClass.getDeclaredMethods() != null) { + Method methods[] = domainClass.getDeclaredMethods(); + for (Method method : methods) { + if (method.getName().toLowerCase().equals(methodName.toLowerCase())) + methodFound = method; + } + domainClass = domainClass.getSuperclass(); } - domainClass = domainClass.getSuperclass(); - } while (methodFound == null); + } while (methodFound == null && domainClass != null); return methodFound; } Modified: sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegateTest.java =================================================================== --- sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegateTest.java 2009-01-17 19:43:48 UTC (rev 2001) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegateTest.java 2009-01-17 20:13:31 UTC (rev 2002) @@ -169,11 +169,26 @@ } @Test + public void testGetId6() { + Image image = new Image(); + long id = 7l; + image.setHibernateId(id); + HelperDao dao = new HelperDao(); + DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(dao); + assertEquals(id, testDaoTestDelegate.getId(image)); + } + + + + @Test public void testSearchMethodUpInTree() { HelperDao dao = new HelperDao(); DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(dao); String methodName = "getMimeType"; assertEquals(methodName, testDaoTestDelegate.searchMethodUpInTree(Image.class, methodName).getName()); } - + + + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |