From dac87a37d21770350dbc8e8c14b41a68e452ac8d Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Tue, 17 Nov 2009 18:44:02 +0000 Subject: [PATCH] NOJIRA added annotation for id in xsd, use mvn -Pddl process-test-classes to generate ddl, account.sql is copied after generation to src/main/resources/db/mysql using maven-ant-run plugin. changed AccountTest to use JPQ update and delete statements instead of find, update/delete, persist sequence test: account.jaxb mvn test M jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java M jaxb/src/main/resources/accounts_common.xsd A jaxb/src/main/resources/db/mysql/account.sql M jaxb/pom.xml --- services/account/jaxb/pom.xml | 63 +++---------------- .../src/main/resources/accounts_common.xsd | 8 ++- .../src/main/resources/db/mysql/account.sql | 8 +++ .../services/account/test/AccountTest.java | 31 ++++----- 4 files changed, 41 insertions(+), 69 deletions(-) create mode 100644 services/account/jaxb/src/main/resources/db/mysql/account.sql diff --git a/services/account/jaxb/pom.xml b/services/account/jaxb/pom.xml index 98f96b175..f4e8dff2e 100644 --- a/services/account/jaxb/pom.xml +++ b/services/account/jaxb/pom.xml @@ -14,7 +14,10 @@ org.collectionspace.services.account.jaxb 1.0 services.account.jaxb - + + account.sql + src/main/resources/db/mysql + @@ -102,7 +105,7 @@ ddl - + - org.apache.maven.plugins maven-antrun-plugin - process-classes - process-test-resources + process-test-classes - - - - - - - - - - + @@ -171,38 +158,6 @@ - - - org.hibernate - hibernate-tools - 3.2.3.GA - - - org.hibernate - hibernate - 3.4.0.GA - - - org.hibernate - hibernate-entitymanager - 3.4.0.GA - - - org.slf4j - slf4j-api - 1.5.2 - - - org.slf4j - slf4j-log4j12 - 1.5.2 - - - commons-logging - commons-logging - 1.1 - - diff --git a/services/account/jaxb/src/main/resources/accounts_common.xsd b/services/account/jaxb/src/main/resources/accounts_common.xsd index fab3f5876..c93750bac 100644 --- a/services/account/jaxb/src/main/resources/accounts_common.xsd +++ b/services/account/jaxb/src/main/resources/accounts_common.xsd @@ -33,7 +33,6 @@ - @@ -42,6 +41,13 @@ + + + + + + + diff --git a/services/account/jaxb/src/main/resources/db/mysql/account.sql b/services/account/jaxb/src/main/resources/db/mysql/account.sql new file mode 100644 index 000000000..4e9d9e6f9 --- /dev/null +++ b/services/account/jaxb/src/main/resources/db/mysql/account.sql @@ -0,0 +1,8 @@ +alter table ACCOUNTLISTITEM drop foreign key FKBD8755BE37E86A94; +drop table if exists ACCOUNTLISTITEM; +drop table if exists ACCOUNTSCOMMON; +drop table if exists ACCOUNTSCOMMONLIST; +create table ACCOUNTLISTITEM (HJID bigint not null auto_increment, ANCHORNAME varchar(255), CSID varchar(255), EMAIL varchar(255), FIRSTNAME varchar(255), LASTNAME varchar(255), MI varchar(255), URI varchar(255), ACCOUNTLISTITEM_ACCOUNTSCOMM_0 bigint, primary key (HJID)); +create table ACCOUNTSCOMMON (CSID varchar(255) not null, ANCHORNAME varchar(255), EMAIL varchar(255), FIRSTNAME varchar(255), LASTNAME varchar(255), MI varchar(255), PHONE varchar(255), primary key (CSID)); +create table ACCOUNTSCOMMONLIST (HJID bigint not null auto_increment, primary key (HJID)); +alter table ACCOUNTLISTITEM add index FKBD8755BE37E86A94 (ACCOUNTLISTITEM_ACCOUNTSCOMM_0), add constraint FKBD8755BE37E86A94 foreign key (ACCOUNTLISTITEM_ACCOUNTSCOMM_0) references ACCOUNTSCOMMONLIST (HJID); diff --git a/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java b/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java index 4a7a08ecf..31ddfaa05 100644 --- a/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java +++ b/services/account/jaxb/src/test/java/org/collectionspace/services/account/test/AccountTest.java @@ -32,6 +32,7 @@ public class AccountTest { private final Logger logger = LoggerFactory.getLogger(AccountTest.class); private EntityManagerFactory emf; private EntityManager em; + private String id; @BeforeMethod public void init() { @@ -54,14 +55,14 @@ public class AccountTest { @SuppressWarnings("unchecked") @Test(dataProvider = "testName", dataProviderClass = AccountTest.class) public void create(String testName) throws Exception { - // Begin transaction - em.getTransaction().begin(); AccountsCommon account = new AccountsCommon(); account.setAnchorName("sanjay"); account.setFirstName("Sanjay"); account.setLastName("Dalal"); account.setEmail("sanjay.dalal@berkeley.edu"); - account.setCsid(UUID.randomUUID().toString()); + id = UUID.randomUUID().toString(); + account.setCsid(id); + em.getTransaction().begin(); em.persist(account); // Commit the transaction em.getTransaction().commit(); @@ -95,14 +96,15 @@ public class AccountTest { @Test(dataProvider = "testName", dataProviderClass = AccountTest.class, dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - // Begin transaction + Query q = em.createQuery("update org.collectionspace.services.account.AccountsCommon set email= :email where csid=:csid"); + q.setParameter("email", "sanjay@berkeley.edu"); + q.setParameter("csid", id); em.getTransaction().begin(); - AccountsCommon account = findAccount("sanjay"); - Assert.assertNotNull(account); - account.setEmail("sanjay@berkeley.edu"); - em.persist(account); + int no = q.executeUpdate(); // Commit the transaction em.getTransaction().commit(); + Assert.assertEquals(no, 1); + AccountsCommon account = findAccount("sanjay"); if (logger.isDebugEnabled()) { logger.debug("updated account " + " first name=" + account.getFirstName() + @@ -114,21 +116,22 @@ public class AccountTest { @Test(dataProvider = "testName", dataProviderClass = AccountTest.class, dependsOnMethods = {"update"}) public void delete(String testName) throws Exception { + Query q = em.createQuery("delete from org.collectionspace.services.account.AccountsCommon where csid=:csid"); + q.setParameter("csid", id); // Begin transaction em.getTransaction().begin(); - AccountsCommon account = findAccount("sanjay"); - Assert.assertNotNull(account); + int no = q.executeUpdate(); + ; if (logger.isDebugEnabled()) { logger.debug("deleting account " + - " first name=" + account.getFirstName() + - " email=" + account.getEmail()); + " csid=" + id); } - em.remove(account); // Commit the transaction em.getTransaction().commit(); + Assert.assertEquals(no, 1); if (logger.isDebugEnabled()) { logger.debug("deleted account " + - " first name=" + account.getFirstName()); + " csid=" + id); } } -- 2.47.3