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;
dependsOnMethods = {"create"})
public void createList(String testName) throws Exception {
}
-
+
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
// 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()) {
// 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,
}
+ @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.
@Override
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
- dependsOnMethods = {"update", "readNonExistent", "testSubmitRequest"})
+ dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
// Perform setup.
// 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.
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,
<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>
<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>
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;
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
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);
String prop) {
return null;
}
+
+ /**
+ * sanitize removes data not needed to be sent to the consumer
+ * @param account
+ */
+ private void sanitize(AccountsCommon account) {
+ account.setTenantid("");
+ }
}