// Submit the request to the service and store the response.
AccountsCommon account =
- createAccountInstance("barney", "hithere08", "barney@dinoland.com", true, true, true);
+ createAccountInstance("barney", "barney", "hithere08", "barney@dinoland.com",
+ true, true, true, true);
ClientResponse<Response> res = client.create(account);
int statusCode = res.getStatus();
}
}
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void createForUniqueUser(String testName) throws Exception {
+
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ AccountsCommon account =
+ createAccountInstance("barney1", "barney", "hithere08", "barney@dinoland.com",
+ true, true, true, true);
+ ClientResponse<Response> res = client.create(account);
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ }
+
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void createForUniqueScreenName(String testName) throws Exception {
+
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ AccountsCommon account =
+ createAccountInstance("barney", "otherUser", "hithere08", "barney@dinoland.com",
+ true, true, true, true);
+ ClientResponse<Response> res = client.create(account);
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+ }
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"create"})
public void createWithoutTenant(String testName) throws Exception {
// Submit the request to the service and store the response.
AccountsCommon account =
- createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", false, true, true);
+ createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
+ true, false, true, true);
ClientResponse<Response> res = client.create(account);
int statusCode = res.getStatus();
// Does it exactly match the expected status code?
// Submit the request to the service and store the response.
AccountsCommon account =
- createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", true, false, true);
+ createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
+ true, true, false, true);
+ ClientResponse<Response> res = client.create(account);
+ int statusCode = res.getStatus();
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+ }
+
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void createWithInvalidEmail(String testName) throws Exception {
+
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ AccountsCommon account =
+ createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
+ true, true, true, true);
+ ClientResponse<Response> res = client.create(account);
+ int statusCode = res.getStatus();
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+ }
+
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void createWithoutScreenName(String testName) throws Exception {
+
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ AccountsCommon account =
+ createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
+ false, true, true, true);
+ ClientResponse<Response> res = client.create(account);
+ int statusCode = res.getStatus();
+ // Does it exactly match the expected status code?
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+ }
+
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void createWithMostInvalid(String testName) throws Exception {
+
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ AccountsCommon account =
+ createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
+ false, false, false, false);
ClientResponse<Response> res = client.create(account);
int statusCode = res.getStatus();
// Does it exactly match the expected status code?
setupCreate(testName);
// Submit the request to the service and store the response.
AccountsCommon account1 =
- createAccountInstance("curious", "hithere08", "curious@george.com", true, true, true);
+ createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
+ true, true, true, true);
ClientResponse<Response> res = client.create(account1);
int statusCode = res.getStatus();
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
resource1Id = extractId(res);
AccountsCommon account2 =
- createAccountInstance("tom", "hithere09", "tom@jerry.com", true, true, true);
+ createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
+ true, true, true, true);
res = client.create(account2);
statusCode = res.getStatus();
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
resource2Id = extractId(res);
AccountsCommon account3 =
- createAccountInstance("mj", "hithere10", "mj@dinoland.com", true, true, true);
+ createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
+ true, true, true, true);
res = client.create(account3);
statusCode = res.getStatus();
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Note: The ID used in this 'create' call may be arbitrary.
// The only relevant ID may be the one used in updateAccount(), below.
AccountsCommon account =
- createAccountInstance("simba", "tiger", "simba@lionking.com", true, true, true);
+ createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
+ true, true, true, true);
ClientResponse<AccountsCommon> res =
client.update(NON_EXISTENT_ID, account);
int statusCode = res.getStatus();
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
- /*
- * createAccountInstance
- * @param tenant fillup tenant
- * @param user to fill up user
- * @param password to fill up password
+ /**
+ * create account instance
+ * @param screenName
+ * @param userName
+ * @param passwd
+ * @param email
+ * @param useScreenName
+ * @param useTenant
+ * @param useUser
+ * @param usePassword
+ * @return
*/
private AccountsCommon createAccountInstance(String screenName,
- String passwd, String email, boolean tenant, boolean user, boolean password) {
+ String userName, String passwd, String email,
+ boolean useScreenName, boolean useTenant, boolean useUser, boolean usePassword) {
AccountsCommon account = new AccountsCommon();
- account.setScreenName(screenName);
- if (user) {
- account.setUserId(screenName);
+ if (useScreenName) {
+ account.setScreenName(screenName);
+ }
+ if (useUser) {
+ account.setUserId(userName);
}
- if (password) {
+ if (usePassword) {
account.setPassword(Base64.encodeBase64(passwd.getBytes()));
}
account.setEmail(email);
account.setPhone("1234567890");
- if (tenant) {
+ if (useTenant) {
List<AccountsCommon.Tenant> atl = new ArrayList<AccountsCommon.Tenant>();
AccountsCommon.Tenant at = new AccountsCommon.Tenant();
at.setId(UUID.randomUUID().toString());
<!--
CollectionSpace default (security) identity provider schema (XSD)
-
+
Entity(s) : users, roles, users_roles
- Used for:
-
+ Used for:
+
$LastChangedRevision: 916 $
$LastChangedDate: 2009-11-05 16:59:20 -0800 (Thu, 05 Nov 2009) $
-->
<xs:schema
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
- xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
- xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
- xmlns:ns="http://collectionspace.org/servics/authentication"
- xmlns="http://collectionspace.org/services/authentication"
- targetNamespace="http://collectionspace.org/services/authentication"
- version="0.1"
- jaxb:extensionBindingPrefixes="hj orm"
->
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
+ xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
+ xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
+ xmlns:ns="http://collectionspace.org/servics/authentication"
+ xmlns="http://collectionspace.org/services/authentication"
+ targetNamespace="http://collectionspace.org/services/authentication"
+ version="0.1"
+ jaxb:extensionBindingPrefixes="hj orm"
+ >
-<!--
+ <!--
Avoid XmlRootElement nightmare:
See http://weblogs.java.net/blog/kohsuke/archive/2006/03/why_does_jaxb_p.html
-->
-
+<!--
+ Notes for MySQL
+ MySQL puts key length limit of 1000 bytes
+ username - rolename constraint shoudl be within 1000 bytes
+ hbm2ddl makes column length >= 256 as long text, such as column cannot be used
+ in defining a key (pk, fk or constraint)
+-->
<xs:element name="user">
<xs:complexType>
<xs:annotation>
<xs:annotation>
<xs:appinfo>
<hj:id>
- <orm:column name="username" nullable="false"/>
+ <orm:column name="username" length="128" nullable="false"/>
</hj:id>
</xs:appinfo>
</xs:annotation>
<xs:annotation>
<xs:appinfo>
<hj:id>
- <orm:column name="rolename" nullable="false"/>
+ <orm:column name="rolename" length="200" nullable="false"/>
</hj:id>
</xs:appinfo>
</xs:annotation>
<xs:annotation>
<xs:appinfo>
<hj:entity>
- <orm:table name="users_roles"/>
+ <orm:table name="users_roles">
+ <orm:unique-constraint>
+ <!-- combined length should be < 1000 bytes -->
+ <orm:column-name>username</orm:column-name>
+ <orm:column-name>rolename</orm:column-name>
+ </orm:unique-constraint>
+ </orm:table>
</hj:entity>
</xs:appinfo>
</xs:annotation>
<xs:annotation>
<xs:appinfo>
<hj:basic>
- <orm:column name="username" nullable="false"/>
+ <orm:column name="username" length="128" nullable="false"/>
</hj:basic>
</xs:appinfo>
</xs:annotation>
<xs:annotation>
<xs:appinfo>
<hj:basic>
- <orm:column name="rolename" nullable="false"/>
+ <orm:column name="rolename" length="200" nullable="false"/>
</hj:basic>
</xs:appinfo>
</xs:annotation>