From: <eri...@us...> - 2008-12-02 15:26:30
|
Revision: 1790 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=1790&view=rev Author: erikvaningen Date: 2008-12-02 15:26:24 +0000 (Tue, 02 Dec 2008) Log Message: ----------- corrected error Modified Paths: -------------- sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDao.java sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/resources/org/geonetwork/domain/ebrim/informationmodel/core/Identifiable.hbm.xml 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 sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDaoTest.java Modified: sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDao.java =================================================================== --- sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDao.java 2008-12-02 15:22:23 UTC (rev 1789) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDao.java 2008-12-02 15:26:24 UTC (rev 1790) @@ -16,7 +16,7 @@ * * @author Erik van Ingen * - * Dao for EmailAddress, Organization, Person, PersonName, PostalAddress, TelephoneNumber, + * Dao for EmailAddress, Organization, Person, PostalAddress, TelephoneNumber, * User * * @@ -98,31 +98,8 @@ return (Person) this.getHibernateTemplate().load(Person.class, id); } - /** - * PersonName - */ + - void savePersonName(PersonName personName) { - this.getHibernateTemplate().save(personName); - } - - void mergePersonName(PersonName personName) { - this.getHibernateTemplate().merge(personName); - } - - void deletePersonName(PersonName personName) { - this.getHibernateTemplate().delete(personName); - } - - @SuppressWarnings("unchecked") - List<PersonName> loadAllPersonName() { - return this.getHibernateTemplate().loadAll(PersonName.class); - } - - PersonName findPersonNameById(long id) { - return (PersonName) this.getHibernateTemplate().load(PersonName.class, id); - } - /** * PostalAddress */ Modified: sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/resources/org/geonetwork/domain/ebrim/informationmodel/core/Identifiable.hbm.xml =================================================================== --- sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/resources/org/geonetwork/domain/ebrim/informationmodel/core/Identifiable.hbm.xml 2008-12-02 15:22:23 UTC (rev 1789) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/main/resources/org/geonetwork/domain/ebrim/informationmodel/core/Identifiable.hbm.xml 2008-12-02 15:26:24 UTC (rev 1790) @@ -102,19 +102,12 @@ </property> </union-subclass> - <!-- - <union-subclass - name="org.geonetwork.domain.ebrim.informationmodel.cooperatingregistries.Federation" - table="FEDERATION"> <comment>Federation</comment> <property name="replicationSyncLatency" - column="REPLICATION_SYNC_LATENCY" - type="org.geonetwork.persistence.ebrim.hibernate.customtype.DurationUserType"/> - </union-subclass> - --> - <union-subclass name="org.geonetwork.domain.ebrim.informationmodel.cooperatingregistries.Federation" table="FEDERATION"> - <property name="erik" column="erik" /> + <comment>Federation</comment> + <property name="replicationSyncLatency" column="REPLICATION_SYNC_LATENCY" + type="org.geonetwork.persistence.ebrim.hibernate.customtype.DurationUserType" /> </union-subclass> 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 2008-12-02 15:22:23 UTC (rev 1789) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegate.java 2008-12-02 15:26:24 UTC (rev 1790) @@ -6,7 +6,7 @@ import java.lang.reflect.Method; import java.util.List; -import org.geonetwork.domain.ebrim.exception.GeoNetworkException; +import org.geonetwork.domain.ebrim.informationmodel.provenance.Person; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** @@ -18,8 +18,8 @@ * * The delegate for merge has however a precondition: * - * -- the domainObject saved has another domainObject as an attribute - * -- this attribute has an String attribute with the name value + * -- the domainObject saved has another domainObject as an attribute -- this attribute has + * an String attribute with the name value * */ public class DaoTestDelegate { @@ -85,19 +85,19 @@ method = factory.getClass().getMethod("create"); testDomainObject = method.invoke(factory); } catch (SecurityException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InstantiationException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (ClassNotFoundException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } return testDomainObject; } @@ -122,15 +122,15 @@ Object[] parameters = { testObject }; saveMergeMethod.invoke(dao, parameters); } catch (SecurityException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } } @@ -144,15 +144,15 @@ List<Object> list = (List<Object>) loadAllMethod.invoke(dao); size = list.size(); } catch (SecurityException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } return size; } @@ -171,15 +171,15 @@ Method getValueMethod = getReturnObject.getClass().getDeclaredMethod("getValue"); valueObject = (String) getValueMethod.invoke(getReturnObject); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (SecurityException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } return valueObject; } @@ -198,15 +198,15 @@ Object[] parameters = { value }; valueSetMethod.invoke(getReturnObject, parameters); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (SecurityException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } } @@ -221,37 +221,54 @@ Object[] parameters = { id }; foundObject = findDomainObjectByIdMethod.invoke(dao, parameters); } catch (SecurityException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } return foundObject; } long getId(Object domainObject) { String getIdMethodName = "getId"; + String getHibernateIdMethodName = "getHibernateId"; Long foundObject = null; try { - Method getIdMethod = domainObject.getClass().getDeclaredMethod(getIdMethodName); - foundObject = (Long) getIdMethod.invoke(domainObject); + 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; + } + // When the domain object is inheriting from Identifiable + if (idMethod == null) + idMethod = domainObject.getClass().getMethod(getHibernateIdMethodName); + foundObject = (Long) idMethod.invoke(domainObject); } catch (SecurityException e) { - throw new GeoNetworkException(e); - } catch (NoSuchMethodException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalArgumentException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (IllegalAccessException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); } catch (InvocationTargetException e) { - throw new GeoNetworkException(e); + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); } return foundObject; } + public Object getValueOOV(Person person, String string) { + // TODO Auto-generated method stub + return null; + } + + + } 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 2008-12-02 15:22:23 UTC (rev 1789) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/DaoTestDelegateTest.java 2008-12-02 15:26:24 UTC (rev 1790) @@ -5,16 +5,18 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.geonetwork.dao.ebrim.provenance.ProvenanceDao; import org.geonetwork.domain.ebrim.informationmodel.provenance.EmailAddress; +import org.geonetwork.domain.ebrim.informationmodel.provenance.Organization; import org.geonetwork.domain.ebrim.test.utilities.provenance.EmailAddressFactory; +import org.geonetwork.domain.ebrim.test.utilities.provenance.OrganizationFactory; import org.junit.Test; public class DaoTestDelegateTest { ProvenanceDao provenanceDao = new ProvenanceDao(); + @Test public void testDaoTestDelegate() { - + DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(provenanceDao); assertNotNull(testDaoTestDelegate); } @@ -54,49 +56,65 @@ @Test public void testCreateTestDomainObject() { - + DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(provenanceDao); Object testObject = testDaoTestDelegate.createTestDomainObject(EmailAddress.class); assertTrue(testObject instanceof EmailAddress); } - + @Test - public void testGetValue(){ + public void testGetValue() { EmailAddress emailAddress = EmailAddressFactory.create(); - String value = emailAddress.getAddress().getValue(); + String value = emailAddress.getAddress().getValue(); DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(provenanceDao); assertEquals(value, testDaoTestDelegate.getValue(emailAddress, "address")); assertEquals(value, testDaoTestDelegate.getValue(emailAddress, "Address")); } @Test - public void testSetValue(){ + public void testSetValue() { EmailAddress emailAddress = EmailAddressFactory.create(); - String value = "fjdklsfjsdl fdsfsd"; + String value = "fjdklsfjsdl fdsfsd"; DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(provenanceDao); testDaoTestDelegate.setValue(emailAddress, "address", value); assertEquals(value, testDaoTestDelegate.getValue(emailAddress, "address")); testDaoTestDelegate.setValue(emailAddress, "Address", value); assertEquals(value, testDaoTestDelegate.getValue(emailAddress, "address")); } - + @Test - public void testFindById(){ + public void testFindById() { EmailAddress emailAddress = EmailAddressFactory.create(); HelperDao dao = new HelperDao(); - dao.saveEmailAddress(emailAddress); + dao.saveEmailAddress(emailAddress); DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(dao); - assertNotNull(testDaoTestDelegate.findById(EmailAddress.class, 456l)); + assertNotNull(testDaoTestDelegate.findById(EmailAddress.class, 456l)); } + + /** + * test with 'normal' domain object + */ @Test - public void testGetId(){ + public void testGetId1() { EmailAddress emailAddress = EmailAddressFactory.create(); - long id = 7l; + long id = 7l; emailAddress.setId(id); HelperDao dao = new HelperDao(); DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(dao); - assertEquals(id, testDaoTestDelegate.getId(emailAddress)); + assertEquals(id, testDaoTestDelegate.getId(emailAddress)); } - + /** + * test with domain object which extends Identifiable + */ + @Test + public void testGetId2() { + Organization organization = OrganizationFactory.create(); + long id = 7l; + organization.setHibernateId(id); + HelperDao dao = new HelperDao(); + DaoTestDelegate testDaoTestDelegate = new DaoTestDelegate(dao); + assertEquals(id, testDaoTestDelegate.getId(organization)); + } + } Modified: sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDaoTest.java =================================================================== --- sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDaoTest.java 2008-12-02 15:22:23 UTC (rev 1789) +++ sandbox/3.0.x/geonetwork-persistence-ebrim/src/test/java/org/geonetwork/dao/ebrim/provenance/ProvenanceDaoTest.java 2008-12-02 15:26:24 UTC (rev 1790) @@ -4,22 +4,21 @@ import org.geonetwork.domain.ebrim.informationmodel.provenance.EmailAddress; import org.geonetwork.domain.ebrim.informationmodel.provenance.Organization; import org.geonetwork.domain.ebrim.informationmodel.provenance.Person; -import org.geonetwork.domain.ebrim.informationmodel.provenance.PersonName; import org.geonetwork.domain.ebrim.informationmodel.provenance.PostalAddress; import org.geonetwork.domain.ebrim.informationmodel.provenance.TelephoneNumber; import org.geonetwork.domain.ebrim.informationmodel.provenance.User; -import org.geonetwork.domain.ebrim.test.utilities.provenance.OrganizationFactory; +import org.geonetwork.domain.ebrim.test.utilities.provenance.PersonFactory; /** * * @author Erik van Ingen * - * TestDao for EmailAddress, Organization, Person, PersonName, PostalAddress, + * TestDao for EmailAddress, Organization, Person, PostalAddress, * TelephoneNumber, User + * Is person needed? * * * - * */ public class ProvenanceDaoTest extends AbstractDaoTest { @@ -49,29 +48,19 @@ * Organization */ public void testSaveOrganization() { - -// Object testObject = createTestDomainObject(domainClass); -// assertEquals(0, getSize(domainClass)); -// save(domainClass, testObject); -// assertEquals(1, getSize(domainClass)); - - Organization organization = OrganizationFactory.create(); - - provenanceDao.saveOrganization(organization); - - -// new DaoTestDelegate(provenanceDao).testSave(Organization.class); + + new DaoTestDelegate(provenanceDao).testSave(Organization.class); } - public void _testMergeOrganization() { - new DaoTestDelegate(provenanceDao).testMerge(Organization.class, "address"); + public void testMergeOrganization() { + new DaoTestDelegate(provenanceDao).testMerge(Organization.class, "parent"); } public void testDeleteOrganization() { new DaoTestDelegate(provenanceDao).testDelete(Organization.class); } - public void _testfindOrganizationById() { + public void testfindOrganizationById() { new DaoTestDelegate(provenanceDao).testfindById(Organization.class); } @@ -82,37 +71,31 @@ new DaoTestDelegate(provenanceDao).testSave(Person.class); } - public void _testMergePerson() { - new DaoTestDelegate(provenanceDao).testMerge(Person.class, "address"); + public void testMergePerson() { + String value = " fdsfksdfj dfsdfklsdj fsfjsdklf lks78907809"; + Person person = PersonFactory.create(); + provenanceDao.savePerson(person); + assertEquals(1, provenanceDao.loadAllPerson().size()); + for (PostalAddress postalAddress : person.getAddresses()) { + postalAddress.getCity().setValue(value); + } + provenanceDao.mergePerson(person); + Person personFound = provenanceDao.loadAllPerson().get(0); + for (PostalAddress postalAddress : personFound.getAddresses()) { + assertEquals(value, postalAddress.getCity().getValue()); + } } public void testDeletePerson() { new DaoTestDelegate(provenanceDao).testDelete(Person.class); } - public void _testfindPersonById() { + public void testfindPersonById() { new DaoTestDelegate(provenanceDao).testfindById(Person.class); } - /** - * PersonName - */ - public void _testSavePersonName() { - new DaoTestDelegate(provenanceDao).testSave(PersonName.class); - } - public void _testMergePersonName() { - new DaoTestDelegate(provenanceDao).testMerge(PersonName.class, "address"); - } - public void _testDeletePersonName() { - new DaoTestDelegate(provenanceDao).testDelete(PersonName.class); - } - - public void _testfindPersonNameById() { - new DaoTestDelegate(provenanceDao).testfindById(PersonName.class); - } - /** * PostalAddress */ @@ -189,7 +172,7 @@ new DaoTestDelegate(provenanceDao).testDelete(User.class); } - public void _testfindUserById() { + public void testfindUserById() { new DaoTestDelegate(provenanceDao).testfindById(User.class); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |