]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-584, CSPACE-651
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 7 Dec 2009 21:52:01 +0000 (21:52 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 7 Dec 2009 21:52:01 +0000 (21:52 +0000)
CSPACE-584 added status attribute to account. XML type 'status' is also added. added test to change status (update/put is required).
CSPACE-651 tenant id is never returned to service consumer. response of get/update is sanitized to remove tenant id.
test: account test

M    account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java
M    account/jaxb/src/main/resources/accounts_common.xsd
M    account/client/src/test/java/org/collectionspace/services/client/test/AccountTest.java
M    account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java
M    account/client/src/main/resources/db/mysql/account.sql

services/account/client/src/main/resources/db/mysql/account.sql
services/account/client/src/test/java/org/collectionspace/services/client/test/AccountServiceTest.java
services/account/client/src/test/java/org/collectionspace/services/client/test/AccountTest.java
services/account/jaxb/src/main/resources/accounts_common.xsd
services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java

index 4f436d8b9f0bebc7f41c3de104c117222844d63f..6a3122c6ffade6d15778bd3f2bc66eb9cb110d86 100644 (file)
@@ -1,2 +1,2 @@
 drop table if exists accounts_common;
-create table accounts_common (csid varchar(255) not null, email longtext not null, first_name longtext not null, last_name longtext not null, mi varchar(1), mobile varchar(15), phone varchar(15), screen_name varchar(128) not null, tenantid varchar(255) not null, userid longtext not null, primary key (csid));
+create table accounts_common (csid varchar(255) not null, email longtext not null, first_name longtext not null, last_name longtext not null, mi varchar(1), mobile varchar(255), phone varchar(255), screen_name varchar(128) not null, status varchar(15) not null, tenantid varchar(255) not null, userid longtext not null, primary key (csid));
index 07950afb52bfce4de221c8b02f916c4378370ac2..9d13184cff2e989ff8161fb215732cf0796e4edf 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.commons.codec.binary.Base64;
 import org.collectionspace.services.client.AccountClient;
 import org.collectionspace.services.account.AccountsCommon;
 import org.collectionspace.services.account.AccountsCommonList;
+import org.collectionspace.services.account.Status;
 import org.jboss.resteasy.client.ClientResponse;
 
 import org.testng.Assert;
@@ -106,7 +107,7 @@ public class AccountServiceTest extends AbstractServiceTest {
     dependsOnMethods = {"create"})
     public void createList(String testName) throws Exception {
     }
-    
+
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
@@ -228,12 +229,13 @@ public class AccountServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
-    dependsOnMethods = {"read", "readNonExistent"})
+    dependsOnMethods = {"read", "readList", "readNonExistent"})
     public void update(String testName) throws Exception {
 
         // Perform setup.
         setupUpdate(testName);
 
+
         ClientResponse<AccountsCommon> res =
                 client.read(knownResourceId);
         if (logger.isDebugEnabled()) {
@@ -250,7 +252,6 @@ public class AccountServiceTest extends AbstractServiceTest {
 
         // Update the content of this resource.
         toUpdateAccount.setEmail("updated-" + toUpdateAccount.getEmail());
-        toUpdateAccount.setPhone("updated-" + toUpdateAccount.getPhone());
         if (logger.isDebugEnabled()) {
             logger.debug("updated object");
             logger.debug(objectAsXmlString(toUpdateAccount,
@@ -278,6 +279,57 @@ public class AccountServiceTest extends AbstractServiceTest {
 
     }
 
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+    dependsOnMethods = {"update"})
+    public void deactivate(String testName) throws Exception {
+
+        // Perform setup.
+        setupUpdate(testName);
+
+
+        ClientResponse<AccountsCommon> res =
+                client.read(knownResourceId);
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": read status = " + res.getStatus());
+        }
+        Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("got object to update with ID: " + knownResourceId);
+        }
+        AccountsCommon toUpdateAccount =
+                (AccountsCommon) res.getEntity();
+        Assert.assertNotNull(toUpdateAccount);
+
+        // Update the content of this resource.
+        toUpdateAccount.setStatus(Status.INACTIVE);
+        if (logger.isDebugEnabled()) {
+            logger.debug("updated object");
+            logger.debug(objectAsXmlString(toUpdateAccount,
+                    AccountsCommon.class));
+        }
+
+        // Submit the request to the service and store the response.
+        res = client.update(knownResourceId, toUpdateAccount);
+        int statusCode = res.getStatus();
+        // Check the status code of the response: does it match the expected response(s)?
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": status = " + statusCode);
+        }
+        Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+        Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+
+        AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
+        Assert.assertNotNull(updatedAccount);
+
+        Assert.assertEquals(updatedAccount.getStatus(),
+                toUpdateAccount.getStatus(),
+                "Data in updated object did not match submitted data.");
+
+    }
+
     // Failure outcomes
     // Placeholders until the three tests below can be uncommented.
     // See Issue CSPACE-401.
@@ -295,7 +347,7 @@ public class AccountServiceTest extends AbstractServiceTest {
 
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
-    dependsOnMethods = {"update", "readNonExistent", "testSubmitRequest"})
+    dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
     public void updateNonExistent(String testName) throws Exception {
 
         // Perform setup.
@@ -327,7 +379,7 @@ public class AccountServiceTest extends AbstractServiceTest {
     // Success outcomes
     @Override
     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
-    dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "updateNonExistent"})
+    dependsOnMethods = {"testSubmitRequest", "updateNonExistent"})
     public void delete(String testName) throws Exception {
 
         // Perform setup.
@@ -412,6 +464,7 @@ public class AccountServiceTest extends AbstractServiceTest {
         byte[] b64passwd = Base64.encodeBase64(passwd.getBytes());
         account.setPassword(b64passwd);
         account.setEmail(email);
+        account.setPhone("1234567890");
         if (logger.isDebugEnabled()) {
             logger.debug("to be created, account common");
             logger.debug(objectAsXmlString(account,
index 2a4f04e5332aa6f0a2754f4d95965f29407adb0b..a2c6ed970949d0eff0f95994677843d16c90f29f 100644 (file)
@@ -5,7 +5,6 @@
 package org.collectionspace.services.client.test;
 
 import java.lang.reflect.Method;
-import java.util.List;
 import java.util.UUID;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
@@ -13,6 +12,7 @@ import javax.persistence.Persistence;
 
 import javax.persistence.Query;
 import org.collectionspace.services.account.AccountsCommon;
+import org.collectionspace.services.account.Status;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -61,6 +61,7 @@ public class AccountTest {
         account.setLastName("Doe");
         account.setEmail("john.doe@berkeley.edu");
         account.setUserId("johndoe");
+        account.setStatus(Status.ACTIVE);
         id = UUID.randomUUID().toString();
         account.setCsid(id);
         account.setTenantid("123"); //set by service runtime
index 9384ea9fa8fd04f776da2c23bbc209f08d5da5fb..169858c3bbf93b4debc6de6f7fe1e651bbbb564c 100644 (file)
@@ -89,7 +89,7 @@
                     <xs:annotation>
                         <xs:appinfo>
                             <hj:basic>
-                                <orm:column name="phone" length="15" nullable="true"/>
+                                <orm:column name="phone" nullable="true"/>
                             </hj:basic>
                         </xs:appinfo>
                     </xs:annotation>
@@ -98,7 +98,7 @@
                     <xs:annotation>
                         <xs:appinfo>
                             <hj:basic>
-                                <orm:column name="mobile" length="15" nullable="true"/>
+                                <orm:column name="mobile" nullable="true"/>
                             </hj:basic>
                         </xs:appinfo>
                     </xs:annotation>
                         </xs:appinfo>
                     </xs:annotation>
                 </xs:element>
+                <xs:element name="status" type="status">
+                    <xs:annotation>
+                        <xs:appinfo>
+                            <hj:basic>
+                                <orm:column name="status" length="15" nullable="false"/>
+                            </hj:basic>
+                        </xs:appinfo>
+                    </xs:annotation>
+                </xs:element>
             </xs:sequence>
             <xs:attribute name="csid" type="xs:string">
                 <xs:annotation>
                             <xs:element name="lastName" type="xs:string" minOccurs="1" />
                             <xs:element name="mi" type="xs:string"/>
                             <xs:element name="email" type="xs:string" minOccurs="1" />
+                            <xs:element name="status" type="status" minOccurs="1" />
                             <!-- uri to retrive collection object details -->
-                            <xs:element name="uri" type="xs:anyURI"
-                                minOccurs="1" />
-                            <xs:element name="csid" type="xs:string"
-                                minOccurs="1" />
+                            <xs:element name="uri" type="xs:anyURI" minOccurs="1" />
+                            <xs:element name="csid" type="xs:string" minOccurs="1" />
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
             </xs:sequence>
         </xs:complexType>
     </xs:element>
-    
+
+    <xs:simpleType name="status">
+        <xs:restriction base="xs:string">
+            <xs:enumeration value="active" />
+            <xs:enumeration value="inactive" />
+        </xs:restriction>
+    </xs:simpleType>
 </xs:schema>
 
index 1273ad5b26556b782ad85498485db3352e2dffa6..2bc63ae64bfda968bd9835c94220439e2b630ed1 100644 (file)
@@ -28,6 +28,7 @@ import java.util.UUID;
 import org.collectionspace.services.account.AccountsCommon;
 import org.collectionspace.services.account.AccountsCommonList;
 import org.collectionspace.services.account.AccountsCommonList.AccountListItem;
+import org.collectionspace.services.account.Status;
 import org.collectionspace.services.common.document.AbstractDocumentHandler;
 import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
@@ -47,17 +48,25 @@ public class AccountDocumentHandler
         String id = UUID.randomUUID().toString();
         AccountsCommon account = wrapDoc.getWrappedObject();
         account.setCsid(id);
+        account.setStatus(Status.ACTIVE);
     }
 
     @Override
     public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
-        getServiceContext().setOutput(getCommonPart());
+        getServiceContext().setOutput(account);
+    }
+
+    @Override
+    public void completeUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
+        AccountsCommon upAcc = wrapDoc.getWrappedObject();
+        sanitize(upAcc);
     }
 
     @Override
     public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
         setCommonPart(extractCommonPart(wrapDoc));
-        getServiceContext().setOutput(getCommonPart());
+        sanitize(getCommonPart());
+        getServiceContext().setOutput(account);
     }
 
     @Override
@@ -95,6 +104,7 @@ public class AccountDocumentHandler
             accListItem.setEmail(account.getEmail());
             accListItem.setFirstName(account.getFirstName());
             accListItem.setLastName(account.getLastName());
+            accListItem.setStatus(account.getStatus());
             String id = account.getCsid();
             accListItem.setUri(getServiceContextPath() + id);
             accListItem.setCsid(id);
@@ -128,4 +138,12 @@ public class AccountDocumentHandler
             String prop) {
         return null;
     }
+
+    /**
+     * sanitize removes data not needed to be sent to the consumer
+     * @param account
+     */
+    private void sanitize(AccountsCommon account) {
+        account.setTenantid("");
+    }
 }