CSPACE-1365 deny user bigbird2010 in ROLE_MMI_CM access (C) to the dimension service
moved authorization generation and seeding to authorization-mgt/client from authorization service
enabled access control for the dimension service only in the security interceptor
added setAuth convenience method into client test framework to change authn properites, httpclient and proxy
test: all service tests, specifically security/client and authorization-mgt/client tests
!!REQUIRES the following sequence of actions at the services level
- mvn clean install -DskipTests
- ant undeploy deploy
- mvn test (note that authorization-mgt/client tests have to run before running dimension/client and security/client tests)
A services/authorization-mgt/service/src/test/javadoc
A services/authorization-mgt/service/src/test/javadoc/org
A services/authorization-mgt/service/src/test/javadoc/org/collectionspace
A services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services
A services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization
A services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization/test
A + services/authorization-mgt/service/src/test/javadoc/org/collectionspace/services/authorization/test/package.html
M services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/AuthorizationDelegate.java
A services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test
A + services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AuthorizationSeedTest.java
A + services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AbstractAuthorizationTestImpl.java
A + services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/test/AuthorizationGen.java
A + services/authorization-mgt/client/src/test/resources/applicationContext-authorization-test.xml
A services/authorization-mgt/client/src/test/resources/test-data
A + services/authorization-mgt/client/src/test/resources/test-data/test-permissions.xml
A + services/authorization-mgt/client/src/test/resources/test-data/test-permissions-roles.xml
M services/authorization-mgt/client/pom.xml
M services/dimension/client/src/test/java/org/collectionspace/services/client/test/DimensionServiceTest.java
A services/dimension/client/src/main/java/org/collectionspace/services/client/DimensionFactory.java
M services/dimension/client/pom.xml
D services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AuthorizationSeedTest.java
D services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AbstractAuthorizationTestImpl.java
D services/authorization/service/src/test/java/org/collectionspace/services/authorization/test/AuthorizationGen.java
D services/authorization/service/src/test/javadoc/org/collectionspace/services/authorization/test/package.html
D services/authorization/service/src/test/resources/applicationContext-authorization-test.xml
D services/authorization/service/src/test/resources/test-data/test-permissions.xml
D services/authorization/service/src/test/resources/test-data/test-permissions-roles.xml
M services/authorization/service/pom.xml
M services/authorization/pstore/src/main/resources/db/mysql/test_authorization.sql
M services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
M services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthenticationServiceTest.java
A services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java
M services/security/client/pom.xml
M services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java
M services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java
M services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
M services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.authorization-mgt.client</artifactId>\r
<name>services.authorization-mgt.client</name>\r
- \r
+ <properties>\r
+ <spring.version>3.0.0.RELEASE</spring.version>\r
+ <spring.security.version>3.0.2.RELEASE</spring.security.version>\r
+ </properties>\r
<dependencies>\r
<!-- keep slf4j dependencies on the top -->\r
<dependency>\r
<groupId>org.slf4j</groupId>\r
<artifactId>slf4j-log4j12</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.authentication.service</artifactId>\r
+ <version>${project.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.authorization.service</artifactId>\r
+ <version>${project.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.authorization.jaxb</artifactId>\r
<!-- Needed if/when client test framework files are moved into -->\r
<!-- /services/client/src/test from /services/client/src/main -->\r
\r
- <dependency>\r
- <groupId>mysql</groupId>\r
- <artifactId>mysql-connector-java</artifactId>\r
- <scope>test</scope>\r
- </dependency> \r
<!-- <dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.client</artifactId>\r
<groupId>org.testng</groupId>\r
<artifactId>testng</artifactId>\r
<version>5.6</version>\r
- </dependency> \r
+ </dependency>\r
<dependency>\r
<groupId>org.jboss.resteasy</groupId>\r
<artifactId>resteasy-jaxrs</artifactId>\r
<artifactId>commons-httpclient</artifactId>\r
<version>3.1</version>\r
</dependency>\r
+\r
+ <dependency>\r
+ <groupId>org.springframework.security</groupId>\r
+ <artifactId>spring-security-core</artifactId>\r
+ <version>${spring.security.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework.security</groupId>\r
+ <artifactId>spring-security-config</artifactId>\r
+ <version>${spring.security.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework.security</groupId>\r
+ <artifactId>spring-security-acl</artifactId>\r
+ <version>${spring.security.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework.security</groupId>\r
+ <artifactId>spring-security-web</artifactId>\r
+ <version>${spring.security.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-context</artifactId>\r
+ <version>${spring.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-context-support</artifactId>\r
+ <version>${spring.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-aop</artifactId>\r
+ <version>${spring.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>aopalliance</groupId>\r
+ <artifactId>aopalliance</artifactId>\r
+ <version>1.0</version>\r
+ <scope>provided</scope>\r
+ </dependency>\r
+ <!--dependency>\r
+ <groupId>org.springframework</groupId>\r
+ <artifactId>spring-tx</artifactId>\r
+ <version>${spring.version}</version>\r
+ <scope>provided</scope>\r
+ </dependency-->\r
+ <dependency>\r
+ <groupId>net.sf.ehcache</groupId>\r
+ <artifactId>ehcache</artifactId>\r
+ <version>1.6.2</version>\r
+ <optional>true</optional>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>mysql</groupId>\r
+ <artifactId>mysql-connector-java</artifactId>\r
+ <scope>test</scope>\r
+ </dependency>\r
</dependencies>\r
\r
<build>\r
<finalName>cspace-services-authorization-mgt-client</finalName>\r
- <plugins> \r
+ <plugins>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-surefire-plugin</artifactId>\r
+ <configuration>\r
+ <systemProperties>\r
+ <property>\r
+ <name>maven.basedir</name>\r
+ <value>${basedir}</value>\r
+ </property>\r
+ <property>\r
+ <name>log4j.configuration</name>\r
+ <value>file:${project.build.directory}/test-classes/log4j.properties</value>\r
+ </property>\r
+ <property>\r
+ <name>spring-beans-config</name>\r
+ <value>applicationContext-authorization-test.xml</value>\r
+ </property>\r
+ </systemProperties>\r
+ </configuration>\r
+ </plugin>\r
</plugins>\r
</build>\r
\r
Permission accPerm = buildCommonPermission("1", "accounts");
apcList.add(accPerm);
- Permission coPerm = buildCommonPermission("2", "collectionobjects");
- apcList.add(coPerm);
+ Permission dimPerm = buildCommonPermission("2", "dimensions");
+ apcList.add(dimPerm);
AbstractAuthorizationTestImpl.toFile(pcList, PermissionsList.class,
AbstractAuthorizationTestImpl.testDataDir + "test-permissions.xml");
logger.info("generated permissions to "
PermissionsRolesList psrsl = new PermissionsRolesList();
ArrayList<PermissionRole> prl = new ArrayList<PermissionRole>();
prl.add(buildCommonPermissionRoles("1", "accounts"));
- prl.add(buildCommonPermissionRoles("2", "collectionobjects"));
+ prl.add(buildCommonPermissionRoles("2", "dimensions"));
psrsl.setPermissionRoles(prl);
AbstractAuthorizationTestImpl.toFile(psrsl, PermissionsRolesList.class,
AbstractAuthorizationTestImpl.testDataDir + "test-permissions-roles.xml");
//import java.util.ArrayList;
//import java.util.List;
+import java.util.ArrayList;
+import java.util.List;
+import org.collectionspace.services.authorization.ActionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.collectionspace.services.client.test.BaseServiceTest;
import org.collectionspace.services.authorization.AuthZ;
+import org.collectionspace.services.authorization.CSpaceAction;
import org.collectionspace.services.authorization.Permission;
+import org.collectionspace.services.authorization.PermissionAction;
+import org.collectionspace.services.authorization.PermissionException;
import org.collectionspace.services.authorization.PermissionRole;
import org.collectionspace.services.authorization.PermissionsList;
import org.collectionspace.services.authorization.PermissionsRolesList;
+import org.collectionspace.services.authorization.RoleValue;
+import org.collectionspace.services.authorization.URIResourceImpl;
import org.springframework.transaction.TransactionStatus;
import org.testng.annotations.BeforeClass;
}
for (PermissionRole pr : pcrList.getPermissionRoles()) {
if (pr.getPermissions().get(0).getPermissionId().equals(p.getCsid())) {
-// authZ.addPermissionsForUri(p, pr);
+ addPermissionsForUri(p, pr);
}
}
}
}
+
+ /**
+ * addPermissionsForUri add permissions from given permission configuration
+ * with assumption that resource is of type URI
+ * @param permission configuration
+ */
+ //FIXME this method should be in the restful web service resource of authz
+ private void addPermissionsForUri(Permission perm,
+ PermissionRole permRole) throws PermissionException {
+ List<String> principals = new ArrayList<String>();
+ if (!perm.getCsid().equals(permRole.getPermissions().get(0).getPermissionId())) {
+ throw new IllegalArgumentException("permission ids do not"
+ + " match for role=" + permRole.getRoles().get(0).getRoleName()
+ + " with permissionId=" + permRole.getPermissions().get(0).getPermissionId()
+ + " for permission with csid=" + perm.getCsid());
+ }
+ for (RoleValue roleValue : permRole.getRoles()) {
+ principals.add(roleValue.getRoleName());
+ }
+ List<PermissionAction> permActions = perm.getActions();
+ for (PermissionAction permAction : permActions) {
+ CSpaceAction action = getAction(permAction.getName());
+ URIResourceImpl uriRes = new URIResourceImpl(perm.getTenantId(),
+ perm.getResourceName(), action);
+ AuthZ.get().addPermissions(uriRes, principals.toArray(new String[0]));
+ }
+ }
+
+
+ /**
+ * getAction is a convenience method to get corresponding action for
+ * given ActionType
+ * @param action
+ * @return
+ */
+ private CSpaceAction getAction(ActionType action) {
+ if (ActionType.CREATE.equals(action)) {
+ return CSpaceAction.CREATE;
+ } else if (ActionType.READ.equals(action)) {
+ return CSpaceAction.READ;
+ } else if (ActionType.UPDATE.equals(action)) {
+ return CSpaceAction.UPDATE;
+ } else if (ActionType.DELETE.equals(action)) {
+ return CSpaceAction.DELETE;
+ } else if (ActionType.SEARCH.equals(action)) {
+ return CSpaceAction.SEARCH;
+ } else if (ActionType.ADMIN.equals(action)) {
+ return CSpaceAction.ADMIN;
+ } else if (ActionType.START.equals(action)) {
+ return CSpaceAction.START;
+ } else if (ActionType.STOP.equals(action)) {
+ return CSpaceAction.STOP;
+ }
+ throw new IllegalArgumentException("action = " + action.toString());
+ }
}
<bean id="cspaceAuthorizationProvider" class="org.collectionspace.services.authorization.spring.SpringAuthorizationProvider">
<property name="providerAclService" ref="aclService"/>
<property name="providerPermissionEvaluator" ref="permissionEvaluator"/>
+ <property name="txManager" ref="transactionManager"/>
</bean>
</beans>
<subject>ROLE</subject>
<permission>
<permissionId>2</permissionId>
- <resourceName>collectionobjects</resourceName>
+ <resourceName>dimensions</resourceName>
</permission>
<role>
<roleId>1</roleId>
<tenant_id>1</tenant_id>
</permission>
<permission csid="2">
- <resourceName>collectionobjects</resourceName>
+ <resourceName>dimensions</resourceName>
<action>
<name>CREATE</name>
</action>
}
}
- /**
- * addPermissionsForUri add permissions from given permission configuration
- * with assumption that resource is of type URI
- * @param permission configuration
- */
- //FIXME this method should be in the restful web service resource of authz
- public void addPermissionsForUri(Permission perm,
- PermissionRole permRole) throws PermissionException {
- List<String> principals = new ArrayList<String>();
- if (!perm.getCsid().equals(permRole.getPermissions().get(0).getPermissionId())) {
- throw new IllegalArgumentException("permission ids do not"
- + " match for role=" + permRole.getRoles().get(0).getRoleName()
- + " with permissionId=" + permRole.getPermissions().get(0).getPermissionId()
- + " for permission with csid=" + perm.getCsid());
- }
- for (RoleValue roleValue : permRole.getRoles()) {
- principals.add(roleValue.getRoleName());
- }
- List<PermissionAction> permActions = perm.getActions();
- for (PermissionAction permAction : permActions) {
- CSpaceAction action = getAction(permAction.getName());
- URIResourceImpl uriRes = new URIResourceImpl(perm.getTenantId(),
- perm.getResourceName(), action);
- AuthZ.get().addPermissions(uriRes, principals.toArray(new String[0]));
- }
- }
+
/**
* getRoles get roles (string) array from given RoleValue list
insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('eeca40d7-dc77-4cc5-b489-16a53c75525a', 'test', '3', 'ROLE_COLLECTIONS_MANAGER', '2010-02-17 16:31:48');\r
\r
-- Additional account introduced during integration on release 0.6, and currently relied upon by the Application Layer.\r
-insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test', '1', 'ROLE_ADMINISTRATOR', '2010-05-03 12:35:00');\r
-insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test', '2', 'ROLE_USERS', '2010-05-03 12:35:00');\r
-insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test', '3', 'ROLE_COLLECTIONS_MANAGER', '2010-05-03 12:35:00');\r
+insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test@collectionspace.org', '1', 'ROLE_ADMINISTRATOR', '2010-05-03 12:35:00');\r
+insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test@collectionspace.org', '2', 'ROLE_USERS', '2010-05-03 12:35:00');\r
+insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('251f98f3-0292-4f3e-aa95-455314050e1b', 'test@collectionspace.org', '3', 'ROLE_COLLECTIONS_MANAGER', '2010-05-03 12:35:00');\r
\r
-- todo: barney is created in security test but accountrole is not yet created there, so add fake account id\r
insert into `accounts_roles`(`account_id`, `user_id`, `role_id`, `role_name`, `created_at`) values ('1', 'barney', '2', 'ROLE_USERS', '2010-02-17 16:31:48');\r
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>org.collectionspace.services.authorization</artifactId>
<groupId>org.collectionspace.services</groupId>
<artifactId>org.collectionspace.services.authorization.jaxb</artifactId>
<version>${project.version}</version>
+ <scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>cspace-services-authz</finalName>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemProperties>
- <property>
- <name>maven.basedir</name>
- <value>${basedir}</value>
- </property>
- <property>
- <name>log4j.configuration</name>
- <value>file:${project.build.directory}/test-classes/log4j.properties</value>
- </property>
- <property>
- <name>spring-beans-config</name>
- <value>applicationContext-authorization-test.xml</value>
- </property>
- </systemProperties>
- </configuration>
- </plugin>
+
</plugins>
</build>
</project>
* @param <ListType> \r
*/\r
public abstract class AbstractServiceClientImpl implements\r
- CollectionSpaceClient {\r
-\r
- /** The logger. */\r
- protected final Logger logger = LoggerFactory\r
- .getLogger(AbstractServiceClientImpl.class);\r
-\r
- /**\r
- * The character used to separate the words in a part label\r
- */\r
- public static final String PART_LABEL_SEPERATOR = "_";\r
-\r
- /** The Constant PART_COMMON_LABEL. */\r
- public static final String PART_COMMON_LABEL = "common";\r
-\r
- /** The properties. */\r
- private Properties properties = new Properties();\r
-\r
- /** The url. */\r
- private URL url;\r
-\r
- /** The http client. */\r
- private HttpClient httpClient;\r
-\r
- /**\r
- * Gets the common part name.\r
- * \r
- * @return the common part name\r
- */\r
- public String getCommonPartName() {\r
- return getCommonPartName(getServicePathComponent());\r
- }\r
-\r
- /**\r
- * Gets the common part name.\r
- * \r
- * @param servicePathComponent\r
- * the service path component\r
- * @return the common part name\r
- */\r
- public String getCommonPartName(String servicePathComponent) {\r
- return servicePathComponent + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;\r
- }\r
-\r
- /**\r
- * Gets the service path component.\r
- * \r
- * @return the service path component\r
- */\r
- abstract public String getServicePathComponent();\r
-\r
- /**\r
- * Instantiates a new abstract service client impl.\r
- */\r
- protected AbstractServiceClientImpl() {\r
- readProperties();\r
- setupHttpClient();\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#getProperty\r
- * (java.lang.String)\r
- */\r
- @Override\r
- public String getProperty(String propName) {\r
- return properties.getProperty(propName);\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#setProperty\r
- * (java.lang.String, java.lang.String)\r
- */\r
- @Override\r
- public void setProperty(String propName, String value) {\r
- properties.setProperty(propName, value);\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#removeProperty\r
- * (java.lang.String)\r
- */\r
- @Override\r
- public Object removeProperty(String propName) {\r
- return properties.remove(propName);\r
- }\r
-\r
- /**\r
- * Prints the properties.\r
- */\r
- public void printProperties() {\r
- for (Object kobj : properties.keySet()) {\r
- String key = (String) kobj;\r
- logger.trace("begin property name=" + key + " value="\r
- + properties.get(key));\r
- }\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#getBaseURL()\r
- */\r
- @Override\r
- public String getBaseURL() {\r
- return properties.getProperty(URL_PROPERTY);\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#getHttpClient()\r
- */\r
- @Override\r
- public HttpClient getHttpClient() {\r
- return httpClient;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth()\r
- */\r
- @Override\r
- public boolean useAuth() {\r
- String auth = properties.getProperty(AUTH_PROPERTY);\r
- return Boolean.valueOf(auth);\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL()\r
- */\r
- @Override\r
- public boolean useSSL() {\r
- String ssl = properties.getProperty(SSL_PROPERTY);\r
- return Boolean.valueOf(ssl);\r
- }\r
-\r
- /**\r
- * readProperties reads properties from system class path as well as it\r
- * overrides properties made available using command line\r
- * \r
- * @exception RuntimeException\r
- */\r
- private void readProperties() {\r
-\r
- ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
- InputStream is = null;\r
- try {\r
- is = cl.getResourceAsStream("collectionspace-client.properties");\r
- properties.load(is);\r
- if (logger.isDebugEnabled()) {\r
- printProperties();\r
- }\r
- String spec = System.getProperty(URL_PROPERTY);\r
- if (spec != null && !"".equals(spec)) {\r
- properties.setProperty(URL_PROPERTY, spec);\r
- }\r
-\r
- spec = properties.getProperty(URL_PROPERTY);\r
- url = new URL(spec);\r
- if (logger.isInfoEnabled()) {\r
- logger.info("readProperties() using url=" + url);\r
- }\r
-\r
- String auth = System.getProperty(AUTH_PROPERTY);\r
- if (auth != null && !"".equals(auth)) {\r
- properties.setProperty(AUTH_PROPERTY, auth);\r
- }\r
- String ssl = System.getProperty(SSL_PROPERTY);\r
- if (ssl != null && !"".equals(ssl)) {\r
- properties.setProperty(AUTH_PROPERTY, ssl);\r
- }\r
- String user = System.getProperty(USER_PROPERTY);\r
- if (user != null && !"".equals(user)) {\r
- properties.setProperty(USER_PROPERTY, user);\r
- }\r
- String password = System.getProperty(PASSWORD_PROPERTY);\r
- if (password != null && !"".equals(password)) {\r
- properties.setProperty(PASSWORD_PROPERTY, password);\r
- }\r
- if (logger.isDebugEnabled()) {\r
- printProperties();\r
- }\r
- } catch (Exception e) {\r
- logger.debug("Caught exception while reading properties", e);\r
- throw new RuntimeException(e);\r
- } finally {\r
- if (is != null) {\r
- try {\r
- is.close();\r
- } catch (Exception e) {\r
- if (logger.isDebugEnabled() == true) {\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * setupHttpClient sets up HTTP client for the service client the setup\r
- * process relies on the following properties URL_PROPERTY USER_PROPERTY\r
- * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY\r
- */\r
- @Override\r
- public void setupHttpClient() {\r
- this.httpClient = new HttpClient();\r
- if (useAuth()) {\r
- String user = properties.getProperty(USER_PROPERTY);\r
- String password = properties.getProperty(PASSWORD_PROPERTY);\r
- if (logger.isInfoEnabled()) {\r
- logger.info("setupHttpClient() using url=" + url + " user="\r
- + user + " password=" + password);\r
- }\r
-\r
- httpClient.getState().setCredentials(\r
- new AuthScope(url.getHost(), url.getPort(),\r
- AuthScope.ANY_REALM),\r
- new UsernamePasswordCredentials(user, password));\r
- // JAXRS client library requires HTTP preemptive authentication\r
- httpClient.getParams().setAuthenticationPreemptive(true);\r
- if (logger.isInfoEnabled()) {\r
- logger.info("setupHttpClient: set preemptive authentication");\r
- }\r
- } else {\r
- if (logger.isInfoEnabled()) {\r
- logger.info("setupHttpClient() : no auth mode!");\r
- }\r
- }\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#isServerSecure\r
- * ()\r
- */\r
- @Override\r
- public boolean isServerSecure() {\r
- return Boolean.getBoolean("cspace.server.secure");\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see\r
- * org.collectionspace.services.client.CollectionSpaceClient#readList(java\r
- * .lang.String, java.lang.String)\r
- */\r
- @Override\r
- public ClientResponse<AbstractCommonList> readList(String pageSize,\r
- String pageNumber) {\r
- return getProxy().readList(pageSize, pageNumber);\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String)\r
- */\r
+ CollectionSpaceClient {\r
+\r
+ /** The logger. */\r
+ protected final Logger logger = LoggerFactory.getLogger(AbstractServiceClientImpl.class);\r
+ /**\r
+ * The character used to separate the words in a part label\r
+ */\r
+ public static final String PART_LABEL_SEPERATOR = "_";\r
+ /** The Constant PART_COMMON_LABEL. */\r
+ public static final String PART_COMMON_LABEL = "common";\r
+ /** The properties. */\r
+ private Properties properties = new Properties();\r
+ /** The url. */\r
+ private URL url;\r
+ /** The http client. */\r
+ private HttpClient httpClient;\r
+\r
+ /**\r
+ * Gets the common part name.\r
+ *\r
+ * @return the common part name\r
+ */\r
+ public String getCommonPartName() {\r
+ return getCommonPartName(getServicePathComponent());\r
+ }\r
+\r
+ /**\r
+ * Gets the common part name.\r
+ *\r
+ * @param servicePathComponent\r
+ * the service path component\r
+ * @return the common part name\r
+ */\r
+ public String getCommonPartName(String servicePathComponent) {\r
+ return servicePathComponent + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;\r
+ }\r
+\r
+ /**\r
+ * Gets the service path component.\r
+ *\r
+ * @return the service path component\r
+ */\r
+ abstract public String getServicePathComponent();\r
+\r
+ /**\r
+ * Instantiates a new abstract service client impl.\r
+ */\r
+ protected AbstractServiceClientImpl() {\r
+ readProperties();\r
+ setupHttpClient();\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#getProperty\r
+ * (java.lang.String)\r
+ */\r
@Override\r
- public ClientResponse<Response> delete(String csid) {\r
- // must override in children if you want behavior\r
- throw new UnsupportedOperationException();\r
- } \r
+ public String getProperty(String propName) {\r
+ return properties.getProperty(propName);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#setProperty\r
+ * (java.lang.String, java.lang.String)\r
+ */\r
+ @Override\r
+ public void setProperty(String propName, String value) {\r
+ properties.setProperty(propName, value);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#removeProperty\r
+ * (java.lang.String)\r
+ */\r
+ @Override\r
+ public Object removeProperty(String propName) {\r
+ return properties.remove(propName);\r
+ }\r
+\r
+ /**\r
+ * Prints the properties.\r
+ */\r
+ public void printProperties() {\r
+ for (Object kobj : properties.keySet()) {\r
+ String key = (String) kobj;\r
+ logger.trace("begin property name=" + key + " value="\r
+ + properties.get(key));\r
+ }\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#getBaseURL()\r
+ */\r
+ @Override\r
+ public String getBaseURL() {\r
+ return properties.getProperty(URL_PROPERTY);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#getHttpClient()\r
+ */\r
+ @Override\r
+ public HttpClient getHttpClient() {\r
+ return httpClient;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see org.collectionspace.services.client.CollectionSpaceClient#useAuth()\r
+ */\r
+ @Override\r
+ public boolean useAuth() {\r
+ String auth = properties.getProperty(AUTH_PROPERTY);\r
+ return Boolean.valueOf(auth);\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see org.collectionspace.services.client.CollectionSpaceClient#useSSL()\r
+ */\r
+ @Override\r
+ public boolean useSSL() {\r
+ String ssl = properties.getProperty(SSL_PROPERTY);\r
+ return Boolean.valueOf(ssl);\r
+ }\r
+\r
+ /**\r
+ * readProperties reads properties from system class path as well as it\r
+ * overrides properties made available using command line\r
+ *\r
+ * @exception RuntimeException\r
+ */\r
+ private void readProperties() {\r
+\r
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
+ InputStream is = null;\r
+ try {\r
+ is = cl.getResourceAsStream("collectionspace-client.properties");\r
+ properties.load(is);\r
+ if (logger.isDebugEnabled()) {\r
+ printProperties();\r
+ }\r
+ String spec = System.getProperty(URL_PROPERTY);\r
+ if (spec != null && !"".equals(spec)) {\r
+ properties.setProperty(URL_PROPERTY, spec);\r
+ }\r
+\r
+ spec = properties.getProperty(URL_PROPERTY);\r
+ url = new URL(spec);\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("readProperties() using url=" + url);\r
+ }\r
+\r
+ String auth = System.getProperty(AUTH_PROPERTY);\r
+ if (auth != null && !"".equals(auth)) {\r
+ properties.setProperty(AUTH_PROPERTY, auth);\r
+ }\r
+ String ssl = System.getProperty(SSL_PROPERTY);\r
+ if (ssl != null && !"".equals(ssl)) {\r
+ properties.setProperty(AUTH_PROPERTY, ssl);\r
+ }\r
+ String user = System.getProperty(USER_PROPERTY);\r
+ if (user != null && !"".equals(user)) {\r
+ properties.setProperty(USER_PROPERTY, user);\r
+ }\r
+ String password = System.getProperty(PASSWORD_PROPERTY);\r
+ if (password != null && !"".equals(password)) {\r
+ properties.setProperty(PASSWORD_PROPERTY, password);\r
+ }\r
+ if (logger.isDebugEnabled()) {\r
+ printProperties();\r
+ }\r
+ } catch (Exception e) {\r
+ logger.debug("Caught exception while reading properties", e);\r
+ throw new RuntimeException(e);\r
+ } finally {\r
+ if (is != null) {\r
+ try {\r
+ is.close();\r
+ } catch (Exception e) {\r
+ if (logger.isDebugEnabled() == true) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * setupHttpClient sets up HTTP client for the service client the setup\r
+ * process relies on the following properties URL_PROPERTY USER_PROPERTY\r
+ * PASSWORD_PROPERTY AUTH_PROPERTY SSL_PROPERTY\r
+ */\r
+ @Override\r
+ public void setupHttpClient() {\r
+ this.httpClient = new HttpClient();\r
+ if (useAuth()) {\r
+ String user = properties.getProperty(USER_PROPERTY);\r
+ String password = properties.getProperty(PASSWORD_PROPERTY);\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("setupHttpClient() using url=" + url + " user="\r
+ + user + " password=" + password);\r
+ }\r
+\r
+ httpClient.getState().setCredentials(\r
+ new AuthScope(url.getHost(), url.getPort(),\r
+ AuthScope.ANY_REALM),\r
+ new UsernamePasswordCredentials(user, password));\r
+ // JAXRS client library requires HTTP preemptive authentication\r
+ httpClient.getParams().setAuthenticationPreemptive(true);\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("setupHttpClient: set preemptive authentication");\r
+ }\r
+ } else {\r
+ if (logger.isInfoEnabled()) {\r
+ logger.info("setupHttpClient() : no auth mode!");\r
+ }\r
+ }\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#isServerSecure\r
+ * ()\r
+ */\r
+ @Override\r
+ public boolean isServerSecure() {\r
+ return Boolean.getBoolean("cspace.server.secure");\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ *\r
+ * @see\r
+ * org.collectionspace.services.client.CollectionSpaceClient#readList(java\r
+ * .lang.String, java.lang.String)\r
+ */\r
+ @Override\r
+ public ClientResponse<AbstractCommonList> readList(String pageSize,\r
+ String pageNumber) {\r
+ return getProxy().readList(pageSize, pageNumber);\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see org.collectionspace.services.client.CollectionSpaceClient#delete(java.lang.String)\r
+ */\r
+ @Override\r
+ public ClientResponse<Response> delete(String csid) {\r
+ // must override in children if you want behavior\r
+ throw new UnsupportedOperationException();\r
+ }\r
+\r
+ @Override\r
+ public abstract CollectionSpaceProxy getProxy();\r
+\r
+ @Override\r
+ public abstract void setProxy();\r
+\r
+ public void setAuth(boolean useAuth,\r
+ String user, boolean useUser,\r
+ String password, boolean usePassword) {\r
+ if (useAuth) {\r
+ setProperty(CollectionSpaceClient.AUTH_PROPERTY,\r
+ "true");\r
+ if (useUser) {\r
+ setProperty(CollectionSpaceClient.USER_PROPERTY,\r
+ user);\r
+ } else {\r
+ removeProperty(CollectionSpaceClient.USER_PROPERTY);\r
+ }\r
+ if (usePassword) {\r
+ setProperty(CollectionSpaceClient.PASSWORD_PROPERTY,\r
+ password);\r
+ } else {\r
+ removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);\r
+ }\r
+ } else {\r
+ removeProperty(CollectionSpaceClient.AUTH_PROPERTY);\r
+ }\r
+ setupHttpClient();\r
+ setProxy();\r
+ }\r
}\r
* limitations under the License.
*/
package org.collectionspace.services.client;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response;
import org.apache.commons.httpclient.HttpClient;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.jboss.resteasy.client.ClientResponse;
*
*/
public interface CollectionSpaceClient {
-
+
/** The AUT h_ property. */
String AUTH_PROPERTY = "cspace.auth";
-
/** The PASSWOR d_ property. */
String PASSWORD_PROPERTY = "cspace.password";
-
/** The SS l_ property. */
String SSL_PROPERTY = "cspace.ssl";
-
/** The UR l_ property. */
String URL_PROPERTY = "cspace.url";
-
/** The USE r_ property. */
String USER_PROPERTY = "cspace.user";
* @return the proxy
*/
CollectionSpaceProxy getProxy();
-
+
/**
* Gets the base url.
*
*/
void setupHttpClient();
+ /**
+ * setProxy for the client
+ * might be useful to reset proxy (based on auth requirements) that is usually created at the time of
+ * constructing a client
+ */
+ void setProxy();
+
+ /**
+ * setAuth sets up authentication properties based on given parameters
+ * @param useAuth
+ * @param user user name
+ * @param useUser indicates using user name
+ * @param password
+ * @param usePassword indicates using password
+ */
+ void setAuth(boolean useAuth,
+ String user, boolean useUser,
+ String password, boolean usePassword);
+
/**
* Use auth.
*
* @return boolean
*/
boolean isServerSecure();
-
+
/**
* Read list.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.collectionspace.services.client;
import javax.ws.rs.core.Response;
* @version $Revision:$
*/
public class TestServiceClient extends AbstractServiceClientImpl {
+
/**
- *
- * Returning NULL since this class is a base-level client, used (only)
- * to obtain the base service URL.
- *
- */
- @Override
- public String getServicePathComponent() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public CollectionSpaceProxy getProxy() {
- throw new UnsupportedOperationException();
- }
-
- public ClientResponse<Response> delete(String csid) {
- throw new UnsupportedOperationException();
- }
+ *
+ * Returning NULL since this class is a base-level client, used (only)
+ * to obtain the base service URL.
+ *
+ */
+ @Override
+ public String getServicePathComponent() {
+ throw new UnsupportedOperationException();
+ }
+
+
+ @Override
+ public CollectionSpaceProxy getProxy() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setProxy() {
+ throw new UnsupportedOperationException();
+ }
+
+ public ClientResponse<Response> delete(String csid) {
+ throw new UnsupportedOperationException();
+ }
}
*/\r
public abstract class BaseServiceTest {\r
\r
- //Maven's base directory -i.e., the one containing the current pom.xml\r
- static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";\r
- \r
+ //Maven's base directory -i.e., the one containing the current pom.xml\r
+ static protected final String MAVEN_BASEDIR_PROPERTY = "maven.basedir";\r
/** The Constant logger. */\r
static protected final Logger logger = LoggerFactory.getLogger(BaseServiceTest.class);\r
- \r
/** The Constant serviceClient. */\r
protected static final TestServiceClient serviceClient = new TestServiceClient();\r
- \r
/** The NO n_ existen t_ id. */\r
protected final String NON_EXISTENT_ID = createNonExistentIdentifier();\r
- \r
/** The EXPECTE d_ statu s_ code. */\r
protected int EXPECTED_STATUS_CODE = 0;\r
- \r
/** The REQUES t_ type. */\r
protected ServiceRequestType REQUEST_TYPE = ServiceRequestType.NON_EXISTENT;\r
- \r
/** The Constant XML_DECLARATION. */\r
protected static final String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";\r
- \r
/** The Constant MALFORMED_XML_DATA. */\r
protected static final String MALFORMED_XML_DATA = XML_DECLARATION\r
+ "<malformed_xml>wrong schema contents</malformed_xml";\r
- \r
/** The WRON g_ xm l_ schem a_ data. */\r
protected final String WRONG_XML_SCHEMA_DATA = XML_DECLARATION\r
+ "<wrong_schema>wrong schema contents</wrong_schema>";\r
- \r
/** The NUL l_ charset. */\r
final String NULL_CHARSET = null;\r
\r
* @return the client\r
*/\r
abstract protected CollectionSpaceClient getClientInstance();\r
- \r
- /**\r
- * Gets the abstract common list.\r
- *\r
- * @param response the response\r
- * @return the abstract common list\r
- */\r
- abstract protected AbstractCommonList getAbstractCommonList(\r
- ClientResponse<AbstractCommonList> response); \r
- \r
+\r
+ /**\r
+ * Gets the abstract common list.\r
+ *\r
+ * @param response the response\r
+ * @return the abstract common list\r
+ */\r
+ abstract protected AbstractCommonList getAbstractCommonList(\r
+ ClientResponse<AbstractCommonList> response);\r
+\r
/**\r
* Returns the name of the currently running test.\r
*\r
import javax.ws.rs.ext.Provider;
import org.collectionspace.authentication.AuthN;
import org.collectionspace.services.authorization.AuthZ;
+import org.collectionspace.services.authorization.CSpaceResource;
+import org.collectionspace.services.authorization.URIResourceImpl;
import org.collectionspace.services.common.document.JaxbUtils;
import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
import org.slf4j.Logger;
logger.debug("received " + httpMethod + " on " + uriPath);
}
checkActive();
- AuthZ authZ = AuthZ.get();
-// CSpaceResource res = new URIResourceImpl(uriPath, httpMethod);
-// if (!authZ.isAccessAllowed(res)) {
-// logger.error("Access to " + res.getId() + " is NOT allowed to " +
-// " user=" + AuthN.get().getUserId());
-// Response response = Response.status(
-// Response.Status.FORBIDDEN).entity(uriPath + " " + httpMethod).type("text/plain").build();
-// throw new WebApplicationException(response);
-// }
-// if(logger.isDebugEnabled()) {
-// logger.debug("Access to " + res.getId() + " is allowed to " +
-// " user=" + AuthN.get().getUserId());
-// }
+ if (uriPath.startsWith("dimensions")) {
+ AuthZ authZ = AuthZ.get();
+ CSpaceResource res = new URIResourceImpl(uriPath, httpMethod);
+ if (!authZ.isAccessAllowed(res)) {
+ logger.error("Access to " + res.getId() + " is NOT allowed to "
+ + " user=" + AuthN.get().getUserId());
+ Response response = Response.status(
+ Response.Status.FORBIDDEN).entity(uriPath + " " + httpMethod).type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Access to " + res.getId() + " is allowed to "
+ + " user=" + AuthN.get().getUserId());
+ }
+ }
return null;
}
}
Object status = JaxbUtils.getValue(account, "getStatus");
if (status != null) {
- String value = (String)JaxbUtils.getValue(status, "value");
+ String value = (String) JaxbUtils.getValue(status, "value");
if ("INACTIVE".equalsIgnoreCase(value)) {
String msg = "User's account is inactive, userId=" + userId;
Response response = Response.status(
<dependency>\r
<groupId>org.slf4j</groupId>\r
<artifactId>slf4j-api</artifactId>\r
- <scope>test</scope>\r
</dependency>\r
<dependency>\r
<groupId>org.slf4j</groupId>\r
<artifactId>slf4j-log4j12</artifactId>\r
- <scope>test</scope>\r
</dependency>\r
<!-- CollectionSpace dependencies -->\r
<dependency>\r
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2010 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.client;
+
+
+
+
+import javax.ws.rs.core.MediaType;
+import org.collectionspace.services.dimension.DimensionsCommon;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author
+ */
+public class DimensionFactory {
+
+ static private final Logger logger =
+ LoggerFactory.getLogger(DimensionFactory.class);
+
+ /**
+ * Creates the dimension instance.
+ *
+ * @param commpnPartName
+ * @param dimension
+ * @return the multipart output
+ */
+ public static MultipartOutput createDimensionInstance(String commonPartName,
+ DimensionsCommon dimension) {
+
+ MultipartOutput multipart = new MultipartOutput();
+ OutputPart commonPart =
+ multipart.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
+ commonPart.getHeaders().add("label", commonPartName);
+
+ return multipart;
+ }
+}
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.client.DimensionClient;
+import org.collectionspace.services.client.DimensionFactory;
import org.collectionspace.services.dimension.DimensionsCommon;
import org.collectionspace.services.dimension.DimensionsCommonList;
import org.collectionspace.services.jaxb.AbstractCommonList;
*/
public class DimensionServiceTest extends AbstractServiceTestImpl {
- /** The logger. */
- private final Logger logger =
- LoggerFactory.getLogger(DimensionServiceTest.class);
-
+ /** The logger. */
+ private final Logger logger =
+ LoggerFactory.getLogger(DimensionServiceTest.class);
// Instance variables specific to this test.
/** The SERVIC e_ pat h_ component. */
final String SERVICE_PATH_COMPONENT = "dimensions";
-
/** The known resource id. */
private String knownResourceId = null;
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new DimensionClient();
+ return new DimensionClient();
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
*/
@Override
- protected AbstractCommonList getAbstractCommonList(
- ClientResponse<AbstractCommonList> response) {
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
return response.getEntity(DimensionsCommonList.class);
}
* @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
public void create(String testName) throws Exception {
// Perform setup, such as initializing the type of service request
// Submit the request to the service and store the response.
DimensionClient client = new DimensionClient();
String identifier = createIdentifier();
- MultipartOutput multipart = createDimensionInstance(identifier);
+ MultipartOutput multipart = createDimensionInstance(client.getCommonPartName(),
+ identifier);
ClientResponse<Response> res = client.create(multipart);
int statusCode = res.getStatus();
// Specifically:
// Does it fall within the set of valid status codes?
// Does it exactly match the expected status code?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Store the ID returned from the first resource created
// for additional tests below.
- if (knownResourceId == null){
+ if (knownResourceId == null) {
knownResourceId = extractId(res);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
public void createList(String testName) throws Exception {
- for(int i = 0; i < 3; i++){
+ for (int i = 0; i < 3; i++) {
create(testName);
}
}
*/
@Override
public void createWithEmptyEntityBody(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithMalformedXml(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
/* (non-Javadoc)
*/
@Override
public void createWithWrongXmlSchema(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
/*
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- dependsOnMethods = {"create", "testSubmitRequest"})
+ dependsOnMethods = {"create", "testSubmitRequest"})
public void createWithEmptyEntityBody(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
if(logger.isDebugEnabled()){
- logger.debug("createWithEmptyEntityBody url=" + url +
- " status=" + statusCode);
- }
+ logger.debug("createWithEmptyEntityBody url=" + url +
+ " status=" + statusCode);
+ }
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- dependsOnMethods = {"create", "testSubmitRequest"})
+ dependsOnMethods = {"create", "testSubmitRequest"})
public void createWithMalformedXml(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
if(logger.isDebugEnabled()){
- logger.debug(testName + ": url=" + url +
- " status=" + statusCode);
- }
+ logger.debug(testName + ": url=" + url +
+ " status=" + statusCode);
+ }
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- dependsOnMethods = {"create", "testSubmitRequest"})
+ dependsOnMethods = {"create", "testSubmitRequest"})
public void createWithWrongXmlSchema(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
if(logger.isDebugEnabled()){
- logger.debug(testName + ": url=" + url +
- " status=" + statusCode);
- }
+ logger.debug(testName + ": url=" + url +
+ " status=" + statusCode);
+ }
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
}
*/
-
// ---------------------------------------------------------------
// CRUD tests : READ tests
// ---------------------------------------------------------------
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"create"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
public void read(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read"})
public void readNonExistent(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read"})
public void readList(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Optionally output additional data about list members for debugging.
boolean iterateThroughList = false;
- if(iterateThroughList && logger.isDebugEnabled()){
+ if (iterateThroughList && logger.isDebugEnabled()) {
List<DimensionsCommonList.DimensionListItem> items =
list.getDimensionListItem();
int i = 0;
- for(DimensionsCommonList.DimensionListItem item : items){
- logger.debug(testName + ": list-item[" + i + "] csid=" +
- item.getCsid());
- logger.debug(testName + ": list-item[" + i + "] objectNumber=" +
- item.getDimension());
- logger.debug(testName + ": list-item[" + i + "] URI=" +
- item.getUri());
+ for (DimensionsCommonList.DimensionListItem item : items) {
+ logger.debug(testName + ": list-item[" + i + "] csid="
+ + item.getCsid());
+ logger.debug(testName + ": list-item[" + i + "] objectNumber="
+ + item.getDimension());
+ logger.debug(testName + ": list-item[" + i + "] URI="
+ + item.getUri());
i++;
}
}
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"read"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read"})
public void update(String testName) throws Exception {
// Perform setup.
DimensionClient client = new DimensionClient();
ClientResponse<MultipartInput> res =
client.read(knownResourceId);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": read status = " + res.getStatus());
}
Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("got object to update with ID: " + knownResourceId);
}
MultipartInput input = (MultipartInput) res.getEntity();
// Update the content of this resource.
dimension.setValue("updated-" + dimension.getValue());
dimension.setValueDate("updated-" + dimension.getValueDate());
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("to be updated object");
logger.debug(objectAsXmlString(dimension, DimensionsCommon.class));
}
res = client.update(knownResourceId, output);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
input = (MultipartInput) res.getEntity();
DimensionsCommon updatedDimension =
(DimensionsCommon) extractPart(input,
- client.getCommonPartName(), DimensionsCommon.class);
+ client.getCommonPartName(), DimensionsCommon.class);
Assert.assertNotNull(updatedDimension);
Assert.assertEquals(updatedDimension.getValueDate(),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
*/
@Override
- public void updateWithEmptyEntityBody(String testName) throws Exception{
- //Should this really be empty?
+ public void updateWithEmptyEntityBody(String testName) throws Exception {
+ //Should this really be empty?
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
*/
@Override
public void updateWithMalformedXml(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
-
+
/* (non-Javadoc)
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
*/
@Override
public void updateWithWrongXmlSchema(String testName) throws Exception {
- //Should this really be empty?
+ //Should this really be empty?
}
/*
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- dependsOnMethods = {"create", "update", "testSubmitRequest"})
+ dependsOnMethods = {"create", "update", "testSubmitRequest"})
public void updateWithEmptyEntityBody(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
if(logger.isDebugEnabled()){
- logger.debug(testName + ": url=" + url +
- " status=" + statusCode);
- }
+ logger.debug(testName + ": url=" + url +
+ " status=" + statusCode);
+ }
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- dependsOnMethods = {"create", "update", "testSubmitRequest"})
+ dependsOnMethods = {"create", "update", "testSubmitRequest"})
public void updateWithMalformedXml(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
if(logger.isDebugEnabled()){
- logger.debug(testName + ": url=" + url +
- " status=" + statusCode);
- }
+ logger.debug(testName + ": url=" + url +
+ " status=" + statusCode);
+ }
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
@Override
@Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
- dependsOnMethods = {"create", "update", "testSubmitRequest"})
+ dependsOnMethods = {"create", "update", "testSubmitRequest"})
public void updateWithWrongXmlSchema(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
if(logger.isDebugEnabled()){
- logger.debug(testName + ": url=" + url +
- " status=" + statusCode);
- }
+ logger.debug(testName + ": url=" + url +
+ " status=" + statusCode);
+ }
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"update", "testSubmitRequest"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"update", "testSubmitRequest"})
public void updateNonExistent(String testName) throws Exception {
// Perform setup.
// Note: The ID used in this 'create' call may be arbitrary.
// The only relevant ID may be the one used in update(), below.
DimensionClient client = new DimensionClient();
- MultipartOutput multipart = createDimensionInstance(NON_EXISTENT_ID);
+ MultipartOutput multipart = createDimensionInstance(client.getCommonPartName(),
+ NON_EXISTENT_ID);
ClientResponse<MultipartInput> res =
client.update(NON_EXISTENT_ID, multipart);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
public void delete(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
* @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
*/
@Override
- @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
- dependsOnMethods = {"delete"})
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"delete"})
public void deleteNonExistent(String testName) throws Exception {
// Perform setup.
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + statusCode);
}
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
// Check the status code of the response: does it match
// the expected response(s)?
- if(logger.isDebugEnabled()){
- logger.debug("testSubmitRequest: url=" + url +
- " status=" + statusCode);
+ if (logger.isDebugEnabled()) {
+ logger.debug("testSubmitRequest: url=" + url
+ + " status=" + statusCode);
}
Assert.assertEquals(statusCode, EXPECTED_STATUS);
* @param identifier the identifier
* @return the multipart output
*/
- private MultipartOutput createDimensionInstance(String identifier) {
- return createDimensionInstance(
- "dimensionType-" + identifier,
+ private MultipartOutput createDimensionInstance(String commonPartName, String identifier) {
+ return createDimensionInstance(commonPartName,
+ "dimensionType-" + identifier,
"entryNumber-" + identifier,
"entryDate-" + identifier);
}
* @param entryDate the entry date
* @return the multipart output
*/
- private MultipartOutput createDimensionInstance(String dimensionType, String entryNumber, String entryDate) {
+ private MultipartOutput createDimensionInstance(String commonPartName, String dimensionType, String entryNumber, String entryDate) {
DimensionsCommon dimension = new DimensionsCommon();
dimension.setDimension(dimensionType);
dimension.setValue(entryNumber);
dimension.setValueDate(entryDate);
- MultipartOutput multipart = new MultipartOutput();
- OutputPart commonPart =
- multipart.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
- commonPart.getHeaders().add("label", new DimensionClient().getCommonPartName());
+ MultipartOutput multipart = DimensionFactory.createDimensionInstance(
+ commonPartName, dimension);
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("to be created, dimension common");
- logger.debug(objectAsXmlString(dimension, DimensionsCommon.class));
+ logger.debug(objectAsXmlString(dimension,
+ DimensionsCommon.class));
}
return multipart;
<artifactId>org.collectionspace.services.collectionobject.client</artifactId>\r
<version>${project.version}</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.dimension.client</artifactId>\r
+ <version>${project.version}</version>\r
+ </dependency>\r
<!-- External dependencies -->\r
<dependency>\r
<groupId>org.testng</groupId>\r
// its associated HTTP method name (e.g. POST, DELETE).
setupCreate(testName);
AccountClient accountClient = new AccountClient();
- accountClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- accountClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "test");
- accountClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+ accountClient.setAuth(true, "test", true, "test", true);
// Submit the request to the service and store the response.
AccountsCommon account =
// its associated HTTP method name (e.g. POST, DELETE).
setupCreate(testName);
AccountClient accountClient = new AccountClient();
- accountClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- accountClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "test");
- accountClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+ accountClient.setAuth(true, "test", true, "test", true);
// Submit the request to the service and store the response.
AccountsCommon account =
public void create(String testName) {
setupCreate(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "barney", true, "barney08", true);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "barney");
- collectionObjectClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "barney08");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error("create: caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug("create: status = " + res.getStatus());
}
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"createActiveAccount"})
+ public void createWithoutAuthn(String testName) {
+ setupCreate(testName);
+ CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(false, "test", true, "test", true);
+ String identifier = BaseServiceTest.createIdentifier();
+ MultipartOutput multipart = createCollectionObjectInstance(
+ collectionObjectClient.getCommonPartName(), identifier);
+ ClientResponse<Response> res = collectionObjectClient.create(multipart);
+ if (logger.isDebugEnabled()) {
+ logger.debug("create: status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(),
+ Response.Status.UNAUTHORIZED.getStatusCode(), "expected "
+ + Response.Status.UNAUTHORIZED.getStatusCode());
+ res.releaseConnection();
+
+ }
+
@Test(dataProvider = "testName", dependsOnMethods = {"createInactiveAccount"})
public void createWithInactiveAccount(String testName) {
banner(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "george", true, "george08", true);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "george");
- collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY,
- "george08");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error(testName + ": caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + res.getStatus());
public void createWithoutPassword(String testName) {
banner(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "test", true, "", false);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "test");
- collectionObjectClient.removeProperty(CollectionSpaceClient.PASSWORD_PROPERTY);
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error(testName + ": caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + res.getStatus());
public void createWithUnknownUser(String testName) {
banner(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "foo", true, "bar", true);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "foo");
- collectionObjectClient.setProperty(CollectionSpaceClient.PASSWORD_PROPERTY,
- "bar");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error(testName + ": caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + res.getStatus());
public void createWithIncorrectPassword(String testName) {
banner(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "test", true, "bar", true);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "test");
- collectionObjectClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error(testName + ": caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = " + res.getStatus());
public void createWithIncorrectUserPassword(String testName) {
banner(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "foo", true, "bar", true);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "foo");
- collectionObjectClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "bar");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error(testName + ": caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = "
public void createWithoutTenant(String testName) {
banner(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+ collectionObjectClient.setAuth(true, "babybop", true, "babybop09", true);
String identifier = BaseServiceTest.createIdentifier();
MultipartOutput multipart = createCollectionObjectInstance(
collectionObjectClient.getCommonPartName(), identifier);
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "babybop");
- collectionObjectClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "babybop09");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error(testName + ": caught " + e.getMessage());
- return;
- }
ClientResponse<Response> res = collectionObjectClient.create(multipart);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": status = "
setupDelete(testName);
CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
collectionObjectClient = new CollectionObjectClient();
-
- collectionObjectClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- collectionObjectClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "test");
- collectionObjectClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "test");
- try {
- collectionObjectClient.setupHttpClient();
- collectionObjectClient.setProxy();
- } catch (Exception e) {
- logger.error("deleteCollectionObject: caught " + e.getMessage());
- return;
- }
+ collectionObjectClient.setAuth(true, "test", true, "test", true);
if (logger.isDebugEnabled()) {
logger.debug("Calling deleteCollectionObject:" + knownResourceId);
}
// Perform setup.
setupDelete(testName);
AccountClient accountClient = new AccountClient();
-
- accountClient.setProperty(CollectionSpaceClient.AUTH_PROPERTY,
- "true");
- accountClient.setProperty(CollectionSpaceClient.USER_PROPERTY,
- "test");
- accountClient.setProperty(
- CollectionSpaceClient.PASSWORD_PROPERTY, "test");
+ accountClient.setAuth(true, "test", true, "test", true);
// Submit the request to the service and store the response.
ClientResponse<Response> res = accountClient.delete(barneyAccountId);
int statusCode = res.getStatus();
*/
private MultipartOutput createCollectionObjectInstance(
String commonPartName, String identifier) {
- return createCollectionObjectInstance(commonPartName, "objectNumber-" + identifier, "objectName-" + identifier);
+ return createCollectionObjectInstance(commonPartName, "objectNumber-"
+ + identifier, "objectName-" + identifier);
}
/**
--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2010 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.security.client.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.collectionspace.services.account.AccountsCommon;
+import org.collectionspace.services.authorization.AccountRole;
+import org.collectionspace.services.authorization.AccountValue;
+import org.collectionspace.services.authorization.EffectType;
+
+import org.collectionspace.services.authorization.Permission;
+import org.collectionspace.services.authorization.PermissionAction;
+import org.collectionspace.services.authorization.PermissionRole;
+import org.collectionspace.services.authorization.PermissionValue;
+import org.collectionspace.services.authorization.Role;
+import org.collectionspace.services.authorization.RoleValue;
+import org.collectionspace.services.client.AccountClient;
+import org.collectionspace.services.client.AccountFactory;
+import org.collectionspace.services.client.AccountRoleClient;
+import org.collectionspace.services.client.AccountRoleFactory;
+import org.collectionspace.services.client.CollectionSpaceClient;
+import org.collectionspace.services.client.DimensionClient;
+import org.collectionspace.services.client.DimensionFactory;
+import org.collectionspace.services.client.PermissionClient;
+import org.collectionspace.services.client.PermissionFactory;
+import org.collectionspace.services.client.PermissionRoleClient;
+import org.collectionspace.services.client.PermissionRoleFactory;
+import org.collectionspace.services.client.RoleClient;
+import org.collectionspace.services.client.RoleFactory;
+import org.collectionspace.services.client.test.AbstractServiceTestImpl;
+import org.collectionspace.services.dimension.DimensionsCommon;
+import org.collectionspace.services.jaxb.AbstractCommonList;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+
+/**
+ * AuthorizationServiceTest, carries out tests against a
+ * deployed and running Permission, Role, AccountRole, PermissionRole and
+ * CollectionObject Services.
+ *
+ * $LastChangedRevision: 917 $
+ * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
+ */
+public class AuthorizationServiceTest extends AbstractServiceTestImpl {
+
+ static private final Logger logger =
+ LoggerFactory.getLogger(AuthorizationServiceTest.class);
+ // Instance variables specific to this test.
+ private String knownResourceId = null;
+ private List<String> allResourceIdsCreated = new ArrayList();
+ //key for accValues is userId
+ private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
+ //key for permValues is id as there could be several perms for the same resource
+ private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
+ //key for roleValues is roleName
+ private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
+ private String bigbirdPermId;
+ private String elmoPermId;
+ /*
+ * This method is called only by the parent class, AbstractServiceTestImpl
+ */
+
+ @Override
+ protected String getServicePathComponent() {
+ return null;
+ }
+
+ @BeforeClass(alwaysRun = true)
+ public void seedData() {
+ seedPermissions();
+ seedRoles();
+ seedAccounts();
+ seedAccountRoles();
+ seedPermissionRoles();
+ }
+
+ private void seedPermissions() {
+ String rc1 = "collectionobjects";
+ bigbirdPermId = createPermission(rc1, EffectType.PERMIT);
+ PermissionValue bbpv = new PermissionValue();
+ bbpv.setResourceName(rc1);
+ bbpv.setPermissionId(bigbirdPermId);
+ permValues.put(bbpv.getPermissionId(), bbpv);
+
+ String rc2 = "collectionobjects";
+ elmoPermId = createPermission(rc2, EffectType.DENY);
+ PermissionValue epv = new PermissionValue();
+ epv.setResourceName(rc2);
+ epv.setPermissionId(elmoPermId);
+ permValues.put(epv.getPermissionId(), epv);
+ }
+
+ private void seedRoles() {
+ String rn1 = "ROLE_MMI_CM";
+ String r1RoleId = createRole(rn1);
+ RoleValue rv1 = new RoleValue();
+ rv1.setRoleId(r1RoleId);
+ rv1.setRoleName(rn1);
+ roleValues.put(rv1.getRoleName(), rv1);
+
+ String rn2 = "ROLE_MMI_INTERN";
+ String r2RoleId = createRole(rn2);
+ RoleValue rv2 = new RoleValue();
+ rv2.setRoleId(r2RoleId);
+ rv2.setRoleName(rn2);
+ roleValues.put(rv2.getRoleName(), rv2);
+ }
+
+ private void seedAccounts() {
+ String userId = "bigbird2010";
+ String accId = createAccount(userId, "bigbird@cspace.org");
+ AccountValue ava = new AccountValue();
+ ava.setScreenName(userId);
+ ava.setUserId(userId);
+ ava.setAccountId(accId);
+ accValues.put(ava.getUserId(), ava);
+
+ String userId2 = "elmo2010";
+ String coAccId = createAccount(userId2, "elmo@cspace.org");
+ AccountValue avc = new AccountValue();
+ avc.setScreenName(userId2);
+ avc.setUserId(userId2);
+ avc.setAccountId(coAccId);
+ accValues.put(avc.getUserId(), avc);
+ }
+
+ private void seedAccountRoles() {
+
+ List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
+ bigbirdRoleValues.add(roleValues.get("ROLE_MMI_CM"));
+ createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
+
+ List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
+ elmoRoleValues.add(roleValues.get("ROLE_MMI_INTERN"));
+ createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
+ }
+
+ private void seedPermissionRoles() {
+
+ List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
+ bigbirdRoleValues.add(roleValues.get("ROLE_MMI_CM"));
+ createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
+
+ List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
+ elmoRoleValues.add(roleValues.get("ROLE_MMI_INTERN"));
+ createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
+ */
+ @Override
+ protected CollectionSpaceClient getClientInstance() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
+ */
+ @Override
+ protected AbstractCommonList getAbstractCommonList(
+ ClientResponse<AbstractCommonList> response) {
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ throw new UnsupportedOperationException();
+ }
+
+ @Test(dataProvider = "testName")
+ @Override
+ public void readPaginatedList(String testName) throws Exception {
+ //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
+ }
+ // ---------------------------------------------------------------
+ // CRUD tests : CREATE tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+ public void create(String testName) throws Exception {
+ setupCreate(testName);
+
+ // Submit the request to the service and store the response.
+ DimensionClient client = new DimensionClient();
+ client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
+ String identifier = createIdentifier();
+ DimensionsCommon dimension = new DimensionsCommon();
+ dimension.setDimension("dimensionType");
+ dimension.setValue("value-" + identifier);
+ dimension.setValueDate(new Date().toString());
+ MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
+ dimension);
+ ClientResponse<Response> res = client.create(multipart);
+
+ 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.FORBIDDEN.getStatusCode());
+ }
+
+ //to not cause uniqueness violation for permRole, createList is removed
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void createList(String testName) throws Exception {
+ }
+
+ // Failure outcomes
+ // Placeholders until the three tests below can be uncommented.
+ // See Issue CSPACE-401.
+ @Override
+ public void createWithEmptyEntityBody(String testName) throws Exception {
+ }
+
+ @Override
+ public void createWithMalformedXml(String testName) throws Exception {
+ }
+
+ @Override
+ public void createWithWrongXmlSchema(String testName) throws Exception {
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : READ tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"create"})
+ public void read(String testName) throws Exception {
+
+ // Perform setup.
+ setupRead(testName);
+
+ }
+
+ // Failure outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+ public void readNonExistent(String testName) throws Exception {
+
+ // Perform setup.
+ setupReadNonExistent(testName);
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : READ_LIST tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"createList", "read"})
+ public void readList(String testName) throws Exception {
+ setupReadList(testName);
+ }
+
+ // Failure outcomes
+ // None at present.
+ // ---------------------------------------------------------------
+ // CRUD tests : UPDATE tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read", "readList", "readNonExistent"})
+ public void update(String testName) throws Exception {
+ setupUpdate(testName);
+ }
+
+ // Failure outcomes
+ // Placeholders until the three tests below can be uncommented.
+ // See Issue CSPACE-401.
+ @Override
+ public void updateWithEmptyEntityBody(String testName) throws Exception {
+ }
+
+ @Override
+ public void updateWithMalformedXml(String testName) throws Exception {
+ }
+
+ @Override
+ public void updateWithWrongXmlSchema(String testName) throws Exception {
+ }
+
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
+ public void updateNonExistent(String testName) throws Exception {
+ }
+
+ // ---------------------------------------------------------------
+ // CRUD tests : DELETE tests
+ // ---------------------------------------------------------------
+ // Success outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ dependsOnMethods = {"read"})
+ public void delete(String testName) throws Exception {
+ // Perform setup.
+ setupDelete(testName);
+
+ }
+
+ // Failure outcomes
+ @Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
+ public void deleteNonExistent(String testName) throws Exception {
+ //ignoring this test as the service side returns 200 now even if it does
+ //not find a record in the db
+ }
+
+ // ---------------------------------------------------------------
+ // Utility tests : tests of code used in tests above
+ // ---------------------------------------------------------------
+ /**
+ * Tests the code for manually submitting data that is used by several
+ * of the methods above.
+ */
+ @Test(dependsOnMethods = {"create"})
+ public void testSubmitRequest() throws Exception {
+ }
+
+ // ---------------------------------------------------------------
+ // Utility methods used by tests above
+ // ---------------------------------------------------------------
+ @AfterClass(alwaysRun = true)
+ public void cleanUp() {
+ setupDelete("cleanup");
+ String noTest = System.getProperty("noTestCleanup");
+ if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Skipping Cleanup phase ...");
+ }
+ return;
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Cleaning up temporary resources created for testing ...");
+ }
+
+ deletePermissionRoles();
+ deleteAccountRoles();
+ deletePermissions();
+ deleteRoles();
+ deleteAccounts();
+ }
+
+ private String createPermission(String resName, EffectType effect) {
+ setupCreate("createPermission");
+ PermissionClient permClient = new PermissionClient();
+ List<PermissionAction> actions = PermissionFactory.createDefaultActions();
+ Permission permission = PermissionFactory.createPermissionInstance(resName,
+ "default permissions for " + resName,
+ actions, effect, true, true, true);
+ ClientResponse<Response> res = permClient.create(permission);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("createPermission: resName=" + resName
+ + " status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ return extractId(res);
+ }
+
+ private void deletePermission(String permId) {
+ setupDelete("deletePermission");
+ PermissionClient permClient = new PermissionClient();
+ ClientResponse<Response> res = permClient.delete(permId);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("deletePermission: delete permission id="
+ + permId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ }
+
+ private String createRole(String roleName) {
+ setupCreate("createRole");
+ RoleClient roleClient = new RoleClient();
+
+ Role role = RoleFactory.createRoleInstance(roleName,
+ "role for " + roleName, true);
+ ClientResponse<Response> res = roleClient.create(role);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("createRole: name=" + roleName
+ + " status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ return extractId(res);
+ }
+
+ private void deleteRole(String roleId) {
+ setupDelete("deleteRole");
+ RoleClient roleClient = new RoleClient();
+ ClientResponse<Response> res = roleClient.delete(roleId);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteRole: delete role id=" + roleId
+ + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ }
+
+ private String createAccount(String userName, String email) {
+ setupCreate("createAccount");
+ AccountClient accClient = new AccountClient();
+ AccountsCommon account = AccountFactory.createAccountInstance(
+ userName, userName, userName, email,
+ true, true, false, true, true);
+ ClientResponse<Response> res = accClient.create(account);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("createAccount: userName=" + userName
+ + " status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ return extractId(res);
+ }
+
+ private void deleteAccount(String accId) {
+ setupDelete("deleteAccount");
+ AccountClient accClient = new AccountClient();
+ ClientResponse<Response> res = accClient.delete(accId);
+ int statusCode = res.getStatus();
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteAccount: delete account id="
+ + accId + " status=" + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ }
+
+ private String createAccountRole(AccountValue av,
+ Collection<RoleValue> rvs) {
+ setupCreate("createAccountRole");
+
+ // Submit the request to the service and store the response.
+ AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
+ av, rvs, true, true);
+ AccountRoleClient client = new AccountRoleClient();
+ ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("createAccountRole: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ return extractId(res);
+ }
+
+ private void deleteAccountRole(String screenName) {
+ // Perform setup.
+ setupDelete("deleteAccountRole");
+
+ // Submit the request to the service and store the response.
+ AccountRoleClient client = new AccountRoleClient();
+ ClientResponse<Response> res = client.delete(
+ accValues.get(screenName).getAccountId(), "123");
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteAccountRole: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ }
+
+ private String createPermissionRole(PermissionValue pv,
+ Collection<RoleValue> rvs) {
+ setupCreate("createPermissionRole");
+ PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
+ pv, rvs, true, true);
+ PermissionRoleClient client = new PermissionRoleClient();
+ ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("createPermissionRole: status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ return extractId(res);
+ }
+
+ private void deletePermissionRole(String permId) {
+
+ // Perform setup.
+ setupDelete("deletePermissionRole");
+
+ // Submit the request to the service and store the response.
+ PermissionRoleClient client = new PermissionRoleClient();
+ ClientResponse<Response> res = client.delete(permId, "123");
+ int statusCode = res.getStatus();
+
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("deletePermissionRole : status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+ res.releaseConnection();
+ }
+
+ private void deletePermissionRoles() {
+
+ //first delete relationships between the entities
+ for (PermissionValue pv : permValues.values()) {
+ deletePermissionRole(pv.getPermissionId());
+ }
+ }
+
+ private void deleteAccountRoles() {
+ for (AccountValue av : accValues.values()) {
+ deleteAccountRole(av.getUserId());
+ }
+ }
+
+ private void deletePermissions() {
+ //delete entities
+ for (PermissionValue pv : permValues.values()) {
+ deletePermission(pv.getPermissionId());
+ }
+ }
+
+ private void deleteRoles() {
+ for (RoleValue rv : roleValues.values()) {
+ deleteRole(rv.getRoleId());
+ }
+ }
+
+ private void deleteAccounts() {
+
+ for (AccountValue av1 : accValues.values()) {
+ deleteAccount(av1.getAccountId());
+ }
+ }
+}