diff --git a/build-dependencies.xml b/build-dependencies.xml index fed1d510a..c71f35e73 100644 --- a/build-dependencies.xml +++ b/build-dependencies.xml @@ -79,8 +79,6 @@ - - @@ -619,7 +617,6 @@ - diff --git a/build.xml b/build.xml index 62945f33e..d8740251c 100644 --- a/build.xml +++ b/build.xml @@ -159,7 +159,6 @@ - diff --git a/components.xml b/components.xml index b36a48e9c..8f81e64df 100644 --- a/components.xml +++ b/components.xml @@ -36,7 +36,6 @@ - diff --git a/components/topcoder_cockpit_task_management_services/META-INF/task/applicationContext.xml b/components/topcoder_cockpit_task_management_services/META-INF/task/applicationContext.xml deleted file mode 100644 index 36ba487cf..000000000 --- a/components/topcoder_cockpit_task_management_services/META-INF/task/applicationContext.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - java:TCS_CATALOG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.util.log.LogManager.getLog - - - - com.topcoder.task.logger - - - - - - - - - - - - - - - task_log - - - - \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/META-INF/task/persistence.xml b/components/topcoder_cockpit_task_management_services/META-INF/task/persistence.xml deleted file mode 100644 index 4e4f7742e..000000000 --- a/components/topcoder_cockpit_task_management_services/META-INF/task/persistence.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - org.hibernate.ejb.HibernatePersistence - META-INF/task/task_orm.xml - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/META-INF/task/task_orm.xml b/components/topcoder_cockpit_task_management_services/META-INF/task/task_orm.xml deleted file mode 100644 index f728234e8..000000000 --- a/components/topcoder_cockpit_task_management_services/META-INF/task/task_orm.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.direct.services.project.task.model.TaskStatus - - - - - com.topcoder.direct.services.project.task.model.TaskPriority - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/README b/components/topcoder_cockpit_task_management_services/README deleted file mode 100644 index 4e7969fff..000000000 --- a/components/topcoder_cockpit_task_management_services/README +++ /dev/null @@ -1,45 +0,0 @@ -This readme file explains how to setup and build this component. -(See: http://www.topcoder.com/wiki/display/tc/Java+Component+Build+Process for an explanation of the build process used.) - -1. Install the component structure in ${basedir} - -2. Create "topcoder_global.properties" in ${basedir}/.. and add the properties from steps 2,3,4,5 - -3. The following standard build script properties must be set - ext_libdir - root of third party libraries - tcs_libdir - root of topcoder components - java_1_3_bootclasspath - installation path for java 1.3 (only needed for compile_targets task) - junit.jar - location of junit.jar (component was written for v4.6) - -4. The following standard build script properties can be changed (defaults are noted) - debug=off - as expected - verbose=no - as expected - cobertura.dir=${ext_libdir}/cobertura/1.8 - installation directory of cobertura script expects {$cobertura.dir}/cobertura.jar - and {$cobertura.dir}/lib/containg Jars for asm, jakarta, and log4j to run cobertura task - -5. The following properties need to be set for this component: - [List the any specialized configuration needed] - ${oracle.database.url} - points to the oracle instance used to run perf testing, e.g. ... - -6. The following third party libraries need to have their location specified - by default the build-dependencies.xml file looks for these under ${ext_libdir}, if you follow the setup listed in that file, you will not need to add these to global: - [List the third party libraries here as their property name, include comment of version to use] - ${log4j.jar} - version 2.3.4 or later, testing only - -7. Ant Commands: - ant clean - removes temporary build files - ant compile - builds the production code - ant compile_tests - builds the test code - ant test - runs the test code - ant reports-all - generates javadoc and code coverage reports - ant deploy-lib - moves the component runtime jar to the location where other components will look for it. - -NB: - The folder ${basedir}/test_reflib contains TopCoder components - that are required by this component's test code. This component is - used to by compile_test and test targets. Components are listed under - the following directory structure "component name"/"component version". - Components are provided AS IS for development purposes only. - - Included: - None. \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/build-dependencies.xml b/components/topcoder_cockpit_task_management_services/build-dependencies.xml deleted file mode 100644 index cbcad8656..000000000 --- a/components/topcoder_cockpit_task_management_services/build-dependencies.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/build.version b/components/topcoder_cockpit_task_management_services/build.version deleted file mode 100644 index 885973080..000000000 --- a/components/topcoder_cockpit_task_management_services/build.version +++ /dev/null @@ -1,14 +0,0 @@ -# Property file defining the component's information. -component.name=TC - Cockpit Tasks Management Backend Task Management Services -component.distfilename=topcoder_cockpit_task_management_services -component.package=com.topcoder.direct.services.project.task -component.packagedir=com/topcoder/direct/services/project/task -component.version.major=1 -component.version.minor=0 -component.version.micro=0 -component.version.build=1 - -# Defines the Main-Class property for the manifest file (e.g. com.topcoder.utility.SomeClass) -# This property is only used for components that can be run from command line. -# Leave the property value empty if not applicable. -component.mainclass= \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/build.xml b/components/topcoder_cockpit_task_management_services/build.xml deleted file mode 100644 index f912200ed..000000000 --- a/components/topcoder_cockpit_task_management_services/build.xml +++ /dev/null @@ -1,447 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The execution of reports is complete. Reports are available in /${reports} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/conf/META-INF/task/applicationContext.xml b/components/topcoder_cockpit_task_management_services/conf/META-INF/task/applicationContext.xml deleted file mode 100644 index 36ba487cf..000000000 --- a/components/topcoder_cockpit_task_management_services/conf/META-INF/task/applicationContext.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - java:TCS_CATALOG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.util.log.LogManager.getLog - - - - com.topcoder.task.logger - - - - - - - - - - - - - - - task_log - - - - \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/conf/META-INF/task/persistence.xml b/components/topcoder_cockpit_task_management_services/conf/META-INF/task/persistence.xml deleted file mode 100644 index 4e4f7742e..000000000 --- a/components/topcoder_cockpit_task_management_services/conf/META-INF/task/persistence.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - org.hibernate.ejb.HibernatePersistence - META-INF/task/task_orm.xml - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/conf/META-INF/task/task_orm.xml b/components/topcoder_cockpit_task_management_services/conf/META-INF/task/task_orm.xml deleted file mode 100644 index f728234e8..000000000 --- a/components/topcoder_cockpit_task_management_services/conf/META-INF/task/task_orm.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.direct.services.project.task.model.TaskStatus - - - - - com.topcoder.direct.services.project.task.model.TaskPriority - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/EntityNotFoundException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/EntityNotFoundException.java deleted file mode 100644 index e0ed9720e..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/EntityNotFoundException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -/** - *

- * This exception is thrown in update / delete method if given entity is not found. - *

- * - *

- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class EntityNotFoundException extends PersistenceException { - /** - *

- * The serial version id. - *

- */ - private static final long serialVersionUID = 4314341295609435285L; - - /** - *

- * Constructs a new EntityNotFoundException instance. - *

- */ - public EntityNotFoundException() { - // empty - } - - /** - *

- * Constructs a new EntityNotFoundException instance with error message. - *

- * - * @param message - * the error message. - */ - public EntityNotFoundException(String message) { - super(message); - } - - /** - *

- * Constructs a new EntityNotFoundException instance with inner cause. - *

- * - * @param cause - * the inner cause. - */ - public EntityNotFoundException(Throwable cause) { - super(cause); - } - - /** - *

- * Constructs a new EntityNotFoundException instance with error message and inner cause. - *

- * - * @param message - * the error message. - * @param cause - * the inner cause. - */ - public EntityNotFoundException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/NotificationException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/NotificationException.java deleted file mode 100644 index 6dbd81c7c..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/NotificationException.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - - -/** - *

- * This exception indicates error with notification sending. - *

- *

- * Thread-Safety:It's not thread-safe because its base class is not thread-safe. - *

- * - * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public class NotificationException extends TaskManagementException { - - /** - *

- * Constructs a new NotificationException instance. - *

- */ - public NotificationException() { - // does nothing - } - - /** - *

- * Constructs a new NotificationException instance with error message. - *

- * - * @param message - * the error message. - */ - public NotificationException(String message) { - super(message); - } - - /** - *

- * Constructs a new NotificationException instance with inner cause. - *

- * - * @param cause - * the inner cause. - */ - public NotificationException(Throwable cause) { - super(cause); - } - - /** - *

- * Constructs a new NotificationException instance with error message and inner cause. - *

- * - * @param message - * the error message. - * @param cause - * the inner cause. - */ - public NotificationException(String message, Throwable cause) { - super(message, cause); - } -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/NotificationService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/NotificationService.java deleted file mode 100644 index afbb66384..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/NotificationService.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskStatus; - -/** - *

- * This is the service contract for sending notifications. - *

- *

- * Thread-Safety: - * Implementations should be thread-safe, but the use of the Spring IoC container to inject configurations - * will not be treated as a factor in thread-safety. Also, it can be assumed that method inputs will not be - * used concurrently. - *

- * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public interface NotificationService { - - /** - *

- * Sends notification about task creation. - *

- * @param userId the id of user performing this action. - * @param task the created task. - * - * @throws IllegalArgumentException if task is null or task.getName() is null/empty or task.getStatus() is - * null or task.getPriority() is null. - * - * @throws NotificationException if any error occurs, for example failed to get the user email from the - * userService. - */ - public void notifyTaskCreation(long userId, Task task) throws NotificationException; - - /** - *

- * Send notification about task status change. - *

- * - *

- * When status changes, the email will sent to the corresponding assignees of the task, and the creator of - * this task. - *

- * - * @param userId the ID of user performing this action. - * @param oldTask the task status before status change. - * @param newTask the task after status change. - * @throws IllegalArgumentException if any of the tasks (oldTask or newTask) is null or have - * Task.getName() null/empty or Task.getStatus() null, or the Task.getCreatedBy is null or empty. - * - * @throws NotificationException if any error occurs, such as failed to get the user's email addresses. - */ - public void notifyTaskStatusChange(long userId, TaskStatus oldTask, Task newTask) throws NotificationException; -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PermissionException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PermissionException.java deleted file mode 100644 index f7c64d6f9..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PermissionException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -/** - *

- * This exception is thrown in modifiable methods if the user isn't permitted to access the task/task list. - *

- * - *

- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class PermissionException extends TaskManagementException { - /** - *

- * The serial version id. - *

- */ - private static final long serialVersionUID = 6378965077902743498L; - - /** - *

- * Constructs a new PermissionException instance. - *

- */ - public PermissionException() { - // empty - } - - /** - *

- * Constructs a new PermissionException instance with error message. - *

- * - * @param message - * the error message. - */ - public PermissionException(String message) { - super(message); - } - - /** - *

- * Constructs a new PermissionException instance with inner cause. - *

- * - * @param cause - * the inner cause. - */ - public PermissionException(Throwable cause) { - super(cause); - } - - /** - *

- * Constructs a new PermissionException instance with error message and inner cause. - *

- * - * @param message - * the error message. - * @param cause - * the inner cause. - */ - public PermissionException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PersistenceException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PersistenceException.java deleted file mode 100644 index 210dd5ab5..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/PersistenceException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -/** - *

- * This exception is thrown for any error related to database persistence. - *

- * - *

- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class PersistenceException extends TaskManagementException { - /** - *

- * The serial version id. - *

- */ - private static final long serialVersionUID = -3439432135588510236L; - - /** - *

- * Constructs a new PersistenceException instance. - *

- */ - public PersistenceException() { - // empty - } - - /** - *

- * Constructs a new PersistenceException instance with error message. - *

- * - * @param message - * the error message. - */ - public PersistenceException(String message) { - super(message); - } - - /** - *

- * Constructs a new PersistenceException instance with inner cause. - *

- * - * @param cause - * the inner cause. - */ - public PersistenceException(Throwable cause) { - super(cause); - } - - /** - *

- * Constructs a new PersistenceException instance with error message and inner cause. - *

- * - * @param message - * the error message. - * @param cause - * the inner cause. - */ - public PersistenceException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskListService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskListService.java deleted file mode 100644 index a1442677c..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskListService.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import java.util.List; - -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; - -/** - *

- * This is the service contract for managing task lists in Cockpit. - *

- *

- * Thread-Safety:Implementations should be thread-safe, - * but the use of the Spring IoC container to inject configurations - * will not be treated as a factor in thread-safety. Also, it can be assumed that method inputs will not be - * used concurrently. - *

- * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public interface TaskListService { - - /** - *

- * Adds a new TaskList, and return the added TaskList entity. - *

- * @param userId the ID of user performing this action. - * @param taskList the task list to add. - * @return the added task list. It will not be null. - * - * @throws IllegalArgumentException if taskList is null or has getName() null/empty. - * @throws PermissionException if specified user doesn't exist. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public TaskList addTaskList(long userId, TaskList taskList) - throws TaskManagementException; - - /** - *

- * Updates an existing TaskList. - *

- * @param userId the operation user id. - * @param taskList the task list to update. - * @throws IllegalArgumentException if taskList is null or has getName() null/empty. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void updateTaskList(long userId, TaskList taskList) - throws TaskManagementException; - - /** - *

- * Retrieve an existing TaskList. - *

- * - * @param userId the ID of user performing this action. - * @param taskListId the ask list ID. - * - * @return the retrieved entity, or null if the task list is not found. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public TaskList getTaskList(long userId, long taskListId) - throws TaskManagementException; - - /** - *

- * Retrieves the default TaskList for a project. - *

- * NOTE, this method will create a default task list if it does not exists. - * - * @param userId the ID of user performing this action. - * @param projectId the project ID. - * @return the default task list. Not null (default task list will be added if not exists yet). - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified project doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public TaskList getDefaultTaskList(long userId, long projectId) - throws TaskManagementException; - - /** - *

- * Deletes an existing TaskList. - *

- * - * @param userId the ID of user performing this action. - * @param taskListId the task list ID. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTaskList(long userId, long taskListId) - throws TaskManagementException; - - /** - *

- * Resolves a TaskList, by marking all Tasks in the list as "Completed" and setting the TaskList - * as inactive (i.e. archived). - *

- * @param userId the ID of user performing this action. - * @param taskListId the task list ID. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws NotificationException if failed to sent the notification emails. - * @throws TaskManagementException if any other error occurs. - */ - public void resolveTaskList(long userId, long taskListId) - throws TaskManagementException; - - /** - *

- * Retrieves TaskList's according to a TaskFilter (without tasks in each taskList). - *

- * - *

- * Note that only TaskList data will be returned, without Task's in TaskList's and only the task lists to - * which the specified user has access will be returned. - *

- * - * @param userId the ID of user performing this action. - * @param taskFilter the task filter. If null, all task lists will be returned (without filtering). - * @return retrieved entities. Empty if none found. Not null. - * - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the query. - * @throws TaskManagementException if any other error occurs. - */ - public List getTaskLists(long userId, TaskFilter taskFilter) - throws TaskManagementException; - - /** - *

- * Retrieves TaskList's according to a TaskFilter (with tasks in each taskList). - *

- * - *

- * Note that only TaskList data will be returned, without Task's in TaskList's and only the task lists to - * which the specified user has access will be returned. - *

- * - * @param userId the ID of user performing this action. - * @param taskFilter the task filter. If null, all task lists will be returned (without filtering). - * @return retrieved entities. Empty if none found. Not null. - * - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the query. - * @throws TaskManagementException if any other error occurs. - */ - public List getTaskListsWithTasks(long userId, TaskFilter taskFilter) - throws TaskManagementException; -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskManagementConfigurationException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskManagementConfigurationException.java deleted file mode 100644 index 9c4920ece..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskManagementConfigurationException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -/** - *

- * This exception is thrown for any configuration error of this application. - *

- * - *

- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class TaskManagementConfigurationException extends RuntimeException { - /** - *

- * The serial version id. - *

- */ - private static final long serialVersionUID = -1777545754399960549L; - - /** - *

- * Constructs a new TaskManagementConfigurationException instance. - *

- */ - public TaskManagementConfigurationException() { - // empty - } - - /** - *

- * Constructs a new TaskManagementConfigurationException instance with error message. - *

- * - * @param message - * the error message. - */ - public TaskManagementConfigurationException(String message) { - super(message); - } - - /** - *

- * Constructs a new TaskManagementConfigurationException instance with inner cause. - *

- * - * @param cause - * the inner cause. - */ - public TaskManagementConfigurationException(Throwable cause) { - super(cause); - } - - /** - *

- * Constructs a new TaskManagementConfigurationException instance with error message and inner cause. - *

- * - * @param message - * the error message. - * @param cause - * the inner cause. - */ - public TaskManagementConfigurationException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskManagementException.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskManagementException.java deleted file mode 100644 index 06caf7308..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskManagementException.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -/** - *

- * This is the base exception for checked exceptions of this application. - *

- * - *

- * Thread Safety: Exception is not thread safe because its base class is not thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class TaskManagementException extends Exception { - /** - *

- * The serial version id. - *

- */ - private static final long serialVersionUID = 7125152408644361137L; - - /** - *

- * Constructs a new TaskManagementException instance. - *

- */ - public TaskManagementException() { - // empty - } - - /** - *

- * Constructs a new TaskManagementException instance with error message. - *

- * - * @param message - * the error message. - */ - public TaskManagementException(String message) { - super(message); - } - - /** - *

- * Constructs a new TaskManagementException instance with inner cause. - *

- * - * @param cause - * the inner cause. - */ - public TaskManagementException(Throwable cause) { - super(cause); - } - - /** - *

- * Constructs a new TaskManagementException instance with error message and inner cause. - *

- * - * @param message - * the error message. - * @param cause - * the inner cause. - */ - public TaskManagementException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskService.java deleted file mode 100644 index 5c584c471..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/TaskService.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import java.io.InputStream; -import java.util.Date; -import java.util.List; -import java.util.SortedMap; - -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; - -/** - *

- * This is the service contract for managing tasks in cockpit. - *

- *

- * Thread-Safety:Implementations should be thread-safe, but the use of the Spring IoC container to - * inject configurations will not be treated as a factor in thread-safety. Also, it can be assumed that method - * inputs will not be used concurrently. - *

- * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public interface TaskService { - - /** - *

- * Adds a new Task, and return the added Task entity. - *

- *

- * Notifications will be sent to all assignees of the task. - *

- * @param userId the ID of user performing this action. - * @param task the task to add. - * @return the added task. It will never be null. - * @throws IllegalArgumentException if task is null or getName() null/empty or getStatus() null or - * getPriority() null. - * @throws EntityNotFoundException if task list referred by task.getTaskListId() doesn't exist in - * persistence. - * @throws PermissionException if specified user doesn't exist. - * @throws PersistenceException if any persistence related error occurs. - * @throws NotificationException if error occurs with sending notifications. - * @throws TaskManagementException if any other error occurs. - */ - public Task addTask(long userId, Task task) - throws TaskManagementException; - - /** - *

- * Updates an existing Task. - *

- *

- * If task status will be changed, then notifications will be sent to all assignees of the task as well as - * the creator of the task. - *

- * - * @param userId the ID of user performing this action. - * @param task the task to update. - * - * @throws IllegalArgumentException If task is null or getName() null/empty or getStatus() null or - * getPriority() null. - * @throws EntityNotFoundException If specified task or task list referred by task.getTaskListId() - * doesn't exist in persistence. - * @throws PermissionException If specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException If any persistence related error occurs. - * @throws NotificationException If error occurs with sending notifications. - * @throws TaskManagementException if any other error occurs. - */ - public void updateTask(long userId, Task task) - throws TaskManagementException; - - /** - *

- * Retrieves an existing Task. - *

- * @param userId the ID of user performing this action. - * @param taskId the id of the task to retrieve. - * - * @return retrieved entity. It will return null if not found or the task list of the task does not exist. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public Task getTask(long userId, long taskId) - throws TaskManagementException; - - /** - *

- * Deletes an existing Task. - *

- * @param userId the ID of user performing this action. - * @param taskId the Task ID. - * - * @throws PermissionException - If specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws EntityNotFoundException - If specified task doesn't exist in persistence. - * @throws PersistenceException - If any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTask(long userId, long taskId) - throws TaskManagementException; - - /** - *

- * Add an attachment to a task, and return the added TaskAttachment entity. - *

- *

- * The attachment content will be passed to the method as an InputStream. - *

- *

- * This method will not close the passed in InputStream. - *

- * @param userId the ID of user performing this action. - * @param attachment the task attachment entity. - * @param inputStream the task attachment content. - * @return the added task attachment. Not null. - * @throws IllegalArgumentException - If any argument is null or attachment has getFileName() null/empty or - * getMimeType() null/empty. - * @throws EntityNotFoundException - If task (referred by attachment.getTaskId()) doesn't exist in - * persistence. - * @throws PermissionException - If specified user doesn't exist. - * @throws PersistenceException - If any persistence related error occurs (including file I/O error, - * because file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public TaskAttachment addTaskAttachment(long userId, TaskAttachment attachment, InputStream inputStream) - throws TaskManagementException; - - /** - *

- * Deletes an existing TaskAttachment. - *

- * - * @param userId the ID of user performing this action. - * @param attachmentId the ask attachment ID to delete. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task attachment doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs (including file I/O error, because - * file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTaskAttachment(long userId, long attachmentId) - throws TaskManagementException; - - /** - *

- * Returns the file content of a TaskAttachment as an InputStream. - *

- * @param userId the ID of user performing this action. - * @param attachmentId the task attachment ID. - * - * @return retrieved task attachment content. It will return null if not found. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws PersistenceException if any persistence related error occurs (including file I/O error, because - * file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public InputStream getTaskAttachmentContent(long userId, long attachmentId) - throws TaskManagementException; - - - /** - *

- * Groups the Tasks of given TaskList's by task priority and return the result. - *

- * - * @param taskLists the Task lists to group by priority. - * - * @return the result of grouping. Map key is task priority value, map value is a list of tasks with - * corresponding task priority. It is not null, and contains no null keys/values nor empty values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getPriority() is null or its - * getCreatedDate is null. - */ - public SortedMap> groupTasksByPriority(List taskLists); - - /** - *

- * Groups the Tasks of given TaskList's by task assignee and return the result. - *

- * - * @param taskLists the task lists to group by assignees. - * - * @return result of grouping. Map key is task assignee, map value is a list of tasks with corresponding - * assignee. If will not be null, or contains no null keys/values nor empty values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getAssignees() is null or - * contains a null element, or the getCreatedDate in the task is null. - */ - public SortedMap> groupTasksByAssignee(List taskLists); - - /** - *

- * Groups the Tasks of given TaskList's by task due date and return the result. - *

- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by the due date. - * @return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getDueDate() is null, or - * the getCreatedDate() is null. - */ - public SortedMap> groupTasksByDueDate(List taskLists); - - /** - *

- * Groups the Tasks of given TaskList's by task start date and return the result. - *

- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by the start date. - * @return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getStartDate() is null, or - * the getCreatedDate() is null. - */ - public SortedMap> groupTasksByStartDate(List taskLists); - - - /** - *

- * Groups the Tasks of given TaskList's by task status and return the result. - *

- * @param taskLists the task lists to group by the status. - * @return the result of grouping. Map key is task status value, map value is a list of tasks with - * corresponding task status. It will not be null, and contains no null keys/values nor empty - * values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getStatus() is null, or its - * getCreatedDate() is null. - */ - public SortedMap> groupTasksByStatus(List taskLists); - - /** - *

- * Gets the number of completed tasks of a given project. - *

- * @param userId the ID of user performing this action. - * @param projectId the Project ID. - * - * @return the amount of completed tasks. It will not be negative. - * - * @throws EntityNotFoundException - If specified project doesn't exist in persistence. - * @throws PersistenceException - If any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the operation. - * @throws TaskManagementException if any other error occurs. - */ - public int getNumberOfCompletedTasks(long userId, long projectId) - throws TaskManagementException; - - /** - *

- * Gets the number of all tasks of a given project. - *

- * - * @param userId the ID of user performing this action. - * @param projectId the project ID. - * - * @return the amount of tasks. Not negative. - * - * @throws EntityNotFoundException if specified project doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the operation. - * @throws TaskManagementException if any other error occurs. - */ - public int getNumberOfAllTasks(long userId, long projectId) - throws TaskManagementException; -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/BaseJPAService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/BaseJPAService.java deleted file mode 100644 index 168a5db01..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/BaseJPAService.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import javax.annotation.PostConstruct; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - -/** - *

- * Base class for the JPA based services of this component. - *

- *

- * It holds common configuration parameters (provides variables, getters, setters and checkInitialization - * method). - *

- *

- * Sample Configuration: (the log is not required) - *

-    <property name="userService" ref="mockUserService"/>
-    <property name="notificationService" ref="notificationService"/>
- * 
- *

- *

- * Thread Safety:This class is mutable, but can be used thread safely under - * following conditions: setters should not be - * called after initialization and method arguments will not be used concurrently. - *

- * - * @author Mozgastik, TCSDEVELOPER - * @version 1.0 - */ -public abstract class BaseJPAService { - - /** - *

- * Represents the logger for performing logging. If null, logging will not be performed. - *

- *

- * It is fully mutable, has protected getter and public setter. - *

- *

- * It can be any value. - *

- */ - private Log log; - - - /** - *

- * Represents the service for managing users. - *

- *

- * It is fully mutable, has protected getter and public setter. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *

- */ - private UserService userService; - - /** - *

- * Represents the JPA entity manager for accessing persistence. - *

- *

- * It is fully mutable, has protected getter and public setter. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *

- */ - @PersistenceContext(unitName = "taskPersistenceUnit") - private EntityManager entityManager; - - /** - *

- * Represents the service for sending notifications. - *

- *

- * It is fully mutable, has protected getter and public setter. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *

- */ - private NotificationService notificationService; - - - - /** - *

- * Creates the instance of BaseJPAService (since this class is an abstract class, it is actually called by - * its concrete subclass). - *

- *

- * This is the default constructor of BaseJPAService. - *

- */ - protected BaseJPAService() { - // does nothing - } - - /** - *

- * Validates configuration parameters. - *

- *

- * NOTE, in this class the required fields are: - * userService, entityManager, notificationService. - * The log is optional. - *

- * - * @throws TaskManagementConfigurationException if any configuration parameter has invalid value. - */ - @PostConstruct - public void checkInitialization() { - ServiceHelper.checkState(userService == null, - "The userService is not properly injected."); - ServiceHelper.checkState(entityManager == null, - "The entityManager is not properly injected."); - ServiceHelper.checkState(notificationService == null, - "The notificationService is not properly injected."); - - } - - /** - *

- * Gets the logger for performing logging. - *

- * @return the logger for performing logging. It may be null. - */ - protected Log getLog() { - return log; - } - - /** - *

- * Sets the logger for performing logging. - *

- * @param log the logger for performing logging. If null, logging will not be performed. - */ - public void setLog(Log log) { - this.log = log; - } - - - /** - *

- * Gets the service for managing users. - *

- * @return the service for managing users. - */ - protected UserService getUserService() { - return userService; - } - - /** - *

- * Sets the service for managing users. - *

- * @param userService the service for managing users. - */ - public void setUserService(UserService userService) { - this.userService = userService; - } - - /** - *

- * Gets the JPA entity manager for accessing persistence. - *

- * @return the JPA entity manager for accessing persistence. - */ - protected EntityManager getEntityManager() { -/* Query query = entityManager.createNativeQuery("set lock mode to wait"); - query.executeUpdate();*/ - return entityManager; - } - - /** - *

- * Sets the JPA entity manager for accessing persistence. - *

- * @param entityManager the JPA entity manager for accessing persistence. - */ - public void setEntityManager(EntityManager entityManager) { - this.entityManager = entityManager; - } - - /** - *

- * Gets the service for sending notifications. - *

- * @return the service for sending notifications. - */ - protected NotificationService getNotificationService() { - return notificationService; - } - - /** - *

- * Sets the service for sending notifications. - *

- * @param notificationService the service for sending notifications. - */ - public void setNotificationService(NotificationService notificationService) { - this.notificationService = notificationService; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationService.java deleted file mode 100644 index 2fe90067d..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationService.java +++ /dev/null @@ -1,673 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.PostConstruct; - -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.message.email.AddressException; -import com.topcoder.message.email.EmailEngine; -import com.topcoder.message.email.SendingException; -import com.topcoder.message.email.TCSEmailMessage; -import com.topcoder.service.user.UserService; -import com.topcoder.service.user.UserServiceException; -import com.topcoder.util.config.ConfigManagerException; -import com.topcoder.util.file.DocumentGenerator; -import com.topcoder.util.file.Template; -import com.topcoder.util.file.TemplateDataFormatException; -import com.topcoder.util.file.TemplateFormatException; -import com.topcoder.util.file.fieldconfig.NodeList; -import com.topcoder.util.file.fieldconfig.NodeListUtility; -import com.topcoder.util.file.fieldconfig.TemplateFields; -import com.topcoder.util.file.templatesource.FileTemplateSource; -import com.topcoder.util.file.templatesource.TemplateSourceException; -import com.topcoder.util.log.Log; - -/** - *

- * This is the Email Engine (TC catalog component) based implementation of service for sending notifications. - *

- *

- * It uses TC catalog components Email Engine and Document Generator to send template based email - * notifications. - *

- *

- * Sample Configuration: - * - *

- *  <bean id="notificationService"
- *     class="com.topcoder.direct.services.project.task.impl.EmailEngineNotificationService">
- *     <property name="userService" ref="mockUserService"/>
- *     <property name="emailSender" value="donotreply@topcoder.com"/>
- *     <property name="taskCreationEmailSubjectTemplateText"
- *     value="Task &quot;%TASK_NAME%&quot; has been creation."/>
- *     <property name="taskCreationEmailBodyTemplatePath"
- *     value="test_files/create_body_template.txt"/>
- *     <property name="taskStatusChangeEmailSubjectTemplateText"
- *     value="Task &quot;%TASK_NAME%&quot; status has been changed."/>
- *     <property name="taskStatusChangeEmailBodyTemplatePath"
- *     value="test_files/status_body_template.txt"/>
- *   </bean>
- * 
- * - *

- *

- * Sample API Usage: - *

- * NotificationService notificationService = (NotificationService) ctx.getBean("notificationService");
- * notificatoinService.notifyTaskCreation(123, task);
- * notivicationService.notifyTaskStatusChange(123, TaskStatus.IN_PROGRESS, newTask);
- * 
- *

- *

- * Thread-Safety: This class is mutable, but can be used thread safely under following conditions: - * setters should not be called after initialization and method arguments will not be used concurrently. - *

- * - *

- * Version 1.1 (Module Assembly TC - Cockpit Tasks Management Services Setup and Quick Add Task) - *

    - *
  • Updates {@link #notifyTaskCreation(long, com.topcoder.direct.services.project.task.model.Task)} - * to get assignee handle from the user service if it's null. - *
  • - *
- *

- * - * @author Mozgastik, TCSASSEMBLER - * @version 1.1 - */ -public class EmailEngineNotificationService extends BaseJPAService implements NotificationService { - - /** - *

- * Represents the name of the class for logging. - *

- */ - private static final String CLASS_NAME = EmailEngineNotificationService.class.getName(); - - /** - *

- * Represents the service for managing users. - *

- *

- * It is used by all public business methods to obtain the user handle. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *

- */ - private UserService userService; - - /** - *

- * Represents the logger for performing logging. If null, logging will not be performed. - *

- *

- * It is used by all public business methods for logging. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * It can be any value. - *

- */ - private Log log; - - /** - *

- * Represents the email address of notification sender. - *

- *

- * It is used by all public business methods to retrieve the sender. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *

- */ - private String emailSender; - - /** - *

- * Represents the email subject template text to be used for constructing messages about task creation. - *

- *

- * It is used by all public business methods. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *

- */ - private String taskCreationEmailSubjectTemplateText; - - /** - *

- * Represents the email body template text to be used for constructing messages about task creation. - *

- *

- * It is used by all public business methods. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *

- */ - private String taskCreationEmailBodyTemplatePath; - - /** - *

- * Represents the email subject template text to be used for constructing messages about task status - * change. - *

- *

- * It is used by all public business methods. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *

- */ - private String taskStatusChangeEmailSubjectTemplateText; - - /** - *

- * Represents the email body template text to be used for constructing messages about task status change. - *

- *

- * It is used by all public business methods. - *

- *

- * It is mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *

- */ - private String taskStatusChangeEmailBodyTemplatePath; - - /** - *

- * Creates the instance of EmailEngineNotificationService. - *

- *

- * This is the default constructor of EmailEngineNotificationService. - *

- */ - public EmailEngineNotificationService() { - // does nothing - } - - /** - *

- * Validates the configuration parameters. - *

- * In this class, the required fields are: - *
-     * userService,
-     * emailSender not null or empty,
-     * taskCreationEmailSubjectTemplateText not null or empty,
-     * taskCreationEmailBodyTemplatePath not null or empty,
-     * taskStatusChangeEmailSubjectTemplateText not null or empty,
-     * taskStatusChangeEmailBodyTemplatePath not null or empty,
-     * 
- * - * Refer to the class document for the demo configuration. - * - * @throws TaskManagementConfigurationException if any configuration parameter has invalid value. - */ - @PostConstruct - public void checkInitialization() { - ServiceHelper.checkState(userService == null, "The userService is not properly injected."); - ServiceHelper.checkState(emailSender == null || emailSender.trim().length() == 0, - "The emailSender cannot be null or empty."); - ServiceHelper.checkState(taskCreationEmailSubjectTemplateText == null - || taskCreationEmailSubjectTemplateText.trim().length() == 0, - "The taskCreationEmailSubjectTemplateText cannot be null or empty."); - ServiceHelper.checkState(taskCreationEmailBodyTemplatePath == null - || taskCreationEmailBodyTemplatePath.trim().length() == 0, - "The taskCreationEmailBodyTemplatePath cannot be null or empty."); - ServiceHelper.checkState(taskStatusChangeEmailSubjectTemplateText == null - || taskStatusChangeEmailSubjectTemplateText.trim().length() == 0, - "The taskStatusChangeEmailSubjectTemplateText cannot be null or empty."); - ServiceHelper.checkState(taskStatusChangeEmailBodyTemplatePath == null - || taskStatusChangeEmailBodyTemplatePath.trim().length() == 0, - "The taskStatusChangeEmailBodyTemplatePath cannot be null or empty."); - - } - - /** - *

- * Sends notification about task creation. - *

- * @param userId the id of user performing this action. - * @param task the created task. - * - * @throws IllegalArgumentException if task is null or task.getName() is null/empty or task.getStatus() is - * null or task.getPriority() is null. - * - * @throws NotificationException if any error occurs, for example failed to get the user email from the - * userService. - */ - public void notifyTaskCreation(long userId, Task task) throws NotificationException { - // prepare for logging - final String methodName = CLASS_NAME + "#notifyTaskCreation(long userId, Task task)"; - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "task"}, new Object[] {userId, task}); - - // validate the parameters - ServiceHelper.checkNull(log, methodName, task, "task"); - ServiceHelper.checkNullOrEmpty(log, methodName, task.getName(), "name in task"); - ServiceHelper.checkNull(log, methodName, task.getStatus(), "status in task"); - ServiceHelper.checkNull(log, methodName, task.getPriority(), "priority in task"); - - // prepare for the email parameter values - String taskName = task.getName(); - String taskNotes = task.getNotes() == null ? "" : task.getNotes(); - DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); - Date taskStartDate = task.getStartDate(); - Date taskDueDate = task.getDueDate(); - String taskStatus = convertTaskStatus(methodName, task.getStatus()); - String taskPriority = convertPriority(methodName, task.getPriority()); - - List> assigneesData = new ArrayList>(); - if (task.getAssignees() != null) { - // each map represents an assignee with its id and handle - for (UserDTO assignee : task.getAssignees()) { - Map map = new HashMap(); - map.put("USER_ID", assignee.getUserId() + ""); - String userHandle = assignee.getHandle(); - try { - if (userHandle == null) { - userHandle = userService.getUserHandle(assignee.getUserId()); - } - } catch (UserServiceException e) { - throw ServiceHelper.logException(log, methodName, - new NotificationException("Failed to get user handle for:" + assignee.getUserId(), e)); - } - map.put("USER_HANDLE", userHandle); - assigneesData.add(map); - } - } - - // populate email content parameters - Map params = new HashMap(); - - // set the corresponding values - params.put("TASK_NAME", taskName); - params.put("TASK_NOTES", taskNotes); - params.put("TASK_START_DATE", taskStartDate != null ? dateFormat.format(taskStartDate) : taskStartDate); - params.put("TASK_DUE_DATE", taskDueDate != null ? dateFormat.format(taskDueDate) : taskDueDate); - params.put("TASK_STATUS", taskStatus); - params.put("TASK_PRIORITY", taskPriority); - params.put("TASK_ASSIGNEES", assigneesData); - - // get Project id and name - TaskList tl = getEntityManager().find(TaskList.class, task.getTaskListId()); - String projectName = ServiceHelper.projectNameById(log, methodName, getEntityManager(), tl.getProjectId()); - params.put("PROJECT_ID", tl.getProjectId()); - params.put("PROJECT_NAME", projectName); - - // send emails - if (task.getAssignees() != null) { - for (UserDTO assignee : task.getAssignees()) { - try { - sendEmail(methodName, taskCreationEmailSubjectTemplateText, taskCreationEmailBodyTemplatePath, - emailSender, userService.getEmailAddress(assignee.getUserId()), params); - } catch (UserServiceException e) { - throw ServiceHelper.logException(log, methodName, - new NotificationException("Failed to send the email to user:" + assignee.getUserId(), e)); - } - } - } - - // log the exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Send notification about task status change. - *

- * - *

- * When status changes, the email will sent to the corresponding assignees of the task, and the creator of - * this task. - *

- * - * @param userId the ID of user performing this action. - * @param oldTask the task status before status change. - * @param newTask the task after status change. - * @throws IllegalArgumentException if any of the tasks (oldTask or newTask) is null or have - * Task.getName() null/empty or Task.getStatus() null, or the Task.getCreatedBy is null or empty. - * - * @throws NotificationException if any error occurs, such as failed to get the user's email addresses. - */ - public void notifyTaskStatusChange(long userId, TaskStatus oldTask, Task newTask) - throws NotificationException { - - // prepare for logging - final String methodName = CLASS_NAME + "#notifyTaskStatusChange(long userId, TaskStatus oldTask, Task newTask)"; - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "oldTask", "newTask"}, - new Object[] {userId, oldTask, newTask}); - - // validate the parameters - ServiceHelper.checkNull(log, methodName, oldTask, "oldTask"); - ServiceHelper.checkNull(log, methodName, newTask, "newTask"); - ServiceHelper.checkNullOrEmpty(log, methodName, newTask.getName(), "name in newTask"); - ServiceHelper.checkNull(log, methodName, newTask.getStatus(), "status in newTask"); - ServiceHelper.checkNullOrEmpty(log, methodName, newTask.getCreatedBy(), "createdBy in newTask"); - - // populate email content parameters - Map params = new HashMap(); - params.put("TASK_NAME", newTask.getName()); - String taskStatusText = convertTaskStatus(methodName, newTask.getStatus()); - params.put("UPDATED_TASK_STATUS", taskStatusText); - - String taskNotes = newTask.getNotes() == null ? "" : newTask.getNotes(); - DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); - Date taskStartDate = newTask.getStartDate(); - Date taskDueDate = newTask.getDueDate(); - String taskStatus = convertTaskStatus(methodName, newTask.getStatus()); - String taskPriority = convertPriority(methodName, newTask.getPriority()); - - List> assigneesData = new ArrayList>(); - if (newTask.getAssignees() != null) { - // each map represents an assignee with its id and handle - for (UserDTO assignee : newTask.getAssignees()) { - Map map = new HashMap(); - map.put("USER_ID", assignee.getUserId() + ""); - String userHandle = assignee.getHandle(); - try { - if (userHandle == null) { - userHandle = userService.getUserHandle(assignee.getUserId()); - } - } catch (UserServiceException e) { - throw ServiceHelper.logException(log, methodName, - new NotificationException("Failed to get user handle for:" + assignee.getUserId(), e)); - } - map.put("USER_HANDLE", userHandle); - assigneesData.add(map); - } - } - - params.put("TASK_NOTES", taskNotes); - params.put("TASK_START_DATE", taskStartDate != null ? dateFormat.format(taskStartDate) : taskStartDate); - params.put("TASK_DUE_DATE", taskDueDate != null ? dateFormat.format(taskDueDate) : taskDueDate); - params.put("TASK_STATUS", taskStatus); - params.put("TASK_PRIORITY", taskPriority); - params.put("TASK_ASSIGNEES", assigneesData); - - // get Project id and name - TaskList tl = getEntityManager().find(TaskList.class, newTask.getTaskListId()); - String projectName = ServiceHelper.projectNameById(log, methodName, getEntityManager(), tl.getProjectId()); - params.put("PROJECT_ID", tl.getProjectId()); - params.put("PROJECT_NAME", projectName); - - // send emails - try { - String createdByHandle = newTask.getCreatedBy(); - boolean createdBySent = false; - if (newTask.getAssignees() != null) { - // send to the assignees - for (UserDTO assignee : newTask.getAssignees()) { - // send to the assignee - sendEmail(methodName, - taskStatusChangeEmailSubjectTemplateText, taskStatusChangeEmailBodyTemplatePath, - emailSender, userService.getEmailAddress(assignee.getUserId()), params); - - // if this is the same handle as the createdBy user, mark it - if (createdByHandle.equals(assignee.getHandle())) { - createdBySent = true; - } - } - } - - if (!createdBySent) { - // send to the creator if it is not sent - sendEmail(methodName, taskStatusChangeEmailSubjectTemplateText, taskStatusChangeEmailBodyTemplatePath, - emailSender, userService.getEmailAddress(createdByHandle), params); - } - - } catch (UserServiceException e) { - // wrap and re-throw it - throw ServiceHelper.logException(log, methodName, - new NotificationException("failed to get the user email address", e)); - } - - // log the exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Converts the priority to a readable string. - *

- * @param methodName the name of the method for logging. - * @param priority the priority to convert. - * @return the readable string of priority. - * @throws NotificationException if the priority is not recognized. - */ - private String convertPriority(String methodName, TaskPriority priority) throws NotificationException { - if (priority == TaskPriority.HIGH) { - return "High"; - } else if (priority == TaskPriority.NORMAL) { - return "Normal"; - } else if (priority == TaskPriority.LOW) { - return "Low"; - } else { - throw ServiceHelper.logException(log, methodName, new NotificationException("Unrecognized task priority:" - + priority)); - } - } - - /** - *

- * Converts the task status to a readable string. - *

- * @param methodName the name of the method for logging. - * @param taskStatus the task status to convert. - * @return the readable string of task status. - * @throws NotificationException if the task status is not recognized. - */ - private String convertTaskStatus(final String methodName, TaskStatus taskStatus) throws NotificationException { - if (taskStatus == TaskStatus.COMPLETED) { - return "Completed"; - } else if (taskStatus == TaskStatus.IN_PROGRESS) { - return "In progress"; - } else if (taskStatus == TaskStatus.NOT_STARTED) { - return "Not started"; - } else if (taskStatus == TaskStatus.WAIT_ON_DEPENDENCY) { - return "Wait on dependency"; - } else { - throw ServiceHelper.logException(log, methodName, new NotificationException("Unrecognized task status:" - + taskStatus)); - } - } - - /** - *

- * Sets the service for managing users. - *

- * @param userService the service for managing users. - */ - public void setUserService(UserService userService) { - this.userService = userService; - } - - /** - *

- * Sets the logger for performing logging. If null, logging will not be performed. - *

- * @param log the logger for performing logging. If null, logging will not be performed. - */ - public void setLog(Log log) { - this.log = log; - } - - /** - *

- * Sets email address of notification sender. - *

- * @param emailSender the email address of notification. - */ - public void setEmailSender(String emailSender) { - this.emailSender = emailSender; - } - - /** - *

- * Sets the email subject template text to be used for constructing messages about task creation. - *

- * @param taskCreationEmailSubjectTemplateText the email subject template text to be used for constructing - * messages about task creation. - */ - public void setTaskCreationEmailSubjectTemplateText(String taskCreationEmailSubjectTemplateText) { - this.taskCreationEmailSubjectTemplateText = taskCreationEmailSubjectTemplateText; - } - - /** - *

- * Set the email body template text to be used for constructing messages about task creation. - *

- * @param taskCreationEmailBodyTemplatePath the email body template text to be used for constructing - * messages about task creation. - */ - public void setTaskCreationEmailBodyTemplatePath(String taskCreationEmailBodyTemplatePath) { - this.taskCreationEmailBodyTemplatePath = taskCreationEmailBodyTemplatePath; - } - - /** - *

- * Sets the email subject template text to be used for constructing messages about task status change. - *

- * @param taskStatusChangeEmailSubjectTemplateText the email subject template text to be used for - * constructing messages about task status change. - */ - public void setTaskStatusChangeEmailSubjectTemplateText(String taskStatusChangeEmailSubjectTemplateText) { - this.taskStatusChangeEmailSubjectTemplateText = taskStatusChangeEmailSubjectTemplateText; - } - - /** - *

- * Sets the email body template text to be used for constructing messages about task status change. - *

- * @param taskStatusChangeEmailBodyTemplatePath the email body template text to be used for constructing - * messages about task status change. - */ - public void setTaskStatusChangeEmailBodyTemplatePath(String taskStatusChangeEmailBodyTemplatePath) { - this.taskStatusChangeEmailBodyTemplatePath = taskStatusChangeEmailBodyTemplatePath; - } - - /** - *

- * Sends an email message generated from templates to the specified recipients. The email message is - * assumed to have HTML content. - *

- * @param methodName the name of the method for logging. - * @param subjectTemplateText the template text of the email message subject. - * @param bodyTemplatePath the resource or file path of the email message body template. - * @param emailSender the email address of sender. - * @param recipient the email address of recipient. - * @param params the template parameters (String, List and Map values are supported). - * - * @throws NotificationException if failed to send the email, for example, failed to parse the template. - */ - private void sendEmail(String methodName, String subjectTemplateText, String bodyTemplatePath, - String emailSender, String recipient, Map params) throws NotificationException { - - // create the document generator - DocumentGenerator documentGenerator = new DocumentGenerator(); - documentGenerator.setDefaultTemplateSource(new FileTemplateSource()); - try { - // parse email title template - Template emailSubjectTemplate = documentGenerator.parseTemplate(subjectTemplateText); - - String templateFilePath = Thread.currentThread().getContextClassLoader().getResource( - bodyTemplatePath).getFile(); - - // read and parse email body template - Template emailBodyTemplate = documentGenerator.getTemplate(templateFilePath); - - // get email subject template fields - TemplateFields fields = emailSubjectTemplate.getFields(); - // populate node list with data - NodeListUtility.populateNodeList(new NodeList(fields.getNodes()), params); - // generate email title from template - String emailSubject = documentGenerator.applyTemplate(fields); - - // get email body template fields - fields = emailBodyTemplate.getFields(); - // populate node list with data - NodeListUtility.populateNodeList(new NodeList(fields.getNodes()), params); - // generate email body from template - String emailBody = documentGenerator.applyTemplate(fields); - - // create email message - TCSEmailMessage message = new TCSEmailMessage(); - // populate the message - message.setSubject(emailSubject); - message.setBody(emailBody); - message.setFromAddress(emailSender); - message.addToAddress(recipient, TCSEmailMessage.TO); - message.setContentType("text/html"); - - // send the message - EmailEngine.send(message); - } catch (TemplateFormatException e) { - // log and wrap - throw ServiceHelper.logException(log, methodName, new NotificationException( - "The format of the template is invalid.", e)); - } catch (TemplateSourceException e) { - // log and wrap - throw ServiceHelper.logException(log, methodName, new NotificationException( - "The source of the template is invalid.", e)); - } catch (TemplateDataFormatException e) { - // log and wrap - throw ServiceHelper.logException(log, methodName, new NotificationException( - "The data format of the template is invalid.", e)); - } catch (AddressException e) { - // log and wrap - throw ServiceHelper.logException(log, methodName, new NotificationException( - "The email addresses are invalid.", e)); - } catch (ConfigManagerException e) { - // log and wrap - throw ServiceHelper.logException(log, methodName, new NotificationException( - "Failed to send the email, configuration problem exists.", e)); - } catch (SendingException e) { - // log and wrap - throw ServiceHelper.logException(log, methodName, new NotificationException( - "Errors occur while sending the email.", e)); - } - } -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/JPATaskListService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/JPATaskListService.java deleted file mode 100644 index fc39cfc62..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/JPATaskListService.java +++ /dev/null @@ -1,619 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.MilestoneDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.util.log.Log; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - *

- * This is the JPA based implementation of service for managing task lists in cockpit. - *

- *

- * It extends BaseJPAService to utilize the common properties. - *

- *

- * It uses JPA EntityManager (configured into base class) to perform the operations with persistence. - *

- *

- * Sample Configuration: (all the fields are required except the log) - * - *

- *  <bean id="taskListService"
- *     class="com.topcoder.direct.services.project.task.impl.JPATaskListService">
- *     <property name="log" ref="logBean" />
- *     <property name="userService" ref="mockUserService" />
- *     <property name="notificationService" ref="notificationService"/>
- *   </bean>
- * 
- * - *

- *

- * Sample API Usage: - *

- * TaskListService taskListService = (TaskListService) ctx.getBean("taskListService");
- * taskListService.addTaskList(123, taskList);
- * other APIs are similar.
- * 
- *

- *

- * Thread-Safety: This class is mutable, but can be used thread safely under following conditions: - * setters should not be called after initialization and method arguments will not be used concurrently. - *

- * - *

- * Version 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - * - Fix the task lists with 0 task issue - *

- * - * @author Mozgastik, TCSASSEMBLER - * @version 1.1 - */ -public class JPATaskListService extends BaseJPAService implements TaskListService { - - /** - *

- * Represents the query statement to retrieve the task list of a given project. - *

- */ - private static final String QUERY_DEFAULT_TASKLIST_STATEMENT = - "SELECT tl.id FROM TaskList tl WHERE tl.projectId = ?1 AND tl.default = true"; - - /** - *

- * Represents the query statement to search tasks with the given criteria. - *

- */ - private static final String QUERY_TASK_LISTS_STATEMENT_PREFIX = - "SELECT DISTINCT tl FROM TaskList tl LEFT JOIN tl.tasks t LEFT JOIN t.assignees a " - + "LEFT JOIN t.associatedToProjectMilestones tm LEFT JOIN tl.associatedToProjectMilestones tlm " - + "LEFT JOIN t.associatedToContests tc LEFT JOIN tl.associatedToContests tlc " - + "LEFT JOIN tl.permittedUsers pu WHERE 1 = 1 "; - - /** - *

- * Represents the name of the class for logging. - *

- */ - private static final String CLASS_NAME = JPATaskListService.class.getName(); - - /** - *

- * Creates the instance of JPATaskListService. - *

- *

- * This is the default constructor of JPATaskListService. - *

- */ - public JPATaskListService() { - // does nothing - } - - /** - *

- * Adds a new TaskList, and return the added TaskList entity. - *

- * @param userId the ID of user performing this action. - * @param taskList the task list to add. - * @return the added task list. It will not be null. - * - * @throws IllegalArgumentException if taskList is null or has getName() null/empty. - * @throws PermissionException if specified user doesn't exist. - * @throws PersistenceException if any persistence related error occurs. - */ - public TaskList addTaskList(long userId, TaskList taskList) throws PersistenceException, PermissionException { - // prepare for logging - final String methodName = CLASS_NAME + "#addTaskList(long userId, TaskList taskList)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "taskList"}, - new Object[] {userId, taskList}); - // check the parameter - ServiceHelper.checkNull(log, methodName, taskList, "taskList"); - ServiceHelper.checkNullOrEmpty(log, methodName, taskList.getName(), "name in taskList"); - - // get the handle of the operator, if the user does not exist, PermissionException - // will be thrown - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - - taskList.setCreatedBy(callerHandle); - taskList.setCreatedDate(new Date()); - taskList.setLastModifiedBy(null); - taskList.setLastModifiedDate(null); - - // persist the object and throw PersistenceException if error occurs - getEntityManager().persist(taskList); - - // flush to update the id - ServiceHelper.flush(log, methodName, getEntityManager()); - - // log and exit - return ServiceHelper.logExit(log, methodName, taskList); - } - - /** - *

- * Updates an existing TaskList. - *

- * @param userId the operation user id. - * @param taskList the task list to update. - * @throws IllegalArgumentException if taskList is null or has getName() null/empty. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException if any persistence related error occurs. - */ - public void updateTaskList(long userId, TaskList taskList) - throws PermissionException, PersistenceException { - // prepare for logging - final String methodName = CLASS_NAME + "#updateTaskList(long userId, TaskList taskList)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "taskList"}, - new Object[] {userId, taskList}); - ServiceHelper.checkNull(log, methodName, taskList, "taskList"); - ServiceHelper.checkNullOrEmpty(log, methodName, taskList.getName(), "name in taskList"); - // check permission and entity existence - TaskList oldTaskList = getTaskList(userId, taskList.getId()); - if (oldTaskList == null) { - throw ServiceHelper.logException(log, methodName, new EntityNotFoundException( - "The task list is not found for id:" + taskList.getId())); - } - // populate audit fields - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - taskList.setCreatedBy(oldTaskList.getCreatedBy()); - taskList.setCreatedDate(oldTaskList.getCreatedDate()); - taskList.setLastModifiedBy(callerHandle); - taskList.setLastModifiedDate(new Date()); - - // perform action - getEntityManager().merge(taskList); - - // flush the update - ServiceHelper.flush(log, methodName, getEntityManager()); - - // log and exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Retrieve an existing TaskList. - *

- * - * @param userId the ID of user performing this action. - * @param taskListId the ask list ID. - * - * @return the retrieved entity, or null if the task list is not found. - * - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException if any persistence related error occurs. - */ - public TaskList getTaskList(long userId, long taskListId) throws PermissionException, PersistenceException { - // prepare for logging - final String methodName = CLASS_NAME + "#getTaskList(long userId, long taskListId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] { - "userId", "taskListId"}, new Object[] {userId, taskListId}); - - // check the permission - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - - // get the task list - TaskList taskList = getEntityManager().find(TaskList.class, taskListId); - if (taskList == null) { - // the task list does not exist, return null - return ServiceHelper.logExit(log, methodName, taskList); - } - - // create the user dto - UserDTO callerUserDTO = new UserDTO(); - callerUserDTO.setUserId(userId); - callerUserDTO.setHandle(callerHandle); - - // check the permission - boolean permitted = false; - if (callerHandle.equals(taskList.getCreatedBy())) { - // if the user is the creator of this task list, should always permitted - permitted = true; - } else if (taskList.getPermittedUsers() == null || taskList.getPermittedUsers().size() == 0) { - // if the task list is public, everyone is permitted - permitted = true; - } else if (taskList.getPermittedUsers().size() > 0) { - // if the user is in the permitted list, should be permitted - List permittedUsers = taskList.getPermittedUsers(); - for(UserDTO ud : permittedUsers) { - if(ud.getUserId() == userId) { - permitted = true; - break; - } - } - } - - if (!permitted) { - throw ServiceHelper.logException(log, methodName, - new PermissionException("The user is not permitted for the operation:" + userId)); - } - - // fetch the tasks since it is lazy-fetch - List tasks = taskList.getTasks(); - if (tasks != null) { - for (int i = 0; i < tasks.size(); i++) { - tasks.get(i); - } - } - - // log and exit - return ServiceHelper.logExit(log, methodName, taskList); - } - - /** - *

- * Retrieves the default TaskList for a project. - *

- * NOTE, this method will create a default task list if it does not exists. - * - * @param userId the ID of user performing this action. - * @param projectId the project ID. - * @return the default task list. Not null (default task list will be added if not exists yet). - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified project doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - */ - public TaskList getDefaultTaskList(long userId, long projectId) throws PermissionException, PersistenceException { - // prepare for logging - final String methodName = CLASS_NAME + "#getDefaultTaskList(long userId, long projectId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] { - "userId", "projectId"}, new Object[] {userId, projectId}); - - // check the existence of the project - ServiceHelper.existsProject(log, methodName, getEntityManager(), projectId); - - // get the default task list id - Long taskListId = ServiceHelper.querySingleResult( - log, methodName, getEntityManager(), - QUERY_DEFAULT_TASKLIST_STATEMENT, new Object[] {projectId}, Long.class); - - TaskList taskList = null; - if (taskListId == null) { - // if the default task list not found, create one - // populate the task list - taskList = new TaskList(); - taskList.setName("Project Tasks"); - taskList.setNotes("The default Project Tasks List"); - taskList.setAssociatedToProjectMilestones(new ArrayList()); - taskList.setAssociatedToContests(new ArrayList()); - taskList.setProjectId(projectId); - taskList.setActive(true); - taskList.setDefault(true); - - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - taskList.setCreatedBy(callerHandle); - taskList.setCreatedDate(new Date()); - - taskList = addTaskList(userId, taskList); - } else { - // get the full list and check the permission - taskList = getTaskList(userId, taskListId); - } - - // log the exit - return ServiceHelper.logExit(log, methodName, taskList); - } - - /** - *

- * Deletes an existing TaskList. - *

- * - * @param userId the ID of user performing this action. - * @param taskListId the task list ID. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - */ - public void deleteTaskList(long userId, long taskListId) throws PermissionException, PersistenceException { - // prepare for logging - final String methodName = CLASS_NAME + "#deleteTaskList(long userId, long taskListId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, - new String[] {"userId", "taskListId"}, new Object[] {userId, taskListId}); - - // get the task list and do the permission check - TaskList taskList = getTaskList(userId, taskListId); - if (taskList == null) { - throw ServiceHelper.logException(log, methodName, - new EntityNotFoundException("The task list does not exists for:" + taskListId)); - } - - // remove the task list - getEntityManager().remove(taskList); - - // log and exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Resolves a TaskList, by marking all Tasks in the list as "Completed" and setting the TaskList - * as inactive (i.e. archived). - *

- * @param userId the ID of user performing this action. - * @param taskListId the task list ID. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task list doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws NotificationException if failed to sent the notification emails. - */ - public void resolveTaskList(long userId, long taskListId) - throws PermissionException, PersistenceException, NotificationException { - // prepare for logging - final String methodName = CLASS_NAME + "#resolveTaskList(long userId, long taskListId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, - new String[] {"userId", "taskListId"}, new Object[] {userId, taskListId}); - - // get the task list and this will check the permission - TaskList taskList = getTaskList(userId, taskListId); - if (taskList == null) { - throw ServiceHelper.logException(log, methodName, - new EntityNotFoundException("The task list for id:" + taskListId + " is not found.")); - } - - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - // Save old versions of task statuses, they will be needed for notifications - List oldTaskStatuses = new ArrayList(); - if (taskList.getTasks() != null) { - for (Task task : taskList.getTasks()) { - // save the old status - oldTaskStatuses.add(task.getStatus()); - - // update the task - task.setStatus(TaskStatus.COMPLETED); - task.setLastModifiedBy(callerHandle); - task.setLastModifiedDate(new Date()); - - // update the task - getEntityManager().merge(task); - } - } - - // UPDATE in TC Cockpit Tasks Management Release 2 - do not archive the default task list - if(!taskList.isDefault()) { - // set the task list archived - taskList.setActive(false); - } - - // update the task list and it will handle the auditing - updateTaskList(userId, taskList); - - // send notifications if necessary - for (int i = 0; i < oldTaskStatuses.size(); i++) { - TaskStatus oldStatus = oldTaskStatuses.get(i); - Task newTask = taskList.getTasks().get(i); - TaskStatus newStatus = newTask.getStatus(); - - if (!oldStatus.equals(newStatus)) { - // sent the notification email if status changed - getNotificationService().notifyTaskStatusChange(userId, oldStatus, newTask); - } - } - - // log the exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Retrieves TaskList's according to a TaskFilter (without tasks in each taskList). - *

- * - *

- * Note that only TaskList data will be returned, without Task's in TaskList's and only the task lists to - * which the specified user has access will be returned. - *

- * - * @param userId the ID of user performing this action. - * @param taskFilter the task filter. If null, all task lists will be returned (without filtering). - * @return retrieved entities. Empty if none found. Not null. - * - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the query. - */ - public List getTaskLists(long userId, TaskFilter taskFilter) - throws PersistenceException, PermissionException { - - // prepare for logging - Log log = getLog(); - final String methodName = CLASS_NAME + "#getTaskLists(long userId, TaskFilter taskFilter)"; - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "taskFilter"}, - new Object[] {userId, taskFilter}); - - // create the query statement and the parameters - List parameters = new ArrayList(); - StringBuilder statementBuilder = new StringBuilder(QUERY_TASK_LISTS_STATEMENT_PREFIX); - int paramIndex = 1; - - // filter by the user id - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - statementBuilder.append("AND ("); - statementBuilder.append("pu.userId IS NULL OR pu.userId = ?").append(paramIndex++); - statementBuilder.append(" OR tl.createdBy = ?").append(paramIndex++); - statementBuilder.append(") "); - - parameters.add(userId); - parameters.add(callerHandle); - - if (taskFilter != null) { - // filter by the task name - String taskName = taskFilter.getName(); - taskName = (taskName == null) ? null : "%" + taskName + "%"; - paramIndex = buildWhereStatement(statementBuilder, - "t.name LIKE ?#", taskName, parameters, paramIndex); - - // filter by the assignee id - Long assigneeId = taskFilter.getAssigneeId(); - paramIndex = buildWhereStatement(statementBuilder, - "a.userId = ?#", assigneeId, parameters, paramIndex); - - // filter by the DueDateFrom - Date dueDateFrom = taskFilter.getDueDateFrom(); - paramIndex = buildWhereStatement(statementBuilder, - "t.dueDate >= ?#", dueDateFrom, parameters, paramIndex); - - // filter by the dueDateTo - Date dueDateTo = taskFilter.getDueDateTo(); - paramIndex = buildWhereStatement(statementBuilder, - "t.dueDate <= ?#", dueDateTo, parameters, paramIndex); - - // filter by the priorities - List priorities = taskFilter.getPriorities(); - paramIndex = buildWhereStatement(statementBuilder, - "t.priority IN (?#)", priorities, parameters, paramIndex); - - // filter by the statuses - List statues = taskFilter.getStatuses(); - paramIndex = buildWhereStatement(statementBuilder, - "t.status IN (?#)", statues, parameters, paramIndex); - - // filter by the milestone - List milestones = taskFilter.getAssociatedToProjectMilestoneIds(); - paramIndex = buildWhereStatement(statementBuilder, - "(tm.milestoneId IN (?#) OR tlm.milestoneId IN (?#))", milestones, parameters, paramIndex); - - // filter by contests - List contests = taskFilter.getAssociatedToContestIds(); - paramIndex = buildWhereStatement(statementBuilder, - "(tc.contestId IN (?#) OR tlc.contestId IN (?#))", contests, parameters, paramIndex); - - // filter by project ids - List projects = taskFilter.getProjectIds(); - paramIndex = buildWhereStatement(statementBuilder, - "tl.projectId IN (?#)", projects, parameters, paramIndex); - - // filter by isActive - Boolean isActive = taskFilter.getProjectActive(); - paramIndex = buildWhereStatement(statementBuilder, - "tl.active = ?#", isActive, parameters, paramIndex); - } - - // query the result with the parameters - List result = ServiceHelper.queryListResult(log, methodName, getEntityManager(), - statementBuilder.toString(), parameters.toArray()); - - // log and exit, since it is lazy fetch, don't print the tasks in the log - return ServiceHelper.logExit(log, methodName, result, false); - } - - /** - *

- * Builds the where clause for the query statement. - *

- * @param sb the string builder of the query statement. - * @param statement the statement to add. - * @param value the value of the parameter. - * @param parameters the existing parameters. - * @param paramIndex the current parameter index. - * @return the new parameter index. - */ - private int buildWhereStatement(StringBuilder sb, String statement, - Object value, List parameters, int paramIndex) { - if (value == null) { - return paramIndex; - } - if (value instanceof List) { - if (((List) value).size() == 0) { - // empty list is not allowed by HQL, consider to be null - return paramIndex; - } - } - - // replace the place holder - statement = statement.replaceAll("\\?#", "?" + paramIndex); - sb.append(" AND ").append(statement); - parameters.add(value); - paramIndex++; - - return paramIndex; - } - - - /** - *

- * Retrieves TaskList's according to a TaskFilter (with tasks in each taskList). - *

- * - *

- * Note that only TaskList data will be returned, without Task's in TaskList's and only the task lists to - * which the specified user has access will be returned. - *

- * - * @param userId the ID of user performing this action. - * @param taskFilter the task filter. If null, all task lists will be returned (without filtering). - * @return retrieved entities. Empty if none found. Not null. - * - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the query. - */ - public List getTaskListsWithTasks(long userId, TaskFilter taskFilter) - throws PersistenceException, PermissionException { - // prepare for logging - final String methodName = CLASS_NAME + "#getTaskListsWithTasks(long userId, TaskFilter taskFilter)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "taskFilter"}, - new Object[] {taskFilter, taskFilter}); - - // get the tasks - List taskLists = getTaskLists(userId, taskFilter); - - // get the task for lazy loaded reason - for (TaskList taskList : taskLists) { - List tasks = taskList.getTasks(); - if (tasks != null) { - // we must iterate the tasks, otherwise we cannot get the tasks - for (int i = 0; i < tasks.size(); i++) { - tasks.get(i); - } - } - } - - // log and exit - return ServiceHelper.logExit(log, methodName, taskLists); - } - - -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/JPATaskService.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/JPATaskService.java deleted file mode 100644 index 1f4f65e5a..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/JPATaskService.java +++ /dev/null @@ -1,1083 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.TaskManagementException; -import com.topcoder.direct.services.project.task.TaskService; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.util.log.Log; - -import javax.annotation.PostConstruct; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.SortedMap; -import java.util.TreeMap; - -/** - *

- * This is the JPA based implementation of service for managing task in Cockpit. - *

- *

- * It extends BaseJPAService to utilize the common properties. - *

- *

- * It uses JPA EntityManager (configured into base class) to perform the operations with persistence. - *

- *

- * It uses NotificationService to send notifications. - *

- *

- * It uses TaskListService to perform operations with task lists and check permissions. - *

- *

- * Sample Configuration: (all the fields are required except the log). - * - *

- *     <bean id="taskService"
- *     class="com.topcoder.direct.services.project.task.impl.JPATaskService">
- *     <property name="log" ref="logBean" />
- *     <property name="userService" ref="mockUserService" />
- *     <property name="notificationService" ref="notificationService"/>
- *     <property name="taskListService" ref="taskListService" />
- *     <property name="attachmentDirectory" value="test_files/attachments/" />
- *     </bean>
- * 
- * - *

- *

- * Sample API Usage: - * taskService.addTask(userId, task); - * other APIs are mainly the same. - *

- *

- * Thread-Safety:This class is mutable, but can be used thread safely under following conditions: - * setters should not be called after initialization and method arguments will not be used concurrently. - *

- * - *

- * Version 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - *

    - *
  • Updates method {@link #updateTask(long, com.topcoder.direct.services.project.task.model.Task)} to reactive task is - * any task is mark as incomplete
  • - *
- *

- * - *

- * Version 1.2 (TC - Cockpit Tasks Management Assembly 3) - *

    - *
  • Updates the method {@link #groupTasksByDueDate(java.util.List)} to fix the checking on due date is null
  • - *
- *

- * - * @author Mozgastik, GreatKevin - * @version 1.2 - */ -public class JPATaskService extends BaseJPAService implements TaskService { - - /** - *

- * Represents the I/O buffer size for reading the attachment. - *

- */ - private static final int IO_BUFFER_SIZE = 4096; - - /** - *

- * Represents the query statement to get the completed tasks number. - *

- */ - private static final String NUMBER_OF_COMPLETED_TASKS_QUERY = - "SELECT COUNT(DISTINCT t) FROM Task t WHERE t.status = ?1 AND t.taskListId IN " - + "(SELECT DISTINCT tl.id FROM TaskList tl LEFT JOIN tl.permittedUsers pu " - + "WHERE tl.projectId = ?2 AND (pu.userId IS NULL OR pu.userId = ?3 OR tl.createdBy = ?4))"; - - /** - *

- * Represents the query statement to get the number of all the tasks corresponding to the user. - *

- */ - private static final String NUMBER_OF_ALL_TASKS_QUERY = "SELECT COUNT(DISTINCT t) FROM Task t " - + "WHERE t.taskListId IN " - + "(SELECT DISTINCT (tl.id) FROM TaskList tl LEFT JOIN tl.permittedUsers pu " - + "WHERE tl.projectId = ?1 AND (pu.userId IS NULL OR pu.userId = ?2 OR tl.createdBy = ?3))"; - - /** - *

- * Represents the name of the class for logging. - *

- */ - private static final String CLASS_NAME = JPATaskService.class.getName(); - - /** - *

- * Represents the path of directory where the task attachment files will be stored. - *

- *

- * It's used by methods which work with task attachments. - *

- *

- * It's mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null/empty. - *

- */ - private String attachmentDirectory; - - /** - *

- * Represents the service for managing task lists. - *

- *

- * It's used by all business methods to obtain task lists and check permissions. - *

- *

- * It's mutable, has setter for injection. - *

- *

- * Technically can be any value, but will be validated in checkInitialization method to be not null. - *

- */ - private TaskListService taskListService; - - /** - *

- * Creates the instance of JPATaskService. - *

- *

- * This is the default constructor of JPATaskService. - *

- */ - public JPATaskService() { - // does nothing - } - - /** - *

- * Validates configuration parameters. - *

- * Note, in this class: the required fields are: - * taskListService(not null), and the attachmentDirectory is not null or empty. - * and the userService, notificationService should also required for super-class. - * @throws TaskManagementConfigurationException if any configuration parameter has invalid value. - */ - @Override - @PostConstruct - public void checkInitialization() { - super.checkInitialization(); - ServiceHelper.checkState(taskListService == null, "The taskListService is not properly injected."); - ServiceHelper.checkState(attachmentDirectory == null || attachmentDirectory.trim().length() == 0, - "The attachmentDirectory cannot be null or empty."); - } - - /** - *

- * Adds a new Task, and return the added Task entity. - *

- *

- * Notifications will be sent to all assignees of the task. - *

- * @param userId the ID of user performing this action. - * @param task the task to add. - * @return the added task. It will never be null. - * @throws IllegalArgumentException if task is null or getName() null/empty or getStatus() null or - * getPriority() null. - * @throws EntityNotFoundException if task list referred by task.getTaskListId() doesn't exist in - * persistence. - * @throws PermissionException if specified user doesn't exist. - * @throws PersistenceException if any persistence related error occurs. - * @throws NotificationException if error occurs with sending notifications. - * @throws TaskManagementException if any other error occurs. - */ - public Task addTask(long userId, Task task) - throws TaskManagementException { - // prepare for logging - final String methodName = CLASS_NAME + "#addTask(long userId, Task task)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, - new String[] {"userId", "task"}, new Object[] {userId, task}); - - // validate the values in the task, IllegalArgumentException should be thrown if invalid, - // or throw the EntityNotFoundException if the taskListId does not exist for task list, - // or throw the PermissionException if the user is not permitted for the operation - validateTask(log, methodName, userId, task); - - // audit and persist the task - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - task.setCreatedBy(callerHandle); - task.setCreatedDate(new Date()); - task.setLastModifiedBy(null); - task.setLastModifiedDate(null); - - // persist to the database - getEntityManager().persist(task); - ServiceHelper.flush(log, methodName, getEntityManager()); - - // Send notifications - getNotificationService().notifyTaskCreation(userId, task); - - // log and exit - return ServiceHelper.logExit(log, methodName, task); - } - - /** - *

- * Validates the task. - *

- * @param log the logger for logging. - * @param methodName the name of the calling method for logging. - * @param userId the id of the operation user. - * @param task the task to be checked. - * @throws TaskManagementException if failed to get the task list. - * - * @throws IllegalArgumentException if the task is null, or the name in the task is null or empty, or the - * status or the priority is null. - * @throws EntityNotFoundException if the task list does not exist. - */ - private void validateTask(Log log, final String methodName, long userId, Task task) - throws TaskManagementException { - - // validate the parameters - checkTaskParameter(log, methodName, task); - - // check permissions - TaskList taskList = taskListService.getTaskList(userId, task.getTaskListId()); - if (taskList == null) { - throw ServiceHelper.logException(log, methodName, - new EntityNotFoundException("The task list for the id:" + task.getTaskListId() + " does not exist.")); - } - } - - /** - *

- * Checks if the task is valid. - *

- * @param log the logger for logging. - * @param methodName the name of the calling method for logging. - * @param task the task to check. - * - * @throws IllegalArgumentException if the task is null, or the name in the task is null or empty, or the - * status or the priority is null. - */ - private void checkTaskParameter(Log log, final String methodName, Task task) { - ServiceHelper.checkNull(log, methodName, task, "task"); - ServiceHelper.checkNullOrEmpty(log, methodName, task.getName(), "name in task"); - ServiceHelper.checkNull(log, methodName, task.getStatus(), "status in task"); - ServiceHelper.checkNull(log, methodName, task.getPriority(), "priority in task"); - } - - /** - *

- * Updates an existing Task. - *

- *

- * If task status will be changed, then notifications will be sent to all assignees of the task as well as - * the creator of the task. - *

- * - * @param userId the ID of user performing this action. - * @param task the task to update. - * @throws IllegalArgumentException If task is null or getName() null/empty or getStatus() null or - * getPriority() null. - * @throws EntityNotFoundException If specified task or task list referred by task.getTaskListId() - * doesn't exist in persistence. - * @throws PermissionException If specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws PersistenceException If any persistence related error occurs. - * @throws NotificationException If error occurs with sending notifications. - * @throws TaskManagementException if any other error occurs.. - */ - public void updateTask(long userId, Task task) throws TaskManagementException { - - // prepare for logging - final String methodName = CLASS_NAME + "#updateTask(long userId, Task task)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "task"}, new Object[] {userId, task}); - - // validate the values in the task, IllegalArgumentException should be thrown if invalid, - // or throw the EntityNotFoundException if the taskListId does not exist for task list, - // or throw the PermissionException if the user is not permitted for the operation - validateTask(log, methodName, userId, task); - - // get the existing version of the task from persistence - Task oldTask = getEntityManager().find(Task.class, task.getId()); - if (oldTask == null) { - throw ServiceHelper.logException(log, methodName, new EntityNotFoundException( - "The task is not found for id:" + task.getId())); - } - - // save the old status (we have to save the status here, otherwise, after merge, - // the oldTask's status will automatically change. - TaskStatus oldStatus = oldTask.getStatus(); - - // audit and update the task - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - task.setCreatedBy(oldTask.getCreatedBy()); - task.setCreatedDate(oldTask.getCreatedDate()); - task.setLastModifiedBy(callerHandle); - task.setLastModifiedDate(new Date()); - - // merge the task - getEntityManager().merge(task); - - if(oldStatus == TaskStatus.COMPLETED && task.getStatus() != oldStatus) { - // new status changed from completed to another status. If task list is - // archived, we need to reactive the task list - TaskList taskList = taskListService.getTaskList(userId, task.getTaskListId()); - if(taskList.isActive() == false) { - taskList.setActive(true); - // do the update - getEntityManager().merge(taskList); - } - } - - // flush to the data base - ServiceHelper.flush(log, methodName, getEntityManager()); - - // send notifications if necessary - if (!task.getStatus().equals(oldStatus)) { - getNotificationService().notifyTaskStatusChange(userId, oldStatus, task); - } - - // log and exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Retrieves an existing Task. - *

- * @param userId the ID of user performing this action. - * @param taskId the id of the task to retrieve. - * - * @return retrieved entity. It will return null if not found or the task list of the task does not exist. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws PersistenceException if any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public Task getTask(long userId, long taskId) throws TaskManagementException { - // prepare for logging. - final String methodName = CLASS_NAME + "#getTask(long userId, long taskId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "taskId"}, new Object[] {userId, taskId}); - - Task task = getEntityManager().find(Task.class, taskId); - if (task != null) { - // check the permission - taskListService.getTaskList(userId, task.getTaskListId()); - } - - // log the exit - return ServiceHelper.logExit(log, methodName, task); - } - - /** - *

- * Deletes an existing Task. - *

- * @param userId the ID of user performing this action. - * @param taskId the Task ID. - * @throws PermissionException - If specified user doesn't exist or isn't permitted to perform the - * requested action. - * @throws EntityNotFoundException - If specified task doesn't exist in persistence. - * @throws PersistenceException - If any persistence related error occurs. - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTask(long userId, long taskId) throws TaskManagementException { - // prepare for logging - final String methodName = CLASS_NAME + "#deleteTask(long userId, long taskId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "taskId"}, new Object[] {userId, taskId}); - // the permission will be check here - Task task = getTask(userId, taskId); - if (task == null) { - throw ServiceHelper.logException( - log, methodName, new EntityNotFoundException("The task is not found:" + taskId)); - } - - // remove the object - getEntityManager().remove(task); - - // log and exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Add an attachment to a task, and return the added TaskAttachment entity. - *

- *

- * The attachment content will be passed to the method as an InputStream. - *

- *

- * This method will not close the passed in InputStream. - *

- * @param userId the ID of user performing this action. - * @param attachment the task attachment entity. - * @param inputStream the task attachment content. - * @return the added task attachment. Not null. - * @throws IllegalArgumentException - If any argument is null or attachment has getFileName() null/empty or - * getMimeType() null/empty. - * @throws EntityNotFoundException - If task (referred by attachment.getTaskId()) doesn't exist in - * persistence. - * @throws PermissionException - If specified user doesn't exist. - * @throws PersistenceException - If any persistence related error occurs (including file I/O error, - * because file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public TaskAttachment addTaskAttachment(long userId, TaskAttachment attachment, InputStream inputStream) - throws TaskManagementException { - // prepare for logging - final String methodName = CLASS_NAME - + "#addTaskAttachment(long userId, TaskAttachment attachment, InputStream inputStream)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "attachment", "inputStream"}, - new Object[] {userId, attachment, inputStream}); - - // validate the parameters - ServiceHelper.checkNull(log, methodName, attachment, "attachment"); - ServiceHelper.checkNullOrEmpty(log, methodName, attachment.getFileName(), "fileName in attachment"); - ServiceHelper.checkNullOrEmpty(log, methodName, attachment.getMimeType(), "mimeType in attachment"); - ServiceHelper.checkNull(log, methodName, inputStream, "inputStream"); - - // check the permission - Task task = getTask(userId, attachment.getTaskId()); - if (task == null) { - throw ServiceHelper.logException(log, methodName, - new EntityNotFoundException("The task " + attachment.getTaskId() + " does not exists.")); - } - - - String callerHandle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - attachment.setCreatedBy(callerHandle); - attachment.setCreatedDate(new Date()); - attachment.setLastModifiedBy(null); - attachment.setLastModifiedDate(null); - - // persist the database - getEntityManager().persist(attachment); - - ServiceHelper.flush(log, methodName, getEntityManager()); - - // update the attachment file - OutputStream outputStream = null; - try { - File attachmentFile = new File(attachmentDirectory, attachment.getId() + ""); - // we must set the append false to make sure the attachment file is fully override - outputStream = new FileOutputStream(attachmentFile, false); - byte[] bytes = new byte[IO_BUFFER_SIZE]; - while (true) { - int len = inputStream.read(bytes); - if (len < 0) { - break; - } - outputStream.write(bytes, 0, len); - } - } catch (FileNotFoundException e) { - throw ServiceHelper.logException(log, methodName, - new PersistenceException( - "File not found:" + attachmentDirectory + File.separator + attachment.getId())); - } catch (IOException e) { - throw ServiceHelper.logException(log, methodName, - new PersistenceException("I/O error occurs while reading the stream or writing to file:" - + attachmentDirectory + File.separator + attachment.getId())); - } finally { - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - // ignore - } - } - } - // log and exit - return ServiceHelper.logExit(log, methodName, attachment); - } - - /** - *

- * Deletes an existing TaskAttachment. - *

- * - * @param userId the ID of user performing this action. - * @param attachmentId the ask attachment ID to delete. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws EntityNotFoundException if specified task attachment doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs (including file I/O error, because - * file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public void deleteTaskAttachment(long userId, long attachmentId) throws TaskManagementException { - // prepare for logging - Log log = getLog(); - final String methodName = CLASS_NAME + "#deleteTaskAttachment(long userId, long attachmentId)"; - // log the entrance - ServiceHelper.logEntrance(log, methodName, - new String[] {"userId", "attachmentId"}, new Object[] {userId, attachmentId}); - - // get the file and delete the entity (this will check the persistence) - File file = getTaskAttachmentFile(log, methodName, userId, attachmentId, true); - if (file == null) { - // does not exist in persistence - throw ServiceHelper.logException(log, methodName, - new EntityNotFoundException("The file for attachmentId is not found:" + attachmentId)); - } - if (!file.exists() || !file.isFile()) { - throw ServiceHelper.logException(log, methodName, - new PersistenceException("File not found:" + attachmentDirectory + File.separator + attachmentId)); - } - // delete the file - file.delete(); - - // log the exit - ServiceHelper.logExit(log, methodName); - } - - /** - *

- * Returns the file content of a TaskAttachment as an InputStream. - *

- * @param userId the ID of user performing this action. - * @param attachmentId the task attachment ID. - * - * @return retrieved task attachment content. It will return null if not found. - * @throws PermissionException if specified user doesn't exist or isn't permitted to perform the requested - * action. - * @throws PersistenceException if any persistence related error occurs (including file I/O error, because - * file system also plays a role of persistence). - * @throws TaskManagementException if any other error occurs. - */ - public InputStream getTaskAttachmentContent(long userId, long attachmentId) - throws TaskManagementException { - // prepare for logging - Log log = getLog(); - final String methodName = CLASS_NAME + "#getTaskAttachmentContent(long userId, long attachmentId)"; - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"userId", "attachmentId"}, - new Object[] {userId, attachmentId}); - - // get the file of the attachment (this will check the persistence) - File file = getTaskAttachmentFile(log, methodName, userId, attachmentId, false); - if (file == null) { - // return null and log it if the attachment is not found - return ServiceHelper.logExit(log, methodName, null); - } - - try { - // create the file stream - return ServiceHelper.logExit(log, methodName, new FileInputStream(file)); - } catch (FileNotFoundException e) { - // the file in the I/O system does not exist - throw ServiceHelper.logException(log, methodName, - new PersistenceException("File not found:" + attachmentDirectory + File.separator + attachmentId, e)); - } - } - - /** - *

- * Gets the file of the attachment, and delete the entity in database if necessary. - *

- * @param log the logger for logging. - * @param methodName the name of the method for logging. - * @param userId the user id of the operation. - * @param attachmentId the id of the attachment to retrieve. - * @param shouldDelete if true, the entity will be deleted in the database. - * @return the file of the attachment, null will return if the attachment is not found. - * @throws TaskManagementException if failed to get the task. - */ - private File getTaskAttachmentFile(Log log, final String methodName, - long userId, long attachmentId, boolean shouldDelete) throws TaskManagementException { - - TaskAttachment taskAttachment = getEntityManager().find(TaskAttachment.class, attachmentId); - if (taskAttachment == null) { - // not found - return null; - } - // check the permission - getTask(userId, taskAttachment.getTaskId()); - - if (shouldDelete) { - // remove from the database - getEntityManager().remove(taskAttachment); - } - - // return the file - return new File(attachmentDirectory, attachmentId + ""); - } - - /** - *

- * Groups the Tasks of given TaskList's by task priority and return the result. - *

- * - * @param taskLists the Task lists to group by priority. - * - * @return the result of grouping. Map key is task priority value, map value is a list of tasks with - * corresponding task priority. It is not null, and contains no null keys/values nor empty values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getPriority() is null or its - * getCreatedDate is null. - */ - public SortedMap> groupTasksByPriority(List taskLists) { - // prepare for logging - final String methodName = CLASS_NAME + "#groupTasksByPriority(List taskLists)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"taskLists"}, new Object[] {taskLists}); - - // validate the parameter - ServiceHelper.checkNull(log, methodName, taskLists, "taskLists"); - // validate the task lists - validateTaskLists(log, methodName, taskLists, "priority"); - - // create the map to store the result - SortedMap> result = new TreeMap>(); - for (TaskList taskList : taskLists) { - for (Task task : taskList.getTasks()) { - List tasks = result.get(task.getPriority()); - if (tasks == null) { - tasks = new ArrayList(); - result.put(task.getPriority(), tasks); - } - tasks.add(task); - } - } - - // sort the result by the create date - for (TaskPriority priority : result.keySet()) { - List tasks = result.get(priority); - sortTasks(tasks); - } - // log and exit - return ServiceHelper.logExit(log, methodName, result); - } - - /** - *

- * Groups the Tasks of given TaskList's by task assignee and return the result. - *

- * - * @param taskLists the task lists to group by assignees. - * - * @return result of grouping. Map key is task assignee, map value is a list of tasks with corresponding - * assignee. If will not be null, or contains no null keys/values nor empty values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getAssignees() is null or - * contains a null element, or the getCreatedDate in the task is null. - */ - public SortedMap> groupTasksByAssignee(List taskLists) { - // prepare for logging - final String methodName = CLASS_NAME + "#groupTasksByAssignee(List taskLists)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"taskLists"}, new Object[] {taskLists}); - - // validate the parameters - ServiceHelper.checkNull(log, methodName, taskLists, "taskLists"); - // validate the task lists - validateTaskLists(log, methodName, taskLists, "assignees"); - - // create the map to store the result - SortedMap> result = new TreeMap>( - new Comparator() { - public int compare(UserDTO user1, UserDTO user2) { - if (user1.getUserId() == user2.getUserId()) { - return 0; - } - return user1.getUserId() > user2.getUserId() ? 1 : -1; - } - } - ); - for (TaskList taskList : taskLists) { - for (Task task : taskList.getTasks()) { - List assignees = task.getAssignees(); - for (UserDTO assignee : assignees) { - List tasks = result.get(assignee); - if (tasks == null) { - tasks = new ArrayList(); - result.put(assignee, tasks); - } - tasks.add(task); - } - } - } - - // sort the result by the create date - for (UserDTO assignee : result.keySet()) { - List tasks = result.get(assignee); - sortTasks(tasks); - } - - // log and exit - return ServiceHelper.logExit(log, methodName, result); - } - - /** - *

- * Groups the Tasks of given TaskList's by task due date and return the result. - *

- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by the due date. - * @return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getDueDate() is null, or - * the getCreatedDate() is null. - */ - public SortedMap> groupTasksByDueDate(List taskLists) { - // prepare for logging - final String methodName = CLASS_NAME + "#groupTasksByDueDate(List taskLists)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"taskLists"}, new Object[] {taskLists}); - - // validate the parameters - ServiceHelper.checkNull(log, methodName, taskLists, "taskLists"); - // validate the task lists - // validateTaskLists(log, methodName, taskLists, "dueDate"); - - // group the result by the due date - SortedMap> result = groupByDate(taskLists, "dueDate"); - - // log and exit - return ServiceHelper.logExit(log, methodName, result); - } - - /** - *

- * Groups the Tasks of given TaskList's by task start date and return the result. - *

- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by the start date. - * @return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getStartDate() is null, or - * the getCreatedDate() is null. - */ - public SortedMap> groupTasksByStartDate(List taskLists) { - // prepare for logging - final String methodName = CLASS_NAME + "#groupTasksByStartDate(List taskLists)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"taskLists"}, new Object[] {taskLists}); - ServiceHelper.checkNull(log, methodName, taskLists, "taskLists"); - - // validate the task lists - validateTaskLists(log, methodName, taskLists, "startDate"); - - // group the result by the start date - SortedMap> result = groupByDate(taskLists, "startDate"); - - // log and exit - return ServiceHelper.logExit(log, methodName, result); - } - - /** - *

- * Group the the taskLists by the startDate or dueDate (given in the propertyName). - *

- * NOTE, the group by date is truncated to the day precision, i.e, - * 2013.08.08 08:08:08 -> 2013.08.08 - * @param taskLists the task lists to group by. - * @param propertyName the name of the field to group by (startDate or dueDate). - * - * @return return the result of grouping. Map key is task start date value, map value is a list of tasks - * with corresponding start date. It will not be null, and contains no null keys/values nor empty - * values. - */ - private SortedMap> groupByDate(List taskLists, String propertyName) { - - // create the result map - SortedMap> result = new TreeMap>(); - for (TaskList taskList : taskLists) { - for (Task task : taskList.getTasks()) { - Date date = null; - if (propertyName.equals("startDate")) { - date = task.getStartDate(); - } else { - date = task.getDueDate(); - } - - if(date == null) { - continue; - } - - // truncate to the day precision, i.e, - // 2013.08.08 08:08:08 -> 2013.08.08 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - date = calendar.getTime(); - List tasks = result.get(date); - if (tasks == null) { - tasks = new ArrayList(); - result.put(date, tasks); - } - tasks.add(task); - } - } - - // sort the result by the create date - for (Date startDate : result.keySet()) { - List tasks = result.get(startDate); - sortTasks(tasks); - } - return result; - } - - /** - *

- * Sorts the list of tasks by the created date. - *

- * @param tasks the task list to sort. - */ - private void sortTasks(List tasks) { - Collections.sort(tasks, new Comparator() { - public int compare(Task task1, Task task2) { - return task1.getCreatedDate().compareTo(task2.getCreatedDate()); - } - }); - } - - /** - *

- * Groups the Tasks of given TaskList's by task status and return the result. - *

- * @param taskLists the task lists to group by the status. - * @return the result of grouping. Map key is task status value, map value is a list of tasks with - * corresponding task status. It will not be null, and contains no null keys/values nor empty - * values. - * - * @throws IllegalArgumentException if argument is null or contains an element which is null or its - * getTasks() is null or contains an element which is null or its getStatus() is null, or its - * getCreatedDate() is null. - */ - public SortedMap> groupTasksByStatus(List taskLists) { - // prepare for logging - final String methodName = CLASS_NAME + "#groupTasksByStatus(List taskLists)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] {"taskLists"}, new Object[] {taskLists}); - ServiceHelper.checkNull(log, methodName, taskLists, "taskLists"); - - // validate the task lists - validateTaskLists(log, methodName, taskLists, "status"); - - // create the map to store the result - SortedMap> result = new TreeMap>(); - for (TaskList taskList : taskLists) { - for (Task task : taskList.getTasks()) { - List tasks = result.get(task.getStatus()); - if (tasks == null) { - tasks = new ArrayList(); - result.put(task.getStatus(), tasks); - } - tasks.add(task); - } - } - - // sort the result by the create date - for (TaskStatus status : result.keySet()) { - List tasks = result.get(status); - sortTasks(tasks); - } - // log and exit - return ServiceHelper.logExit(log, methodName, result); - } - - /** - *

- * Validates the task lists. - *

- *

- * This is a helper method using in the group by methods. - *

- * @param log the name of the logger for logging. - * @param methodName the name of the method. - * @param taskLists the task lists to validate. - * @param propertyName the name of the task to validate. - * - * @throws IllegalArgumentException if the task list is invalid. - */ - private void validateTaskLists(Log log, final String methodName, List taskLists, String propertyName) { - for (TaskList taskList : taskLists) { - // validate the taskList - ServiceHelper.checkNull(log, methodName, taskList, "taskList in taskLists"); - - // validate the tasks - List tasks = taskList.getTasks(); - ServiceHelper.checkNull(log, methodName, tasks, "tasks in taskLists"); - for (Task task : tasks) { - // validate the task - ServiceHelper.checkNull(log, methodName, task, "task in tasks"); - - // validate the createdDate - ServiceHelper.checkNull(log, methodName, task.getCreatedDate(), "createDate in task"); - - // validate the properties - if (propertyName.equals("status")) { - ServiceHelper.checkNull(log, methodName, task.getStatus(), "status in task"); - } else if (propertyName.equals("startDate")) { - ServiceHelper.checkNull(log, methodName, task.getStartDate(), "startDate in task"); - } else if (propertyName.equals("dueDate")) { - ServiceHelper.checkNull(log, methodName, task.getDueDate(), "dueDate in task"); - } else if (propertyName.equals("assignees")) { - // validate the assignees - List assignees = task.getAssignees(); - ServiceHelper.checkNull(log, methodName, assignees, "assignees in task"); - for (UserDTO assignee : assignees) { - ServiceHelper.checkNull(log, methodName, assignee, "assignee in assignees"); - } - } else if (propertyName.equals("priority")) { - ServiceHelper.checkNull(log, methodName, task.getPriority(), "priority in task"); - } - } - } - } - - /** - *

- * Gets the number of completed tasks of a given project. - *

- * @param userId the ID of user performing this action. - * @param projectId the Project ID. - * - * @return the amount of completed tasks. It will not be negative. - * - * @throws EntityNotFoundException - If specified project doesn't exist in persistence. - * @throws PersistenceException - If any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the operation. - */ - public int getNumberOfCompletedTasks(long userId, long projectId) - throws PersistenceException, PermissionException { - - // prepare for logging - final String methodName = CLASS_NAME + "#getNumberOfCompletedTasks(long userId, long projectId)"; - Log log = getLog(); - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] { - "userId", "projectId"}, new Object[] {userId, projectId}); - - // check the existence of the project - ServiceHelper.existsProject(log, methodName, getEntityManager(), projectId); - - // perform the operation of retrieving all the number completed tasks - String handle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - - // get the number of the completed tasks - int resultNum = ServiceHelper.queryRecordNum(log, methodName, - getEntityManager(), NUMBER_OF_COMPLETED_TASKS_QUERY, new Object[] { - TaskStatus.COMPLETED, projectId, userId, handle}); - - // log and return the result - return ServiceHelper.logExit(log, methodName, resultNum); - } - - /** - *

- * Gets the number of all tasks of a given project. - *

- * - * @param userId the ID of user performing this action. - * @param projectId the project ID. - * - * @return the amount of tasks. Not negative. - * - * @throws EntityNotFoundException if specified project doesn't exist in persistence. - * @throws PersistenceException if any persistence related error occurs. - * @throws PermissionException if the user is not permitted for the operation. - */ - public int getNumberOfAllTasks(long userId, long projectId) - throws PersistenceException, PermissionException { - // prepare for logging - final String methodName = CLASS_NAME + "#getNumberOfAllTasks(long userId, long projectId)"; - Log log = getLog(); - - // log the entrance - ServiceHelper.logEntrance(log, methodName, new String[] { - "userId", "projectId"}, new Object[] {userId, projectId}); - - // check the existence of the project - ServiceHelper.existsProject(log, methodName, getEntityManager(), projectId); - - // get the user handle - String handle = ServiceHelper.getUserHandle(log, methodName, getUserService(), userId); - - // perform the operation of retrieving all the number tasks - int resultNum = ServiceHelper.queryRecordNum(log, methodName, - getEntityManager(), NUMBER_OF_ALL_TASKS_QUERY, new Object[] {projectId, userId, handle}); - - return ServiceHelper.logExit(log, methodName, resultNum); - } - - - - - /** - *

- * Sets the path of directory where the task attachment files will be stored. - *

- * @param attachmentDirectory - * the path of directory where the task attachment files will be stored. - */ - public void setAttachmentDirectory(String attachmentDirectory) { - this.attachmentDirectory = attachmentDirectory; - } - - /** - *

- * Sets the service for managing task lists. - *

- * - * @param taskListService the service for managing task lists. - */ - public void setTaskListService(TaskListService taskListService) { - this.taskListService = taskListService; - } - -} - diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/ServiceHelper.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/ServiceHelper.java deleted file mode 100644 index 5652d24b9..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/impl/ServiceHelper.java +++ /dev/null @@ -1,615 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.math.BigDecimal; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import javax.persistence.EntityManager; -import javax.persistence.NoResultException; -import javax.persistence.NonUniqueResultException; -import javax.persistence.Query; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.MilestoneDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.UserService; -import com.topcoder.service.user.UserServiceException; -import com.topcoder.util.log.Level; -import com.topcoder.util.log.Log; - -/** - *

- * This is a helper class using in the package: com.topcoder.direct.services.project.task.impl. - *

- * @author TCSDEVELOPER - * @version 1.0 - * - */ -final class ServiceHelper { - - /** - *

- * Selects the number of the tasks for the project id. - *

- */ - private static final String QUERY_PROJECT_NUM_STATEMENT = "SELECT COUNT(*) FROM tc_direct_project p WHERE p.project_id = ?"; - - /** - *

- * Selects project name from project_id. - *

- */ - private static final String QUERY_PROJECT_NAME_BY_ID = "SELECT name from tc_direct_project p WHERE p.project_id = ?"; - - /** - *

- * Represents the entrance message. - *

- */ - private static final String MESSAGE_ENTRANCE = "Entering method %1$s."; - - /** - *

- * Represents the exit message. - *

- */ - private static final String MESSAGE_EXIT = "Exiting method %1$s."; - - /** - *

- * Represents the error message. - *

- */ - private static final String MESSAGE_ERROR = "Error in method %1$s. Details:"; - - /** - *

- * Represents the list of entity types to print out in the log. - *

- */ - private static final Class[] POJOS = new Class[] { - TaskList.class, - Task.class, - ContestDTO.class, - MilestoneDTO.class, - UserDTO.class, - TaskAttachment.class - }; - - /** - *

- * Prevents to create the instance and it has a private modifier. - *

- */ - private ServiceHelper() { - // does nothing - } - - /** - *

- * Checks state of object. - *

- * - * @param isInvalid - * the state of object. - * @param message - * the error message. - * - * @throws TaskManagementConfigurationException - * if isInvalid is true - */ - static void checkState(boolean isInvalid, String message) { - if (isInvalid) { - throw new TaskManagementConfigurationException(message); - } - } - - /** - *

- * Validates the value of a variable. The value can not be null. - *

- * - * @param logger - * the logger object. - * @param signature - * the signature of the method to be logged. - * @param value - * the value of the variable to be validated. - * @param name - * the name of the variable to be validated. - * - * @throws IllegalArgumentException - * if the value of the variable is null. - */ - static void checkNull(Log logger, String signature, Object value, String name) { - if (value == null) { - // Log exception - throw logException(logger, signature, new IllegalArgumentException("'" + name - + "' should not be null.")); - } - } - - - - /** - *

- * Validates the value of a string. The value can not be null or an empty string. - *

- * - * @param logger - * the logger object (not null). - * @param signature - * the signature of the method to be logged. - * @param value - * the value of the variable to be validated. - * @param name - * the name of the variable to be validated. - * - * @throws IllegalArgumentException - * if the given string is null or an empty string. - */ - static void checkNullOrEmpty(Log logger, String signature, String value, String name) { - checkNull(logger, signature, value, name); - - if (value.trim().length() == 0) { - // Log exception - throw logException(logger, signature, new IllegalArgumentException("'" + name - + "' should not be an empty string.")); - } - } - - - /** - *

- * Logs for entrance into public methods at DEBUG level. - *

- * - * @param logger - * the logger object (not null). - * @param signature - * the signature of the method to be logged. - * @param paramNames - * the names of parameters to log . - * @param params - * the values of parameters to log. - */ - static void logEntrance(Log logger, String signature, String[] paramNames, Object[] params) { - if (logger != null) { - // Do logging - logger.log(Level.DEBUG, String.format(MESSAGE_ENTRANCE, signature)); - if (paramNames != null) { - // Log parameters - logParameters(logger, paramNames, params); - } - } - } - - /** - *

- * Logs for exit from public methods at DEBUG level. - *

- * - * @param logger - * the logger object (not null). - * @param signature - * the signature of the method to be logged. - * - * @param value - * the return value to log. - * @param lazyFetch - * check if this is lazy fetch. - * @param - * the type of the return value. - * @return the return object. - */ - static T logExit(Log logger, String signature, T value, boolean lazyFetch) { - if (logger != null) { - // Do logging - logger.log(Level.DEBUG, String.format(MESSAGE_EXIT, signature)); - // Log return value - logger.log(Level.DEBUG, "The return value: " + toString(value, lazyFetch)); - - } - return value; - } - - /** - *

- * Logs for exit from public methods at DEBUG level. - *

- * - * @param logger - * the logger object (not null). - * @param signature - * the signature of the method to be logged. - * - * @param value - * the return value to log. - * @param - * the type of the return value. - * @return the return object. - */ - static T logExit(Log logger, String signature, T value) { - if (logger != null) { - // Do logging - logger.log(Level.DEBUG, String.format(MESSAGE_EXIT, signature)); - // Log return value - logger.log(Level.DEBUG, "The return value: " + toString(value, false)); - - } - return value; - } - - /** - *

- * Logs for exit from public methods at DEBUG level. The calling method does not have a return value. - *

- * - * @param logger - * the logger object (not null). - * @param signature - * the signature of the method to be logged. - */ - static void logExit(Log logger, String signature) { - if (logger != null) { - // Do logging - logger.log(Level.DEBUG, String.format(MESSAGE_EXIT, signature)); - } - } - - /** - *

- * Logs the given exception and message at ERROR level. The calling method has a return value. - *

- * - * @param - * the exception type. - * @param logger - * the logger object). - * @param signature - * the signature of the method to log. - * @param e - * the exception to log. - * - * @return the passed in exception. - */ - static T logException(Log logger, String signature, T e) { - if (logger != null) { - String errorMessage = String.format(MESSAGE_ERROR, signature); - - // Do logging - logger.log(Level.ERROR, e, errorMessage); - } - return e; - } - - /** - *

- * Logs the parameters at DEBUG level. - *

- * - * - * @param logger - * the logger object (not null). - * @param paramNames - * the names of parameters to log (not null). - * @param params - * the values of parameters to log (not null). - */ - private static void logParameters(Log logger, String[] paramNames, Object[] params) { - StringBuffer sb = new StringBuffer("The parameters: {"); - - for (int i = 0; i < params.length; i++) { - - if (i > 0) { - // Append a comma - sb.append(", "); - } - - sb.append(paramNames[i]).append(":").append(toString(params[i], false)); - } - sb.append("}."); - - // Do logging - logger.log(Level.DEBUG, sb.toString()); - } - - /** - * Create the string of parameter object. - * - * @param paramObj - * the parameter object - * @param lazyFetch - * specifies if this is a lazy fetch object. - * @return the string of parameter object - */ - private static String toString(Object paramObj, boolean lazyFetch) { - StringBuilder sb = new StringBuilder(); - if (paramObj == null) { - return "null"; - } - if (Arrays.asList(POJOS).contains(paramObj.getClass())) { - // print out each field - printPOJO(paramObj, lazyFetch, sb); - return sb.toString(); - } - if (paramObj instanceof List) { - List list = (List) paramObj; - sb.append("["); - for (Object obj : list) { - sb.append(toString(obj, lazyFetch)).append(","); - } - sb.append("]"); - return sb.toString(); - } - if (paramObj instanceof Map) { - Map map = (Map) paramObj; - for (Object key : map.keySet()) { - Object value = map.get(key); - if (sb.length() > 0) { - sb.append(","); - } - sb.append("{").append(toString(key, lazyFetch)).append(":").append(toString(value, lazyFetch)) - .append("}"); - } - return sb.toString(); - } - - return paramObj.toString(); - } - - /** - *

- * Prints out the pojos to the log. - *

- * @param paramObj the object to print. - * @param lazyFetch if lazy fetch, the tasks are not printed. - * @param sb to build the log. - */ - private static void printPOJO(Object paramObj, boolean lazyFetch, StringBuilder sb) { - Method[] methods = paramObj.getClass().getMethods(); - for (Method method : methods) { - if (method.getName().startsWith("get") || method.getName().startsWith("is")) { - if (lazyFetch && paramObj instanceof TaskList && method.getName().equals("getTasks")) { - // ignore the lazy fetch - continue; - } - if (method.getName().equals("getClass")) { - continue; - } - Object value = null; - try { - value = method.invoke(paramObj); - } catch (IllegalArgumentException e) { - // ignore - } catch (IllegalAccessException e) { - // ignore - } catch (InvocationTargetException e) { - // ignore - } - String fieldName = method.getName(); - if (fieldName.startsWith("get")) { - fieldName = fieldName.substring("get".length()); - } - if (fieldName.startsWith("is")) { - fieldName = fieldName.substring("is".length()); - } - fieldName = fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1); - // print the value - if (sb.length() > 0) { - sb.append(","); - } - sb.append("{").append(fieldName).append(":").append(toString(value, lazyFetch)).append("}"); - } - } - } - - /** - *

- * Query the list result from the query statement. - *

- * @param log the logger for logging. - * @param methodName the name of the method for logging. - * @param entityManager the entityManager. - * @param statement the statement to retrieve the list. - * @param parameters the parameters to set into the statement. - * @param the type of the object. - * @return the list of the query result. - */ - @SuppressWarnings("unchecked") - static List queryListResult(Log log, String methodName, - EntityManager entityManager, String statement, Object[] parameters) { - Query query = createQuery(entityManager, statement, parameters); - return query.getResultList(); - } - - /** - *

- * Queries the single result. - *

- * @param log the logger for logging. - * @param methodName the name of the method for logging. - * @param entityManager the entity manager to access the database. - * @param statement the statement to query the result. - * @param parameters the parameters to set into the statement. - * @param clazz the type of the entity. - * @param the type of the object. - * @return the entity, or null if not exist. - * @throws PersistenceException if failed to get the object. - */ - static T querySingleResult(Log log, String methodName, EntityManager entityManager, - String statement, Object[] parameters, Class clazz) throws PersistenceException { - try { - Query query = createQuery(entityManager, statement, parameters); - return clazz.cast(query.getSingleResult()); - } catch (ClassCastException e) { - throw ServiceHelper.logException( - log, methodName, new PersistenceException("The retrieving object is not in correct type.", e)); - } catch (NoResultException e) { - // return null if the record not found - return null; - } catch (NonUniqueResultException e) { - throw ServiceHelper.logException( - log, methodName, new PersistenceException("The retrieving object is not unique.", e)); - } - - } - - /** - *

- * Query the number count of the entities for a query statement. - *

- * @param log the logger for logging. - * @param methodName the name of the method for logging. - * @param entityManager the entity manager to access the database. - * @param statement the query statement. - * @param parameters the parameters to set into the statement. - * @return the number that retrieved. - */ - static int queryRecordNum(Log log, String methodName, - EntityManager entityManager, String statement, Object[] parameters) { - Query query = createQuery(entityManager, statement, parameters); - return ((Long) query.getSingleResult()).intValue(); - } - - /** - *

- * Creates the native query. - *

- * @param entityManager the entity manager to access the database. - * @param statement the statement to retrieve the result. - * @param parameters the parameters to set into the statement. - * @return the created query. - */ - private static Query createNativeQuery(EntityManager entityManager, String statement, Object[] parameters) { - Query query = entityManager.createNativeQuery(statement); - setParameters(query, parameters); - return query; - } - - /** - *

- * Creates the hibernate query. - *

- * @param entityManager the entity manager to access the database. - * @param statement the statement to retrieve the result. - * @param parameters the parameters to set into the statement. - * @return the created query. - */ - private static Query createQuery(EntityManager entityManager, String statement, Object[] parameters) { - Query query = entityManager.createQuery(statement); - setParameters(query, parameters); - return query; - } - - /** - *

- * Sets the parameters to the query. - *

- * @param query the query to set the parameters. - * @param parameters the parameter value to set. - */ - private static void setParameters(Query query, Object[] parameters) { - if (parameters != null) { - for (int i = 0; i < parameters.length; i++) { - query.setParameter(i + 1, parameters[i]); - } - } - - } - - /** - *

- * Checks if the project exists. - *

- * @param log the logger for logging. - * @param methodName the name of the method for logging. - * @param entityManager the entity manager to access the database. - * @param projectId the id of the project. - * @throws EntityNotFoundException if the project not found. - */ - static void existsProject(Log log, final String methodName, EntityManager entityManager, long projectId) - throws EntityNotFoundException { - Query query = createNativeQuery(entityManager, QUERY_PROJECT_NUM_STATEMENT, new Object[] {projectId}); - int resultNum = ((BigDecimal) query.getSingleResult()).intValue(); - if (resultNum == 0) { - throw ServiceHelper.logException(log, methodName, - new EntityNotFoundException("The project does not exist for id:" + projectId)); - } - } - - /** - - *

- * Get project name by id. - *

- * @param log the logger for logging. - * @param methodName the name of the method for logging. - * - * @param entityManager the entity manager to access the database. - * @param projectId the id of the project. - */ - static String projectNameById(Log log, final String methodName, EntityManager entityManager, long projectId) - { - Query query = createNativeQuery(entityManager, QUERY_PROJECT_NAME_BY_ID, new Object[] {projectId}); - String projectName = (String) query.getSingleResult(); - return projectName; - } - - /** - *

- * Gets the user handle. - *

- * @param log the log for logging. - * @param methodName the name of the name for logging. - * @param userService the user service to retrieve the user info. - * @param userId the id of the user. - * @return the handle of the user. - * @throws PermissionException if the user does not exist or other error occurs. - */ - static String getUserHandle(Log log, final String methodName, UserService userService, long userId) - throws PermissionException { - String callerHandle; - try { - callerHandle = userService.getUserHandle(userId); - } catch (UserServiceException e) { - throw ServiceHelper.logException(log, methodName, - new PermissionException("Failed to get the handle for the userId:" + userId, e)); - } - return callerHandle; - } - - /** - *

- * Performs the flush operation and wrapped the exception. - *

- * @param log the logger for logging. - * @param methodName the name of the calling method for logging. - * @param entityManager the entity manager to access the database. - * @throws PersistenceException if failed to do the flush. - */ - static void flush(Log log, final String methodName, EntityManager entityManager) - throws PersistenceException { - try { - // flush it to the database to update the id - entityManager.flush(); - } catch (javax.persistence.PersistenceException e) { - // wrap the exception - throw ServiceHelper.logException(log, methodName, new PersistenceException( - "Failed to persist the object to database.", e)); - } - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/AuditableEntity.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/AuditableEntity.java deleted file mode 100644 index ab239b683..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/AuditableEntity.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.util.Date; - -/** - *

- * AuditableEntity is the base class for all entities with auditing fields (i.e. createdDate, createdBy, - * lastModifiedDate, lastModifiedBy). - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public abstract class AuditableEntity extends IdentifiableEntity { - /** - * The serial version ID. - */ - private static final long serialVersionUID = 1492605651891811100L; - /** - *

- * Represents the created date. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Date createdDate; - /** - *

- * Represents the name that created the record. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String createdBy; - /** - *

- * Represents the last modified date. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Date lastModifiedDate; - /** - *

- * Represents the last name that modified the record. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String lastModifiedBy; - - /** - * Creates an instance of AuditableEntity. - */ - protected AuditableEntity() { - // Empty - } - - /** - * Gets the created date. - * - * @return the created date. - */ - public Date getCreatedDate() { - return createdDate; - } - - /** - * Sets the created date. - * - * @param createdDate - * the created date. - */ - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - /** - * Gets the name that created the record. - * - * @return the name that created the record. - */ - public String getCreatedBy() { - return createdBy; - } - - /** - * Sets the name that created the record. - * - * @param createdBy - * the name that created the record. - */ - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - /** - * Gets the last modified date. - * - * @return the last modified date. - */ - public Date getLastModifiedDate() { - return lastModifiedDate; - } - - /** - * Sets the last modified date. - * - * @param lastModifiedDate - * the last modified date. - */ - public void setLastModifiedDate(Date lastModifiedDate) { - this.lastModifiedDate = lastModifiedDate; - } - - /** - * Gets the last name that modified the record. - * - * @return the last name that modified the record. - */ - public String getLastModifiedBy() { - return lastModifiedBy; - } - - /** - * Sets the last name that modified the record. - * - * @param lastModifiedBy - * the last name that modified the record. - */ - public void setLastModifiedBy(String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/BaseTaskEntity.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/BaseTaskEntity.java deleted file mode 100644 index 70d05502c..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/BaseTaskEntity.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.util.List; - -/** - *

- * This is a base class that holds name, notes and associated project milestones / contests. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public abstract class BaseTaskEntity extends AuditableEntity { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -6856159602466730709L; - /** - *

- * Represents the name. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String name; - /** - *

- * Represents the notes. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String notes; - /** - *

- * Represents the associated to project milestones. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List associatedToProjectMilestones; - /** - *

- * Represents the associated to contests. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List associatedToContests; - - /** - * Creates an instance of BaseTaskEntity. - */ - protected BaseTaskEntity() { - // Empty - } - - /** - * Gets the name. - * - * @return the name. - */ - public String getName() { - return name; - } - - /** - * Sets the name. - * - * @param name - * the name. - */ - public void setName(String name) { - this.name = name; - } - - /** - * Gets the notes. - * - * @return the notes. - */ - public String getNotes() { - return notes; - } - - /** - * Sets the notes. - * - * @param notes - * the notes. - */ - public void setNotes(String notes) { - this.notes = notes; - } - - /** - * Gets the associated to project milestones. - * - * @return the associated to project milestones. - */ - public List getAssociatedToProjectMilestones() { - return associatedToProjectMilestones; - } - - /** - * Sets the associated to project milestones. - * - * @param associatedToProjectMilestones - * the associated to project milestones. - */ - public void setAssociatedToProjectMilestones(List associatedToProjectMilestones) { - this.associatedToProjectMilestones = associatedToProjectMilestones; - } - - /** - * Gets the associated to contests. - * - * @return the associated to contests. - */ - public List getAssociatedToContests() { - return associatedToContests; - } - - /** - * Sets the associated to contests. - * - * @param associatedToContests - * the associated to contests. - */ - public void setAssociatedToContests(List associatedToContests) { - this.associatedToContests = associatedToContests; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/ContestDTO.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/ContestDTO.java deleted file mode 100644 index 55b8135fc..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/ContestDTO.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.io.Serializable; - -/** - *

- * This is the DTO for a contest, which holds the contest ID and contest name. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - *

- * Version 1.1 (TC - Cockpit Tasks Management Assembly 3) - *

    - *
  • Overrides hashcode and equals so it can be used in hashmap and hashset
  • - *
- *

- * - * @author albertwang, sparemax, GreatKevin - * @version 1.1 - */ -public class ContestDTO implements Serializable { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -2063888071456209632L; - /** - *

- * Represents the contest id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long contestId; - /** - *

- * Represents the contest name. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String contestName; - - /** - * Creates an instance of ContestDTO. - */ - public ContestDTO() { - // Empty - } - - /** - * Gets the contest id. - * - * @return the contest id. - */ - public long getContestId() { - return contestId; - } - - /** - * Sets the contest id. - * - * @param contestId - * the contest id. - */ - public void setContestId(long contestId) { - this.contestId = contestId; - } - - /** - * Gets the contest name. - * - * @return the contest name. - */ - public String getContestName() { - return contestName; - } - - /** - * Sets the contest name. - * - * @param contestName - * the contest name. - */ - public void setContestName(String contestName) { - this.contestName = contestName; - } - - /** - * Gets the hashcode. - * - * @return the hash code. - * @since 1.1 - */ - @Override - public int hashCode() { - return (int) this.contestId; - } - - /** - * Gets the equals method. - * - * @param obj the object to compare - * @return true if equals, false otherwise. - * @since 1.1 - */ - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ContestDTO)) { - return false; - } - - return this.contestId == ((ContestDTO) obj).getContestId(); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/IdentifiableEntity.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/IdentifiableEntity.java deleted file mode 100644 index cde9817aa..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/IdentifiableEntity.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.io.Serializable; - -/** - *

- * IdentifiableEntity is the base class for all entities with an ID. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public abstract class IdentifiableEntity implements Serializable { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -3500034164767072252L; - - /** - * The number 31. - */ - private static final int HASH_31 = 31; - - /** - * The number 32. - */ - private static final int HASH_32 = 32; - /** - *

- * Represents the id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long id; - - /** - * Creates an instance of IdentifiableEntity. - */ - protected IdentifiableEntity() { - // Empty - } - - /** - * Gets the id. - * - * @return the id. - */ - public long getId() { - return id; - } - - /** - * Sets the id. - * - * @param id - * the id. - */ - public void setId(long id) { - this.id = id; - } - - /** - * Determines whether the specified Object is equal to the current Object. - * - * @param obj - * the Object to compare with the current Object - * - * @return true if the specified Object is equal to the current Object; false otherwise. - */ - @Override - public boolean equals(Object obj) { - return (this == obj) - || ((obj != null) && (getClass() == obj.getClass()) && (id == ((IdentifiableEntity) obj).id)); - } - - /** - * Serves as a hash function for a particular type. - * - * @return the hash code for the current Object. - */ - @Override - public int hashCode() { - int hashCode = hashCode(1, getClass().hashCode()); - - hashCode = hashCode(hashCode, (int) (id ^ (id >>> HASH_32))); - - return hashCode; - } - - /** - * Gets the hash code. - * - * @param result - * the previous result - * @param hashCode - * the hash code - * - * @return the hash code. - */ - private static int hashCode(int result, int hashCode) { - return HASH_31 * result + hashCode; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/MilestoneDTO.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/MilestoneDTO.java deleted file mode 100644 index 04450b6d0..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/MilestoneDTO.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.io.Serializable; - -/** - *

- * This is the DTO for a project milestone, which holds the milestone ID and milestone name. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - *

- * Version 1.1 (TC - Cockpit Tasks Management Assembly 3) - *

    - *
  • Overrides hashcode and equals so it can be used in hashmap and hashset
  • - *
- *

- * - * @author albertwang, sparemax, GreatKevin - * @version 1.1 - */ -public class MilestoneDTO implements Serializable { - /** - * The serial version ID. - */ - private static final long serialVersionUID = 1681667751385868810L; - /** - *

- * Represents the milestone id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long milestoneId; - /** - *

- * Represents the milestone name. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String milestoneName; - - /** - * Creates an instance of MilestoneDTO. - */ - public MilestoneDTO() { - // Empty - } - - /** - * Gets the milestone id. - * - * @return the milestone id. - */ - public long getMilestoneId() { - return milestoneId; - } - - /** - * Sets the milestone id. - * - * @param milestoneId - * the milestone id. - */ - public void setMilestoneId(long milestoneId) { - this.milestoneId = milestoneId; - } - - /** - * Gets the milestone name. - * - * @return the milestone name. - */ - public String getMilestoneName() { - return milestoneName; - } - - /** - * Sets the milestone name. - * - * @param milestoneName - * the milestone name. - */ - public void setMilestoneName(String milestoneName) { - this.milestoneName = milestoneName; - } - - /** - * Gets the hash code. - * - * @return the hash code. - * @since 1.1 - */ - @Override - public int hashCode() { - return (int) this.milestoneId; - } - - /** - * Compare if equals to the specified object. - * - * @param obj the object used to compare - * @return true if equals, false otherwise. - * @since 1.1 - */ - @Override - public boolean equals(Object obj) { - if (!(obj instanceof MilestoneDTO)) { - return false; - } - - return this.milestoneId == ((MilestoneDTO) obj).getMilestoneId(); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/Task.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/Task.java deleted file mode 100644 index 3413d530f..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/Task.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.util.Date; -import java.util.List; - -/** - *

- * This entity represents a Task. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class Task extends BaseTaskEntity { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -7142083599292799710L; - /** - *

- * Represents the start date. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Date startDate; - /** - *

- * Represents the due date. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Date dueDate; - /** - *

- * Represents the assignees. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List assignees; - /** - *

- * Represents the priority. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private TaskPriority priority; - /** - *

- * Represents the attachments. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List attachments; - /** - *

- * Represents the status. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private TaskStatus status; - /** - *

- * Represents the task list id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long taskListId; - - /** - * Creates an instance of Task. - */ - public Task() { - // Empty - } - - /** - * Gets the start date. - * - * @return the start date. - */ - public Date getStartDate() { - return startDate; - } - - /** - * Sets the start date. - * - * @param startDate - * the start date. - */ - public void setStartDate(Date startDate) { - this.startDate = startDate; - } - - /** - * Gets the due date. - * - * @return the due date. - */ - public Date getDueDate() { - return dueDate; - } - - /** - * Sets the due date. - * - * @param dueDate - * the due date. - */ - public void setDueDate(Date dueDate) { - this.dueDate = dueDate; - } - - /** - * Gets the assignees. - * - * @return the assignees. - */ - public List getAssignees() { - return assignees; - } - - /** - * Sets the assignees. - * - * @param assignees - * the assignees. - */ - public void setAssignees(List assignees) { - this.assignees = assignees; - } - - /** - * Gets the priority. - * - * @return the priority. - */ - public TaskPriority getPriority() { - return priority; - } - - /** - * Sets the priority. - * - * @param priority - * the priority. - */ - public void setPriority(TaskPriority priority) { - this.priority = priority; - } - - /** - * Gets the attachments. - * - * @return the attachments. - */ - public List getAttachments() { - return attachments; - } - - /** - * Sets the attachments. - * - * @param attachments - * the attachments. - */ - public void setAttachments(List attachments) { - this.attachments = attachments; - } - - /** - * Gets the status. - * - * @return the status. - */ - public TaskStatus getStatus() { - return status; - } - - /** - * Sets the status. - * - * @param status - * the status. - */ - public void setStatus(TaskStatus status) { - this.status = status; - } - - /** - * Gets the task list id. - * - * @return the task list id. - */ - public long getTaskListId() { - return taskListId; - } - - /** - * Sets the task list id. - * - * @param taskListId - * the task list id. - */ - public void setTaskListId(long taskListId) { - this.taskListId = taskListId; - } - - public boolean isOverdue() { - if(this.dueDate == null) { - return false; - } - return this.dueDate.compareTo(new Date()) < 0; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskAttachment.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskAttachment.java deleted file mode 100644 index 6689cb525..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskAttachment.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -/** - *

- * This entity represents a task attachment. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class TaskAttachment extends AuditableEntity { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -7290387856053876913L; - /** - *

- * Represents the file name. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String fileName; - /** - *

- * Represents the mime type. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String mimeType; - /** - *

- * Represents the task id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long taskId; - - /** - * Creates an instance of TaskAttachment. - */ - public TaskAttachment() { - // Empty - } - - /** - * Gets the file name. - * - * @return the file name. - */ - public String getFileName() { - return fileName; - } - - /** - * Sets the file name. - * - * @param fileName - * the file name. - */ - public void setFileName(String fileName) { - this.fileName = fileName; - } - - /** - * Gets the mime type. - * - * @return the mime type. - */ - public String getMimeType() { - return mimeType; - } - - /** - * Sets the mime type. - * - * @param mimeType - * the mime type. - */ - public void setMimeType(String mimeType) { - this.mimeType = mimeType; - } - - /** - * Gets the task id. - * - * @return the task id. - */ - public long getTaskId() { - return taskId; - } - - /** - * Sets the task id. - * - * @param taskId - * the task id. - */ - public void setTaskId(long taskId) { - this.taskId = taskId; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskFilter.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskFilter.java deleted file mode 100644 index 3a32ee23e..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskFilter.java +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -/** - *

- * This is the search filter for tasks. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class TaskFilter implements Serializable { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -7834592721896878174L; - - /** - *

- * Represents the name. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String name; - /** - *

- * Represents the assignee id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Long assigneeId; - /** - *

- * Represents the start due date. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Date dueDateFrom; - /** - *

- * Represents the end due date. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Date dueDateTo; - /** - *

- * Represents the priorities. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List priorities; - /** - *

- * Represents the statuses. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List statuses; - /** - *

- * Represents the associated to project milestone ids. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List associatedToProjectMilestoneIds; - /** - *

- * Represents the associated to contest ids. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List associatedToContestIds; - /** - *

- * Represents the project ids. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List projectIds; - /** - *

- * Represents the flag indicating whether the project is active. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private Boolean isProjectActive; - - /** - * Creates an instance of TaskFilter. - */ - public TaskFilter() { - // Empty - } - - /** - * Gets the name. - * - * @return the name. - */ - public String getName() { - return name; - } - - /** - * Sets the name. - * - * @param name - * the name. - */ - public void setName(String name) { - this.name = name; - } - - /** - * Gets the assignee id. - * - * @return the assignee id. - */ - public Long getAssigneeId() { - return assigneeId; - } - - /** - * Sets the assignee id. - * - * @param assigneeId - * the assignee id. - */ - public void setAssigneeId(Long assigneeId) { - this.assigneeId = assigneeId; - } - - /** - * Gets the start due date. - * - * @return the start due date. - */ - public Date getDueDateFrom() { - return dueDateFrom; - } - - /** - * Sets the start due date. - * - * @param dueDateFrom - * the start due date. - */ - public void setDueDateFrom(Date dueDateFrom) { - this.dueDateFrom = dueDateFrom; - } - - /** - * Gets the end due date. - * - * @return the end due date. - */ - public Date getDueDateTo() { - return dueDateTo; - } - - /** - * Sets the end due date. - * - * @param dueDateTo - * the end due date. - */ - public void setDueDateTo(Date dueDateTo) { - this.dueDateTo = dueDateTo; - } - - /** - * Gets the priorities. - * - * @return the priorities. - */ - public List getPriorities() { - return priorities; - } - - /** - * Sets the priorities. - * - * @param priorities - * the priorities. - */ - public void setPriorities(List priorities) { - this.priorities = priorities; - } - - /** - * Gets the statuses. - * - * @return the statuses. - */ - public List getStatuses() { - return statuses; - } - - /** - * Sets the statuses. - * - * @param statuses - * the statuses. - */ - public void setStatuses(List statuses) { - this.statuses = statuses; - } - - /** - * Gets the associated to project milestone ids. - * - * @return the associated to project milestone ids. - */ - public List getAssociatedToProjectMilestoneIds() { - return associatedToProjectMilestoneIds; - } - - /** - * Sets the associated to project milestone ids. - * - * @param associatedToProjectMilestoneIds - * the associated to project milestone ids. - */ - public void setAssociatedToProjectMilestoneIds(List associatedToProjectMilestoneIds) { - this.associatedToProjectMilestoneIds = associatedToProjectMilestoneIds; - } - - /** - * Gets the associated to contest ids. - * - * @return the associated to contest ids. - */ - public List getAssociatedToContestIds() { - return associatedToContestIds; - } - - /** - * Sets the associated to contest ids. - * - * @param associatedToContestIds - * the associated to contest ids. - */ - public void setAssociatedToContestIds(List associatedToContestIds) { - this.associatedToContestIds = associatedToContestIds; - } - - /** - * Gets the project ids. - * - * @return the project ids. - */ - public List getProjectIds() { - return projectIds; - } - - /** - * Sets the project ids. - * - * @param projectIds - * the project ids. - */ - public void setProjectIds(List projectIds) { - this.projectIds = projectIds; - } - - /** - * Gets the flag indicating whether the project is active. - * - * @return the flag indicating whether the project is active. - */ - public Boolean getProjectActive() { - return isProjectActive; - } - - /** - * Sets the flag indicating whether the project is active. - * - * @param isProjectActive - * the flag indicating whether the project is active. - */ - public void setProjectActive(Boolean isProjectActive) { - this.isProjectActive = isProjectActive; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskList.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskList.java deleted file mode 100644 index 0956da0db..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskList.java +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.util.ArrayList; -import java.util.List; - -/** - *

- * This entity represents a Task List. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - *

- * Version 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - *

    - *
  • Adds method {@link #getActiveTasks()}
  • - *
  • Adds method {@link #getCompletedTasks()} ()}
  • - *
- *

- * - * @author albertwang, sparemax, TCSASSEMBLER - * @version 1.1 - */ -public class TaskList extends BaseTaskEntity { - /** - * The serial version ID. - */ - private static final long serialVersionUID = -4113704202279716348L; - /** - *

- * Represents the permitted users. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List permittedUsers; - /** - *

- * Represents the project id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long projectId; - /** - *

- * Represents the number of completed tasks. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private int numberOfCompletedTasks; - /** - *

- * Represents the number of all tasks. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private int numberOfAllTasks; - /** - *

- * Represents the tasks. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private List tasks; - /** - *

- * Represents the flag indicating whether the task list is active. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private boolean isActive; - /** - *

- * Represents the flag indicating whether the task list is the default "Project Task List" of this project. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private boolean isDefault; - - /** - * Creates an instance of TaskList. - */ - public TaskList() { - // Empty - } - - /** - * Gets the permitted users. - * - * @return the permitted users. - */ - public List getPermittedUsers() { - return permittedUsers; - } - - /** - * Sets the permitted users. - * - * @param permittedUsers - * the permitted users. - */ - public void setPermittedUsers(List permittedUsers) { - this.permittedUsers = permittedUsers; - } - - /** - * Gets the project id. - * - * @return the project id. - */ - public long getProjectId() { - return projectId; - } - - /** - * Sets the project id. - * - * @param projectId - * the project id. - */ - public void setProjectId(long projectId) { - this.projectId = projectId; - } - - /** - * Gets the number of completed tasks. - * - * @return the number of completed tasks. - */ - public int getNumberOfCompletedTasks() { - return numberOfCompletedTasks; - } - - /** - * Sets the number of completed tasks. - * - * @param numberOfCompletedTasks - * the number of completed tasks. - */ - public void setNumberOfCompletedTasks(int numberOfCompletedTasks) { - this.numberOfCompletedTasks = numberOfCompletedTasks; - } - - /** - * Gets the number of all tasks. - * - * @return the number of all tasks. - */ - public int getNumberOfAllTasks() { - return numberOfAllTasks; - } - - /** - * Sets the number of all tasks. - * - * @param numberOfAllTasks - * the number of all tasks. - */ - public void setNumberOfAllTasks(int numberOfAllTasks) { - this.numberOfAllTasks = numberOfAllTasks; - } - - /** - * Gets the tasks. - * - * @return the tasks. - */ - public List getTasks() { - return tasks; - } - - /** - * Gets the completed tasks. - * - * @return the completed tasks. - * @since 1.1 - */ - public List getCompletedTasks() { - List completedTasks = new ArrayList(); - - if(tasks == null || tasks.size() == 0) { - return completedTasks; - } - - for(Task t : tasks) { - if(t.getStatus() == TaskStatus.COMPLETED) { - completedTasks.add(t); - } - } - - return completedTasks; - } - - /** - * Gets the active tasks. - * - * @return the active tasks. - * @since 1.1 - */ - public List getActiveTasks() { - List activeTasks = new ArrayList(); - - if(tasks == null || tasks.size() == 0) { - return activeTasks; - } - - for(Task t : tasks) { - if(t.getStatus() != TaskStatus.COMPLETED) { - activeTasks.add(t); - } - } - - return activeTasks; - } - - /** - * Sets the tasks. - * - * @param tasks - * the tasks. - */ - public void setTasks(List tasks) { - this.tasks = tasks; - } - - /** - * Gets the flag indicating whether the task list is active. - * - * @return the flag indicating whether the task list is active. - */ - public boolean isActive() { - return isActive; - } - - /** - * Sets the flag indicating whether the task list is active. - * - * @param isActive - * the flag indicating whether the task list is active. - */ - public void setActive(boolean isActive) { - this.isActive = isActive; - } - - /** - * Gets the flag indicating whether the task list is the default "Project Task List" of this project. - * - * @return the flag indicating whether the task list is the default "Project Task List" of this project. - */ - public boolean isDefault() { - return isDefault; - } - - /** - * Sets the flag indicating whether the task list is the default "Project Task List" of this project. - * - * @param isDefault - * the flag indicating whether the task list is the default "Project Task List" of this project. - */ - public void setDefault(boolean isDefault) { - this.isDefault = isDefault; - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskPriority.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskPriority.java deleted file mode 100644 index 52054de62..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskPriority.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -/** - *

- * This is an enumeration for task priority. - *

- *

- *

- * Thread Safety: This enumeration is immutable and thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public enum TaskPriority { - /** - * This is 'high' task priority. - */ - HIGH(0L, "High"), - - /** - * This is 'low' task priority. - */ - LOW(1L, "Low"), - - /** - * This is 'normal' task priority. - */ - NORMAL(2L, "Normal"); - - private long id; - - private String name; - - private TaskPriority(long id, String name) { - this.id = id; - this.name = name; - } - - public long getId() { - return id; - } - - public String getName() { - return name; - } - - public static TaskPriority forId(long id) { - TaskPriority[] priorities = TaskPriority.values(); - for (int i = 0; i < priorities.length; i++) { - TaskPriority p = priorities[i]; - if (p.id == id) { - return p; - } - } - return null; - } - - public static TaskPriority forName(String name) { - TaskPriority[] priorities = TaskPriority.values(); - for (int i = 0; i < priorities.length; i++) { - TaskPriority p = priorities[i]; - if (p.name.equalsIgnoreCase(name)) { - return p; - } - } - return null; - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskStatus.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskStatus.java deleted file mode 100644 index 5e54d78e7..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/TaskStatus.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - - -/** - *

- * This is an enumeration for task status. - *

- * - *

- * Thread Safety: This enumeration is immutable and thread safe. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public enum TaskStatus { - /** - * This is 'not started' task status. - */ - NOT_STARTED(0L, "Not Started"), - - /** - * This is 'in progress' task status. - */ - IN_PROGRESS(1L, "In Progress"), - - /** - * This is 'wait on dependency' task status. - */ - WAIT_ON_DEPENDENCY(2L, "Wait On Dependency"), - - /** - * This is 'completed' task status. - */ - COMPLETED(3L, "Completed"); - - private long id; - - private String name; - - private TaskStatus(long id, String name) { - this.id = id; - this.name = name; - } - - public long getId() { - return id; - } - - public String getName() { - return name; - } - - public static TaskStatus forId(long id) { - TaskStatus[] statuses = TaskStatus.values(); - for (int i = 0; i < statuses.length; i++) { - TaskStatus s = statuses[i]; - if (s.id == id) { - return s; - } - } - return null; - } - - public static TaskStatus forName(String name) { - TaskStatus[] statuses = TaskStatus.values(); - for (int i = 0; i < statuses.length; i++) { - TaskStatus s = statuses[i]; - if (s.name.equalsIgnoreCase(name)) { - return s; - } - } - return null; - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/UserDTO.java b/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/UserDTO.java deleted file mode 100644 index d1c8714ad..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/main/com/topcoder/direct/services/project/task/model/UserDTO.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import java.io.Serializable; - -/** - *

- * This is the DTO for a user, which holds the user ID and user handle. - *

- * - *

- * Thread Safety: This class is not thread safe because it is mutable. - *

- * - *

- * Version 1.1 (TC - Cockpit Tasks Management Assembly 3) - *

    - *
  • Overrides hashcode and equals so it can be used in hashmap and hashset
  • - *
- *

- * - * @author albertwang, sparemax, GreatKevin - * @version 1.1 - */ -public class UserDTO implements Serializable { - /** - * The serial version ID. - */ - private static final long serialVersionUID = 8939342833412108795L; - /** - *

- * Represents the user id. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private long userId; - /** - *

- * Represents the handle. - *

- * - *

- * Can be any value. Has getter and setter. - *

- */ - private String handle; - - /** - * Creates an instance of UserDTO. - */ - public UserDTO() { - // Empty - } - - /** - * Gets the user id. - * - * @return the user id. - */ - public long getUserId() { - return userId; - } - - /** - * Sets the user id. - * - * @param userId - * the user id. - */ - public void setUserId(long userId) { - this.userId = userId; - } - - /** - * Gets the handle. - * - * @return the handle. - */ - public String getHandle() { - return handle; - } - - /** - * Sets the handle. - * - * @param handle - * the handle. - */ - public void setHandle(String handle) { - this.handle = handle; - } - - /** - * Gets the hash code. - * - * @return the hash code. - * @since 1.1 - */ - @Override - public int hashCode() { - return (int) this.userId; - } - - /** - * Compares if it equals. - * - * @param obj the object used to compare - * @return true if it equals, false otherwise. - * @since 1.1 - */ - @Override - public boolean equals(Object obj) { - if (!(obj instanceof UserDTO)) { - return false; - } - - return this.userId == ((UserDTO) obj).getUserId(); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/AllTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/AllTests.java deleted file mode 100644 index 3197ae3e5..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/AllTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import com.topcoder.direct.services.project.task.failuretests.FailureTests; -import com.topcoder.direct.services.project.task.stresstests.StressTests; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import com.topcoder.direct.services.project.task.accuracytests.AccuracyTests; - -/** - *

- * This test case aggregates all test cases. - *

- * - * @author TCSDEVELOPER - * @version 1.0 - */ -public class AllTests extends TestCase { - /** - *

- * The test suite. - *

- * - * @return the test suite - */ - public static Test suite() { - final TestSuite suite = new TestSuite(); - - // unit tests - suite.addTest(UnitTests.suite()); - suite.addTest(AccuracyTests.suite()); - suite.addTest(FailureTests.suite()); - suite.addTest(StressTests.suite()); - - return suite; - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/Demo.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/Demo.java deleted file mode 100644 index be84e8d81..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/Demo.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Test; - -import com.topcoder.direct.services.project.task.model.UserDTO; - -/** - *

- * Shows usage for the component. - *

- * - * @author albertwang, sparemax - * @version 1.0 - */ -public class Demo { - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(Demo.class); - } - - /** - *

- * Demo API usage of model classes. - *

- */ - @SuppressWarnings("unused") - @Test - public void testDemoModel() { - // Create an instance of UserDTO - UserDTO userDTO = new UserDTO(); - // Set properties - userDTO.setUserId(1); - userDTO.setHandle("handle"); - - // Get properties - long userId = userDTO.getUserId(); - String handle = userDTO.getHandle(); - - // Other model classes can be used similarly - } - - /** - *

- * Demo API usage of exceptions. - *

- */ - @SuppressWarnings("unused") - @Test - public void testDemoException() { - // Create a TaskManagementException exception - TaskManagementException exception1 = new TaskManagementException(); - - // Create a TaskManagementException exception with message - TaskManagementException exception2 = new TaskManagementException("The error message."); - - Exception cause = new Exception("Exception for testing."); - - // Create a TaskManagementException exception with inner cause - TaskManagementException exception3 = new TaskManagementException(cause); - - // Create a TaskManagementException exception with inner cause - TaskManagementException exception4 = new TaskManagementException("The error message.", cause); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/DemoTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/DemoTests.java deleted file mode 100644 index 213ae6682..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/DemoTests.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.impl.BaseUnitTests; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; - - -/** - *

- * This class shows the main usage of this component. - *

- * @author TCSDEVELOPER - * @version 1.0 - * - */ -public class DemoTests extends BaseUnitTests { - - /** - *

- * Instance of TaskListService for the demo. - *

- */ - private TaskListService taskListService; - - /** - *

- * Instance of TaskService for the demo. - *

- */ - private TaskService taskService; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(DemoTests.class); - } - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - taskListService = - (TaskListService) super.getApplicationContext().getBean("taskListService"); - taskService = - (TaskService) super.getApplicationContext().getBean("taskService"); - } - - /** - *

- * Shows the usage of the task list service. - *

- * @throws Exception to JUnit. - */ - @Test - public void testShowTaskListService() throws Exception { - // prepare the data - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - - // add the task list - taskList = taskListService.addTaskList(user.getUserId(), taskList); - - // update the task list - taskList.setActive(false); - taskListService.updateTaskList(user.getUserId(), taskList); - - // get the task list by the id - taskListService.getTaskList(user.getUserId(), taskList.getId()); - - // query the task lists with task - taskListService.getTaskListsWithTasks(user.getUserId(), new TaskFilter()); - - // query the task lists without task - taskListService.getTaskLists(user.getUserId(), new TaskFilter()); - - // resolve the task list - taskListService.resolveTaskList(user.getUserId(), taskList.getId()); - - // delete the task list - taskListService.deleteTaskList(user.getUserId(), taskList.getId()); - } - - /** - *

- * Shows the usage of the task service. - *

- * @throws Exception to JUnit. - */ - @Test - public void testShowTaskService() throws Exception { - // prepare the data - User user = super.createUsers().get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - taskList = taskListService.addTaskList(user.getUserId(), taskList); - - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - // set the assignee - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - List assignees = new ArrayList(); - assignees.add(assignee); - task.setAssignees(assignees); - - // add the task - task = taskService.addTask(user.getUserId(), task); - - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abcde".getBytes()); - - // add the task attachment and delete it - try { - attachment = taskService.addTaskAttachment(user.getUserId(), - attachment, inputStream); - // get the task attachment - taskService.getTaskAttachmentContent( - user.getUserId(), attachment.getId()); - } finally { - taskService.deleteTaskAttachment( - user.getUserId(), attachment.getId()); - } - - // get the number of tasks - taskService.getNumberOfAllTasks(user.getUserId(), projectId); - // get the number of all completed tasks - taskService.getNumberOfCompletedTasks( - user.getUserId(), projectId); - - // group by status, others are similar - List taskLists = taskListService.getTaskListsWithTasks( - user.getUserId(), null); - taskService.groupTasksByStatus(taskLists); - - // get the task - taskService.getTask(user.getUserId(), task.getId()); - - // delete the task - taskService.deleteTask(user.getUserId(), task.getId()); - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/EntityNotFoundExceptionUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/EntityNotFoundExceptionUnitTests.java deleted file mode 100644 index f2be8a556..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/EntityNotFoundExceptionUnitTests.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import junit.framework.JUnit4TestAdapter; - -/** - *

- * Unit tests for {@link EntityNotFoundException} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class EntityNotFoundExceptionUnitTests { - /** - *

- * Represents a detail message. - *

- */ - private static final String DETAIL_MESSAGE = "detail"; - - /** - *

- * Represents an error cause. - *

- */ - private static final Throwable CAUSE = new Exception("UnitTests"); - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(EntityNotFoundExceptionUnitTests.class); - } - - /** - *

- * EntityNotFoundException should be subclass of PersistenceException. - *

- */ - @Test - public void testInheritance() { - assertTrue("EntityNotFoundException should be subclass of PersistenceException.", - EntityNotFoundException.class.getSuperclass() == PersistenceException.class); - } - - /** - *

- * Tests accuracy of EntityNotFoundException() constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor1() { - EntityNotFoundException exception = new EntityNotFoundException(); - - // Verify the error message - assertNull("PersistenceException message should be null.", exception.getMessage()); - // Verify the error cause - assertNull("Error cause should be null.", exception.getCause()); - } - - /** - *

- * Tests accuracy of EntityNotFoundException(String) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor2() { - EntityNotFoundException exception = - new EntityNotFoundException(DETAIL_MESSAGE); - - // Verify the error message - assertEquals("PersistenceException message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - } - - /** - *

- * Tests accuracy of EntityNotFoundException(Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor3() { - EntityNotFoundException exception = new EntityNotFoundException(CAUSE); - - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } - - /** - *

- * Tests accuracy of EntityNotFoundException(String, Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor4() { - EntityNotFoundException exception = - new EntityNotFoundException(DETAIL_MESSAGE, CAUSE); - - // Verify the error message - assertEquals("Error message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/NotificationExceptionTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/NotificationExceptionTests.java deleted file mode 100644 index b02ffc8ae..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/NotificationExceptionTests.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Test; - -/** - *

- * Unit tests for {@link NotificationException} class. - *

- * - * @author TCSDEVELOPER - * @version 1.0 - */ -public class NotificationExceptionTests { - /** - *

- * Represents a detail message. - *

- */ - private static final String DETAIL_MESSAGE = "detail"; - - /** - *

- * Represents an error cause. - *

- */ - private static final Throwable CAUSE = new Exception("UnitTests"); - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(NotificationExceptionTests.class); - } - - /** - *

- * NotificationException should be subclass of RuntimeException. - *

- */ - @Test - public void testInheritance() { - assertTrue("NotificationException should be subclass of RuntimeException.", - NotificationException.class.getSuperclass() == TaskManagementException.class); - } - - /** - *

- * Tests accuracy of NotificationException() constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor1() { - NotificationException exception = new NotificationException(); - - // Verify the error message - assertNull("RuntimeException message should be null.", exception.getMessage()); - // Verify the error cause - assertNull("Error cause should be null.", exception.getCause()); - } - - /** - *

- * Tests accuracy of NotificationException(String) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor2() { - NotificationException exception = - new NotificationException(DETAIL_MESSAGE); - - // Verify the error message - assertEquals("RuntimeException message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - } - - /** - *

- * Tests accuracy of NotificationException(Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor3() { - NotificationException exception = new NotificationException(CAUSE); - - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } - - /** - *

- * Tests accuracy of NotificationException(String, Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor4() { - NotificationException exception = - new NotificationException(DETAIL_MESSAGE, CAUSE); - - // Verify the error message - assertEquals("Error message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/PermissionExceptionUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/PermissionExceptionUnitTests.java deleted file mode 100644 index 710c464b4..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/PermissionExceptionUnitTests.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import junit.framework.JUnit4TestAdapter; - -/** - *

- * Unit tests for {@link PermissionException} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class PermissionExceptionUnitTests { - /** - *

- * Represents a detail message. - *

- */ - private static final String DETAIL_MESSAGE = "detail"; - - /** - *

- * Represents an error cause. - *

- */ - private static final Throwable CAUSE = new Exception("UnitTests"); - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PermissionExceptionUnitTests.class); - } - - /** - *

- * PermissionException should be subclass of TaskManagementException. - *

- */ - @Test - public void testInheritance() { - assertTrue("PermissionException should be subclass of TaskManagementException.", - PermissionException.class.getSuperclass() == TaskManagementException.class); - } - - /** - *

- * Tests accuracy of PermissionException() constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor1() { - PermissionException exception = new PermissionException(); - - // Verify the error message - assertNull("TaskManagementException message should be null.", exception.getMessage()); - // Verify the error cause - assertNull("Error cause should be null.", exception.getCause()); - } - - /** - *

- * Tests accuracy of PermissionException(String) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor2() { - PermissionException exception = - new PermissionException(DETAIL_MESSAGE); - - // Verify the error message - assertEquals("TaskManagementException message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - } - - /** - *

- * Tests accuracy of PermissionException(Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor3() { - PermissionException exception = new PermissionException(CAUSE); - - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } - - /** - *

- * Tests accuracy of PermissionException(String, Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor4() { - PermissionException exception = - new PermissionException(DETAIL_MESSAGE, CAUSE); - - // Verify the error message - assertEquals("Error message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/PersistenceExceptionUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/PersistenceExceptionUnitTests.java deleted file mode 100644 index e2b39f105..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/PersistenceExceptionUnitTests.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import junit.framework.JUnit4TestAdapter; - -/** - *

- * Unit tests for {@link PersistenceException} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class PersistenceExceptionUnitTests { - /** - *

- * Represents a detail message. - *

- */ - private static final String DETAIL_MESSAGE = "detail"; - - /** - *

- * Represents an error cause. - *

- */ - private static final Throwable CAUSE = new Exception("UnitTests"); - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PersistenceExceptionUnitTests.class); - } - - /** - *

- * PersistenceException should be subclass of TaskManagementException. - *

- */ - @Test - public void testInheritance() { - assertTrue("PersistenceException should be subclass of TaskManagementException.", - PersistenceException.class.getSuperclass() == TaskManagementException.class); - } - - /** - *

- * Tests accuracy of PersistenceException() constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor1() { - PersistenceException exception = new PersistenceException(); - - // Verify the error message - assertNull("TaskManagementException message should be null.", exception.getMessage()); - // Verify the error cause - assertNull("Error cause should be null.", exception.getCause()); - } - - /** - *

- * Tests accuracy of PersistenceException(String) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor2() { - PersistenceException exception = - new PersistenceException(DETAIL_MESSAGE); - - // Verify the error message - assertEquals("TaskManagementException message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - } - - /** - *

- * Tests accuracy of PersistenceException(Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor3() { - PersistenceException exception = new PersistenceException(CAUSE); - - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } - - /** - *

- * Tests accuracy of PersistenceException(String, Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor4() { - PersistenceException exception = - new PersistenceException(DETAIL_MESSAGE, CAUSE); - - // Verify the error message - assertEquals("Error message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TaskManagementConfigurationExceptionUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TaskManagementConfigurationExceptionUnitTests.java deleted file mode 100644 index c0f5455b4..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TaskManagementConfigurationExceptionUnitTests.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import junit.framework.JUnit4TestAdapter; - -/** - *

- * Unit tests for {@link TaskManagementConfigurationException} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskManagementConfigurationExceptionUnitTests { - /** - *

- * Represents a detail message. - *

- */ - private static final String DETAIL_MESSAGE = "detail"; - - /** - *

- * Represents an error cause. - *

- */ - private static final Throwable CAUSE = new Exception("UnitTests"); - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskManagementConfigurationExceptionUnitTests.class); - } - - /** - *

- * TaskManagementConfigurationException should be subclass of RuntimeException. - *

- */ - @Test - public void testInheritance() { - assertTrue("TaskManagementConfigurationException should be subclass of RuntimeException.", - TaskManagementConfigurationException.class.getSuperclass() == RuntimeException.class); - } - - /** - *

- * Tests accuracy of TaskManagementConfigurationException() constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor1() { - TaskManagementConfigurationException exception = new TaskManagementConfigurationException(); - - // Verify the error message - assertNull("RuntimeException message should be null.", exception.getMessage()); - // Verify the error cause - assertNull("Error cause should be null.", exception.getCause()); - } - - /** - *

- * Tests accuracy of TaskManagementConfigurationException(String) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor2() { - TaskManagementConfigurationException exception = - new TaskManagementConfigurationException(DETAIL_MESSAGE); - - // Verify the error message - assertEquals("RuntimeException message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - } - - /** - *

- * Tests accuracy of TaskManagementConfigurationException(Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor3() { - TaskManagementConfigurationException exception = new TaskManagementConfigurationException(CAUSE); - - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } - - /** - *

- * Tests accuracy of TaskManagementConfigurationException(String, Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor4() { - TaskManagementConfigurationException exception = - new TaskManagementConfigurationException(DETAIL_MESSAGE, CAUSE); - - // Verify the error message - assertEquals("Error message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TaskManagementExceptionUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TaskManagementExceptionUnitTests.java deleted file mode 100644 index c5fb90d3c..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TaskManagementExceptionUnitTests.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import junit.framework.JUnit4TestAdapter; - -/** - *

- * Unit tests for {@link TaskManagementException} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskManagementExceptionUnitTests { - /** - *

- * Represents a detail message. - *

- */ - private static final String DETAIL_MESSAGE = "detail"; - - /** - *

- * Represents an error cause. - *

- */ - private static final Throwable CAUSE = new Exception("UnitTests"); - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskManagementExceptionUnitTests.class); - } - - /** - *

- * TaskManagementException should be subclass of Exception. - *

- */ - @Test - public void testInheritance() { - assertTrue("TaskManagementException should be subclass of Exception.", - TaskManagementException.class.getSuperclass() == Exception.class); - } - - /** - *

- * Tests accuracy of TaskManagementException() constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor1() { - TaskManagementException exception = new TaskManagementException(); - - // Verify the error message - assertNull("Exception message should be null.", exception.getMessage()); - // Verify the error cause - assertNull("Error cause should be null.", exception.getCause()); - } - - /** - *

- * Tests accuracy of TaskManagementException(String) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor2() { - TaskManagementException exception = - new TaskManagementException(DETAIL_MESSAGE); - - // Verify the error message - assertEquals("Exception message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - } - - /** - *

- * Tests accuracy of TaskManagementException(Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor3() { - TaskManagementException exception = new TaskManagementException(CAUSE); - - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } - - /** - *

- * Tests accuracy of TaskManagementException(String, Throwable) constructor.
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor4() { - TaskManagementException exception = - new TaskManagementException(DETAIL_MESSAGE, CAUSE); - - // Verify the error message - assertEquals("Error message should be correct.", DETAIL_MESSAGE, exception.getMessage()); - // Verify the error cause - assertSame("Error cause should be correct.", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TestsHelper.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TestsHelper.java deleted file mode 100644 index c798cc0dc..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/TestsHelper.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import java.lang.reflect.Field; - -/** - *

- * The base class for unit tests. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TestsHelper { - /** - * Creates an instance of TestsHelper. - */ - private TestsHelper() { - // Empty - } - - /** - *

- * Gets value for field of given object. - *

- * - * @param obj - * the given object. - * @param field - * the field name. - * - * @return the field value. - */ - public static Object getField(Object obj, String field) { - Object value = null; - try { - Field declaredField = null; - try { - declaredField = obj.getClass().getDeclaredField(field); - } catch (NoSuchFieldException e) { - // Ignore - } - if (declaredField == null) { - try { - declaredField = obj.getClass().getSuperclass().getDeclaredField(field); - } catch (NoSuchFieldException e) { - // Ignore - } - } - - if (declaredField == null) { - declaredField = obj.getClass().getSuperclass().getSuperclass().getDeclaredField(field); - } - - declaredField.setAccessible(true); - - try { - value = declaredField.get(obj); - } finally { - declaredField.setAccessible(false); - } - } catch (IllegalAccessException e) { - // Ignore - } catch (NoSuchFieldException e) { - // Ignore - } - - return value; - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/UnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/UnitTests.java deleted file mode 100644 index bc3f114c8..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/UnitTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task; - -import com.topcoder.direct.services.project.task.impl.BaseJPAServiceTests; -import com.topcoder.direct.services.project.task.impl.EmailEngineNotificationServiceTests; -import com.topcoder.direct.services.project.task.impl.JPATaskListServiceTests; -import com.topcoder.direct.services.project.task.impl.JPATaskServiceTests; -import com.topcoder.direct.services.project.task.impl.ServiceHelperTests; -import com.topcoder.direct.services.project.task.model.*; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - *

This test case aggregates all Unit test cases.

- * - * @author TCSDEVELOPER - * @version 1.0 - */ -public class UnitTests extends TestCase { - - /** - *

- * Aggregates all the unit tests. - *

- * @return all the unit tests. - */ - public static Test suite() { - final TestSuite suite = new TestSuite(); - - suite.addTest(DemoTests.suite()); - suite.addTest(NotificationExceptionTests.suite()); - - suite.addTest(BaseJPAServiceTests.suite()); - suite.addTest(EmailEngineNotificationServiceTests.suite()); - suite.addTest(JPATaskListServiceTests.suite()); - suite.addTest(JPATaskServiceTests.suite()); - suite.addTest(ServiceHelperTests.suite()); - - suite.addTest(Demo.suite()); - - suite.addTest(TaskPriorityUnitTests.suite()); - suite.addTest(TaskStatusUnitTests.suite()); - - suite.addTest(AuditableEntityUnitTests.suite()); - suite.addTest(BaseTaskEntityUnitTests.suite()); - suite.addTest(ContestDTOUnitTests.suite()); - suite.addTest(IdentifiableEntityUnitTests.suite()); - suite.addTest(MilestoneDTOUnitTests.suite()); - suite.addTest(TaskAttachmentUnitTests.suite()); - suite.addTest(TaskFilterUnitTests.suite()); - suite.addTest(TaskListUnitTests.suite()); - suite.addTest(TaskUnitTests.suite()); - suite.addTest(UserDTOUnitTests.suite()); - - // Exceptions - suite.addTest(TaskManagementConfigurationExceptionUnitTests.suite()); - suite.addTest(TaskManagementExceptionUnitTests.suite()); - suite.addTest(PersistenceExceptionUnitTests.suite()); - suite.addTest(PermissionExceptionUnitTests.suite()); - suite.addTest(EntityNotFoundExceptionUnitTests.suite()); - - return suite; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AccTestHelper.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AccTestHelper.java deleted file mode 100644 index e773c93ef..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AccTestHelper.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.lang.reflect.Field; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; -/** - * Accuracy Helper. - * - * @author amazingpig - * @version 1.0 - */ -public class AccTestHelper { - public static EntityManager entityManager; - static { - ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml"); - EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("entityManagerFactory"); - entityManager = emf.createEntityManager(); - } - public static Object getPrivateField(Class privateClass, Object instance, String fieldName) throws Exception { - Field privateField = privateClass.getDeclaredField("fieldName"); - privateField.setAccessible(true); - Object result = privateField.get(instance); - privateField.setAccessible(false); - return result; - } - - public static void initDataBase() throws Exception { - runSql("test_files/accuracy" + File.separator + "initDataBase.sql", entityManager); - } - public static void clearUpDataBase() throws Exception { - runSql("test_files/accuracy" + File.separator + "clearUpDataBase.sql", entityManager); - } - - private static void runSql(String filePath, EntityManager entityManager) throws Exception { - FileReader fr = new FileReader(filePath); - BufferedReader br = new BufferedReader(fr); - String sql = null; - entityManager.getTransaction().begin(); - while (br.ready()) { - sql = br.readLine().trim(); - if (sql.length() > 0 && !sql.startsWith("#")) { - entityManager.createNativeQuery(sql).executeUpdate(); - } - } - entityManager.getTransaction().commit(); - br.close(); - fr.close(); - } - - public static void persist(T obj) { - entityManager.getTransaction().begin(); - entityManager.persist(obj); - entityManager.getTransaction().commit(); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AccuracyTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AccuracyTests.java deleted file mode 100644 index 09ea00c39..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AccuracyTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * Copyright (c) 2013, TopCoder, Inc. All rights reserved - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -import junit.framework.JUnit4TestAdapter; - -/** - *

This test case aggregates all Accuracy test cases.

- * - * @author amazingpig - * @version 1.0 - */ -public class AccuracyTests extends TestCase { - - public static Test suite() { - final TestSuite suite = new TestSuite(); - - suite.addTestSuite(EmailEngineNotificationServiceAccTests.class); - suite.addTestSuite(JPATaskServiceAccTests.class); - suite.addTestSuite(JPATaskListServiceAccTests.class); - - suite.addTest(new JUnit4TestAdapter(MilestoneDTOTests.class)); - suite.addTest(new JUnit4TestAdapter(IdentifiableEntityTests.class)); - suite.addTest(new JUnit4TestAdapter(ContestDTOTests.class)); - suite.addTest(new JUnit4TestAdapter(BaseTaskEntityTests.class)); - suite.addTest(new JUnit4TestAdapter(AuditableEntityTests.class)); - suite.addTest(new JUnit4TestAdapter(TaskAttachmentTests.class)); - suite.addTest(new JUnit4TestAdapter(TaskFilterTests.class)); - suite.addTest(new JUnit4TestAdapter(TaskListTests.class)); - suite.addTest(new JUnit4TestAdapter(TaskTests.class)); - suite.addTest(new JUnit4TestAdapter(UserDTOTests.class)); - suite.addTest(new JUnit4TestAdapter(EntityNotFoundExceptionTests.class)); - suite.addTest(new JUnit4TestAdapter(PermissionExceptionTests.class)); - suite.addTest(new JUnit4TestAdapter(PersistenceExceptionTests.class)); - suite.addTest(new JUnit4TestAdapter(TaskManagementConfigurationExceptionTests.class)); - suite.addTest(new JUnit4TestAdapter(TaskManagementExceptionTests.class)); - return suite; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AuditableEntityTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AuditableEntityTests.java deleted file mode 100644 index 7e194488b..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/AuditableEntityTests.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.AuditableEntity; -import com.topcoder.direct.services.project.task.model.IdentifiableEntity; - -import junit.framework.TestCase; - -import java.util.Date; - - -/** - *

Unit tests for {@link AuditableEntity} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class AuditableEntityTests extends TestCase { - /** AuditableEntity instance to be used for the testing. */ - private MockAuditableEntity instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new MockAuditableEntity(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", AuditableEntity.class.getSuperclass() == IdentifiableEntity.class); - } - - /** - *

Accuracy test for {@link AuditableEntity#getCreatedDate()}.

- */ - public void test_getCreatedDate() { - assertEquals("Invalid default value.", null, instance.getCreatedDate()); - - Date date = new Date(); - instance.setCreatedDate(date); - assertEquals("Invalid return value.", date, instance.getCreatedDate()); - } - - /** - *

Accuracy test for {@link AuditableEntity#setCreatedDate()}.

- */ - public void test_setCreatedDate() { - Date date = new Date(); - instance.setCreatedDate(date); - assertEquals("Invalid return value.", date, instance.getCreatedDate()); - instance.setCreatedDate(null); - assertEquals("Invalid value is set.", null, instance.getCreatedDate()); - } - - /** - *

Accuracy test for {@link AuditableEntity#getCreatedBy()}.

- */ - public void test_getCreatedBy() { - assertEquals("Invalid default value.", null, instance.getCreatedBy()); - instance.setCreatedBy("tester"); - assertEquals("Invalid return value.", "tester", instance.getCreatedBy()); - } - - /** - *

Accuracy test for {@link AuditableEntity#setCreatedBy()}.

- */ - public void test_setCreatedBy() { - instance.setCreatedBy("tester"); - assertEquals("Invalid value is set.", "tester", instance.getCreatedBy()); - instance.setCreatedBy(null); - assertEquals("Invalid value is set.", null, instance.getCreatedBy()); - } - - /** - *

Accuracy test for {@link AuditableEntity#getLastModifiedDate()}.

- */ - public void test_getLastModifiedDate() { - assertEquals("Invalid default value.", null, instance.getLastModifiedDate()); - - Date date = new Date(); - instance.setLastModifiedDate(date); - assertEquals("Invalid return value.", date, instance.getLastModifiedDate()); - } - - /** - *

Accuracy test for {@link AuditableEntity#setLastModifiedDate()}.

- */ - public void test_setLastModifiedDate() { - Date date = new Date(); - instance.setLastModifiedDate(date); - assertEquals("Invalid return value.", date, instance.getLastModifiedDate()); - instance.setLastModifiedDate(null); - assertEquals("Invalid value is set.", null, instance.getLastModifiedDate()); - } - - /** - *

Accuracy test for {@link AuditableEntity#getLastModifiedBy()}.

- */ - public void test_getLastModifiedBy() { - assertEquals("Invalid default value.", null, instance.getLastModifiedBy()); - instance.setLastModifiedBy("tester"); - assertEquals("Invalid return value.", "tester", instance.getLastModifiedBy()); - } - - /** - *

Accuracy test for {@link AuditableEntity#setLastModifiedBy()}.

- */ - public void test_setLastModifiedBy() { - instance.setLastModifiedBy("tester"); - assertEquals("Invalid value is set.", "tester", instance.getLastModifiedBy()); - instance.setLastModifiedBy(null); - assertEquals("Invalid value is set.", null, instance.getLastModifiedBy()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/BaseTaskEntityTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/BaseTaskEntityTests.java deleted file mode 100644 index dfa7715bf..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/BaseTaskEntityTests.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.AuditableEntity; -import com.topcoder.direct.services.project.task.model.BaseTaskEntity; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.MilestoneDTO; - -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.List; - - -/** - *

Unit tests for {@link BaseTaskEntity} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class BaseTaskEntityTests extends TestCase { - /** BaseTaskEntity instance to be used for the testing. */ - private MockBaseTaskEntity instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new MockBaseTaskEntity(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", BaseTaskEntity.class.getSuperclass() == AuditableEntity.class); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#getName()}.

- */ - public void test_getName() { - assertEquals("Invalid default value.", null, instance.getName()); - instance.setName("tester"); - assertEquals("Invalid return value.", "tester", instance.getName()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#setName()}.

- */ - public void test_setName() { - instance.setName("tester"); - assertEquals("Invalid value is set.", "tester", instance.getName()); - instance.setName(null); - assertEquals("Invalid value is set.", null, instance.getName()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#getNotes()}.

- */ - public void test_getNotes() { - assertEquals("Invalid default value.", null, instance.getNotes()); - instance.setNotes("tester"); - assertEquals("Invalid return value.", "tester", instance.getNotes()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#setNotes()}.

- */ - public void test_setNotes() { - instance.setNotes("tester"); - assertEquals("Invalid value is set.", "tester", instance.getNotes()); - instance.setNotes(null); - assertEquals("Invalid value is set.", null, instance.getNotes()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#getAssociatedToProjectMilestones()}.

- */ - public void test_getAssociatedToProjectMilestones() { - assertEquals("Invalid default value.", null, instance.getAssociatedToProjectMilestones()); - - List field = new ArrayList(); - instance.setAssociatedToProjectMilestones(field); - assertEquals("Invalid return value.", field, instance.getAssociatedToProjectMilestones()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#setAssociatedToProjectMilestones()}.

- */ - public void test_setAssociatedToProjectMilestones() { - List field = new ArrayList(); - instance.setAssociatedToProjectMilestones(field); - assertEquals("Invalid return value.", field, instance.getAssociatedToProjectMilestones()); - instance.setAssociatedToProjectMilestones(null); - assertEquals("Invalid value is set.", null, instance.getAssociatedToProjectMilestones()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#getAssociatedToContests()}.

- */ - public void test_getAssociatedToContests() { - assertEquals("Invalid default value.", null, instance.getAssociatedToContests()); - - List field = new ArrayList(); - instance.setAssociatedToContests(field); - assertEquals("Invalid return value.", field, instance.getAssociatedToContests()); - } - - /** - *

Accuracy test for {@link BaseTaskEntity#setAssociatedToContests()}.

- */ - public void test_setAssociatedToContests() { - List field = new ArrayList(); - instance.setAssociatedToContests(field); - assertEquals("Invalid value is set.", field, instance.getAssociatedToContests()); - instance.setAssociatedToContests(null); - assertEquals("Invalid value is set.", null, instance.getAssociatedToContests()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/ContestDTOTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/ContestDTOTests.java deleted file mode 100644 index 108f21944..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/ContestDTOTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.ContestDTO; - -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link ContestDTO} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class ContestDTOTests extends TestCase { - /** ContestDTO instance to be used for the testing. */ - private ContestDTO instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new ContestDTO(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", ContestDTO.class.getSuperclass() == Object.class); - } - - /** - *

Accuracy test for {@link ContestDTO#getContestId()}.

- */ - public void test_getContestId() { - assertEquals("Invalid default value.", 0, instance.getContestId()); - instance.setContestId(2); - assertEquals("Invalid return value.", 2, instance.getContestId()); - } - - /** - *

Accuracy test for {@link ContestDTO#setContestId()}.

- */ - public void test_setContestId() { - instance.setContestId(2); - assertEquals("Invalid value is set.", 2, instance.getContestId()); - instance.setContestId(0); - assertEquals("Invalid value is set.", 0, instance.getContestId()); - } - - /** - *

Accuracy test for {@link ContestDTO#getContestName()}.

- */ - public void test_getContestName() { - assertEquals("Invalid default value.", null, instance.getContestName()); - instance.setContestName("tester"); - assertEquals("Invalid return value.", "tester", instance.getContestName()); - } - - /** - *

Accuracy test for {@link ContestDTO#setContestName()}.

- */ - public void test_setContestName() { - instance.setContestName("tester"); - assertEquals("Invalid value is set.", "tester", instance.getContestName()); - instance.setContestName(null); - assertEquals("Invalid value is set.", null, instance.getContestName()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/EmailEngineNotificationServiceAccTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/EmailEngineNotificationServiceAccTests.java deleted file mode 100644 index e48325436..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/EmailEngineNotificationServiceAccTests.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; - -import com.topcoder.direct.services.project.task.impl.EmailEngineNotificationService; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.log4j.Log4jLogFactory; - -/** - * Accuracy tests for EmailEngineNotificationService. - * - * @author amazingpig - * @version 1.0 - */ -public class EmailEngineNotificationServiceAccTests extends TestCase { - /** - * Represents the EmailEngineNotificationService instance to test. - * */ - private EmailEngineNotificationService instance; - /** - *

Sets up the unit tests.

- */ - public void setUp() throws Exception { - instance = new EmailEngineNotificationService(); - instance.setEmailSender("from@tc.com"); - instance.setLog(new Log4jLogFactory().createLog("test")); - instance.setTaskCreationEmailBodyTemplatePath("test_files/accuracy/taskcreationbody.txt"); - instance.setTaskCreationEmailSubjectTemplateText("test_files/accuracy/taskcreationsubject.txt"); - instance.setTaskStatusChangeEmailBodyTemplatePath("test_files/accuracy/statuschangebody.txt"); - instance.setTaskStatusChangeEmailSubjectTemplateText("test_files/accuracy/statuschangesubject.txt"); - - } - - /** - *

Cleans up the unit tests.

- */ - public void tearDown() { - instance = null; - } - - /** - * Accuracy test for method notifyTaskCreation. - * @throws Exception - */ - public void test_notifyTaskCreation() throws Exception { - UserService us = EasyMock.createNiceMock(UserService.class); - EasyMock.expect(us.getUser(1)).andReturn(new User()); - EasyMock.expect(us.getEmailAddress(0)).andReturn("to1@tc.com").anyTimes(); - EasyMock.expect(us.getEmailAddress(1)).andReturn("to1@tc.com").anyTimes(); - EasyMock.expect(us.getEmailAddress(2)).andReturn("to2@tc.com").anyTimes(); - - EasyMock.replay(us); - instance.setUserService(us); - - Task task = new Task(); - task.setName("t1"); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setPriority(TaskPriority.HIGH); - UserDTO u1 = new UserDTO(); - u1.setHandle("to1@tc.com"); - u1.setUserId(1); - UserDTO u2 = new UserDTO(); - u2.setHandle("to1@tc.com"); - u2.setUserId(1); - task.setAssignees(Arrays.asList(u1, u2)); - - instance.notifyTaskCreation(1, task ); - //manually check the mails - } - - /** - * Accuracy test for method notifyTaskStatusChange. - * @throws Exception - */ - public void test_notifyTaskStatusChange() throws Exception { - UserService us = EasyMock.createNiceMock(UserService.class); - EasyMock.expect(us.getUser(1)).andReturn(new User()); - EasyMock.expect(us.getEmailAddress(0)).andReturn("to1@tc.com").anyTimes(); - EasyMock.expect(us.getEmailAddress(1)).andReturn("to1@tc.com").anyTimes(); - EasyMock.expect(us.getEmailAddress(2)).andReturn("to2@tc.com").anyTimes(); - EasyMock.expect(us.getEmailAddress("admin")).andReturn("to2@tc.com").anyTimes(); - - EasyMock.replay(us); - instance.setUserService(us); - - Task task = new Task(); - task.setName("t1"); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setPriority(TaskPriority.HIGH); - UserDTO u1 = new UserDTO(); - u1.setHandle("to1@tc.com"); - u1.setUserId(1); - UserDTO u2 = new UserDTO(); - u2.setHandle("to1@tc.com"); - u2.setUserId(1); - task.setAssignees(Arrays.asList(u1, u2)); - task.setCreatedBy("admin"); - - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task ); - //manually check the mails - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/EntityNotFoundExceptionTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/EntityNotFoundExceptionTests.java deleted file mode 100644 index 809641c41..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/EntityNotFoundExceptionTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.PersistenceException; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link EntityNotFoundException} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class EntityNotFoundExceptionTests extends TestCase { - /** - *

This represents the error message.

- */ - private static final String MESSAGE = "message"; - - /** - *

This represents the error cause.

- */ - private static final Throwable CAUSE = new Exception("cause"); - - /** - *

A instance used for test.

- */ - private EntityNotFoundException exception; - - /** - *

Adapter for earlier versions of JUnit.

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(EntityNotFoundExceptionTests.class); - } - - /** - *

Accuracy tests for inheritance.

- */ - public void testInheritence() { - assertEquals("inheritance is wrong", PersistenceException.class, EntityNotFoundException.class.getSuperclass()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor1() { - exception = new EntityNotFoundException(MESSAGE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor2() { - exception = new EntityNotFoundException(MESSAGE, CAUSE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - assertNotNull("cause is not set", exception.getCause()); - assertEquals("cause is not set", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/IdentifiableEntityTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/IdentifiableEntityTests.java deleted file mode 100644 index 449d68089..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/IdentifiableEntityTests.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import junit.framework.TestCase; - -import com.topcoder.direct.services.project.task.model.IdentifiableEntity; -import com.topcoder.direct.services.project.task.model.Task; - - -/** - *

Unit tests for {@link IdentifiableEntity} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class IdentifiableEntityTests extends TestCase { - /** IdentifiableEntity instance to be used for the testing. */ - private MockIdentifiableEntity instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new MockIdentifiableEntity(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", IdentifiableEntity.class.getSuperclass() == Object.class); - } - - /** - *

Accuracy test for {@link IdentifiableEntity#getId()}.

- */ - public void test_getId() { - assertEquals("Invalid default value.", 0, instance.getId()); - instance.setId(2); - assertEquals("Invalid return value.", 2, instance.getId()); - } - - /** - *

Accuracy test for {@link IdentifiableEntity#setId()}.

- */ - public void test_setId() { - instance.setId(2); - assertEquals("Invalid value is set.", 2, instance.getId()); - instance.setId(0); - assertEquals("Invalid value is set.", 0, instance.getId()); - } - - /** - *

Accuracy test for {@link IdentifiableEntity#equals()}.

- */ - public void test_equals() { - assertEquals("invalid return value", true, instance.equals(instance)); - assertEquals("invalid return value", false, instance.equals(null)); - instance.setId(2); - MockIdentifiableEntity instance2 = new MockIdentifiableEntity(); - instance2.setId(2); - assertEquals("invalid return value", true, instance.equals(instance2)); - Task task = new Task(); - task.setId(2); - assertEquals("invalid return value", false, instance.equals(task)); - } - - /** - *

Accuracy test for {@link IdentifiableEntity#hashCode()}.

- */ - public void test_hashCode() { - long hashCode = instance.hashCode(); - assertTrue("invalid return value", hashCode > 0); - instance.setId(2); - assertTrue("invalid return value", hashCode != instance.hashCode()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/JPATaskListServiceAccTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/JPATaskListServiceAccTests.java deleted file mode 100644 index 03845e8b3..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/JPATaskListServiceAccTests.java +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import java.util.Arrays; -import java.util.List; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.impl.JPATaskListService; -import com.topcoder.direct.services.project.task.impl.JPATaskService; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.log4j.Log4jLogFactory; - -/** - * Accuracy tests for JPATaskListService. - * - * @author amazingpig - * @version 1.0 - */ -public class JPATaskListServiceAccTests extends TestCase { - /** - * Represents the JPATaskListService instance to test. - * */ - private JPATaskListService instance; - /** - *

Sets up the unit tests.

- */ - @Override - public void setUp() throws Exception { - AccTestHelper.clearUpDataBase(); - AccTestHelper.initDataBase(); - instance = new JPATaskListService(); - instance.setLog(new Log4jLogFactory().createLog("test")); - instance.setEntityManager(AccTestHelper.entityManager); - instance.setNotificationService(EasyMock.createNiceMock(NotificationService.class)); - UserService userService = EasyMock.createNiceMock(UserService.class); - instance.setUserService(userService); - - EasyMock.expect(userService.getUser(1)).andReturn(new User()).anyTimes(); - EasyMock.expect(userService.getUserHandle(1)).andReturn("tc").anyTimes(); - EasyMock.expect(userService.getEmailAddress(1)).andReturn("to1@tc.com"); - EasyMock.expect(userService.getEmailAddress(2)).andReturn("to2@tc.com"); - EasyMock.replay(userService); - - } - - /** - *

Cleans up the unit tests.

- */ - @Override - public void tearDown() throws Exception { - instance = null; - try { - if (AccTestHelper.entityManager.getTransaction().isActive()) { - AccTestHelper.entityManager.getTransaction().rollback(); - } - } catch (Exception e) { - //ignore - } - AccTestHelper.clearUpDataBase(); - } - - /** - * Accuracy test for method getTaskListsWithTasks. - * @throws Exception - */ - public void test_getTaskListsWithTasks() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("namefilter"); - tasklist.setDefault(true); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - - JPATaskService taskService = new JPATaskService(); - taskService.setAttachmentDirectory("test_files/accuracy/attachmentDirectory"); - taskService.setLog(new Log4jLogFactory().createLog("test")); - taskService.setEntityManager(AccTestHelper.entityManager); - taskService.setNotificationService(EasyMock.createNiceMock(NotificationService.class)); - UserService userService = EasyMock.createNiceMock(UserService.class); - taskService.setUserService(userService); - - User user = new User(); - user.setUserId(1); - user.setHandle("u1"); - EasyMock.expect(userService.getUser(1)).andReturn(user).anyTimes(); - EasyMock.expect(userService.getUserHandle(1)).andReturn("u1").anyTimes(); - EasyMock.expect(userService.getUserHandle(2)).andReturn("u2").anyTimes(); - EasyMock.expect(userService.getEmailAddress(1)).andReturn("to1@tc.com"); - EasyMock.expect(userService.getEmailAddress(2)).andReturn("to2@tc.com"); - EasyMock.replay(userService); - - taskService.setTaskListService(instance); - - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - AccTestHelper.entityManager.getTransaction().begin(); - taskService.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - tasklist.setTasks(Arrays.asList(task)); - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - TaskFilter taskFilter = new TaskFilter(); - List ret = instance.getTaskListsWithTasks(1, taskFilter ); - - assertEquals(ret.size(), 1); - assertEquals(ret.get(0).getId(), 1); - } - - - /** - * Accuracy test for method getTaskListsWithTasks. - * @throws Exception - */ - public void test_getTaskLists() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("namefilter"); - tasklist.setDefault(true); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - - JPATaskService taskService = new JPATaskService(); - taskService.setAttachmentDirectory("test_files/accuracy/attachmentDirectory"); - taskService.setLog(new Log4jLogFactory().createLog("test")); - taskService.setEntityManager(AccTestHelper.entityManager); - taskService.setNotificationService(EasyMock.createNiceMock(NotificationService.class)); - UserService userService = EasyMock.createNiceMock(UserService.class); - taskService.setUserService(userService); - - User user = new User(); - user.setUserId(1); - user.setHandle("u1"); - EasyMock.expect(userService.getUser(1)).andReturn(user).anyTimes(); - EasyMock.expect(userService.getUserHandle(1)).andReturn("u1").anyTimes(); - EasyMock.expect(userService.getUserHandle(2)).andReturn("u2").anyTimes(); - EasyMock.expect(userService.getEmailAddress(1)).andReturn("to1@tc.com"); - EasyMock.expect(userService.getEmailAddress(2)).andReturn("to2@tc.com"); - EasyMock.replay(userService); - - taskService.setTaskListService(instance); - - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - AccTestHelper.entityManager.getTransaction().begin(); - taskService.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - tasklist.setTasks(Arrays.asList(task)); - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setName("1"); - List ret = instance.getTaskListsWithTasks(1, taskFilter ); - - assertEquals(ret.size(), 1); - assertEquals(ret.get(0).getId(), 1); - } - /** - * Accuracy test for method resolveTaskList. - * @throws Exception - */ - public void test_resolveTaskList() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("name1"); - tasklist.setDefault(true); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - - JPATaskService taskService = new JPATaskService(); - taskService.setAttachmentDirectory("test_files/accuracy/attachmentDirectory"); - taskService.setLog(new Log4jLogFactory().createLog("test")); - taskService.setEntityManager(AccTestHelper.entityManager); - taskService.setNotificationService(EasyMock.createNiceMock(NotificationService.class)); - UserService userService = EasyMock.createNiceMock(UserService.class); - taskService.setUserService(userService); - - User user = new User(); - user.setUserId(1); - user.setHandle("u1"); - EasyMock.expect(userService.getUser(1)).andReturn(user).anyTimes(); - EasyMock.expect(userService.getUserHandle(1)).andReturn("u1").anyTimes(); - EasyMock.expect(userService.getUserHandle(2)).andReturn("u2").anyTimes(); - EasyMock.expect(userService.getEmailAddress(1)).andReturn("to1@tc.com"); - EasyMock.expect(userService.getEmailAddress(2)).andReturn("to2@tc.com"); - EasyMock.replay(userService); - - taskService.setTaskListService(instance); - - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(tasklist.getId()); - - AccTestHelper.entityManager.getTransaction().begin(); - taskService.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - AccTestHelper.entityManager.clear(); - - AccTestHelper.entityManager.getTransaction().begin(); - instance.resolveTaskList(1, tasklist.getId()); - AccTestHelper.entityManager.getTransaction().commit(); - - AccTestHelper.entityManager.clear(); - tasklist = instance.getTaskList(1, tasklist.getId()); - AccTestHelper.entityManager.clear(); - task = AccTestHelper.entityManager.find(Task.class, task.getId()); - //marking all Tasks in the list as "Completed" and setting the TaskList - //* as inactive (i.e. archived). - assertEquals(false, tasklist.isActive()); - assertEquals(TaskStatus.COMPLETED, task.getStatus()); - } - /** - * Accuracy test for method addTaskList. - * @throws Exception - */ - public void test_addTaskList() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("name1"); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1 )); - - - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - assertEquals(created.getId() > 0, true); - assertEquals(created.getName(), "name1"); - assertEquals(created.getCreatedBy(), "tc"); - assertEquals(created.getNumberOfAllTasks(), 10); - assertEquals(created.getAssociatedToContests().get(0).getContestId(), 1); - } - - - /** - * Accuracy test for method updateTaskList. - * @throws Exception - */ - public void test_updateTaskList() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("name1"); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - - created.setName("name2"); - created.setNumberOfAllTasks(20); - AccTestHelper.entityManager.clear(); - - AccTestHelper.entityManager.getTransaction().begin(); - instance.updateTaskList(1, created ); - AccTestHelper.entityManager.getTransaction().commit(); - - TaskList updated = instance.getTaskList(1, created.getId()); - assertEquals(updated.getId() > 0, true); - assertEquals(updated.getName(), "name2"); - assertEquals(updated.getCreatedBy(), "tc"); - assertEquals(updated.getNumberOfAllTasks(), 20); - assertEquals(updated.getLastModifiedBy(), "tc"); - } - - - /** - * Accuracy test for method getTaskList. - * @throws Exception - */ - public void test_getTaskList() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("name1"); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - - TaskList updated = instance.getTaskList(1, created.getId()); - assertEquals(updated.getId() > 0, true); - assertEquals(updated.getName(), "name1"); - assertEquals(updated.getCreatedBy(), "tc"); - assertEquals(updated.getNumberOfAllTasks(), 10); - } - - /** - * Accuracy test for method deleteTaskList. - * @throws Exception - */ - public void test_deleteTaskList() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("name1"); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - AccTestHelper.entityManager.getTransaction().begin(); - instance.deleteTaskList(1, created.getId()); - AccTestHelper.entityManager.getTransaction().commit(); - TaskList updated = instance.getTaskList(1, created.getId()); - assertEquals(updated, null); - } - /** - * Accuracy test for method getDefaultTaskList. - * @throws Exception - */ - public void test_getDefaultTaskList() throws Exception { - TaskList tasklist = new TaskList(); - tasklist.setActive(true); - tasklist.setProjectId(1); - tasklist.setName("name1"); - tasklist.setDefault(true); - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - tasklist.setAssociatedToContests(associatedToContests ); - tasklist.setNotes("notes1"); - tasklist.setNumberOfAllTasks(10); - tasklist.setNumberOfCompletedTasks(1); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - tasklist.setPermittedUsers(Arrays.asList(u1)); - - - AccTestHelper.entityManager.getTransaction().begin(); - TaskList created = instance.addTaskList(1, tasklist ); - AccTestHelper.entityManager.getTransaction().commit(); - - TaskList defaultlist = instance.getDefaultTaskList(1, 1); - assertEquals(created.getId(), defaultlist.getId()); - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/JPATaskServiceAccTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/JPATaskServiceAccTests.java deleted file mode 100644 index 5dd4ca849..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/JPATaskServiceAccTests.java +++ /dev/null @@ -1,680 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.SortedMap; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.impl.JPATaskListService; -import com.topcoder.direct.services.project.task.impl.JPATaskService; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.log4j.Log4jLogFactory; - -/** - * Accuracy tests for JPATaskService. - * - * @author amazingpig - * @version 1.0 - */ -public class JPATaskServiceAccTests extends TestCase { - /** - * Represents the JPATaskService instance to test. - * */ - private JPATaskService instance; - /** - *

Sets up the unit tests.

- */ - @Override - public void setUp() throws Exception { - AccTestHelper.clearUpDataBase(); - AccTestHelper.initDataBase(); - instance = new JPATaskService(); - instance.setAttachmentDirectory("test_files/accuracy/attachmentDirectory"); - instance.setLog(new Log4jLogFactory().createLog("test")); - instance.setEntityManager(AccTestHelper.entityManager); - instance.setNotificationService(EasyMock.createNiceMock(NotificationService.class)); - UserService userService = EasyMock.createNiceMock(UserService.class); - instance.setUserService(userService); - - User user = new User(); - user.setUserId(1); - user.setHandle("u1"); - EasyMock.expect(userService.getUser(1)).andReturn(user).anyTimes(); - EasyMock.expect(userService.getUserHandle(1)).andReturn("u1").anyTimes(); - EasyMock.expect(userService.getUserHandle(2)).andReturn("u2").anyTimes(); - EasyMock.expect(userService.getEmailAddress(1)).andReturn("to1@tc.com"); - EasyMock.expect(userService.getEmailAddress(2)).andReturn("to2@tc.com"); - EasyMock.replay(userService); - - - JPATaskListService listService = new JPATaskListService(); - listService.setLog(new Log4jLogFactory().createLog("test")); - listService.setEntityManager(AccTestHelper.entityManager); - listService.setNotificationService(EasyMock.createNiceMock(NotificationService.class)); - listService.setUserService(userService); - - instance.setTaskListService(listService); - - } - - /** - *

Cleans up the unit tests.

- */ - @Override - public void tearDown() throws Exception { - instance = null; - try { - if (AccTestHelper.entityManager.getTransaction().isActive()) { - AccTestHelper.entityManager.getTransaction().rollback(); - } - } catch (Exception e) { - //ignore - } - AccTestHelper.clearUpDataBase(); - } - /** - * Accuracy test for method addTaskAttachment. - * @throws Exception - */ - public void test_add_get_delete_TaskAttachment() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - - TaskAttachment attachment = new TaskAttachment(); - attachment.setFileName("a.txt"); - attachment.setTaskId(1); - attachment.setMimeType("txt"); - AccTestHelper.entityManager.getTransaction().begin(); - instance.addTaskAttachment(1, attachment , new ByteArrayInputStream("hello".getBytes())); - AccTestHelper.entityManager.getTransaction().commit(); - - InputStream res = instance.getTaskAttachmentContent(1, attachment.getId()); - byte[] b = new byte[res.available()]; - //the content should be correct - res.read(b ); - assertEquals(new String(b),"hello"); - - AccTestHelper.entityManager.getTransaction().begin(); - instance.deleteTaskAttachment(1, attachment.getId()); - AccTestHelper.entityManager.getTransaction().commit(); - - //should be deleted - res = instance.getTaskAttachmentContent(1, attachment.getId()); - assertNull(res); - } - /** - * Accuracy test for method groupTasksByStatus. - * @throws Exception - */ - public void test_groupTasksByStatus() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - Task task2 = new Task(); - task2.setName("name2"); - task2.setStatus(TaskStatus.IN_PROGRESS); - task2.setNotes("n1"); - task2.setPriority(TaskPriority.HIGH); - task2.setTaskListId(1); - - ContestDTO contest2 = new ContestDTO(); - contest2.setContestId(2); - List associatedToContests2 = Arrays.asList(contest ); - task2.setAssociatedToContests(associatedToContests2); - - - - Task task3 = new Task(); - task3.setName("name3"); - task3.setStatus(TaskStatus.IN_PROGRESS); - task3.setNotes("n1"); - task3.setPriority(TaskPriority.HIGH); - task3.setTaskListId(1); - - ContestDTO contest3 = new ContestDTO(); - contest3.setContestId(2); - List associatedToContests3 = Arrays.asList(contest ); - task3.setAssociatedToContests(associatedToContests3); - - - TaskList tl1 = new TaskList(); - tl1.setTasks(Arrays.asList(task, task2)); - TaskList tl2 = new TaskList(); - tl2.setTasks(Arrays.asList(task3)); - - task.setCreatedDate(new Date(1)); - task2.setCreatedDate(new Date(2)); - task3.setCreatedDate(new Date(3)); - SortedMap> res = instance.groupTasksByStatus(Arrays.asList(tl1, tl2)); - - assertEquals(res.size(), 2); - assertEquals(res.get(TaskStatus.COMPLETED).size(), 1); - assertEquals(res.get(TaskStatus.COMPLETED).get(0).getName(), "name1"); - assertEquals(res.get(TaskStatus.IN_PROGRESS).size(), 2); - assertEquals(res.get(TaskStatus.IN_PROGRESS).get(0).getName(), "name2"); - assertEquals(res.get(TaskStatus.IN_PROGRESS).get(1).getName(), "name3"); - } - - - /** - * Accuracy test for method groupTasksByStartDate. - * @throws Exception - */ - public void test_groupTasksByStartDate() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - Task task2 = new Task(); - task2.setName("name2"); - task2.setStatus(TaskStatus.COMPLETED); - task2.setNotes("n1"); - task2.setPriority(TaskPriority.HIGH); - task2.setTaskListId(1); - - ContestDTO contest2 = new ContestDTO(); - contest2.setContestId(2); - List associatedToContests2 = Arrays.asList(contest ); - task2.setAssociatedToContests(associatedToContests2); - - - - Task task3 = new Task(); - task3.setName("name3"); - task3.setStatus(TaskStatus.COMPLETED); - task3.setNotes("n1"); - task3.setPriority(TaskPriority.HIGH); - task3.setTaskListId(1); - - ContestDTO contest3 = new ContestDTO(); - contest3.setContestId(2); - List associatedToContests3 = Arrays.asList(contest ); - task3.setAssociatedToContests(associatedToContests3); - - - TaskList tl1 = new TaskList(); - tl1.setTasks(Arrays.asList(task, task2)); - TaskList tl2 = new TaskList(); - tl2.setTasks(Arrays.asList(task3)); - - task.setCreatedDate(new Date(1)); - task2.setCreatedDate(new Date(2)); - task3.setCreatedDate(new Date(3)); - task.setStartDate(new Date(10*24*3600L*1000)); - task2.setStartDate(new Date(10*24*3600L*1000)); - Date date = new Date(1000*24*3600L*1000); - task3.setStartDate(date); - SortedMap> res = instance.groupTasksByStartDate(Arrays.asList(tl1, tl2)); - - - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date(10*24*3600L*1000)); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - Date date1 = calendar.getTime(); - - calendar = Calendar.getInstance(); - calendar.setTime(new Date(1000*24*3600L*1000)); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - Date date2 = calendar.getTime(); - - assertEquals(res.size(), 2); - assertEquals(res.get(date1).size(), 2); - assertEquals(res.get(date1).get(0).getName(), "name1"); - assertEquals(res.get(date1).get(1).getName(), "name2"); - assertEquals(res.get(date2).size(), 1); - assertEquals(res.get(date2).get(0).getName(), "name3"); - } - /** - * Accuracy test for method groupTasksByDueDate. - * @throws Exception - */ - public void test_groupTasksByDueDate() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - Task task2 = new Task(); - task2.setName("name2"); - task2.setStatus(TaskStatus.COMPLETED); - task2.setNotes("n1"); - task2.setPriority(TaskPriority.HIGH); - task2.setTaskListId(1); - - ContestDTO contest2 = new ContestDTO(); - contest2.setContestId(2); - List associatedToContests2 = Arrays.asList(contest ); - task2.setAssociatedToContests(associatedToContests2); - - - - Task task3 = new Task(); - task3.setName("name3"); - task3.setStatus(TaskStatus.COMPLETED); - task3.setNotes("n1"); - task3.setPriority(TaskPriority.HIGH); - task3.setTaskListId(1); - - ContestDTO contest3 = new ContestDTO(); - contest3.setContestId(2); - List associatedToContests3 = Arrays.asList(contest ); - task3.setAssociatedToContests(associatedToContests3); - - - TaskList tl1 = new TaskList(); - tl1.setTasks(Arrays.asList(task, task2)); - TaskList tl2 = new TaskList(); - tl2.setTasks(Arrays.asList(task3)); - - task.setCreatedDate(new Date(1)); - task2.setCreatedDate(new Date(2)); - task3.setCreatedDate(new Date(3)); - task.setDueDate(new Date(10*24*3600L*1000)); - task2.setDueDate(new Date(1000*24*3600L*1000)); - Date date = new Date(10*24*3600L*1000); - task3.setDueDate(date); - SortedMap> res = instance.groupTasksByDueDate(Arrays.asList(tl1, tl2)); - - - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date(10*24*3600L*1000)); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - Date date1 = calendar.getTime(); - - calendar = Calendar.getInstance(); - calendar.setTime(new Date(1000*24*3600L*1000)); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - Date date2 = calendar.getTime(); - - assertEquals(res.size(), 2); - assertEquals(res.get(date1).size(), 2); - assertEquals(res.get(date1).get(0).getName(), "name1"); - assertEquals(res.get(date1).get(1).getName(), "name3"); - assertEquals(res.get(date2).size(), 1); - assertEquals(res.get(date2).get(0).getName(), "name2"); - } - - /** - * Accuracy test for method groupTasksByAssignee. - * @throws Exception - */ - public void test_groupTasksByAssignee() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - Task task2 = new Task(); - task2.setName("name2"); - task2.setStatus(TaskStatus.COMPLETED); - task2.setNotes("n1"); - task2.setPriority(TaskPriority.HIGH); - task2.setTaskListId(1); - - ContestDTO contest2 = new ContestDTO(); - contest2.setContestId(2); - List associatedToContests2 = Arrays.asList(contest ); - task2.setAssociatedToContests(associatedToContests2); - - - - Task task3 = new Task(); - task3.setName("name3"); - task3.setStatus(TaskStatus.COMPLETED); - task3.setNotes("n1"); - task3.setPriority(TaskPriority.HIGH); - task3.setTaskListId(1); - - ContestDTO contest3 = new ContestDTO(); - contest3.setContestId(2); - List associatedToContests3 = Arrays.asList(contest ); - task3.setAssociatedToContests(associatedToContests3); - - - TaskList tl1 = new TaskList(); - tl1.setTasks(Arrays.asList(task, task2)); - TaskList tl2 = new TaskList(); - tl2.setTasks(Arrays.asList(task3)); - - task.setCreatedDate(new Date(1)); - task2.setCreatedDate(new Date(2)); - task3.setCreatedDate(new Date(3)); - UserDTO u1 = new UserDTO(); - u1.setUserId(1); - UserDTO u2 = new UserDTO(); - u2.setUserId(2); - task.setAssignees(Arrays.asList(u1 , u2)); - task2.setAssignees(Arrays.asList(u1)); - task3.setAssignees(Arrays.asList( u2)); - SortedMap> res = instance.groupTasksByAssignee(Arrays.asList(tl1, tl2)); - - assertEquals(res.size(), 2); - assertEquals(res.get(u1).size(), 2); - assertEquals(res.get(u1).get(0).getName(), "name1"); - assertEquals(res.get(u1).get(1).getName(), "name2"); - assertEquals(res.get(u2).size(), 2); - assertEquals(res.get(u2).get(0).getName(), "name1"); - assertEquals(res.get(u2).get(1).getName(), "name3"); - } - /** - * Accuracy test for method groupTasksByPriority. - * @throws Exception - */ - public void test_groupTasksByPriority() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - Task task2 = new Task(); - task2.setName("name2"); - task2.setStatus(TaskStatus.COMPLETED); - task2.setNotes("n1"); - task2.setPriority(TaskPriority.LOW); - task2.setTaskListId(1); - - ContestDTO contest2 = new ContestDTO(); - contest2.setContestId(2); - List associatedToContests2 = Arrays.asList(contest ); - task2.setAssociatedToContests(associatedToContests2); - - - - Task task3 = new Task(); - task3.setName("name3"); - task3.setStatus(TaskStatus.COMPLETED); - task3.setNotes("n1"); - task3.setPriority(TaskPriority.HIGH); - task3.setTaskListId(1); - - ContestDTO contest3 = new ContestDTO(); - contest3.setContestId(2); - List associatedToContests3 = Arrays.asList(contest ); - task3.setAssociatedToContests(associatedToContests3); - - - TaskList tl1 = new TaskList(); - tl1.setTasks(Arrays.asList(task, task2)); - TaskList tl2 = new TaskList(); - tl2.setTasks(Arrays.asList(task3)); - - task.setCreatedDate(new Date(1)); - task2.setCreatedDate(new Date(2)); - task3.setCreatedDate(new Date(3)); - SortedMap> res = instance.groupTasksByPriority(Arrays.asList(tl1, tl2)); - - assertEquals(res.size(), 2); - assertEquals(res.get(TaskPriority.LOW).size(), 1); - assertEquals(res.get(TaskPriority.LOW).get(0).getName(), "name2"); - assertEquals(res.get(TaskPriority.HIGH).size(), 2); - assertEquals(res.get(TaskPriority.HIGH).get(0).getName(), "name1"); - assertEquals(res.get(TaskPriority.HIGH).get(1).getName(), "name3"); - } - - /** - * Accuracy test for method addTaskList. - * @throws Exception - */ - public void test_addTaskList() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - assertEquals(created.getId() > 0, true); - assertEquals(created.getName(), "name1"); - assertEquals(created.getCreatedBy(), "u1"); - assertEquals(created.getNotes(), "n1"); - assertEquals(created.getAssociatedToContests().get(0).getContestId(), 1); - } - - /** - * Accuracy test for method updateTask. - * @throws Exception - */ - public void test_updateTask() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = AccTestHelper.entityManager.find(ContestDTO.class, 1L); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - created.setName("n2"); - AccTestHelper.entityManager.clear(); - AccTestHelper.entityManager.getTransaction().begin(); - instance.updateTask(1, created); - AccTestHelper.entityManager.getTransaction().commit(); - - assertEquals(created.getId() > 0, true); - assertEquals(created.getName(), "n2"); - assertEquals(created.getCreatedBy(), "u1"); - assertEquals(created.getNotes(), "n1"); - assertEquals(created.getAssociatedToContests().get(0).getContestId(), 1); - } - /** - * Accuracy test for method getTask. - * @throws Exception - */ - public void test_getTask() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - Task got = instance.getTask(1, created.getId()); - - assertEquals(got.getId() > 0, true); - assertEquals(got.getName(), "name1"); - assertEquals(got.getCreatedBy(), "u1"); - assertEquals(got.getNotes(), "n1"); - assertEquals(got.getAssociatedToContests().get(0).getContestId(), 1); - } - - /** - * Accuracy test for method deleteTask. - * @throws Exception - */ - public void test_deleteTask() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - - AccTestHelper.entityManager.getTransaction().begin(); - instance.deleteTask(1, created.getId()); - AccTestHelper.entityManager.getTransaction().commit(); - - Task got = instance.getTask(1, created.getId()); - - assertEquals(got, null); - } - - /** - * Accuracy test for method getNumberOfAllTasks. - * @throws Exception - */ - public void test_getNumberOfAllTasks() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - int got = instance.getNumberOfAllTasks(1, 1); - - assertEquals(got, 1); - } - - /** - * Accuracy test for method getNumberOfCompletedTasks. - * @throws Exception - */ - public void test_getNumberOfCompletedTasks() throws Exception { - Task task = new Task(); - task.setName("name1"); - task.setStatus(TaskStatus.COMPLETED); - task.setNotes("n1"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(1); - - ContestDTO contest = new ContestDTO(); - contest.setContestId(1); - List associatedToContests = Arrays.asList(contest ); - task.setAssociatedToContests(associatedToContests ); - - - AccTestHelper.entityManager.getTransaction().begin(); - Task created = instance.addTask(1, task); - AccTestHelper.entityManager.getTransaction().commit(); - - int got = instance.getNumberOfCompletedTasks(1, 1); - - assertEquals(got, 1); - } - - - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MilestoneDTOTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MilestoneDTOTests.java deleted file mode 100644 index 14b29cdbd..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MilestoneDTOTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.MilestoneDTO; - -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link MilestoneDTO} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class MilestoneDTOTests extends TestCase { - /** MilestoneDTO instance to be used for the testing. */ - private MilestoneDTO instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new MilestoneDTO(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", MilestoneDTO.class.getSuperclass() == Object.class); - } - - /** - *

Accuracy test for {@link MilestoneDTO#getMilestoneId()}.

- */ - public void test_getMilestoneId() { - assertEquals("Invalid default value.", 0, instance.getMilestoneId()); - instance.setMilestoneId(2); - assertEquals("Invalid return value.", 2, instance.getMilestoneId()); - } - - /** - *

Accuracy test for {@link MilestoneDTO#setMilestoneId()}.

- */ - public void test_setMilestoneId() { - instance.setMilestoneId(2); - assertEquals("Invalid value is set.", 2, instance.getMilestoneId()); - instance.setMilestoneId(0); - assertEquals("Invalid value is set.", 0, instance.getMilestoneId()); - } - - /** - *

Accuracy test for {@link MilestoneDTO#getMilestoneName()}.

- */ - public void test_getMilestoneName() { - assertEquals("Invalid default value.", null, instance.getMilestoneName()); - instance.setMilestoneName("tester"); - assertEquals("Invalid return value.", "tester", instance.getMilestoneName()); - } - - /** - *

Accuracy test for {@link MilestoneDTO#setMilestoneName()}.

- */ - public void test_setMilestoneName() { - instance.setMilestoneName("tester"); - assertEquals("Invalid value is set.", "tester", instance.getMilestoneName()); - instance.setMilestoneName(null); - assertEquals("Invalid value is set.", null, instance.getMilestoneName()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockAuditableEntity.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockAuditableEntity.java deleted file mode 100644 index 466fc3b11..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockAuditableEntity.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.AuditableEntity; - - -/** - * Mock implementation of AuditableEntity. - * - * @author gjw99 - * @version 1.0 - */ -public class MockAuditableEntity extends AuditableEntity { -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockBaseTaskEntity.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockBaseTaskEntity.java deleted file mode 100644 index b02425470..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockBaseTaskEntity.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.BaseTaskEntity; - - -/** - * Mock implementation of BaseTaskEntity. - * - * @author gjw99 - * @version 1.0 - */ -public class MockBaseTaskEntity extends BaseTaskEntity { -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockIdentifiableEntity.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockIdentifiableEntity.java deleted file mode 100644 index df103fe11..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/MockIdentifiableEntity.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.IdentifiableEntity; - - -/** - * Mock implementation of IdentifiableEntity. - * - * @author gjw99 - * @version 1.0 - */ -public class MockIdentifiableEntity extends IdentifiableEntity { -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/PermissionExceptionTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/PermissionExceptionTests.java deleted file mode 100644 index 27b015a56..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/PermissionExceptionTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.TaskManagementException; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link PermissionException} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class PermissionExceptionTests extends TestCase { - /** - *

This represents the error message.

- */ - private static final String MESSAGE = "message"; - - /** - *

This represents the error cause.

- */ - private static final Throwable CAUSE = new Exception("cause"); - - /** - *

A instance used for test.

- */ - private PermissionException exception; - - /** - *

Adapter for earlier versions of JUnit.

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PermissionExceptionTests.class); - } - - /** - *

Accuracy tests for inheritance.

- */ - public void testInheritence() { - assertEquals("inheritance is wrong", TaskManagementException.class, PermissionException.class.getSuperclass()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor1() { - exception = new PermissionException(MESSAGE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor2() { - exception = new PermissionException(MESSAGE, CAUSE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - assertNotNull("cause is not set", exception.getCause()); - assertEquals("cause is not set", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/PersistenceExceptionTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/PersistenceExceptionTests.java deleted file mode 100644 index 11f8a8192..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/PersistenceExceptionTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskManagementException; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link PersistenceException} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class PersistenceExceptionTests extends TestCase { - /** - *

This represents the error message.

- */ - private static final String MESSAGE = "message"; - - /** - *

This represents the error cause.

- */ - private static final Throwable CAUSE = new Exception("cause"); - - /** - *

A instance used for test.

- */ - private PersistenceException exception; - - /** - *

Adapter for earlier versions of JUnit.

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PersistenceExceptionTests.class); - } - - /** - *

Accuracy tests for inheritance.

- */ - public void testInheritence() { - assertEquals("inheritance is wrong", TaskManagementException.class, PersistenceException.class.getSuperclass()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor1() { - exception = new PersistenceException(MESSAGE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor2() { - exception = new PersistenceException(MESSAGE, CAUSE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - assertNotNull("cause is not set", exception.getCause()); - assertEquals("cause is not set", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskAttachmentTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskAttachmentTests.java deleted file mode 100644 index 65366bfca..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskAttachmentTests.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.AuditableEntity; -import com.topcoder.direct.services.project.task.model.TaskAttachment; - -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link TaskAttachment} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class TaskAttachmentTests extends TestCase { - /** TaskAttachment instance to be used for the testing. */ - private TaskAttachment instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new TaskAttachment(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", TaskAttachment.class.getSuperclass() == AuditableEntity.class); - } - - /** - *

Accuracy test for {@link TaskAttachment#getFileName()}.

- */ - public void test_getFileName() { - assertEquals("Invalid default value.", null, instance.getFileName()); - instance.setFileName("tester"); - assertEquals("Invalid return value.", "tester", instance.getFileName()); - } - - /** - *

Accuracy test for {@link TaskAttachment#setFileName()}.

- */ - public void test_setFileName() { - instance.setFileName("tester"); - assertEquals("Invalid value is set.", "tester", instance.getFileName()); - instance.setFileName(null); - assertEquals("Invalid value is set.", null, instance.getFileName()); - } - - /** - *

Accuracy test for {@link TaskAttachment#getMimeType()}.

- */ - public void test_getMimeType() { - assertEquals("Invalid default value.", null, instance.getMimeType()); - instance.setMimeType("tester"); - assertEquals("Invalid return value.", "tester", instance.getMimeType()); - } - - /** - *

Accuracy test for {@link TaskAttachment#setMimeType()}.

- */ - public void test_setMimeType() { - instance.setMimeType("tester"); - assertEquals("Invalid value is set.", "tester", instance.getMimeType()); - instance.setMimeType(null); - assertEquals("Invalid value is set.", null, instance.getMimeType()); - } - - /** - *

Accuracy test for {@link TaskAttachment#getTaskId()}.

- */ - public void test_getTaskId() { - assertEquals("Invalid default value.", 0, instance.getTaskId()); - instance.setTaskId(2); - assertEquals("Invalid return value.", 2, instance.getTaskId()); - } - - /** - *

Accuracy test for {@link TaskAttachment#setTaskId()}.

- */ - public void test_setTaskId() { - instance.setTaskId(2); - assertEquals("Invalid value is set.", 2, instance.getTaskId()); - instance.setTaskId(0); - assertEquals("Invalid value is set.", 0, instance.getTaskId()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskFilterTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskFilterTests.java deleted file mode 100644 index 5c9ef77db..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskFilterTests.java +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import junit.framework.TestCase; - -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; - -/** - *

- * Unit tests for {@link TaskFilter} class. - *

- * - * @author gjw99 - * @version 1.0 - */ -public class TaskFilterTests extends TestCase { - /** TaskFilter instance to be used for the testing. */ - private TaskFilter instance = null; - - /** - *

- * Sets up the environment for the TestCase. - *

- */ - @Override - public void setUp() { - instance = new TaskFilter(); - } - - /** - *

- * Tears down the environment after the TestCase. - *

- */ - @Override - public void tearDown() { - instance = null; - } - - /** - *

- * Accuracy test for the constructor. - *

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

- * Accuracy test for the inheritence. - *

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", TaskFilter.class.getSuperclass() == Object.class); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getName()}. - *

- */ - public void test_getName() { - assertEquals("Invalid default value.", null, instance.getName()); - instance.setName("tester"); - assertEquals("Invalid return value.", "tester", instance.getName()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setName()}. - *

- */ - public void test_setName() { - instance.setName("tester"); - assertEquals("Invalid value is set.", "tester", instance.getName()); - instance.setName(null); - assertEquals("Invalid value is set.", null, instance.getName()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getAssigneeId()}. - *

- */ - public void test_getAssigneeId() { - assertEquals("Invalid default value.", null, instance.getAssigneeId()); - - Long field = new Long(2); - instance.setAssigneeId(field); - assertEquals("Invalid return value.", field, instance.getAssigneeId()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setAssigneeId()}. - *

- */ - public void test_setAssigneeId() { - Long field = new Long(2); - instance.setAssigneeId(field); - assertEquals("Invalid value is set.", field, instance.getAssigneeId()); - instance.setAssigneeId(null); - assertEquals("Invalid value is set.", null, instance.getAssigneeId()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getDueDateFrom()}. - *

- */ - public void test_getDueDateFrom() { - assertEquals("Invalid default value.", null, instance.getDueDateFrom()); - - Date date = new Date(); - instance.setDueDateFrom(date); - assertEquals("Invalid return value.", date, instance.getDueDateFrom()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setDueDateFrom()}. - *

- */ - public void test_setDueDateFrom() { - Date date = new Date(); - instance.setDueDateFrom(date); - assertEquals("Invalid return value.", date, instance.getDueDateFrom()); - instance.setDueDateFrom(null); - assertEquals("Invalid value is set.", null, instance.getDueDateFrom()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getDueDateTo()}. - *

- */ - public void test_getDueDateTo() { - assertEquals("Invalid default value.", null, instance.getDueDateTo()); - - Date date = new Date(); - instance.setDueDateTo(date); - assertEquals("Invalid return value.", date, instance.getDueDateTo()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setDueDateTo()}. - *

- */ - public void test_setDueDateTo() { - Date date = new Date(); - instance.setDueDateTo(date); - assertEquals("Invalid return value.", date, instance.getDueDateTo()); - instance.setDueDateTo(null); - assertEquals("Invalid value is set.", null, instance.getDueDateTo()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getPriorities()}. - *

- */ - public void test_getPriorities() { - assertEquals("Invalid default value.", null, instance.getPriorities()); - - List field = new ArrayList(); - instance.setPriorities(field); - assertEquals("Invalid return value.", field, instance.getPriorities()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setPriorities()}. - *

- */ - public void test_setPriorities() { - List field = new ArrayList(); - instance.setPriorities(field); - assertEquals("Invalid value is set.", field, instance.getPriorities()); - instance.setPriorities(null); - assertEquals("Invalid value is set.", null, instance.getPriorities()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getStatuses()}. - *

- */ - public void test_getStatuses() { - assertEquals("Invalid default value.", null, instance.getStatuses()); - - List field = new ArrayList(); - instance.setStatuses(field); - assertEquals("Invalid return value.", field, instance.getStatuses()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setStatuses()}. - *

- */ - public void test_setStatuses() { - List field = new ArrayList(); - instance.setStatuses(field); - assertEquals("Invalid value is set.", field, instance.getStatuses()); - instance.setStatuses(null); - assertEquals("Invalid value is set.", null, instance.getStatuses()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getAssociatedToProjectMilestoneIds()} - * . - *

- */ - public void test_getAssociatedToProjectMilestoneIds() { - assertEquals("Invalid default value.", null, instance.getAssociatedToProjectMilestoneIds()); - - List field = new ArrayList(); - instance.setAssociatedToProjectMilestoneIds(field); - assertEquals("Invalid return value.", field, instance.getAssociatedToProjectMilestoneIds()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setAssociatedToProjectMilestoneIds()} - * . - *

- */ - public void test_setAssociatedToProjectMilestoneIds() { - List field = new ArrayList(); - instance.setAssociatedToProjectMilestoneIds(field); - assertEquals("Invalid value is set.", field, instance.getAssociatedToProjectMilestoneIds()); - instance.setAssociatedToProjectMilestoneIds(null); - assertEquals("Invalid value is set.", null, instance.getAssociatedToProjectMilestoneIds()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getAssociatedToContestIds()}. - *

- */ - public void test_getAssociatedToContestIds() { - assertEquals("Invalid default value.", null, instance.getAssociatedToContestIds()); - - List field = new ArrayList(); - instance.setAssociatedToContestIds(field); - assertEquals("Invalid return value.", field, instance.getAssociatedToContestIds()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setAssociatedToContestIds()}. - *

- */ - public void test_setAssociatedToContestIds() { - List field = new ArrayList(); - instance.setAssociatedToContestIds(field); - assertEquals("Invalid value is set.", field, instance.getAssociatedToContestIds()); - instance.setAssociatedToContestIds(null); - assertEquals("Invalid value is set.", null, instance.getAssociatedToContestIds()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getProjectIds()}. - *

- */ - public void test_getProjectIds() { - assertEquals("Invalid default value.", null, instance.getProjectIds()); - - List field = new ArrayList(); - instance.setProjectIds(field); - assertEquals("Invalid return value.", field, instance.getProjectIds()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setProjectIds()}. - *

- */ - public void test_setProjectIds() { - List field = new ArrayList(); - instance.setProjectIds(field); - assertEquals("Invalid value is set.", field, instance.getProjectIds()); - instance.setProjectIds(null); - assertEquals("Invalid value is set.", null, instance.getProjectIds()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#getIsProjectActive()}. - *

- */ - public void test_isProjectActive() { - assertEquals("Invalid default value.", null, instance.getProjectActive()); - instance.setProjectActive(Boolean.TRUE); - assertEquals("Invalid return value.", Boolean.TRUE, instance.getProjectActive()); - } - - /** - *

- * Accuracy test for {@link TaskFilter#setIsProjectActive()}. - *

- */ - public void test_setProjectActive() { - instance.setProjectActive(Boolean.TRUE); - assertEquals("Invalid return value.", Boolean.TRUE, instance.getProjectActive()); - instance.setProjectActive(null); - assertEquals("Invalid value is set.", null, instance.getProjectActive()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskListTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskListTests.java deleted file mode 100644 index 02b176e29..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskListTests.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.BaseTaskEntity; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.UserDTO; - -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.List; - - -/** - *

Unit tests for {@link TaskList} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class TaskListTests extends TestCase { - /** TaskList instance to be used for the testing. */ - private TaskList instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new TaskList(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", TaskList.class.getSuperclass() == BaseTaskEntity.class); - } - - /** - *

Accuracy test for {@link TaskList#getPermittedUsers()}.

- */ - public void test_getPermittedUsers() { - assertEquals("Invalid default value.", null, instance.getPermittedUsers()); - - List field = new ArrayList(); - instance.setPermittedUsers(field); - assertEquals("Invalid return value.", field, instance.getPermittedUsers()); - } - - /** - *

Accuracy test for {@link TaskList#setPermittedUsers()}.

- */ - public void test_setPermittedUsers() { - List field = new ArrayList(); - instance.setPermittedUsers(field); - assertEquals("Invalid value is set.", field, instance.getPermittedUsers()); - instance.setPermittedUsers(null); - assertEquals("Invalid value is set.", null, instance.getPermittedUsers()); - } - - /** - *

Accuracy test for {@link TaskList#getProjectId()}.

- */ - public void test_getProjectId() { - assertEquals("Invalid default value.", 0, instance.getProjectId()); - instance.setProjectId(2); - assertEquals("Invalid return value.", 2, instance.getProjectId()); - } - - /** - *

Accuracy test for {@link TaskList#setProjectId()}.

- */ - public void test_setProjectId() { - instance.setProjectId(2); - assertEquals("Invalid value is set.", 2, instance.getProjectId()); - instance.setProjectId(0); - assertEquals("Invalid value is set.", 0, instance.getProjectId()); - } - - /** - *

Accuracy test for {@link TaskList#getNumberOfCompletedTasks()}.

- */ - public void test_getNumberOfCompletedTasks() { - assertEquals("Invalid default value.", 0, instance.getNumberOfCompletedTasks()); - instance.setNumberOfCompletedTasks(2); - assertEquals("Invalid return value.", 2, instance.getNumberOfCompletedTasks()); - } - - /** - *

Accuracy test for {@link TaskList#setNumberOfCompletedTasks()}.

- */ - public void test_setNumberOfCompletedTasks() { - instance.setNumberOfCompletedTasks(2); - assertEquals("Invalid value is set.", 2, instance.getNumberOfCompletedTasks()); - instance.setNumberOfCompletedTasks(0); - assertEquals("Invalid value is set.", 0, instance.getNumberOfCompletedTasks()); - } - - /** - *

Accuracy test for {@link TaskList#getNumberOfAllTasks()}.

- */ - public void test_getNumberOfAllTasks() { - assertEquals("Invalid default value.", 0, instance.getNumberOfAllTasks()); - instance.setNumberOfAllTasks(2); - assertEquals("Invalid return value.", 2, instance.getNumberOfAllTasks()); - } - - /** - *

Accuracy test for {@link TaskList#setNumberOfAllTasks()}.

- */ - public void test_setNumberOfAllTasks() { - instance.setNumberOfAllTasks(2); - assertEquals("Invalid value is set.", 2, instance.getNumberOfAllTasks()); - instance.setNumberOfAllTasks(0); - assertEquals("Invalid value is set.", 0, instance.getNumberOfAllTasks()); - } - - /** - *

Accuracy test for {@link TaskList#getTasks()}.

- */ - public void test_getTasks() { - assertEquals("Invalid default value.", null, instance.getTasks()); - - List field = new ArrayList(); - instance.setTasks(field); - assertEquals("Invalid return value.", field, instance.getTasks()); - } - - /** - *

Accuracy test for {@link TaskList#setTasks()}.

- */ - public void test_setTasks() { - List field = new ArrayList(); - instance.setTasks(field); - assertEquals("Invalid value is set.", field, instance.getTasks()); - instance.setTasks(null); - assertEquals("Invalid value is set.", null, instance.getTasks()); - } - - /** - *

Accuracy test for {@link TaskList#getIsActive()}.

- */ - public void test_getIsActive() { - assertEquals("Invalid default value.", false, instance.isActive()); - instance.setActive(true); - assertEquals("Invalid return value.", true, instance.isActive()); - } - - /** - *

Accuracy test for {@link TaskList#setIsActive()}.

- */ - public void test_setIsActive() { - instance.setActive(true); - assertEquals("Invalid return value.", true, instance.isActive()); - instance.setActive(false); - assertEquals("Invalid value is set.", false, instance.isActive()); - } - - /** - *

Accuracy test for {@link TaskList#getIsDefault()}.

- */ - public void test_getIsDefault() { - assertEquals("Invalid default value.", false, instance.isDefault()); - instance.setDefault(true); - assertEquals("Invalid return value.", true, instance.isDefault()); - } - - /** - *

Accuracy test for {@link TaskList#setIsDefault()}.

- */ - public void test_setIsDefault() { - instance.setDefault(true); - assertEquals("Invalid return value.", true, instance.isDefault()); - instance.setDefault(false); - assertEquals("Invalid value is set.", false, instance.isDefault()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskManagementConfigurationExceptionTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskManagementConfigurationExceptionTests.java deleted file mode 100644 index 0446d44c8..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskManagementConfigurationExceptionTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link TaskManagementConfigurationException} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class TaskManagementConfigurationExceptionTests extends TestCase { - /** - *

This represents the error message.

- */ - private static final String MESSAGE = "message"; - - /** - *

This represents the error cause.

- */ - private static final Throwable CAUSE = new Exception("cause"); - - /** - *

A instance used for test.

- */ - private TaskManagementConfigurationException exception; - - /** - *

Adapter for earlier versions of JUnit.

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskManagementConfigurationExceptionTests.class); - } - - /** - *

Accuracy tests for inheritance.

- */ - public void testInheritence() { - assertEquals("inheritance is wrong", RuntimeException.class, - TaskManagementConfigurationException.class.getSuperclass()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor1() { - exception = new TaskManagementConfigurationException(MESSAGE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor2() { - exception = new TaskManagementConfigurationException(MESSAGE, CAUSE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - assertNotNull("cause is not set", exception.getCause()); - assertEquals("cause is not set", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskManagementExceptionTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskManagementExceptionTests.java deleted file mode 100644 index b70043194..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskManagementExceptionTests.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.TaskManagementException; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link TaskManagementException} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class TaskManagementExceptionTests extends TestCase { - /** - *

This represents the error message.

- */ - private static final String MESSAGE = "message"; - - /** - *

This represents the error cause.

- */ - private static final Throwable CAUSE = new Exception("cause"); - - /** - *

A instance used for test.

- */ - private TaskManagementException exception; - - /** - *

Adapter for earlier versions of JUnit.

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskManagementExceptionTests.class); - } - - /** - *

Accuracy tests for inheritance.

- */ - public void testInheritence() { - assertEquals("inheritance is wrong", Exception.class, TaskManagementException.class.getSuperclass()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor1() { - exception = new TaskManagementException(MESSAGE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - } - - /** - * Accuracy test for the constructor. - */ - public void testCtor2() { - exception = new TaskManagementException(MESSAGE, CAUSE); - assertNotNull("message is not set", exception.getMessage()); - assertEquals("message is not set", MESSAGE, exception.getMessage()); - assertNotNull("cause is not set", exception.getCause()); - assertEquals("cause is not set", CAUSE, exception.getCause()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskTests.java deleted file mode 100644 index 215a7c7bc..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/TaskTests.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.BaseTaskEntity; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; - -import junit.framework.TestCase; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - - -/** - *

Unit tests for {@link Task} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class TaskTests extends TestCase { - /** Task instance to be used for the testing. */ - private Task instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new Task(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", Task.class.getSuperclass() == BaseTaskEntity.class); - } - - /** - *

Accuracy test for {@link Task#getStartDate()}.

- */ - public void test_getStartDate() { - assertEquals("Invalid default value.", null, instance.getStartDate()); - - Date date = new Date(); - instance.setStartDate(date); - assertEquals("Invalid return value.", date, instance.getStartDate()); - } - - /** - *

Accuracy test for {@link Task#setStartDate()}.

- */ - public void test_setStartDate() { - Date date = new Date(); - instance.setStartDate(date); - assertEquals("Invalid return value.", date, instance.getStartDate()); - instance.setStartDate(null); - assertEquals("Invalid value is set.", null, instance.getStartDate()); - } - - /** - *

Accuracy test for {@link Task#getDueDate()}.

- */ - public void test_getDueDate() { - assertEquals("Invalid default value.", null, instance.getDueDate()); - - Date date = new Date(); - instance.setDueDate(date); - assertEquals("Invalid return value.", date, instance.getDueDate()); - } - - /** - *

Accuracy test for {@link Task#setDueDate()}.

- */ - public void test_setDueDate() { - Date date = new Date(); - instance.setDueDate(date); - assertEquals("Invalid return value.", date, instance.getDueDate()); - instance.setDueDate(null); - assertEquals("Invalid value is set.", null, instance.getDueDate()); - } - - /** - *

Accuracy test for {@link Task#getAssignees()}.

- */ - public void test_getAssignees() { - assertEquals("Invalid default value.", null, instance.getAssignees()); - - List field = new ArrayList(); - instance.setAssignees(field); - assertEquals("Invalid return value.", field, instance.getAssignees()); - } - - /** - *

Accuracy test for {@link Task#setAssignees()}.

- */ - public void test_setAssignees() { - List field = new ArrayList(); - instance.setAssignees(field); - assertEquals("Invalid value is set.", field, instance.getAssignees()); - instance.setAssignees(null); - assertEquals("Invalid value is set.", null, instance.getAssignees()); - } - - /** - *

Accuracy test for {@link Task#getPriority()}.

- */ - public void test_getPriority() { - assertEquals("Invalid default value.", null, instance.getPriority()); - - TaskPriority field = TaskPriority.HIGH; - instance.setPriority(field); - assertEquals("Invalid return value.", field, instance.getPriority()); - } - - /** - *

Accuracy test for {@link Task#setPriority()}.

- */ - public void test_setPriority() { - TaskPriority field = TaskPriority.HIGH; - instance.setPriority(field); - assertEquals("Invalid value is set.", field, instance.getPriority()); - instance.setPriority(null); - assertEquals("Invalid value is set.", null, instance.getPriority()); - } - - /** - *

Accuracy test for {@link Task#getAttachments()}.

- */ - public void test_getAttachments() { - assertEquals("Invalid default value.", null, instance.getAttachments()); - - List field = new ArrayList(); - instance.setAttachments(field); - assertEquals("Invalid return value.", field, instance.getAttachments()); - } - - /** - *

Accuracy test for {@link Task#setAttachments()}.

- */ - public void test_setAttachments() { - List field = new ArrayList(); - instance.setAttachments(field); - assertEquals("Invalid value is set.", field, instance.getAttachments()); - instance.setAttachments(null); - assertEquals("Invalid value is set.", null, instance.getAttachments()); - } - - /** - *

Accuracy test for {@link Task#getStatus()}.

- */ - public void test_getStatus() { - assertEquals("Invalid default value.", null, instance.getStatus()); - - TaskStatus field = TaskStatus.COMPLETED; - instance.setStatus(field); - assertEquals("Invalid return value.", field, instance.getStatus()); - } - - /** - *

Accuracy test for {@link Task#setStatus()}.

- */ - public void test_setStatus() { - TaskStatus field = TaskStatus.COMPLETED; - instance.setStatus(field); - assertEquals("Invalid value is set.", field, instance.getStatus()); - instance.setStatus(null); - assertEquals("Invalid value is set.", null, instance.getStatus()); - } - - /** - *

Accuracy test for {@link Task#getTaskListId()}.

- */ - public void test_getTaskListId() { - assertEquals("Invalid default value.", 0, instance.getTaskListId()); - instance.setTaskListId(2); - assertEquals("Invalid return value.", 2, instance.getTaskListId()); - } - - /** - *

Accuracy test for {@link Task#setTaskListId()}.

- */ - public void test_setTaskListId() { - instance.setTaskListId(2); - assertEquals("Invalid value is set.", 2, instance.getTaskListId()); - instance.setTaskListId(0); - assertEquals("Invalid value is set.", 0, instance.getTaskListId()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/UserDTOTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/UserDTOTests.java deleted file mode 100644 index adee608a2..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/accuracytests/UserDTOTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.accuracytests; - -import com.topcoder.direct.services.project.task.model.UserDTO; - -import junit.framework.TestCase; - - -/** - *

Unit tests for {@link UserDTO} class.

- * - * @author gjw99 - * @version 1.0 - */ -public class UserDTOTests extends TestCase { - /** UserDTO instance to be used for the testing. */ - private UserDTO instance = null; - - /** - *

Sets up the environment for the TestCase.

- */ - public void setUp() { - instance = new UserDTO(); - } - - /** - *

Tears down the environment after the TestCase.

- */ - public void tearDown() { - instance = null; - } - - /** - *

Accuracy test for the constructor.

- */ - public void test_ctor() { - assertNotNull("instance should be created.", instance); - } - - /** - *

Accuracy test for the inheritence.

- */ - public void test_inheritence() { - assertTrue("invalid inheritence.", UserDTO.class.getSuperclass() == Object.class); - } - - /** - *

Accuracy test for {@link UserDTO#getUserId()}.

- */ - public void test_getUserId() { - assertEquals("Invalid default value.", 0, instance.getUserId()); - instance.setUserId(2); - assertEquals("Invalid return value.", 2, instance.getUserId()); - } - - /** - *

Accuracy test for {@link UserDTO#setUserId()}.

- */ - public void test_setUserId() { - instance.setUserId(2); - assertEquals("Invalid value is set.", 2, instance.getUserId()); - instance.setUserId(0); - assertEquals("Invalid value is set.", 0, instance.getUserId()); - } - - /** - *

Accuracy test for {@link UserDTO#getHandle()}.

- */ - public void test_getHandle() { - assertEquals("Invalid default value.", null, instance.getHandle()); - instance.setHandle("tester"); - assertEquals("Invalid return value.", "tester", instance.getHandle()); - } - - /** - *

Accuracy test for {@link UserDTO#setHandle()}.

- */ - public void test_setHandle() { - instance.setHandle("tester"); - assertEquals("Invalid value is set.", "tester", instance.getHandle()); - instance.setHandle(null); - assertEquals("Invalid value is set.", null, instance.getHandle()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/BaseJPAServiceFailureTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/BaseJPAServiceFailureTests.java deleted file mode 100644 index 5ed84dca0..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/BaseJPAServiceFailureTests.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.failuretests; - -import static org.mockito.Mockito.mock; - -import javax.persistence.EntityManager; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.impl.BaseJPAService; -import com.topcoder.service.user.UserService; - -import junit.framework.TestSuite; -import junit.framework.Test; -import junit.framework.TestCase; - -/** - *

- * Failure test cases for BaseJPAService. - *

- * - * @author victorsam - * @version 1.0 - */ -public class BaseJPAServiceFailureTests extends TestCase { - - /** - *

- * The BaseJPAService instance for testing. - *

- */ - private BaseJPAService instance; - - /** - *

- * Setup test environment. - *

- * - */ - protected void setUp() { - instance = new BaseJPAService() { - }; - - UserService userService = mock(UserService.class); - EntityManager entityManager = mock(EntityManager.class); - NotificationService notificationService = mock(NotificationService.class); - - instance.setUserService(userService); - instance.setEntityManager(entityManager); - instance.setNotificationService(notificationService); - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(BaseJPAServiceFailureTests.class); - } - - /** - *

- * Tests BaseJPAService#checkInitialization() for failure. - * It tests the case that when userService is null and expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure1() { - instance.setUserService(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests BaseJPAService#checkInitialization() for failure. - * It tests the case that when entityManager is null and expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure2() { - instance.setEntityManager(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests BaseJPAService#checkInitialization() for failure. - * It tests the case that when notificationService is null and expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure3() { - instance.setNotificationService(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/EmailEngineNotificationServiceFailureTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/EmailEngineNotificationServiceFailureTests.java deleted file mode 100644 index eacd9da18..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/EmailEngineNotificationServiceFailureTests.java +++ /dev/null @@ -1,504 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.failuretests; - -import static org.mockito.Mockito.mock; -import java.util.ArrayList; -import java.util.List; - -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.impl.EmailEngineNotificationService; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.UserService; - -import junit.framework.TestSuite; -import junit.framework.Test; -import junit.framework.TestCase; - -/** - *

- * Failure test cases for EmailEngineNotificationService. - *

- * - * @author victorsam - * @version 1.0 - */ -public class EmailEngineNotificationServiceFailureTests extends TestCase { - /** - *

- * The EmailEngineNotificationService instance for testing. - *

- */ - private EmailEngineNotificationService instance; - - /** - *

- * The Task instance for testing. - *

- */ - private Task task; - - /** - *

- * Setup test environment. - *

- * - */ - protected void setUp() { - instance = new EmailEngineNotificationService(); - - UserService userService = mock(UserService.class); - - instance.setUserService(userService); - instance.setEmailSender("emailSender"); - instance.setTaskCreationEmailBodyTemplatePath("taskCreationEmailBodyTemplatePath"); - instance.setTaskCreationEmailSubjectTemplateText("taskCreationEmailSubjectTemplateText"); - instance.setTaskStatusChangeEmailBodyTemplatePath("taskStatusChangeEmailBodyTemplatePath"); - instance.setTaskStatusChangeEmailSubjectTemplateText("taskStatusChangeEmailSubjectTemplateText"); - - task = new Task(); - task.setName("name"); - task.setPriority(TaskPriority.NORMAL); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setCreatedBy("CN"); - - List assignees = new ArrayList(); - UserDTO assignee = new UserDTO(); - assignee.setHandle("TC"); - assignee.setUserId(1); - assignees.add(assignee); - - task.setAssignees(assignees); - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(EmailEngineNotificationServiceFailureTests.class); - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when userService is null and expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure1() { - instance.setUserService(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when emailSender is null and expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure2() { - instance.setEmailSender(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when emailSender is empty and expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure3() { - instance.setEmailSender(" "); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskCreationEmailSubjectTemplateText is null and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure4() { - instance.setTaskCreationEmailSubjectTemplateText(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskCreationEmailSubjectTemplateText is empty and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure5() { - instance.setTaskCreationEmailSubjectTemplateText(" "); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskCreationEmailBodyTemplatePath is null and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure6() { - instance.setTaskCreationEmailBodyTemplatePath(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskCreationEmailBodyTemplatePath is empty and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure7() { - instance.setTaskCreationEmailBodyTemplatePath(" "); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskStatusChangeEmailBodyTemplatePath is null and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure8() { - instance.setTaskStatusChangeEmailBodyTemplatePath(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskStatusChangeEmailBodyTemplatePath is empty and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure9() { - instance.setTaskStatusChangeEmailBodyTemplatePath(" "); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskStatusChangeEmailSubjectTemplateText is null and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure10() { - instance.setTaskStatusChangeEmailSubjectTemplateText(null); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#checkInitialization() for failure. - * It tests the case that when taskStatusChangeEmailSubjectTemplateText is empty and - * expects TaskManagementConfigurationException. - *

- */ - public void testCheckInitialization_Failure11() { - instance.setTaskStatusChangeEmailSubjectTemplateText(" "); - try { - instance.checkInitialization(); - fail("TaskManagementConfigurationException expected."); - } catch (TaskManagementConfigurationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation(long,Task) for failure. - * It tests the case that when task is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskCreation_NullTask() throws Exception { - try { - instance.notifyTaskCreation(1, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation(long,Task) for failure. - * It tests the case that when task name is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskCreation_NullTaskName() throws Exception { - task.setName(null); - try { - instance.notifyTaskCreation(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation(long,Task) for failure. - * It tests the case that when task name is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskCreation_EmptyTaskName() throws Exception { - task.setName(" "); - try { - instance.notifyTaskCreation(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation(long,Task) for failure. - * It tests the case that when task Status is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskCreation_NullTaskStatus() throws Exception { - task.setStatus(null); - try { - instance.notifyTaskCreation(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation(long,Task) for failure. - * It tests the case that when task Priority is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskCreation_NullTaskPriority() throws Exception { - task.setPriority(null); - try { - instance.notifyTaskCreation(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation(long,Task) for failure. - * Expects NotificationException. - *

- */ - public void testNotifyTaskCreation_NotificationException() { - try { - instance.notifyTaskCreation(1, task); - fail("NotificationException expected."); - } catch (NotificationException e) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when oldTask is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_NullOldTask() throws Exception { - try { - instance.notifyTaskStatusChange(1, null, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when newTask is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_NullNewTask() throws Exception { - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when newTask name is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_NullNewTaskName() throws Exception { - task.setName(null); - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when newTask name is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_EmptyNewTaskName() throws Exception { - task.setName(" "); - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when newTask Status is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_NullNewTaskStatus() throws Exception { - task.setStatus(null); - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when newTask CreatedBy is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_NullNewTaskCreatedBy() throws Exception { - task.setCreatedBy(null); - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * It tests the case that when newTask CreatedBy is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testNotifyTaskStatusChange_EmptyNewTaskCreatedBy() throws Exception { - task.setCreatedBy(" "); - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange(long,TaskStatus,Task) for failure. - * Expects NotificationException. - *

- */ - public void testNotifyTaskStatusChange_NotificationException() { - try { - instance.notifyTaskStatusChange(1, TaskStatus.COMPLETED, task); - fail("NotificationException expected."); - } catch (NotificationException e) { - //good - } - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/FailureTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/FailureTests.java deleted file mode 100644 index 458e11257..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/FailureTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.failuretests; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - *

- * This test case aggregates all Failure test cases. - *

- * - * @author victorsam - * @version 1.0 - */ -public class FailureTests extends TestCase { - /** - * Test suite for the failure tests. - * - * @return the test suite - */ - public static Test suite() { - final TestSuite suite = new TestSuite(); - suite.addTest(JPATaskListServiceFailureTests.suite()); - suite.addTest(BaseJPAServiceFailureTests.suite()); - suite.addTest(EmailEngineNotificationServiceFailureTests.suite()); - suite.addTest(JPATaskServiceFailureTests.suite()); - - return suite; - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/JPATaskListServiceFailureTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/JPATaskListServiceFailureTests.java deleted file mode 100644 index 79b5c6f33..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/JPATaskListServiceFailureTests.java +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.failuretests; - -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.math.BigDecimal; - -import javax.persistence.EntityManager; -import javax.persistence.Query; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.impl.JPATaskListService; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.service.user.UserService; -import com.topcoder.service.user.UserServiceException; - -import junit.framework.TestSuite; -import junit.framework.Test; -import junit.framework.TestCase; - -/** - *

- * Failure test cases for JPATaskListService. - *

- * - * @author victorsam - * @version 1.0 - */ -public class JPATaskListServiceFailureTests extends TestCase { - /** - *

- * The JPATaskListService instance for testing. - *

- */ - private JPATaskListService instance; - - /** - *

- * The TaskList instance for testing. - *

- */ - private TaskList taskList; - - /** - *

- * The UserService instance for testing. - *

- */ - private UserService userService; - - /** - *

- * The EntityManager instance for testing. - *

- */ - private EntityManager entityManager; - - /** - *

- * Setup test environment. - *

- * - */ - protected void setUp() { - instance = new JPATaskListService(); - - userService = mock(UserService.class); - entityManager = mock(EntityManager.class); - NotificationService notificationService = mock(NotificationService.class); - - instance.setUserService(userService); - instance.setEntityManager(entityManager); - instance.setNotificationService(notificationService); - - taskList = new TaskList(); - taskList.setName("TC"); - taskList.setId(8); - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(JPATaskListServiceFailureTests.class); - } - - /** - *

- * Tests JPATaskListService#addTaskList(long,TaskList) for failure. - * It tests the case that when taskList is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskList_NullTaskList() throws Exception { - try { - instance.addTaskList(1, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskListService#addTaskList(long,TaskList) for failure. - * It tests the case that when taskList name is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskList_NullTaskListName() throws Exception { - taskList.setName(null); - try { - instance.addTaskList(1, taskList); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskListService#addTaskList(long,TaskList) for failure. - * It tests the case that when taskList name is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskList_EmptyTaskListName() throws Exception { - taskList.setName(" "); - try { - instance.addTaskList(1, taskList); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskListService#addTaskList(long,TaskList) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskList_PermissionException() throws Exception { - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.addTaskList(1, taskList); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#updateTaskList(long,TaskList) for failure. - * It tests the case that when taskList is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTaskList_NullTaskList() throws Exception { - try { - instance.updateTaskList(1, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskListService#updateTaskList(long,TaskList) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTaskList_EntityNotFoundException() throws Exception { - try { - instance.updateTaskList(1, taskList); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#updateTaskList(long,TaskList) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTaskList_PermissionException() throws Exception { - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.updateTaskList(1, taskList); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#getTaskList(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetTaskList_PermissionException() throws Exception { - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.getTaskList(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#getDefaultTaskList(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testGetDefaultTaskList_EntityNotFoundException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(0)); - try { - instance.getDefaultTaskList(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#getDefaultTaskList(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetDefaultTaskList_PermissionException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(1)); - - query = mock(Query.class); - when(entityManager.createQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new Long(1)); - - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.getDefaultTaskList(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#getDefaultTaskList(long,long) for failure. - * Expects PersistenceException. - *

- * @throws Exception to JUnit - */ - public void testGetDefaultTaskList_PersistenceException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(1)); - - query = mock(Query.class); - when(entityManager.createQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn("invalid"); - try { - instance.getDefaultTaskList(1, 1); - fail("PersistenceException expected."); - } catch (PersistenceException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#deleteTaskList(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTaskList_EntityNotFoundException() throws Exception { - try { - instance.deleteTaskList(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#deleteTaskList(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTaskList_PermissionException() throws Exception { - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.deleteTaskList(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#resolveTaskList(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testResolveTaskList_EntityNotFoundException() throws Exception { - try { - instance.resolveTaskList(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#resolveTaskList(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testResolveTaskList_PermissionException() throws Exception { - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.resolveTaskList(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskListService#getTaskLists(long,TaskFilter) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetTaskLists_PermissionException() throws Exception { - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.getTaskLists(1, null); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/JPATaskServiceFailureTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/JPATaskServiceFailureTests.java deleted file mode 100644 index 812c945c0..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/failuretests/JPATaskServiceFailureTests.java +++ /dev/null @@ -1,1065 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.failuretests; - -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.doThrow; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.Query; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.impl.JPATaskService; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.UserService; -import com.topcoder.service.user.UserServiceException; - -import junit.framework.TestSuite; -import junit.framework.Test; -import junit.framework.TestCase; - -/** - *

- * Failure test cases for JPATaskService. - *

- * - * @author victorsam - * @version 1.0 - */ -public class JPATaskServiceFailureTests extends TestCase { - /** - *

- * The JPATaskService instance for testing. - *

- */ - private JPATaskService instance; - - /** - *

- * The TaskList instance for testing. - *

- */ - private TaskList taskList; - - /** - *

- * The NotificationService instance for testing. - *

- */ - private NotificationService notificationService; - - /** - *

- * The UserService instance for testing. - *

- */ - private UserService userService; - - /** - *

- * The EntityManager instance for testing. - *

- */ - private EntityManager entityManager; - - /** - *

- * The TaskListService instance for testing. - *

- */ - private TaskListService taskListService; - - /** - *

- * The TaskList list for testing. - *

- */ - private List taskLists; - - /** - *

- * The UserDTO list for testing. - *

- */ - private List assignees; - - /** - *

- * The Task list for testing. - *

- */ - private List tasks; - - /** - *

- * The Task instance for testing. - *

- */ - private Task task; - - /** - *

- * The TaskAttachment instance for testing. - *

- */ - private TaskAttachment attachment; - - /** - *

- * The InputStream instance for testing. - *

- */ - private InputStream inputStream; - - /** - *

- * Setup test environment. - *

- * - */ - protected void setUp() { - instance = new JPATaskService(); - - userService = mock(UserService.class); - entityManager = mock(EntityManager.class); - taskListService = mock(TaskListService.class); - notificationService = mock(NotificationService.class); - - instance.setUserService(userService); - instance.setEntityManager(entityManager); - instance.setTaskListService(taskListService); - instance.setAttachmentDirectory("test_files"); - instance.setNotificationService(notificationService); - - taskList = new TaskList(); - taskList.setName("TC"); - taskList.setId(8); - - task = new Task(); - assignees = new ArrayList(); - task.setAssignees(assignees); - task.setCreatedDate(new Date()); - task.setName("name"); - task.setPriority(TaskPriority.HIGH); - task.setStatus(TaskStatus.COMPLETED); - task.setTaskListId(1); - task.setId(1); - - tasks = new ArrayList(); - tasks.add(task); - - taskList.setTasks(tasks); - taskList.setCreatedDate(new Date()); - - taskLists = new ArrayList(); - taskLists.add(taskList); - - attachment = new TaskAttachment(); - attachment.setFileName("test"); - attachment.setMimeType("text"); - attachment.setTaskId(1); - - inputStream = new ByteArrayInputStream("test".getBytes()); - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(JPATaskServiceFailureTests.class); - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when taskLists is null and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullTaskLists() { - try { - instance.groupTasksByAssignee(null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when taskLists contains null element and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullInTaskLists() { - taskLists.add(null); - try { - instance.groupTasksByAssignee(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when getTasks() is null and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullTasks() { - taskList.setTasks(null); - taskLists.add(taskList); - try { - instance.groupTasksByAssignee(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when getTasks() contains null and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullInTasks() { - tasks.add(null); - taskLists.add(taskList); - try { - instance.groupTasksByAssignee(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when getAssignees() is null and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullAssignees() { - task.setAssignees(null); - taskLists.add(taskList); - try { - instance.groupTasksByAssignee(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when getAssignees() contains null and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullInAssignees() { - assignees.add(null); - taskLists.add(taskList); - try { - instance.groupTasksByAssignee(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByAssignee(List) for failure. - * It tests the case that when getCreatedDate() is null and expects IllegalArgumentException. - *

- */ - public void testGroupTasksByAssignee_NullCreatedDate() { - task.setCreatedDate(null); - taskLists.add(taskList); - try { - instance.groupTasksByAssignee(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * It tests the case that when task is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_NullTask() throws Exception { - try { - instance.addTask(1, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * It tests the case that when task name is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_NullTaskName() throws Exception { - task.setName(null); - try { - instance.addTask(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * It tests the case that when task name is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_EmptyTaskName() throws Exception { - task.setName(" "); - try { - instance.addTask(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * It tests the case that when task Status is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_NullTaskStatus() throws Exception { - task.setStatus(null); - try { - instance.addTask(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * It tests the case that when task Priority is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_NullTaskPriority() throws Exception { - task.setPriority(null); - try { - instance.addTask(1, task); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_EntityNotFoundException() throws Exception { - try { - instance.addTask(1, task); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_PermissionException() throws Exception { - when(taskListService.getTaskList(1, 1)).thenReturn(taskList); - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.addTask(1, task); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTask(long,Task) for failure. - * Expects NotificationException. - *

- * @throws Exception to JUnit - */ - public void testAddTask_NotificationException() throws Exception { - when(taskListService.getTaskList(1, 1)).thenReturn(taskList); - doThrow(new NotificationException("error")).when(notificationService).notifyTaskCreation(1, task); - try { - instance.addTask(1, task); - fail("NotificationException expected."); - } catch (NotificationException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#updateTask(long,Task) for failure. - * It tests the case that when task is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTask_NullTask() throws Exception { - try { - instance.updateTask(1, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#updateTask(long,Task) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTask_EntityNotFoundException() throws Exception { - try { - instance.updateTask(1, task); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#updateTask(long,Task) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTask_PermissionException() throws Exception { - when(taskListService.getTaskList(1, 1)).thenReturn(taskList); - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.updateTask(1, task); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#updateTask(long,Task) for failure. - * Expects NotificationException. - *

- * @throws Exception to JUnit - */ - public void testUpdateTask_NotificationException() throws Exception { - when(taskListService.getTaskList(1, 1)).thenReturn(taskList); - Task oldTask = new Task(); - oldTask.setStatus(TaskStatus.IN_PROGRESS); - when(entityManager.find(Task.class, 1L)).thenReturn(oldTask); - doThrow(new NotificationException("error")).when(notificationService).notifyTaskStatusChange(1, - TaskStatus.IN_PROGRESS, task); - try { - instance.updateTask(1, task); - fail("NotificationException expected."); - } catch (NotificationException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getTask(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetTask_PermissionException() throws Exception { - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PermissionException("error")); - try { - instance.getTask(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getTask(long,long) for failure. - * Expects PersistenceException. - *

- * @throws Exception to JUnit - */ - public void testGetTask_PersistenceException() throws Exception { - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PersistenceException("error")); - try { - instance.getTask(1, 1); - fail("PersistenceException expected."); - } catch (PersistenceException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#deleteTask(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTask_EntityNotFoundException() throws Exception { - try { - instance.deleteTask(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#deleteTask(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTask_PermissionException() throws Exception { - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PermissionException("error")); - try { - instance.deleteTask(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#deleteTask(long,long) for failure. - * Expects PersistenceException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTask_PersistenceException() throws Exception { - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PersistenceException("error")); - try { - instance.deleteTask(1, 1); - fail("PersistenceException expected."); - } catch (PersistenceException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * It tests the case that when attachment is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_NullAttachment() throws Exception { - try { - instance.addTaskAttachment(1, null, inputStream); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * It tests the case that when getFileName() is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_NullFileName() throws Exception { - attachment.setFileName(null); - try { - instance.addTaskAttachment(1, attachment, inputStream); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * It tests the case that when getFileName() is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_EmptyFileName() throws Exception { - attachment.setFileName(" "); - try { - instance.addTaskAttachment(1, attachment, inputStream); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * It tests the case that when getMimeType() is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_NullMimeType() throws Exception { - attachment.setMimeType(null); - try { - instance.addTaskAttachment(1, attachment, inputStream); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * It tests the case that when getMimeType() is empty and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_EmptyMimeType() throws Exception { - attachment.setMimeType(" "); - try { - instance.addTaskAttachment(1, attachment, inputStream); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * It tests the case that when inputStream is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_NullInputStream() throws Exception { - try { - instance.addTaskAttachment(1, attachment, null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_EntityNotFoundException() throws Exception { - try { - instance.addTaskAttachment(1, attachment, inputStream); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#addTaskAttachment(long,TaskAttachment,InputStream) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testAddTaskAttachment_PermissionException() throws Exception { - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PermissionException("error")); - try { - instance.addTaskAttachment(1, attachment, inputStream); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#deleteTaskAttachment(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTaskAttachment_EntityNotFoundException() throws Exception { - try { - instance.deleteTaskAttachment(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#deleteTaskAttachment(long,long) for failure. - * Expects PersistenceException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTaskAttachment_PersistenceException() throws Exception { - when(entityManager.find(TaskAttachment.class, 1L)).thenReturn(attachment); - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PersistenceException("error")); - try { - instance.deleteTaskAttachment(1, 1); - fail("PersistenceException expected."); - } catch (PersistenceException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#deleteTaskAttachment(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testDeleteTaskAttachment_PermissionException() throws Exception { - when(entityManager.find(TaskAttachment.class, 1L)).thenReturn(attachment); - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PermissionException("error")); - try { - instance.deleteTaskAttachment(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getTaskAttachmentContent(long,long) for failure. - * Expects PersistenceException. - *

- * @throws Exception to JUnit - */ - public void testGetTaskAttachmentContent_PersistenceException() throws Exception { - when(entityManager.find(TaskAttachment.class, 1L)).thenReturn(attachment); - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PersistenceException("error")); - try { - instance.getTaskAttachmentContent(1, 1); - fail("PersistenceException expected."); - } catch (PersistenceException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getTaskAttachmentContent(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetTaskAttachmentContent_PermissionException() throws Exception { - when(entityManager.find(TaskAttachment.class, 1L)).thenReturn(attachment); - when(entityManager.find(Task.class, 1L)).thenReturn(task); - when(taskListService.getTaskList(1, 1)).thenThrow(new PermissionException("error")); - try { - instance.getTaskAttachmentContent(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByPriority(List) for failure. - * It tests the case that when taskLists is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByPriority_NullTaskLists() throws Exception { - try { - instance.groupTasksByPriority(null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByPriority(List) for failure. - * It tests the case that when getPriority is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByPriority_NullPriority() throws Exception { - task.setPriority(null); - taskLists.add(taskList); - try { - instance.groupTasksByPriority(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByPriority(List) for failure. - * It tests the case that when taskLists contains null element and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByPriority_NullInTaskLists() throws Exception { - taskLists.add(null); - try { - instance.groupTasksByPriority(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByDueDate(List) for failure. - * It tests the case that when taskLists is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByDueDate_NullTaskLists() throws Exception { - try { - instance.groupTasksByDueDate(null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByDueDate(List) for failure. - * It tests the case that when taskLists contains null element and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByDueDate_NullInTaskLists() throws Exception { - taskLists.add(null); - try { - instance.groupTasksByDueDate(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByStartDate(List) for failure. - * It tests the case that when taskLists is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByStartDate_NullTaskLists() throws Exception { - try { - instance.groupTasksByStartDate(null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByStartDate(List) for failure. - * It tests the case that when taskLists contains null element and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByStartDate_NullInTaskLists() throws Exception { - taskLists.add(null); - try { - instance.groupTasksByStartDate(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByStatus(List) for failure. - * It tests the case that when taskLists is null and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByStatus_NullTaskLists() throws Exception { - try { - instance.groupTasksByStatus(null); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#groupTasksByStatus(List) for failure. - * It tests the case that when taskLists contains null element and expects IllegalArgumentException. - *

- * @throws Exception to JUnit - */ - public void testGroupTasksByStatus_NullInTaskLists() throws Exception { - taskLists.add(null); - try { - instance.groupTasksByStatus(taskLists); - fail("IllegalArgumentException expected."); - } catch (IllegalArgumentException iae) { - //good - } - } - - /** - *

- * Tests JPATaskService#getNumberOfCompletedTasks(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testGetNumberOfCompletedTasks_EntityNotFoundException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(0)); - try { - instance.getNumberOfCompletedTasks(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getNumberOfCompletedTasks(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetNumberOfCompletedTasks_PermissionException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(1)); - - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.getNumberOfCompletedTasks(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getNumberOfAllTasks(long,long) for failure. - * Expects EntityNotFoundException. - *

- * @throws Exception to JUnit - */ - public void testGetNumberOfAllTasks_EntityNotFoundException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(0)); - try { - instance.getNumberOfAllTasks(1, 1); - fail("EntityNotFoundException expected."); - } catch (EntityNotFoundException e) { - //good - } - } - - /** - *

- * Tests JPATaskService#getNumberOfAllTasks(long,long) for failure. - * Expects PermissionException. - *

- * @throws Exception to JUnit - */ - public void testGetNumberOfAllTasks_PermissionException() throws Exception { - Query query = mock(Query.class); - when(entityManager.createNativeQuery(anyString())).thenReturn(query); - when(query.getSingleResult()).thenReturn(new BigDecimal(1)); - - when(userService.getUserHandle(1)).thenThrow(new UserServiceException("error")); - try { - instance.getNumberOfAllTasks(1, 1); - fail("PermissionException expected."); - } catch (PermissionException e) { - //good - } - } - -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/BaseJPAServiceTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/BaseJPAServiceTests.java deleted file mode 100644 index 7b371444d..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/BaseJPAServiceTests.java +++ /dev/null @@ -1,562 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import javax.persistence.EntityManager; - -import junit.framework.Assert; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.ApplicationContext; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - -/** - *

- * All unit tests class for BaseJPAService. - *

- *

- * Since this class is an abstract class, so a mock up subclass MockJPATestService is to do the concrete - * tests. - *

- * @author TCSDEVELOPER - * @version 1.0 - */ -public class BaseJPAServiceTests extends BaseUnitTests { - - - /** - *

- * Represents the spring application context for unit tests. - *

- */ - private ApplicationContext ctx; - - /** - *

- * Represents the MockTestService and its concrete bean is expected from BaseJPAService for unit tests. - *

- */ - private MockTestService mockTestService; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(BaseJPAServiceTests.class); - } - - - - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - ctx = super.getApplicationContext(); - mockTestService = (MockTestService) ctx.getBean("mockTestService"); - } - - /** - *

- * Tests the constructor: {@link BaseJPAService#BaseJPAService()}. - *

- * Accuracy test to check if the instance can be created correctly. - * @throws Exception to JUnit. - */ - @Test - public void testBaseJPAService() throws Exception { - BaseJPAService baseService = new BaseJPAService() { - }; - assertNotNull("The instance cannot be created.", baseService); - assertTrue("Should be the instance of BaseJPAService", baseService instanceof BaseJPAService); - } - - /** - *

- * Tests the method: {@link BaseJPAService#checkInitialization()}. - *

- * If the entityManager is not injected, TaskManagementConfigurationException is expected. - */ - @Test (expected = TaskManagementConfigurationException.class) - public void testCheckInitializationMissingUserService() { - BaseJPAService baseService = new BaseJPAService() { - }; - EntityManager entityManager = mockTestService.getTestEntityManager(); - Log log = mockTestService.getTestLog(); - NotificationService notificationService = mockTestService.getTestNotificationService(); - UserService userService = null; - - baseService.setEntityManager(entityManager); - baseService.setLog(log); - baseService.setNotificationService(notificationService); - baseService.setUserService(userService); - - baseService.checkInitialization(); - } - - /** - *

- * Tests the method: {@link BaseJPAService#checkInitialization()}. - *

- * If the entityManager is not injected, TaskManagementConfigurationException is expected. - */ - @Test (expected = TaskManagementConfigurationException.class) - public void testCheckInitializationMissingNotificationService() { - BaseJPAService baseService = new BaseJPAService() { - }; - EntityManager entityManager = mockTestService.getTestEntityManager(); - Log log = mockTestService.getTestLog(); - NotificationService notificationService = null; - UserService userService = mockTestService.getTestUserService(); - - baseService.setEntityManager(entityManager); - baseService.setLog(log); - baseService.setNotificationService(notificationService); - baseService.setUserService(userService); - - baseService.checkInitialization(); - } - - /** - *

- * Tests the method: {@link BaseJPAService#checkInitialization()}. - *

- * If the entityManager is not injected, TaskManagementConfigurationException is expected. - */ - @Test (expected = TaskManagementConfigurationException.class) - public void testCheckInitializationMissingEntityManager() { - BaseJPAService baseService = new BaseJPAService() { - }; - EntityManager entityManager = null; - Log log = mockTestService.getTestLog(); - NotificationService notificationService = mockTestService.getTestNotificationService(); - UserService userService = mockTestService.getTestUserService(); - - baseService.setEntityManager(entityManager); - baseService.setLog(log); - baseService.setNotificationService(notificationService); - baseService.setUserService(userService); - - baseService.checkInitialization(); - } - - /** - *

- * Tests the method: {@link BaseJPAService#checkInitialization()}. - *

- * No exception should be thrown if all fields are properly injected. - */ - @Test - public void testCheckInitializationAccuracy() { - BaseJPAService baseService = new BaseJPAService() { - }; - EntityManager entityManager = mockTestService.getTestEntityManager(); - Log log = mockTestService.getTestLog(); - NotificationService notificationService = mockTestService.getTestNotificationService(); - UserService userService = mockTestService.getTestUserService(); - - baseService.setEntityManager(entityManager); - baseService.setLog(log); - baseService.setNotificationService(notificationService); - baseService.setUserService(userService); - - baseService.checkInitialization(); - - } - - /** - *

- * Tests the method: {@link BaseJPAService#checkInitialization()}. - *

- * The Log is optional field, no exception should be thrown if the log is null. - */ - @Test - public void testCheckInitializationMissingLog() { - BaseJPAService baseService = new BaseJPAService() { - }; - EntityManager entityManager = mockTestService.getTestEntityManager(); - Log log = null; - NotificationService notificationService = mockTestService.getTestNotificationService(); - UserService userService = mockTestService.getTestUserService(); - - baseService.setEntityManager(entityManager); - baseService.setLog(log); - baseService.setNotificationService(notificationService); - baseService.setUserService(userService); - - baseService.checkInitialization(); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setLog(Log log)}. - *

- *

- * Checks if the log is null, the log is properly set. - *

- */ - @Test - public void testSetLogNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - Log log = null; - // set the log to the baseJPAService - baseJPAService.setLog(log); - // checks if the log is properly set - Assert.assertEquals("The log is not properly set if is null", log, baseJPAService.getLog()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setLog(Log log)}. - *

- *

- * Checks if the log is not null, the log is properly set. - *

- */ - @Test - public void testSetLogNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - Log log = mockTestService.getTestLog(); - // set the log to the baseJPAService - baseJPAService.setLog(log); - // checks if the log is properly set - Assert.assertEquals("The log is not properly set if is not null", - log, baseJPAService.getLog()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getLog()}. - *

- *

- * Checks if the log is null, the log can be properly retrieved. - *

- */ - @Test - public void testGetLogNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - Log log = null; - // set the log to the baseJPAService - baseJPAService.setLog(log); - // checks if the log is properly retrieved - Assert.assertEquals("The log is not properly set if is null", log, baseJPAService.getLog()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getLog()}. - *

- *

- * Checks if the log is not null, the log can be properly retrieved. - *

- */ - @Test - public void testGetLogNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - Log log = mockTestService.getTestLog(); - // set the log to the baseJPAService - baseJPAService.setLog(log); - // checks if the log is properly retrieved - Assert.assertEquals("The log is not properly set if is not null", - log, baseJPAService.getLog()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setUserService(UserService userService)}. - *

- *

- * Checks if the userService is null, the userService is properly set. - *

- */ - @Test - public void testSetUserServiceNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - UserService userService = null; - // set the userService to the baseJPAService - baseJPAService.setUserService(userService); - // checks if the userService is properly set - Assert.assertEquals("The userService is not properly set if is null", - userService, baseJPAService.getUserService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setUserService(UserService userService)}. - *

- *

- * Checks if the userService is not null, the userService is properly set. - *

- */ - @Test - public void testSetUserServiceNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - UserService userService = mockTestService.getTestUserService(); - // set the userService to the baseJPAService - baseJPAService.setUserService(userService); - // checks if the userService is properly set - Assert.assertEquals("The userService is not properly set if is not null", - userService, baseJPAService.getUserService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getUserService()}. - *

- *

- * Checks if the userService is null, the userService can be properly retrieved. - *

- */ - @Test - public void testGetUserServiceNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - UserService userService = null; - // set the userService to the baseJPAService - baseJPAService.setUserService(userService); - // checks if the userService is properly retrieved - Assert.assertEquals("The userService is not properly set if is null", - userService, baseJPAService.getUserService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getUserService()}. - *

- *

- * Checks if the userService is not null, the userService can be properly retrieved. - *

- */ - @Test - public void testGetUserServiceNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - UserService userService = mockTestService.getTestUserService(); - // set the userService to the baseJPAService - baseJPAService.setUserService(userService); - // checks if the userService is properly retrieved - Assert.assertEquals("The userService is not properly set if is not null", - userService, baseJPAService.getUserService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setEntityManager(EntityManager entityManager)}. - *

- *

- * Checks if the entityManager is null, the entityManager is properly set. - *

- */ - @Test - public void testSetEntityManagerNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - EntityManager entityManager = null; - // set the entityManager to the baseJPAService - baseJPAService.setEntityManager(entityManager); - // checks if the entityManager is properly set - Assert.assertEquals("The entityManager is not properly set if is null", - entityManager, baseJPAService.getEntityManager()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setEntityManager(EntityManager entityManager)}. - *

- *

- * Checks if the entityManager is not null, the entityManager is properly set. - *

- */ - @Test - public void testSetEntityManagerNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - EntityManager entityManager = mockTestService.getTestEntityManager(); - // set the entityManager to the baseJPAService - baseJPAService.setEntityManager(entityManager); - // checks if the entityManager is properly set - Assert.assertEquals("The entityManager is not properly set if is not null", - entityManager, baseJPAService.getEntityManager()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getEntityManager()}. - *

- *

- * Checks if the entityManager is null, the entityManager can be properly retrieved. - *

- */ - @Test - public void testGetEntityManagerNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - EntityManager entityManager = null; - // set the entityManager to the baseJPAService - baseJPAService.setEntityManager(entityManager); - // checks if the entityManager is properly retrieved - Assert.assertEquals("The entityManager is not properly set if is null", - entityManager, baseJPAService.getEntityManager()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getEntityManager()}. - *

- *

- * Checks if the entityManager is not null, the entityManager can be properly retrieved. - *

- */ - @Test - public void testGetEntityManagerNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - }; - // set the value - EntityManager entityManager = mockTestService.getTestEntityManager(); - // set the entityManager to the baseJPAService - baseJPAService.setEntityManager(entityManager); - // checks if the entityManager is properly retrieved - Assert.assertEquals("The entityManager is not properly set if is not null", - entityManager, baseJPAService.getEntityManager()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setNotificationService(NotificationService notificationService)}. - *

- *

- * Checks if the notificationService is null, the notificationService is properly set. - *

- */ - @Test - public void testSetNotificationServiceNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - - }; - // set the value - NotificationService notificationService = null; - // set the notificationService to the baseJPAService - baseJPAService.setNotificationService(notificationService); - // checks if the notificationService is properly set - Assert.assertEquals("The notificationService is not properly set if is null", - notificationService, baseJPAService.getNotificationService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#setNotificationService(NotificationService notificationService)}. - *

- *

- * Checks if the notificationService is not null, the notificationService is properly set. - *

- */ - @Test - public void testSetNotificationServiceNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - - }; - // set the value - NotificationService notificationService = mockTestService.getTestNotificationService(); - // set the notificationService to the baseJPAService - baseJPAService.setNotificationService(notificationService); - // checks if the notificationService is properly set - Assert.assertEquals("The notificationService is not properly set if is not null", - notificationService, baseJPAService.getNotificationService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getNotificationService()}. - *

- *

- * Checks if the notificationService is null, the notificationService can be properly retrieved. - *

- */ - @Test - public void testGetNotificationServiceNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - - }; - // set the value - NotificationService notificationService = null; - // set the notificationService to the baseJPAService - baseJPAService.setNotificationService(notificationService); - // checks if the notificationService is properly retrieved - Assert.assertEquals("The notificationService is not properly set if is null", - notificationService, baseJPAService.getNotificationService()); - } - - /** - *

- * Tests the method: {@link BaseJPAService#getNotificationService()}. - *

- *

- * Checks if the notificationService is not null, the notificationService can be properly retrieved. - *

- */ - @Test - public void testGetNotificationServiceNotNull() { - // create the BaseJPAService instance for unit tests - BaseJPAService baseJPAService = new BaseJPAService() { - - }; - // set the value - NotificationService notificationService = mockTestService.getTestNotificationService(); - // set the notificationService to the baseJPAService - baseJPAService.setNotificationService(notificationService); - // checks if the notificationService is properly retrieved - Assert.assertEquals("The notificationService is not properly set if is not null", - notificationService, baseJPAService.getNotificationService()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/BaseUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/BaseUnitTests.java deleted file mode 100644 index 62d01225c..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/BaseUnitTests.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; - -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import com.topcoder.service.user.User; -import com.topcoder.util.config.ConfigManager; - -/** - *

- * The base class of unit tests. - *

- * @author TCSDEVELOPER - * @version 1.0 - * - */ -public class BaseUnitTests { - - - /** - *

- * Represents the path of the test files. - *

- */ - private static final String TEST_FILES = "test_files" + File.separator; - - /** - *

- * Represents the configuration file. - *

- */ - private static final String TEST_CONFIG = TEST_FILES + "test.properties"; - - /** - *

- * Represents the spring application context for unit tests. - *

- */ - private static ApplicationContext ctx; - - /** - *

- * Represents the entity manager for unit tests. - *

- */ - private EntityManager entityManager; - - /** - *

- * Represents the configuration for unit tests. - *

- */ - private Properties properties; - - - - /** - *

- * Initializes the spring beans. - *

- */ - @BeforeClass - public static void init() { - ctx = new ClassPathXmlApplicationContext("spring.xml"); - } - - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Before - public void setUp() throws Exception { - - EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("entityManagerFactory"); - entityManager = emf.createEntityManager(); - - InputStream is = new FileInputStream(new File(TEST_CONFIG)); - properties = new Properties(); - properties.load(is); - is.close(); - - // set the config manager - ConfigManager cm = ConfigManager.getInstance(); - for (Iterator it = cm.getAllNamespaces(); it.hasNext();) { - String namespace = it.next(); - cm.removeNamespace(namespace); - } - clearDB(); - - // insert enums - insertEnums(); - } - - /** - *

- * Inserts the enum value to the database. - *

- * - * @throws Exception to JUnit. - */ - private void insertEnums() throws Exception { - executeSQL(TEST_FILES + "enums.sql"); - } - - /** - *

- * Tears down the test environment. - *

- * @throws Exception to JUnit. - */ - @After - public void tearDown() throws Exception { - clearDB(); - if (entityManager.isOpen()) { - entityManager.close(); - } - entityManager = null; - } - - /** - *

- * Gets the spring ApplicationContext for unit tests. - *

- * @return to ApplicationContext instance. - */ - protected ApplicationContext getApplicationContext() { - return ctx; - } - - /** - *

- * Creates a list of users for unit tests. - *

- * @return the list of created users. - */ - protected List createUsers() { - return this.createUsers(10); - } - - /** - *

- * Persists an object. - *

- * @param obj the object to persist. - * @param the type of the object. - */ - protected void persist(T obj) { - entityManager.getTransaction().begin(); - entityManager.persist(obj); - entityManager.getTransaction().commit(); - } - - /** - *

- * Clears the database. - *

- * @throws Exception to JUnit. - */ - private void clearDB() throws Exception { - executeSQL(TEST_FILES + "clear.sql"); - } - - /** - *

- * Executes the SQL statements in the file. - *

- * @param file the file. - * @throws Exception to JUnit. - */ - private void executeSQL(String file) throws Exception { - EntityManagerFactory emf = (EntityManagerFactory) ctx.getBean("entityManagerFactory"); - EntityManager em = emf.createEntityManager(); - em.getTransaction().begin(); - - final String[] values = readFile(file).split(";"); - - for (int i = 0; i < values.length; i++) { - final String sql = values[i].trim(); - if ((sql.length() != 0) && (!sql.startsWith("#"))) { - em.createNativeQuery(sql).executeUpdate(); - } - } - - em.getTransaction().commit(); - if (em.isOpen()) { - em.close(); - } - em = null; - } - - /** - *

- * Reads the content of a given file. - *

- * @param fileName the name of the file to read. - * @return a string represents the content. - * @throws IOException if any error occurs during reading. - */ - protected static String readFile(String fileName) throws IOException { - final Reader reader = new FileReader(fileName); - - try { - // Create a StringBuilder instance - final StringBuilder sb = new StringBuilder(); - - // Buffer for reading - final char[] buffer = new char[1024]; - - // Number of read chars - int k = 0; - - // Read characters and append to string builder - while ((k = reader.read(buffer)) != -1) { - sb.append(buffer, 0, k); - } - - // Return read content - return sb.toString(); - } finally { - try { - reader.close(); - } catch (final IOException ioe) { - // Ignore - } - } - } - - /** - *

- * Gets the entity manager. - *

- * @return the entity manager. - */ - protected EntityManager getEntityManager() { - return entityManager; - } - - /** - *

- * Creates the users. - *

- * @param userNum the number of the users. - * @return the created users. - */ - protected List createUsers(int userNum) { - List result = new ArrayList(); - for (int i = 0; i < userNum; i++) { - String handle = "tcs" + (i + 1); - String address = handle + "@126.com"; - User user = new User(); - user.setEmailAddress(address); - user.setHandle(handle); - persist(user); - result.add(user); - } - return result; - } - - /** - *

- * Gets value for field of given object. - *

- * @param obj the given object. - * @param field the field name. - * @return the field value. - */ - protected Object getField(Object obj, String field) { - Object value = null; - try { - Field declaredField = null; - try { - declaredField = obj.getClass().getDeclaredField(field); - } catch (final NoSuchFieldException e) { - // Ignore - } - if (declaredField == null) { - // From the superclass - declaredField = obj.getClass().getSuperclass().getDeclaredField(field); - } - - declaredField.setAccessible(true); - - try { - value = declaredField.get(obj); - } finally { - declaredField.setAccessible(false); - } - } catch (final IllegalAccessException e) { - // Ignore - } catch (final NoSuchFieldException e) { - // Ignore - } - if (value == null) { - throw new IllegalStateException("Failed to get the field:" + field); - } - return value; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationServiceTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationServiceTests.java deleted file mode 100644 index 11b96cf22..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/EmailEngineNotificationServiceTests.java +++ /dev/null @@ -1,852 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; -import org.springframework.context.ApplicationContext; - -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; -import com.topcoder.util.log.LogFactory; -import com.topcoder.util.log.LogManager; -import com.topcoder.util.log.log4j.Log4jLogFactory; - -/** - *

- * All unit tests class for EmailEngineNotificationService. - *

- * @author TCSDEVELOPER - * @version 1.0 - */ -public class EmailEngineNotificationServiceTests extends BaseUnitTests { - - /** - *

- * Represents the spring application context for unit tests. - *

- */ - private ApplicationContext ctx; - - /** - *

- * Represents the instance of NotificationService for unit tests. - *

- */ - private NotificationService notificationService; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(EmailEngineNotificationServiceTests.class); - } - - - - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - ctx = super.getApplicationContext(); - notificationService = (NotificationService) ctx.getBean("notificationService"); - } - - /** - *

- * Tests the constructor: {@link EmailEngineNotificationService#EmailEngineNotificationService()}. - *

- * Accuracy test to check if the instance can be created correctly. - * @throws Exception to JUnit. - */ - @Test - public void testEmailEngineNotificationService() throws Exception { - EmailEngineNotificationService instance = new EmailEngineNotificationService(); - assertNotNull("The instance cannot be created.", instance); - assertTrue("Should be the instance of EmailEngineNotificationService", - instance instanceof EmailEngineNotificationService); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * Accuracy test if all the fields are properly injected, no exceptions should be thrown. - *

- * @throws Exception to JUnit. - */ - @Test - public void testCheckInitialization() throws Exception { - - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - LogFactory factory = new Log4jLogFactory(); - Log log = factory.createLog("test_log"); - - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * Accuracy test if the optional log is not injected, no exceptions should be thrown. - *

- */ - @Test - public void testCheckInitializationMissingLog() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = null; - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the userService is not properly injected, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationMissingUserService() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = null; - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the sender is null, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationSenderNull() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = null; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the sender is empty, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationSenderEmpty() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = " "; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the create subject template is null, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationCreateSubjectTemplateNull() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = null; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the create subject template is empty, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationCreateSubjectTemplateEmpty() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = " "; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the create body template is null, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationCreateBodyTemplateNull() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = null; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the create body template is empty, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationCreateBodyTemplateEmpty() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = " "; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the status subject template is null, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationStatusSubjectTemplateNull() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = null; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the status subject template is empty, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationStatusSubjectTemplateEmpty() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = "test_files"; - String taskStatusChangeEmailSubjectTemplateText = " "; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the status body template is null, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationStatusBodyTemplateNull() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = null; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#checkInitialization()}. - *

- *

- * If the status body template is empty, TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationStatusBodyTemplateEmpty() { - LogManager.setLogFactory(new Log4jLogFactory()); - EmailEngineNotificationService bean = new EmailEngineNotificationService(); - - Log log = LogManager.getLog(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - String emailSender = "tc@tc.com"; - String taskCreationEmailBodyTemplatePath = "test_files"; - String taskCreationEmailSubjectTemplateText = "test_string"; - String taskStatusChangeEmailBodyTemplatePath = " "; - String taskStatusChangeEmailSubjectTemplateText = "test_string"; - - bean.setEmailSender(emailSender); - bean.setLog(log); - bean.setTaskCreationEmailBodyTemplatePath(taskCreationEmailBodyTemplatePath); - bean.setTaskCreationEmailSubjectTemplateText(taskCreationEmailSubjectTemplateText); - bean.setTaskStatusChangeEmailBodyTemplatePath(taskStatusChangeEmailBodyTemplatePath); - bean.setTaskStatusChangeEmailSubjectTemplateText(taskStatusChangeEmailSubjectTemplateText); - bean.setUserService(userService); - bean.checkInitialization(); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskStatusChange(long, TaskStatus, Task)} - * . - *

- * Accuracy tests to check if the task status change emails can be successfully sent. - * @throws Exception to JUnit. - */ - @Test - public void testNotifyTaskStatusChange() throws Exception { - List users = super.createUsers(); - // create the task to send the mail - Task task = new Task(); - List assignees = new ArrayList(); - for (User user : users) { - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - assignees.add(assignee); - } - task.setAssignees(assignees); - task.setStatus(TaskStatus.COMPLETED); - task.setName("Test Status Change Project"); - task.setCreatedBy(users.get(1).getHandle()); - notificationService.notifyTaskStatusChange(users.get(0).getUserId(), TaskStatus.IN_PROGRESS, task); - // the mails should send, and you will see it in the smtp dev null - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskStatusChange(long, TaskStatus, Task)} - * . - *

- * Exception should be thrown if the email cannot be sent. - * @throws Exception to JUnit. - */ - @Test (expected = NotificationException.class) - public void testNotifyTaskStatusChangeFailedToSend() throws Exception { - List users = super.createUsers(); - // create the task to send the mail - Task task = new Task(); - List assignees = new ArrayList(); - for (User user : users) { - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId() + 10001); - assignees.add(assignee); - } - task.setAssignees(assignees); - task.setStatus(TaskStatus.COMPLETED); - task.setName("Test Status Change Project"); - task.setCreatedBy(users.get(1).getHandle()); - notificationService.notifyTaskStatusChange(users.get(0).getUserId(), TaskStatus.IN_PROGRESS, task); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskStatusChange(long, TaskStatus, Task)} - * . - *

- * Accuracy tests to check if the task status change emails can be successfully sent, - * if the assignee is not the same as the created user. - * @throws Exception to JUnit. - */ - @Test - public void testNotifyTaskStatusChangeDiffrenUser() throws Exception { - List users = super.createUsers(); - // create the task to send the mail - Task task = new Task(); - List assignees = new ArrayList(); - for (User user : users) { - if (user.getUserId() == users.get(1).getUserId()) { - // ignore the creator - continue; - } - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - assignees.add(assignee); - } - task.setAssignees(assignees); - task.setStatus(TaskStatus.COMPLETED); - task.setName("Test Status Change Project"); - task.setCreatedBy(users.get(1).getHandle()); - notificationService.notifyTaskStatusChange(users.get(0).getUserId(), TaskStatus.IN_PROGRESS, task); - // the mails should send, and you will see it in the smtp dev null - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskStatusChange(long, TaskStatus, Task)} - * . - *

- * If the task is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test(expected = IllegalArgumentException.class) - public void testNotifyTaskStatusChangeInvalidTask() throws Exception { - List users = super.createUsers(); - notificationService.notifyTaskStatusChange(users.get(0).getUserId(), TaskStatus.IN_PROGRESS, null); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskCreation(long, Task)}. - *

- *

- * Accuracy test to check if the email can be successfully sent. - *

- * @throws Exception to JUnit. - */ - @Test - public void testNotifyTaskCreation() throws Exception { - List users = super.createUsers(); - // create the task to send the mail - Task task = new Task(); - List assignees = new ArrayList(); - for (User user : users) { - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - assignees.add(assignee); - } - task.setStartDate(new Date()); - task.setDueDate(new Date(new Date().getTime() + 86400 * 1000L * 5)); - task.setAssignees(assignees); - task.setName("Test Project"); - task.setStatus(TaskStatus.COMPLETED); - task.setPriority(TaskPriority.HIGH); - - // send the mail - notificationService.notifyTaskCreation(users.get(0).getUserId(), task); - - // the mails should send, and you will see it in the smtp dev null - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskCreation(long, Task)}. - *

- *

- * Accuracy test to check if the email can be successfully sent. - *

- * @throws Exception to JUnit. - */ - @Test - public void testNotifyTaskCreationDifferents() throws Exception { - List users = super.createUsers(); - // create the task to send the mail - - List assignees = new ArrayList(); - for (User user : users) { - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - assignees.add(assignee); - } - - TaskStatus[] statues = new TaskStatus[] { - TaskStatus.COMPLETED, - TaskStatus.IN_PROGRESS, - TaskStatus.NOT_STARTED, - TaskStatus.WAIT_ON_DEPENDENCY - }; - - TaskPriority [] priorities = new TaskPriority[] { - TaskPriority.HIGH, - TaskPriority.LOW, - TaskPriority.NORMAL - }; - - for (TaskStatus status : statues) { - for (TaskPriority priority : priorities) { - Task task = new Task(); - task.setStartDate(new Date()); - task.setDueDate(new Date(new Date().getTime() + 86400 * 1000L * 5)); - task.setAssignees(assignees); - task.setName("Test Project"); - task.setStatus(status); - task.setPriority(priority); - // send the mail - notificationService.notifyTaskCreation(users.get(0).getUserId(), task); - } - } - - // the mails should send, and you will see it in the smtp dev null - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskCreation(long, Task)}. - *

- *

- * If the task is null, IllegalArgumentException is expected. - *

- * @throws Exception to JUnit. - */ - @Test(expected = IllegalArgumentException.class) - public void testNotifyTaskCreationNullTask() throws Exception { - List users = super.createUsers(); - // send the mail - notificationService.notifyTaskCreation(users.get(0).getUserId(), null); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#notifyTaskCreation(long, Task)}. - *

- *

- * If the mail is failed to sent, NotificationException is expected. - *

- * @throws Exception to JUnit. - */ - @Test(expected = NotificationException.class) - public void testNotifyTaskCreationFailedToSend() throws Exception { - List users = super.createUsers(); - // create the task to send the mail - Task task = new Task(); - List assignees = new ArrayList(); - for (User user : users) { - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId() + 10001); - assignees.add(assignee); - } - task.setStartDate(new Date()); - task.setDueDate(new Date(new Date().getTime() + 86400 * 1000L * 5)); - task.setAssignees(assignees); - task.setName("Test Project"); - task.setStatus(TaskStatus.COMPLETED); - task.setPriority(TaskPriority.HIGH); - - // send the mail - notificationService.notifyTaskCreation(users.get(0).getUserId(), task); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#setUserService(UserService)}. - *

- * Accuracy test to check if the user service is successfully set. - * @throws Exception to JUnit. - */ - @Test - public void testSetUserService() throws Exception { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - UserService userService = (UserService) ctx.getBean("mockUserService"); - service.setUserService(userService); - UserService result = (UserService) super.getField(service, "userService"); - assertEquals("should be equal.", userService, result); - - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#setLog(Log)}. - *

- * Accuracy test to check if the log is successfully set. - * @throws Exception to JUnit. - */ - @Test - public void testSetLog() throws Exception { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - Log log = (Log) ctx.getBean("logBean"); - service.setLog(log); - Log result = (Log) super.getField(service, "log"); - assertEquals("should be equal.", log, result); - } - - /** - *

- * Tests the method: {@link EmailEngineNotificationService#setEmailSender(String)}. - *

- * Accuracy test to check if the email sender is successfully set. - */ - @Test - public void testSetEmailSender() { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - String sender = "tc@tc.com"; - service.setEmailSender(sender); - String result = (String) super.getField(service, "emailSender"); - assertEquals("should be equal.", sender, result); - } - - /** - *

- * Tests the method: - * {@link EmailEngineNotificationService#setTaskCreationEmailSubjectTemplateText(String)}. - *

- * Accuracy test to check if the create email subject is successfully set. - */ - @Test - public void testSetTaskCreationEmailSubjectTemplateText() { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - String value = "abc"; - service.setTaskCreationEmailSubjectTemplateText(value); - String result = (String) super.getField(service, "taskCreationEmailSubjectTemplateText"); - assertEquals("should be equal.", value, result); - } - - /** - *

- * Tests the method: - * {@link EmailEngineNotificationService#setTaskCreationEmailBodyTemplatePath(String)}. - *

- * Accuracy test to check if the creation body template is successfully set. - */ - @Test - public void testSetTaskCreationEmailBodyTemplatePath() { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - String value = "abc"; - service.setTaskCreationEmailBodyTemplatePath(value); - String result = (String) super.getField(service, "taskCreationEmailBodyTemplatePath"); - assertEquals("should be equal.", value, result); - } - - /** - *

- * Tests the method: - * {@link EmailEngineNotificationService#setTaskStatusChangeEmailSubjectTemplateText(String)} - *

- * Accuracy test to check if the status change subject is successfully set. - */ - @Test - public void testSetTaskStatusChangeEmailSubjectTemplateText() { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - String value = "abc"; - service.setTaskStatusChangeEmailSubjectTemplateText(value); - String result = (String) super.getField(service, "taskStatusChangeEmailSubjectTemplateText"); - assertEquals("should be equal.", value, result); - } - - /** - *

- * Tests the method: - * {@link EmailEngineNotificationService#setTaskStatusChangeEmailBodyTemplatePath(String)} - *

- * Accuracy test to check if the status change body template is successfully set. - */ - @Test - public void testSetTaskStatusChangeEmailBodyTemplatePath() { - EmailEngineNotificationService service = new EmailEngineNotificationService(); - String value = "abc"; - service.setTaskStatusChangeEmailBodyTemplatePath(value); - String result = (String) super.getField(service, "taskStatusChangeEmailBodyTemplatePath"); - assertEquals("should be equal.", value, result); - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/JPATaskListServiceTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/JPATaskListServiceTests.java deleted file mode 100644 index 8f197836b..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/JPATaskListServiceTests.java +++ /dev/null @@ -1,1728 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import javax.persistence.Query; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.MilestoneDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; - -/** - *

- * All unit tests for class: JPATaskListService. - *

- * @author TCSDEVELOPER - * @version 1.0 - * - */ -public class JPATaskListServiceTests extends BaseUnitTests { - - - /** - *

- * Represents the instance of TaskListService for unit tests. - *

- */ - private TaskListService taskListService; - - /** - *

- * Represents the bean for failure tests. - *

- */ - private JPATaskListService beanFailure; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(JPATaskListServiceTests.class); - } - - - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - taskListService = (TaskListService) super.getApplicationContext().getBean("taskListService"); - beanFailure = new JPATaskListService(); - beanFailure.setEntityManager(super.getEntityManager()); - NotificationService notificationService = - (NotificationService) super.getApplicationContext().getBean("notificationService"); - UserService userService = - (UserService) super.getApplicationContext().getBean("mockUserService"); - beanFailure.setNotificationService(notificationService); - beanFailure.setUserService(userService); - } - - /** - *

- * Tests the constructor: {@link JPATaskListService#JPATaskListService()}. - *

- * Accuracy test to check if the instance of JPATaskListService can be created correctly. - */ - @Test - public void testJPATaskListService() { - JPATaskListService instance = new JPATaskListService(); - assertNotNull("The instance is not created.", instance); - assertTrue("The instance cannot be created properly.", instance instanceof JPATaskListService); - } - - /** - *

- * Tests the method: {@link JPATaskListService#addTaskList(long, TaskList)}. - *

- * Accuracy test to check if the taskList can be added. - * @throws Exception to JUnit. - */ - @Test - public void testAddTaskList() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#addTaskList(long, TaskList)}. - *

- * If the task list is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskListNullTaskList() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - taskListService.addTaskList(user.getUserId(), null); - } - - /** - *

- * Tests the method: {@link JPATaskListService#addTaskList(long, TaskList)}. - *

- * If the user does not exist, PermissionException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testAddTaskListNotPermitted() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - taskListService.addTaskList(user.getUserId() + 10001, taskList); - } - - /** - *

- * Tests the method: {@link JPATaskListService#addTaskList(long, TaskList)}. - *

- * Accuracy test to check if the taskList can be added, mainly checking the boolean values. - * @throws Exception to JUnit. - */ - @Test - public void testAddTaskListBooleanFields() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - taskList.setActive(true); - taskList.setDefault(true); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - assertEquals("Should be active.", true, taskList.isActive()); - assertEquals("Should be default.", true, taskList.isDefault()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#updateTaskList(long, TaskList)}. - *

- *

- * Accuracy test to check if the taskList can be updated. - *

- * @throws Exception to JUnit. - */ - @Test - public void testUpdateTaskList() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - - // update the name of the taskList - result.setName("Test Update Project"); - // update it - taskListService.updateTaskList(users.get(1).getUserId(), result); - - // retrieve it from database - TaskList updatedResult = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("The name of the taskList should be updated.", "Test Update Project", updatedResult.getName()); - assertEquals("The modifier of the taskList should be updated.", - users.get(1).getHandle(), updatedResult.getLastModifiedBy()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#updateTaskList(long, TaskList)}. - *

- *

- * If the task list cannot be found, EntityNotFoundException is excpected. - *

- * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testUpdateTaskListOldTaskListNotFound() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - taskList.setId(123321); - taskListService.updateTaskList(user.getUserId(), taskList); - } - - /** - *

- * Tests the method: {@link JPATaskListService#updateTaskList(long, TaskList)}. - *

- *

- * If the task list is null, IllegalArgumentException is expected. - *

- * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testUpdateTaskListNullTaskList() throws Exception { - List users = super.createUsers(); - // update it - taskListService.updateTaskList(users.get(1).getUserId(), null); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListAccuracy() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is not exist, null should be returned. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListNotExist() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - TaskList result = taskListService.getTaskList(user.getUserId(), 10001); - assertNull("The id of the taskList should be updated.", result); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved if the operator is the creator. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListPermittedByCreator() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved if the task list is public to everyone. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListPermittedByPublic() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(users.get(1).getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved if the operator is in the permitted list. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListPermittedByPermittedUsers() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - List permittedUsers = new ArrayList(); - UserDTO dto = new UserDTO(); - dto.setHandle(users.get(2).getHandle()); - dto.setUserId(users.get(2).getUserId()); - permittedUsers.add(dto); - taskList.setPermittedUsers(permittedUsers); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(users.get(2).getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - // check if the permitted list is correct - assertEquals("should contains the permitted users", 1, result.getPermittedUsers().size()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * If the operator is not permitted, PermissionException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskListNotPermitted() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - List permittedUsers = new ArrayList(); - UserDTO dto = new UserDTO(); - dto.setHandle(users.get(2).getHandle()); - dto.setUserId(users.get(2).getUserId()); - permittedUsers.add(dto); - taskList.setPermittedUsers(permittedUsers); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // the user is not permitted - taskListService.getTaskList(users.get(3).getUserId(), result.getId()); - - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved, and mainly test the task list. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListAccuracyTasks() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task = new Task(); - task.setTaskListId(result.getId()); - task.setName("Task1"); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setStatus(TaskStatus.COMPLETED); - task.setPriority(TaskPriority.NORMAL); - persist(task); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("should contains the task.", 1, result.getTasks().size()); - Task task2 = result.getTasks().get(0); - assertEquals("should be equal", task.getStatus(), task2.getStatus()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved, and mainly test the permitted user list. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListAccuracyPermittedUsers() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - List permittedUsers = new ArrayList(); - UserDTO dto = new UserDTO(); - dto.setHandle(users.get(2).getHandle()); - dto.setUserId(users.get(2).getUserId()); - permittedUsers.add(dto); - taskList.setPermittedUsers(permittedUsers); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(users.get(2).getUserId(), result.getId()); - assertEquals("The name of the task should be equal.", result.getName(), taskList.getName()); - // check if the permitted list is correct - assertEquals("should contains the permitted users", 1, result.getPermittedUsers().size()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved, and mainly test the number of all tasks. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListAccuracyNumberOfAllTasks() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task1 = new Task(); - task1.setTaskListId(result.getId()); - task1.setName("Task1"); - task1.setCreatedBy(user.getHandle()); - task1.setCreatedDate(new Date()); - task1.setStatus(TaskStatus.COMPLETED); - task1.setPriority(TaskPriority.NORMAL); - persist(task1); - - Task task2 = new Task(); - task2.setTaskListId(result.getId()); - task2.setName("Task2"); - task2.setCreatedBy(user.getHandle()); - task2.setCreatedDate(new Date()); - task2.setStatus(TaskStatus.NOT_STARTED); - task2.setPriority(TaskPriority.NORMAL); - persist(task2); - - Task task3 = new Task(); - task3.setTaskListId(result.getId()); - task3.setName("Task3"); - task3.setCreatedBy(user.getHandle()); - task3.setCreatedDate(new Date()); - task3.setStatus(TaskStatus.COMPLETED); - task3.setPriority(TaskPriority.NORMAL); - persist(task3); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("should contains 3 tasks.", 3, result.getNumberOfAllTasks()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved, and mainly test the number of completed tasks. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListAccuracyNumberOfCompletedTasks() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task1 = new Task(); - task1.setTaskListId(result.getId()); - task1.setName("Task1"); - task1.setCreatedBy(user.getHandle()); - task1.setCreatedDate(new Date()); - task1.setStatus(TaskStatus.COMPLETED); - task1.setPriority(TaskPriority.NORMAL); - persist(task1); - - Task task2 = new Task(); - task2.setTaskListId(result.getId()); - task2.setName("Task2"); - task2.setCreatedBy(user.getHandle()); - task2.setCreatedDate(new Date()); - task2.setStatus(TaskStatus.NOT_STARTED); - task2.setPriority(TaskPriority.NORMAL); - persist(task2); - - Task task3 = new Task(); - task3.setTaskListId(result.getId()); - task3.setName("Task3"); - task3.setCreatedBy(user.getHandle()); - task3.setCreatedDate(new Date()); - task3.setStatus(TaskStatus.COMPLETED); - task3.setPriority(TaskPriority.NORMAL); - persist(task3); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("should contains 2 completed tasks.", 2, result.getNumberOfCompletedTasks()); - } - - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test to check if the task list is properly retrieved, and mainly test the contests and milestones. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskListAccuracyContestMileStore() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - List associatedToContests = new ArrayList(); - associatedToContests.add(project); - taskList.setAssociatedToContests(associatedToContests); - - List associatedToProjectMilestones = new ArrayList(); - MilestoneDTO milestone = new MilestoneDTO(); - milestone.setMilestoneName("milestone1"); - milestone.setMilestoneId(456); - persist(milestone); - associatedToProjectMilestones.add(milestone); - taskList.setAssociatedToProjectMilestones(associatedToProjectMilestones); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // find the taskList from the database - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("should contains 1 contest.", 1, result.getAssociatedToContests().size()); - assertEquals("should contains 1 milestone.", "milestone1", - result.getAssociatedToProjectMilestones().get(0).getMilestoneName()); - } - - - /** - *

- * Tests the method: {@link JPATaskListService#getDefaultTaskList(long, long)}. - *

- * Accuracy test to check if the default task list can be retrieved if there is no default task list. - * - * @throws Exception to JUnit. - */ - @Test - public void testGetDefaultTaskListNoDefault() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = taskListService.getDefaultTaskList(user.getUserId(), project.getContestId()); - assertEquals("should has the correct name", "Project Tasks List", taskList.getName()); - assertEquals("should be default", true, taskList.isDefault()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getDefaultTaskList(long, long)}. - *

- * Accuracy test to check if the default task list can be retrieved if there is default task list existed. - * - * @throws Exception to JUnit. - */ - @Test - public void testGetDefaultTaskListExistDefault() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = taskListService.getDefaultTaskList(user.getUserId(), project.getContestId()); - assertEquals("should has the correct name", "Project Tasks List", taskList.getName()); - - // should return the previous task list - taskList = taskListService.getDefaultTaskList(user.getUserId(), project.getContestId()); - assertEquals("should has the correct name", "Project Tasks List", taskList.getName()); - assertEquals("should be default", true, taskList.isDefault()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#deleteTaskList(long, long)}. - *

- * Accuracy test to check if the task list can be removed. - * @throws Exception to JUnit. - */ - @Test - public void testDeleteTaskList() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - - // add the task list - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - - // remove the task list - taskListService.deleteTaskList(user.getUserId(), result.getId()); - - // check the existence - assertNull("The task list should be removed.", - taskListService.getTaskList(user.getUserId(), taskList.getId())); - } - - /** - *

- * Tests the method: {@link JPATaskListService#deleteTaskList(long, long)}. - *

- * If the task list does not exist, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testDeleteTaskListNotExist() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - - // remove the task list - taskListService.deleteTaskList(user.getUserId(), 1); - } - - /** - *

- * Tests the method: {@link JPATaskListService#resolveTaskList(long, long)}. - *

- * Accuracy test to check if the task can be resolved. - * @throws Exception to JUnit. - */ - @Test - public void testResolveTaskList() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task = new Task(); - task.setTaskListId(result.getId()); - task.setName("Task1"); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setPriority(TaskPriority.NORMAL); - persist(task); - - Task task2 = new Task(); - task2.setTaskListId(result.getId()); - task2.setName("Task2"); - task2.setCreatedBy(user.getHandle()); - task2.setCreatedDate(new Date()); - task2.setStatus(TaskStatus.IN_PROGRESS); - task2.setPriority(TaskPriority.NORMAL); - persist(task2); - - // resolve the task list - taskListService.resolveTaskList(user.getUserId(), result.getId()); - - // check the status list - result = taskListService.getTaskList(user.getUserId(), result.getId()); - assertEquals("Should not be active.", false, result.isActive()); - assertEquals("Should have 2 tasks.", 2, result.getTasks().size()); - for (Task task3 : result.getTasks()) { - assertEquals("should be completed.", TaskStatus.COMPLETED, task3.getStatus()); - } - } - - /** - *

- * Tests the method: {@link JPATaskListService#resolveTaskList(long, long)}. - *

- * If the task list does not exist, EntityNotFoundException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testResolveTaskListNotExist() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - - // resolve the task list - taskListService.resolveTaskList(user.getUserId(), 100001); - - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * Accuracy test if the task is properly retrieved when the filter is null. - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskLists() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - List result = taskListService.getTaskLists(users.get(0).getUserId(), null); - assertEquals("should have 8 result.", 8, result.size()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when task name in the filter is null. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsNullTaskName() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertEquals("should have 8 result.", 8, result.size()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when task name in the filter is not exist. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskNameNotExist() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setName("NOT_EXIST"); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertEquals("not exist task name.", 0, result.size()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when assignee in the filter does not exist. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskAssigneeIdNotExist() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setAssigneeId(new Long(100001)); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertEquals("not exist task assignee.", 0, result.size()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when assignee in the filter exists. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskAssigneeIdExist() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setAssigneeId(users.get(0).getUserId()); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist task assignee.", result.size() > 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the dueDateFrom or dueDateTo is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskDueDate() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setDueDateFrom(new Date()); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist task from due date.", result.size() > 0); - - taskFilter.setDueDateTo(new Date(new Date().getTime() + 100L * 86400L * 1000L)); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist task to duedate.", result.size() > 0); - - // not exists - taskFilter.setDueDateTo(new Date(new Date().getTime() + 5L * 86400L * 1000L)); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("does not exist task to duedate.", result.size() == 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the status is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskStatus() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - List statuses = new ArrayList(); - statuses.add(TaskStatus.COMPLETED); - statuses.add(TaskStatus.WAIT_ON_DEPENDENCY); - taskFilter.setStatuses(statuses); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist task status.", result.size() > 0); - - statuses = new ArrayList(); - statuses.add(TaskStatus.WAIT_ON_DEPENDENCY); - taskFilter.setStatuses(statuses); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("not exist task status.", result.size() == 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the priority is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskPriority() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - List priorities = new ArrayList(); - priorities.add(TaskPriority.HIGH); - priorities.add(TaskPriority.LOW); - taskFilter.setPriorities(priorities); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist task priority.", result.size() > 0); - - priorities = new ArrayList(); - priorities.add(TaskPriority.NORMAL); - taskFilter.setPriorities(priorities); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("not exist task priority.", result.size() == 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the milestones is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsMilestones() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - List milestones = getEntityManager().createQuery( - "select milestone.milestoneId from MilestoneDTO milestone").getResultList(); - taskFilter.setAssociatedToProjectMilestoneIds(milestones); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist milestone.", result.size() > 0); - - milestones = new ArrayList(); - taskFilter.setAssociatedToProjectMilestoneIds(milestones); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("empty milestone.", result.size() > 0); - - milestones = new ArrayList(); - milestones.add(123321L); - taskFilter.setAssociatedToProjectMilestoneIds(milestones); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("not exist milestone.", result.size() == 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the contests is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsContests() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - List contests = getEntityManager().createQuery( - "select contest.contestId from ContestDTO contest").getResultList(); - taskFilter.setAssociatedToContestIds(contests); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist contest.", result.size() > 0); - - contests = new ArrayList(); - taskFilter.setAssociatedToContestIds(contests); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("empty contest.", result.size() > 0); - - contests = new ArrayList(); - contests.add(123321L); - taskFilter.setAssociatedToContestIds(contests); - result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("not exist contest.", result.size() == 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the projectIds is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsProjectIds() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - List contests = getEntityManager().createQuery( - "select contest.contestId from ContestDTO contest").getResultList(); - List projectIds = new ArrayList(); - projectIds.add(contests.get(0)); - taskFilter.setProjectIds(projectIds); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist projects.", result.size() > 0); - for (TaskList taskList : result) { - assertEquals("should be equal project", contests.get(0), new Long(taskList.getProjectId())); - } - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when the isActive is set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsActive() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setProjectActive(true); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist projects.", result.size() > 0); - for (TaskList taskList : result) { - assertEquals("should be active project", true, taskList.isActive()); - } - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when several fields are set. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsCombine() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setProjectActive(true); - List projectIds = new ArrayList(); - List contests = getEntityManager().createQuery( - "select contest.contestId from ContestDTO contest").getResultList(); - projectIds.add(contests.get(0)); - taskFilter.setProjectIds(projectIds); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist projects.", result.size() > 0); - for (TaskList taskList : result) { - assertEquals("should be active project", true, taskList.isActive()); - assertEquals("should be equal project", contests.get(0), new Long(taskList.getProjectId())); - } - } - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * - * Accuracy test if the task is properly retrieved when task name in the filter is null. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsTaskName() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setName("COMPLETED"); - List result = taskListService.getTaskLists(users.get(0).getUserId(), taskFilter); - assertTrue("exist task name.", result.size() > 0); - } - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskListsWithTasks(long, TaskFilter)}. - *

- * - * Accuracy test to check if the tasks can be loaded. - * - * @throws Exception to JUnit. - */ - @SuppressWarnings("unchecked") - @Test - public void testGetTaskListsWithTasks() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - List users = query.getResultList(); - TaskFilter taskFilter = new TaskFilter(); - taskFilter.setName("COMPLETED"); - List result = taskListService.getTaskListsWithTasks(users.get(0).getUserId(), taskFilter); - assertTrue("exist task name.", result.size() > 0); - for (TaskList taskList : result) { - List tasks = taskList.getTasks(); - boolean containsCompleted = false; - for (Task task : tasks) { - // check the task name - assertTrue("Should contains the name.", task.getName().startsWith("Task Name")); - if (task.getStatus() == TaskStatus.COMPLETED) { - containsCompleted = true; - } - } - assertTrue("should contains complete tasks.", containsCompleted); - } - } - - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskListsWithTasks(long, TaskFilter)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskListsWithTasksPermissionError() throws Exception { - taskListService.getTaskListsWithTasks(10001, null); - } - - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskLists(long, TaskFilter)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskListsWithPermissionError() throws Exception { - taskListService.getTaskLists(10001, null); - } - - /** - *

- * Tests the method: {@link JPATaskListService#resolveTaskList(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testResolveTaskListPermissionError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task = new Task(); - task.setTaskListId(result.getId()); - task.setName("Task1"); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setPriority(TaskPriority.NORMAL); - persist(task); - - Task task2 = new Task(); - task2.setTaskListId(result.getId()); - task2.setName("Task2"); - task2.setCreatedBy(user.getHandle()); - task2.setCreatedDate(new Date()); - task2.setStatus(TaskStatus.IN_PROGRESS); - task2.setPriority(TaskPriority.NORMAL); - persist(task2); - - // resolve the task list - taskListService.resolveTaskList(user.getUserId() + 1000, result.getId()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#resolveTaskList(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test(expected = PersistenceException.class) - public void testResolveTaskListPersistenceError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task = new Task(); - task.setTaskListId(result.getId()); - task.setName("Task1"); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setPriority(TaskPriority.NORMAL); - persist(task); - - Task task2 = new Task(); - task2.setTaskListId(result.getId()); - task2.setName("Task2"); - task2.setCreatedBy(user.getHandle()); - task2.setCreatedDate(new Date()); - task2.setStatus(TaskStatus.IN_PROGRESS); - task2.setPriority(TaskPriority.NORMAL); - persist(task2); - - // resolve the task list - beanFailure.resolveTaskList(user.getUserId(), result.getId()); - } - - /** - *

- * Tests the method: {@link JPATaskListService#resolveTaskList(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test(expected = NotificationException.class) - public void testResolveTaskListNotificationError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - assertTrue("The id of the taskList should be updated.", result.getId() > 0); - - // create a task for that taskList - Task task = new Task(); - task.setTaskListId(result.getId()); - task.setName("Task1"); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setStatus(TaskStatus.IN_PROGRESS); - task.setPriority(TaskPriority.NORMAL); - persist(task); - - Task task2 = new Task(); - task2.setTaskListId(result.getId()); - task2.setName("Task2"); - task2.setCreatedBy(user.getHandle()); - task2.setCreatedDate(new Date()); - task2.setStatus(TaskStatus.IN_PROGRESS); - task2.setPriority(TaskPriority.NORMAL); - persist(task2); - - NotificationService notificationService = Mockito.mock(NotificationService.class); - Mockito.doThrow(NotificationException.class).when(notificationService).notifyTaskStatusChange( - Mockito.anyLong(), Mockito.any(TaskStatus.class), Mockito.any(Task.class)); - beanFailure.setNotificationService(notificationService); - - try { - // resolve the task list - super.getEntityManager().getTransaction().begin(); - beanFailure.resolveTaskList(user.getUserId(), result.getId()); - super.getEntityManager().getTransaction().commit(); - } catch (Exception e) { - super.getEntityManager().getTransaction().rollback(); - throw e; - } - } - - /** - *

- * Tests the method: {@link JPATaskListService#deleteTaskList(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testDeleteTaskListPermissionError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - - // add the task list - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - - // remove the task list - taskListService.deleteTaskList(user.getUserId() + 1000, result.getId()); - } - - - /** - *

- * Tests the method: {@link JPATaskListService#getDefaultTaskList(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetDefaultTaskListPermissionError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - taskListService.getDefaultTaskList(user.getUserId() + 1000, project.getContestId()); - } - - - /** - *

- * Tests the method: {@link JPATaskListService#getTaskList(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskListWithPermissionError() throws Exception { - createTaskLists(); - // get a user - Query query = super.getEntityManager().createQuery("select u from UserDTO u"); - @SuppressWarnings("unchecked") - List users = query.getResultList(); - taskListService.getTaskLists(users.get(0).getUserId() + 1000, null); - } - - /** - *

- * Tests the method: {@link JPATaskListService#updateTaskList(long, TaskList)}. - *

- * @throws Exception to JUnit. - */ - @Test(expected = PersistenceException.class) - public void testUpdateTaskListWithPersistenceError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - - // update the name of the taskList - result.setName("Test Update Project"); - // update it - beanFailure.updateTaskList(users.get(1).getUserId(), result); - } - - /** - *

- * Tests the method: {@link JPATaskListService#updateTaskList(long, TaskList)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testUpdateTaskListWithPermissionError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - TaskList result = taskListService.addTaskList(user.getUserId(), taskList); - - // update the name of the taskList - result.setName("Test Update Project"); - // update it - taskListService.updateTaskList(users.get(1).getUserId() + 1000, result); - } - - /** - *

- * Tests the method: {@link JPATaskListService#addTaskList(long, TaskList)}. - *

- * @throws Exception to JUnit. - */ - @Test(expected = PersistenceException.class) - public void testAddTaskListWithPersistenceError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - beanFailure.addTaskList(user.getUserId(), taskList); - } - - /** - *

- * Tests the method: {@link JPATaskListService#addTaskList(long, TaskList)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testAddTaskListWithPermissionError() throws Exception { - List users = super.createUsers(); - User user = users.get(0); - ContestDTO project = new ContestDTO(); - project.setContestId(123); - project.setContestName("Test Project"); - persist(project); - - TaskList taskList = new TaskList(); - long projectId = project.getContestId(); - taskList.setProjectId(projectId); - taskList.setName("Test TaskList"); - taskListService.addTaskList(user.getUserId() + 10001, taskList); - } - - - /** - *

- * Creates the task lists for unit tests. - *

- * @throws Exception to JUnit. - */ - private void createTaskLists() throws Exception { - List users = super.createUsers(2); - List contests = createContests(); - List milestones = createMilestones(contests); - - for (User user : users) { - for (int i = 0; i < 2; i++) { - createTaskLists(user, users, contests, milestones); - } - } - } - - - /** - *

- * Creates the mile stones for the given contests. - *

- * @param contests the contests to create. - * @return the milestones created. - */ - private List createMilestones(List contests) { - int id = 1; - List milestones = new ArrayList(); - for (int i = 0; i < contests.size(); i++) { - for (int j = 0; j < 2; j++) { - MilestoneDTO milestone = new MilestoneDTO(); - milestone.setMilestoneId(id++); - milestone.setMilestoneName("Milestone: " + id); - persist(milestone); - milestones.add(milestone); - } - } - return milestones; - } - - - /** - *

- * Creates the contests. - *

- * @return the created contests. - */ - private List createContests() { - List contests = new ArrayList(); - for (int i = 0; i < 2; i++) { - ContestDTO contest = new ContestDTO(); - contest.setContestId(i + 1); - contest.setContestName("Contest " + i + 1); - persist(contest); - contests.add(contest); - } - return contests; - } - - - /** - *

- * Creates the task lists. - *

- * @param user the user to create the task lists. - * @param users the users to be the assignees. - * @param contests the contests to associate. - * @param milestones the milestones to associate. - * @throws Exception to JUnit. - */ - private void createTaskLists(User user, List users, - List contests, List milestones) throws Exception { - createTaskList(user, users, contests, milestones, true); - createTaskList(user, users, contests, milestones, false); - } - - - /** - *

- * Create a task list. - *

- * @param user the user to create the task list. - * @param users the list of the users. - * @param contests the list of the contests. - * @param milestones the list of the milestones. - * @param isActive if true, the task list is active, otherwise false. - * @throws Exception to JUnit. - */ - private void createTaskList(User user, List users, - List contests, List milestones, boolean isActive) throws Exception { - TaskList taskList = new TaskList(); - taskList.setActive(isActive); - taskList.setAssociatedToContests(contests); - taskList.setAssociatedToProjectMilestones(milestones); - taskList.setCreatedBy(user.getHandle()); - taskList.setCreatedDate(new Date()); - taskList.setName("Acive:" + isActive + " taskList"); - List permittedUsers = new ArrayList(); - for (User u : users) { - UserDTO dto = new UserDTO(); - dto.setHandle(u.getHandle()); - dto.setUserId(u.getUserId()); - permittedUsers.add(dto); - } - taskList.setPermittedUsers(permittedUsers); - taskList.setProjectId(contests.get(0).getContestId()); - - taskList = taskListService.addTaskList(user.getUserId(), taskList); - - // create the tasks - TaskStatus[] statuses = new TaskStatus[] {TaskStatus.COMPLETED, TaskStatus.IN_PROGRESS}; - - TaskPriority[] priorities = new TaskPriority[] {TaskPriority.HIGH, TaskPriority.LOW}; - - for (TaskStatus status : statuses) { - for (TaskPriority priority : priorities) { - Task task = new Task(); - task.setStatus(status); - task.setAssignees(permittedUsers); - task.setAssociatedToContests(contests); - task.setAssociatedToProjectMilestones(milestones); - task.setPriority(priority); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setStartDate(new Date()); - task.setDueDate(new Date(new Date().getTime() + 86400L * 1000L * 10)); - task.setTaskListId(taskList.getId()); - task.setName("Task Name{" + taskList.getId() + "," + status + "," + priority); - persist(task); - } - } - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/JPATaskServiceTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/JPATaskServiceTests.java deleted file mode 100644 index ae6dbb50a..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/JPATaskServiceTests.java +++ /dev/null @@ -1,1690 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; -import java.util.SortedMap; - -import javax.persistence.EntityManager; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.springframework.context.ApplicationContext; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.NotificationException; -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.TaskService; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - -/** - *

- * All unit tests for class: JPATaskService. - *

- * - * @author TCSDEVELOPER - * @version 1.0 - * - */ -public class JPATaskServiceTests extends BaseUnitTests { - - /** - *

- * Represents the instance of TaskService for unit tests. - *

- */ - private TaskService taskService; - - - /** - *

- * Represents the created project for unit tests. - *

- */ - private ContestDTO contest; - - /** - *

- * Represents the created user for unit tests. - *

- */ - private User user; - - /** - *

- * Represents the created task list for unit tests. - *

- */ - private TaskList taskList; - - - /** - *

- * Represents the task service for failure tests. - *

- */ - private JPATaskService beanFailure; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(JPATaskServiceTests.class); - } - - - - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - ApplicationContext ctx = super.getApplicationContext(); - taskService = (TaskService) ctx.getBean("taskService"); - - user = super.createUsers(1).get(0); - contest = new ContestDTO(); - contest.setContestId(123); - contest.setContestName("test_contest"); - persist(contest); - - taskList = new TaskList(); - taskList.setActive(true); - taskList.setCreatedBy(user.getHandle()); - taskList.setCreatedDate(new Date()); - taskList.setProjectId(contest.getContestId()); - taskList.setName("task list name for test"); - // set the permitted users - UserDTO permittedUser = new UserDTO(); - permittedUser.setHandle(user.getHandle()); - permittedUser.setUserId(user.getUserId()); - List users = new ArrayList(); - users.add(permittedUser); - taskList.setPermittedUsers(users); - - persist(taskList); - - beanFailure = new JPATaskService(); - beanFailure.setEntityManager(super.getEntityManager()); - Log log = (Log) ctx.getBean("logBean"); - beanFailure.setLog(log); - NotificationService notificationService = (NotificationService) ctx.getBean("notificationService"); - beanFailure.setNotificationService(notificationService); - UserService userService = (UserService) ctx.getBean("mockUserService"); - beanFailure.setUserService(userService); - - String attacmentDirectory = "test_files" + File.separator + "attachments"; - TaskListService taskListService = (TaskListService) ctx.getBean("taskListService"); - beanFailure.setAttachmentDirectory(attacmentDirectory); - beanFailure.setTaskListService(taskListService); - } - - /** - *

- * Tests the method: {@link JPATaskService#checkInitialization()}. - *

- * Accuracy test if all fields are properly set, no exceptions should be thrown. - */ - @Test - public void testCheckInitialization() { - ApplicationContext ctx = super.getApplicationContext(); - JPATaskService bean = new JPATaskService(); - bean.setEntityManager(super.getEntityManager()); - Log log = (Log) ctx.getBean("logBean"); - bean.setLog(log); - NotificationService notificationService = (NotificationService) ctx.getBean("notificationService"); - bean.setNotificationService(notificationService); - UserService userService = (UserService) ctx.getBean("mockUserService"); - bean.setUserService(userService); - - String attacmentDirectory = "test_files" + File.separator + "attachments"; - TaskListService taskListService = (TaskListService) ctx.getBean("taskListService"); - bean.setAttachmentDirectory(attacmentDirectory); - bean.setTaskListService(taskListService); - - bean.checkInitialization(); - - } - - /** - *

- * Tests the method: {@link JPATaskService#checkInitialization()}. - *

- * Accuracy test if all fields are properly set, no exceptions should be thrown. - */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationNullDirectory() { - ApplicationContext ctx = super.getApplicationContext(); - JPATaskService bean = new JPATaskService(); - bean.setEntityManager(super.getEntityManager()); - Log log = (Log) ctx.getBean("logBean"); - bean.setLog(log); - NotificationService notificationService = (NotificationService) ctx.getBean("notificationService"); - bean.setNotificationService(notificationService); - UserService userService = (UserService) ctx.getBean("mockUserService"); - bean.setUserService(userService); - - String attacmentDirectory = null; - TaskListService taskListService = (TaskListService) ctx.getBean("taskListService"); - bean.setAttachmentDirectory(attacmentDirectory); - bean.setTaskListService(taskListService); - - bean.checkInitialization(); - - } - - /** - *

- * Tests the method: {@link JPATaskService#checkInitialization()}. - *

- * Accuracy test if all fields are properly set, no exceptions should be thrown. - */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationEmptyDirectory() { - ApplicationContext ctx = super.getApplicationContext(); - JPATaskService bean = new JPATaskService(); - bean.setEntityManager(super.getEntityManager()); - Log log = (Log) ctx.getBean("logBean"); - bean.setLog(log); - NotificationService notificationService = (NotificationService) ctx.getBean("notificationService"); - bean.setNotificationService(notificationService); - UserService userService = (UserService) ctx.getBean("mockUserService"); - bean.setUserService(userService); - - String attacmentDirectory = " "; - TaskListService taskListService = (TaskListService) ctx.getBean("taskListService"); - bean.setAttachmentDirectory(attacmentDirectory); - bean.setTaskListService(taskListService); - - bean.checkInitialization(); - - } - - /** - *

- * Tests the method: {@link JPATaskService#checkInitialization()}. - *

- * Accuracy test if all fields are properly set, no exceptions should be thrown. - */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckInitializationNullTaskListService() { - ApplicationContext ctx = super.getApplicationContext(); - JPATaskService bean = new JPATaskService(); - bean.setEntityManager(super.getEntityManager()); - Log log = (Log) ctx.getBean("logBean"); - bean.setLog(log); - NotificationService notificationService = (NotificationService) ctx.getBean("notificationService"); - bean.setNotificationService(notificationService); - UserService userService = (UserService) ctx.getBean("mockUserService"); - bean.setUserService(userService); - - String attacmentDirectory = "test_files" + File.separator + "attachments"; - TaskListService taskListService = null; - bean.setAttachmentDirectory(attacmentDirectory); - bean.setTaskListService(taskListService); - - bean.checkInitialization(); - - } - - /** - *

- * Tests the constructor: {@link JPATaskService#JPATaskService()}. - *

- * Accuracy test to check if the instance can be created properly. - */ - @Test - public void testJPATaskService() { - JPATaskService instance = new JPATaskService(); - assertNotNull("The instance cannot be created.", instance); - assertTrue("The instance should has correct type.", instance instanceof JPATaskService); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * Accuracy test to check if the task can be added. - * @throws Exception to JUnit. - */ - @Test - public void testAddTask() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - // set the assignee - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - List assignees = new ArrayList(); - assignees.add(assignee); - task.setAssignees(assignees); - Task result = taskService.addTask(user.getUserId(), task); - // email should be sent to the assignees - Task finalResult = taskService.getTask(user.getUserId(), result.getId()); - assertEquals("should has the same name.", "Task Name", finalResult.getName()); - assertEquals("assignees should be correct.", user.getHandle(), finalResult.getAssignees().get(0).getHandle()); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * If the task list id does not exist, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testAddTaskTaskListNotExists() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId() + 10001); - taskService.addTask(user.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * If the user is not permitted, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testAddTaskTaskListNoPermission() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - - User newUser = super.createUsers(1).get(0); - newUser.setHandle("NEW_USER"); - persist(newUser); - taskService.addTask(newUser.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * If the name of the task is null or empty, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskInvalidTaskName() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName(null); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - - taskService.addTask(user.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * If the name of the task is null or empty, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskInvalidTaskName2() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName(" "); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - - taskService.addTask(user.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * If the task is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskNullTask() throws Exception { - taskService.addTask(user.getUserId(), null); - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * Accuracy test to check if the task is updated. - * @throws Exception to JUnit. - */ - @Test - public void testUpdateTask() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - task.setStatus(TaskStatus.COMPLETED); - taskService.updateTask(user.getUserId(), task); - super.getEntityManager().clear(); - task = super.getEntityManager().find(Task.class, task.getId()); - assertEquals("The task should be updated.", TaskStatus.COMPLETED, task.getStatus()); - // the notification email should send - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * If the old task does not exist, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testUpdateTaskNotFound() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - task.setStatus(TaskStatus.COMPLETED); - task.setId(10001); - taskService.updateTask(user.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * Accuracy test to check if the task status is not change, no email should send. - * @throws Exception to JUnit. - */ - @Test - public void testUpdateTaskNotChange() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - taskService.updateTask(user.getUserId(), task); - super.getEntityManager().clear(); - task = super.getEntityManager().find(Task.class, task.getId()); - assertEquals("The task should be updated.", TaskStatus.IN_PROGRESS, task.getStatus()); - // the notification email should not be send - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * Failure test if the task is not valid. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testUpdateTaskInvalidTask() throws Exception { - taskService.updateTask(user.getUserId(), null); - } - - /** - *

- * Tests the method: {@link JPATaskService#getTask(long, long)}. - *

- * Accuracy test to check if the task can be retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetTask() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - Task result = taskService.getTask(user.getUserId(), taskId); - assertEquals("should has the same name.", result.getName(), task.getName()); - } - /** - *

- * Tests the method: {@link JPATaskService#getTask(long, long)}. - *

- * Accuracy test to check if the task does not exist, null should be returned. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskNotExist() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - Task result = taskService.getTask(user.getUserId(), taskId + 10001); - assertNull("should be null.", result); - } - - - /** - *

- * Tests the method: {@link JPATaskService#getTask(long, long)}. - *

- * If the user is not permitted, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskNotPermitted() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - User newUser = super.createUsers().get(0); - newUser.setHandle("NEW_ONE"); - persist(newUser); - taskService.getTask(newUser.getUserId(), taskId); - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTask(long, long)}. - *

- * Accuracy test to check if the task can be deleted. - * @throws Exception to JUnit. - */ - @Test - public void testDeleteTask() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - taskService.deleteTask(user.getUserId(), taskId); - // find the task - super.getEntityManager().clear(); - task = super.getEntityManager().find(Task.class, taskId); - assertNull("The task should be deleted.", task); - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTask(long, long)}. - *

- * If the task does not exist, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testDeleteTaskNotExist() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - taskService.deleteTask(user.getUserId(), taskId + 10001); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTaskAttachment(long, TaskAttachment, InputStream)}. - *

- * Accuracy test to check if the attachment can be successfully added. - * @throws Exception to JUnit. - */ - @Test - public void testAddTaskAttachment() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abcde".getBytes()); - try { - taskService.addTaskAttachment(user.getUserId(), attachment, inputStream); - inputStream.close(); - inputStream = taskService.getTaskAttachmentContent(user.getUserId(), attachment.getId()); - // check the content - byte[] bytes = new byte[10240]; - int len = inputStream.read(bytes); - assertTrue("should contains content.", len > 0 && len < 10); - inputStream.close(); - } finally { - taskService.deleteTaskAttachment(user.getUserId(), attachment.getId()); - } - - } - - /** - *

- * Tests the method: {@link JPATaskService#addTaskAttachment(long, TaskAttachment, InputStream)}. - *

- * If the attachment is invalid, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskAttachmentInvalidAttachment() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abc".getBytes()); - taskService.addTaskAttachment(user.getUserId(), null, inputStream); - inputStream.close(); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTaskAttachment(long, TaskAttachment, InputStream)}. - *

- * If the attachment task is not found, EntityNotFoundException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testAddTaskAttachmentTaskNotFound() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId() + 1000); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abc".getBytes()); - taskService.addTaskAttachment(user.getUserId(), attachment, inputStream); - inputStream.close(); - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTaskAttachment(long, long). - *

- * Accuracy test to check if the attachment can be deleted. - * @throws Exception to JUnit. - */ - @Test - public void testDeleteTaskAttachment() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setCreatedBy(user.getHandle()); - attachment.setCreatedDate(new Date()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - attachment.setTaskId(task.getId()); - persist(attachment); - // create the file - File file = new File("test_files" + File.separator + "attachments" + File.separator + attachment.getId()); - try { - // write something to the attachment file - String content = "This is a test. Hahahahahha"; - OutputStream os = new FileOutputStream(file); - os.write(content.getBytes()); - os.close(); - - taskService.deleteTaskAttachment(user.getUserId(), attachment.getId()); - - assertFalse("the file should be deleted.", file.exists()); - - // entity is removed - super.getEntityManager().clear(); - assertNull("should be deleted", - super.getEntityManager().find(TaskAttachment.class, attachment.getId())); - } finally { - file.delete(); - } - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTaskAttachment(long, long). - *

- * EntityNotFoundException is expected if the attachment does not exist in the persistence. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testDeleteTaskAttachmenNotExistInPersistence() throws Exception { - taskService.deleteTaskAttachment(user.getUserId(), 10001); - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTaskAttachment(long, long). - *

- * If the file does not exist, throw PersistenceException. - * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testDeleteTaskAttachmentNotExitFile() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setCreatedBy(user.getHandle()); - attachment.setCreatedDate(new Date()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - attachment.setTaskId(task.getId()); - persist(attachment); - taskService.deleteTaskAttachment(user.getUserId(), attachment.getId()); - } - - /** - *

- * Tests the method: {@link JPATaskService#getTaskAttachmentContent(long, long)}. - *

- * Accuracy tests to check if the attachment content can be found. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskAttachmentContent() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setCreatedBy(user.getHandle()); - attachment.setCreatedDate(new Date()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - attachment.setTaskId(task.getId()); - persist(attachment); - // create the file - File file = new File("test_files" + File.separator + "attachments" + File.separator + attachment.getId()); - try { - // write something to the attachment file - String content = "This is a test. Hahahahahha"; - OutputStream os = new FileOutputStream(file); - os.write(content.getBytes()); - os.close(); - - InputStream is = taskService.getTaskAttachmentContent(user.getUserId(), attachment.getId()); - // check the content - byte[] bytes = new byte[10240]; - int len = is.read(bytes); - assertTrue("should contains content.", len > 10); - is.close(); - } finally { - file.delete(); - } - } - - /** - *

- * Tests the method: {@link JPATaskService#getTaskAttachmentContent(long, long)}. - *

- * Accuracy tests to check if the attachment content can not be found, null should return. - * @throws Exception to JUnit. - */ - @Test - public void testGetTaskAttachmentContentNotExist() throws Exception { - InputStream is = taskService.getTaskAttachmentContent(user.getUserId(), 100001); - assertNull("null should return.", is); - } - - /** - *

- * Tests the method: {@link JPATaskService#getTaskAttachmentContent(long, long)}. - *

- * Accuracy tests to check if the attachment content can be found. - * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testGetTaskAttachmentContentFileNotFound() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setCreatedBy(user.getHandle()); - attachment.setCreatedDate(new Date()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - attachment.setTaskId(task.getId()); - persist(attachment); - - taskService.getTaskAttachmentContent(user.getUserId(), attachment.getId()); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * Accuracy tests to check if the order of the tasks are properly sorted. - */ - @Test - public void testGroupTasksByPriority() { - List taskLists = new ArrayList(); - TaskPriority[] priorityes = new TaskPriority[] {TaskPriority.LOW, TaskPriority.HIGH, TaskPriority.NORMAL}; - int totalTaskCount = 0; - for (int i = 0; i < 3; i++) { - TaskList taskList1 = new TaskList(); - List tasks = new ArrayList(); - for (TaskPriority priority : priorityes) { - for (int j = 0; j < 3; j++) { - Task task = new Task(); - task.setCreatedDate(new Date(new Date().getTime() - (long) (Math.random() * 1000))); - task.setPriority(priority); - tasks.add(task); - totalTaskCount++; - } - } - taskList1.setTasks(tasks); - taskLists.add(taskList1); - } - - int resultNum = 0; - SortedMap> result = taskService.groupTasksByPriority(taskLists); - for (TaskPriority priority : result.keySet()) { - List tasks = result.get(priority); - long prev = 0; - for (Task task : tasks) { - assertEquals("should group by priority.", priority, task.getPriority()); - // sorted by createdDate - assertTrue("should be ascending.", task.getCreatedDate().getTime() >= prev); - prev = task.getCreatedDate().getTime(); - resultNum++; - } - } - assertEquals("The total num should be equal.", totalTaskCount, resultNum); - - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * If the task list is null. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByPriorityNulLList() { - List taskLists = null; - taskService.groupTasksByPriority(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * If the task list contains null. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByPriorityContainsNull() { - List taskLists = new ArrayList(); - taskLists.add(null); - taskService.groupTasksByPriority(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * If the task list contains null tasks. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByPriorityNullTasks() { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = null; - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByPriority(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * If the task list contains null tasks. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByPriorityNullTask() { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - tasks.add(null); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByPriority(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * If the task list contains null priority. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByPriorityNullPriority() { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - task.setPriority(null); - task.setCreatedDate(new Date()); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByPriority(taskLists); - } - - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByPriority(List)}. - *

- * If the task list contains null created date. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByPriorityNullCreatedDate() { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - task.setPriority(TaskPriority.HIGH); - task.setCreatedDate(null); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByPriority(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByAssignee(List)}. - *

- * Accuracy test to check if the task lists are group by assignees. - * @throws Exception to JUnit. - */ - @Test - public void testGroupTasksByAssignee() throws Exception { - List taskLists = new ArrayList(); - UserDTO[] assignees = new UserDTO[] {new UserDTO(), new UserDTO(), new UserDTO(), new UserDTO()}; - int index = 1; - for (UserDTO assignee : assignees) { - assignee.setHandle("user_" + index++); - assignee.setUserId(index); - } - int totalTaskCount = 0; - for (int i = 0; i < 3; i++) { - TaskList taskList1 = new TaskList(); - List tasks = new ArrayList(); - - for (int j = 0; j < 3; j++) { - Task task = new Task(); - task.setCreatedDate(new Date(new Date().getTime() - (long) (Math.random() * 1000))); - task.setAssignees(Arrays.asList(assignees)); - tasks.add(task); - totalTaskCount++; - } - - taskList1.setTasks(tasks); - taskLists.add(taskList1); - } - - int resultNum = 0; - SortedMap> result = taskService.groupTasksByAssignee(taskLists); - // check the key set - result.keySet().containsAll(Arrays.asList(assignees)); - Arrays.asList(assignees).contains(result.keySet()); - for (UserDTO assignee : result.keySet()) { - List tasks = result.get(assignee); - long prev = 0; - - for (Task task : tasks) { - // sorted by createdDate - assertTrue("should be ascending.", task.getCreatedDate().getTime() >= prev); - prev = task.getCreatedDate().getTime(); - resultNum++; - } - } - assertEquals("The total num should be equal.", totalTaskCount * assignees.length, resultNum); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByAssignee(List)}. - *

- * If the assignees is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByAssigneeNullAssignee() throws Exception { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - List assignees = null; - task.setAssignees(assignees); - task.setCreatedDate(new Date()); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByAssignee(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByAssignee(List)}. - *

- * If the assignees is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByAssigneeContainsNullAssignee() throws Exception { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - List assignees = new ArrayList(); - assignees.add(null); - task.setAssignees(assignees); - task.setCreatedDate(new Date()); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByAssignee(taskLists); - } - - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByDueDate(List)}. - *

- * Accuracy test to check if the order of the tasks are properly sorted by dueDate. - * @throws Exception to JUnit. - */ - @Test - public void testGroupTasksByDueDate() throws Exception { - List taskLists = new ArrayList(); - DateFormat df = new SimpleDateFormat("yyyy.MM.dd"); - Date[] dueDates = - new Date[] {df.parse("2012.04.01"), df.parse("2012.04.02"), df.parse("2012.04.03"), df.parse("2012.04.04")}; - int totalTaskCount = 0; - for (int i = 0; i < 3; i++) { - TaskList taskList1 = new TaskList(); - List tasks = new ArrayList(); - for (Date dueDate : dueDates) { - for (int j = 0; j < 3; j++) { - Task task = new Task(); - task.setCreatedDate(new Date(new Date().getTime() - (long) (Math.random() * 1000))); - task.setDueDate(new Date(dueDate.getTime() + (long) (Math.random() * 1000L * 1000L))); - tasks.add(task); - totalTaskCount++; - } - } - taskList1.setTasks(tasks); - taskLists.add(taskList1); - } - - int resultNum = 0; - SortedMap> result = taskService.groupTasksByDueDate(taskLists); - // check the key set - result.keySet().containsAll(Arrays.asList(dueDates)); - Arrays.asList(dueDates).contains(result.keySet()); - for (Date dueDate : result.keySet()) { - List tasks = result.get(dueDate); - long prev = 0; - - for (Task task : tasks) { - assertEquals("should group by status.", df.format(dueDate), df.format(task.getDueDate())); - // sorted by createdDate - assertTrue("should be ascending.", task.getCreatedDate().getTime() >= prev); - prev = task.getCreatedDate().getTime(); - resultNum++; - } - } - assertEquals("The total num should be equal.", totalTaskCount, resultNum); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByDueDate(List)}. - *

- * If the due date in the task is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByDueDateNullDueDate() throws Exception { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - task.setDueDate(null); - task.setCreatedDate(new Date()); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByAssignee(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByStartDate(List)}. - *

- * Accuracy test to check if the order of the tasks are properly sorted by startDate. - * @throws Exception to JUnit. - */ - @Test - public void testGroupTasksByStartDate() throws Exception { - List taskLists = new ArrayList(); - DateFormat df = new SimpleDateFormat("yyyy.MM.dd"); - Date[] startDates = - new Date[] {df.parse("2012.04.01"), df.parse("2012.04.02"), df.parse("2012.04.03"), df.parse("2012.04.04")}; - int totalTaskCount = 0; - for (int i = 0; i < 3; i++) { - TaskList taskList1 = new TaskList(); - List tasks = new ArrayList(); - for (Date startDate : startDates) { - for (int j = 0; j < 3; j++) { - Task task = new Task(); - task.setCreatedDate(new Date(new Date().getTime() - (long) (Math.random() * 1000))); - task.setStartDate(new Date(startDate.getTime() + (long) (Math.random() * 1000L * 1000L))); - tasks.add(task); - totalTaskCount++; - } - } - taskList1.setTasks(tasks); - taskLists.add(taskList1); - } - - int resultNum = 0; - SortedMap> result = taskService.groupTasksByStartDate(taskLists); - // check the key set - result.keySet().containsAll(Arrays.asList(startDates)); - Arrays.asList(startDates).contains(result.keySet()); - for (Date startDate : result.keySet()) { - List tasks = result.get(startDate); - long prev = 0; - - for (Task task : tasks) { - assertEquals("should group by status.", df.format(startDate), df.format(task.getStartDate())); - // sorted by createdDate - assertTrue("should be ascending.", task.getCreatedDate().getTime() >= prev); - prev = task.getCreatedDate().getTime(); - resultNum++; - } - } - assertEquals("The total num should be equal.", totalTaskCount, resultNum); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByStartDate(List)}. - *

- * If the start date in the task is null, IllegalArgumentException is expected. - * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByDueDateNullStartDate() throws Exception { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - task.setStartDate(null); - task.setCreatedDate(new Date()); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByAssignee(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByStatus(List)}. - *

- * Accuracy tests to check if the order of the tasks are properly sorted. - */ - @Test - public void testGroupTasksByStatus() { - List taskLists = new ArrayList(); - TaskStatus[] statuses = - new TaskStatus[] {TaskStatus.COMPLETED, TaskStatus.IN_PROGRESS, TaskStatus.WAIT_ON_DEPENDENCY, - TaskStatus.NOT_STARTED}; - int totalTaskCount = 0; - for (int i = 0; i < 3; i++) { - TaskList taskList1 = new TaskList(); - List tasks = new ArrayList(); - for (TaskStatus status : statuses) { - for (int j = 0; j < 3; j++) { - Task task = new Task(); - task.setCreatedDate(new Date(new Date().getTime() - (long) (Math.random() * 1000))); - task.setStatus(status); - tasks.add(task); - totalTaskCount++; - } - } - taskList1.setTasks(tasks); - taskLists.add(taskList1); - } - - int resultNum = 0; - SortedMap> result = taskService.groupTasksByStatus(taskLists); - for (TaskStatus status : result.keySet()) { - List tasks = result.get(status); - long prev = 0; - for (Task task : tasks) { - assertEquals("should group by status.", status, task.getStatus()); - // sorted by createdDate - assertTrue("should be ascending.", task.getCreatedDate().getTime() >= prev); - prev = task.getCreatedDate().getTime(); - resultNum++; - } - } - assertEquals("The total num should be equal.", totalTaskCount, resultNum); - - } - - /** - *

- * Tests the method: {@link JPATaskService#groupTasksByStatus(List)}. - *

- * If the task list contains null status. - */ - @Test (expected = IllegalArgumentException.class) - public void testGroupTasksByStatusNullStatus() { - List taskLists = new ArrayList(); - taskList = new TaskList(); - List tasks = new ArrayList(); - Task task = new Task(); - task.setName("test name"); - task.setStatus(null); - task.setCreatedDate(new Date()); - tasks.add(task); - taskList.setTasks(tasks); - taskLists.add(taskList); - taskService.groupTasksByStatus(taskLists); - } - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfCompletedTasks(long, long)}. - *

- * Accuracy test to check if the number of the completed task is properly retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetNumberOfCompletedTasks() throws Exception { - createTask(TaskStatus.COMPLETED); - createTask(TaskStatus.NOT_STARTED); - createTask(TaskStatus.COMPLETED); - int num = taskService.getNumberOfCompletedTasks(user.getUserId(), contest.getContestId()); - assertEquals("2 completed tasks of the project.", 2, num); - } - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfCompletedTasks(long, long)}. - *

- * If the project is not found, EntityNotFoundException should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testGetNumberOfCompletedTasksProjectNotExist() throws Exception { - taskService.getNumberOfCompletedTasks(user.getUserId(), 10001); - } - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfCompletedTasks(long, long)}. - *

- * Accuracy test to check if the number of the completed task is properly retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetNumberOfCompletedTasksNo() throws Exception { - createTask(TaskStatus.NOT_STARTED); - createTask(TaskStatus.NOT_STARTED); - createTask(TaskStatus.NOT_STARTED); - int num = taskService.getNumberOfCompletedTasks(user.getUserId(), contest.getContestId()); - assertEquals("2 completed tasks of the project.", 0, num); - } - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfAllTasks(long, long)}. - *

- * Accuracy test to check if the tasks can be retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetNumberOfAllTasks() throws Exception { - // no task - int num = taskService.getNumberOfAllTasks(user.getUserId(), contest.getContestId()); - assertEquals("no task of the project.", 0, num); - } - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfAllTasks(long, long)}. - *

- * If the project is not found, EntityNotFoundException should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testGetNumberOfAllTasksProjectNotExist() throws Exception { - taskService.getNumberOfAllTasks(user.getUserId(), 10001); - } - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfAllTasks(long, long)}. - *

- * Accuracy test to check if the tasks can be retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetNumberOfAllTasksHasTasks() throws Exception { - createTask(TaskStatus.COMPLETED); - createTask(TaskStatus.NOT_STARTED); - int num = taskService.getNumberOfAllTasks(user.getUserId(), contest.getContestId()); - assertEquals("2 tasks of the project.", 2, num); - } - - /** - *

- * Creates a task for unit tests. - *

- * @param status the status of the task to create. - * @return the created task. - */ - private Task createTask(TaskStatus status) { - Task task = new Task(); - task.setStatus(status); - task.setPriority(TaskPriority.HIGH); - task.setCreatedBy(user.getHandle()); - task.setCreatedDate(new Date()); - task.setName("name"); - task.setNotes("something to note"); - task.setTaskListId(taskList.getId()); - persist(task); - return task; - } - - - /** - *

- * Tests the method: {@link JPATaskService#setTaskListService(TaskListService)}. - *

- * Accuracy test to check if the taskListService can be set. - */ - @Test - public void testSetTaskListService() { - JPATaskService service = new JPATaskService(); - TaskListService taskListService = - (TaskListService) super.getApplicationContext().getBean("taskListService"); - - service.setTaskListService(taskListService); - TaskListService value = (TaskListService) getField(service, "taskListService"); - assertEquals("should be equal.", value, taskListService); - } - - /** - *

- * Tests the method: {@link JPATaskService#setAttachmentDirectory(String)}. - *

- * Accuracy test to check if the attachmentDirectory can be successfully set. - * - * @throws Exception to JUnit. - */ - @Test - public void testSetAttachmentDirectory() throws Exception { - JPATaskService service = new JPATaskService(); - service.setAttachmentDirectory("abc"); - String value = (String) getField(service, "attachmentDirectory"); - assertEquals("should be equal.", value, "abc"); - } - - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfAllTasks(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetNumberOfAllTasksPermisionError() throws Exception { - taskService.getNumberOfAllTasks(user.getUserId() + 10001, contest.getContestId()); - } - - - /** - *

- * Tests the method: {@link JPATaskService#getNumberOfCompletedTasks(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetNumberOfCompletedTasksPermisionError() throws Exception { - taskService.getNumberOfCompletedTasks(user.getUserId() + 10001, contest.getContestId()); - } - - /** - *

- * Tests the method: {@link JPATaskService#getTaskAttachmentContent(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskAttachmentContentPermisionError() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setCreatedBy(user.getHandle()); - attachment.setCreatedDate(new Date()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - attachment.setTaskId(task.getId()); - persist(attachment); - // create the file - File file = new File("test_files" + File.separator + "attachments" + File.separator + attachment.getId()); - try { - // write something to the attachment file - String content = "This is a test. Hahahahahha"; - OutputStream os = new FileOutputStream(file); - os.write(content.getBytes()); - os.close(); - - taskService.getTaskAttachmentContent(user.getUserId() + 10000, attachment.getId()); - - } finally { - file.delete(); - } - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTaskAttachment(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testDeleteTaskAttachmentContentPermisionError() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setCreatedBy(user.getHandle()); - attachment.setCreatedDate(new Date()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - attachment.setTaskId(task.getId()); - persist(attachment); - // create the file - File file = new File("test_files" + File.separator + "attachments" + File.separator + attachment.getId()); - try { - // write something to the attachment file - String content = "This is a test. Hahahahahha"; - OutputStream os = new FileOutputStream(file); - os.write(content.getBytes()); - os.close(); - - taskService.deleteTaskAttachment(user.getUserId() + 1000, attachment.getId()); - - } finally { - file.delete(); - } - } - - /** - *

- * Tests the method: {@link JPATaskService#addTaskAttachment(long, TaskAttachment, InputStream)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testAddTaskAttachmentContentPersistenceError() throws Exception { - EntityManager entityManagerFailure = Mockito.mock(EntityManager.class); - Mockito.doThrow(javax.persistence.PersistenceException.class).when(entityManagerFailure).flush(); - beanFailure.setEntityManager(entityManagerFailure); - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abcde".getBytes()); - beanFailure.addTaskAttachment(user.getUserId(), attachment, inputStream); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTaskAttachment(long, - * TaskAttachment, InputStream)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testAddTaskAttachmentContentPermisionError() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abcde".getBytes()); - taskService.addTaskAttachment(user.getUserId() + 1000, attachment, inputStream); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTaskAttachment(long, TaskAttachment, InputStream)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskAttachmentContentIAE() throws Exception { - // create the task - Task task = createTask(TaskStatus.IN_PROGRESS); - // create the attachment - TaskAttachment attachment = new TaskAttachment(); - attachment.setTaskId(task.getId()); - attachment.setFileName("test_file"); - attachment.setMimeType("text"); - InputStream inputStream = new ByteArrayInputStream("abcde".getBytes()); - taskService.addTaskAttachment(user.getUserId(), null, inputStream); - } - - /** - *

- * Tests the method: {@link JPATaskService#deleteTask(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testDeleteTaskPermisionError() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - taskService.deleteTask(user.getUserId() + 1000, taskId); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testAddTaskIAE() throws Exception { - taskService.addTask(user.getUserId(), null); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testAddTaskPersistenceError() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - // set the assignee - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - List assignees = new ArrayList(); - assignees.add(assignee); - task.setAssignees(assignees); - beanFailure.addTask(user.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testAddTaskPermisionError() throws Exception { - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - // set the assignee - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - List assignees = new ArrayList(); - assignees.add(assignee); - task.setAssignees(assignees); - taskService.addTask(user.getUserId() + 1000, task); - } - - /** - *

- * Tests the method: {@link JPATaskService#addTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = NotificationException.class) - public void testAddTaskNotificationError() throws Exception { - NotificationService notificationService = Mockito.mock(NotificationService.class); - Mockito.doThrow(NotificationException.class).when(notificationService).notifyTaskCreation( - Mockito.anyLong(), Mockito.any(Task.class)); - beanFailure.setNotificationService(notificationService); - Task task = new Task(); - task.setStatus(TaskStatus.NOT_STARTED); - task.setName("Task Name"); - task.setPriority(TaskPriority.HIGH); - task.setTaskListId(taskList.getId()); - // set the assignee - UserDTO assignee = new UserDTO(); - assignee.setHandle(user.getHandle()); - assignee.setUserId(user.getUserId()); - List assignees = new ArrayList(); - assignees.add(assignee); - task.setAssignees(assignees); - try { - super.getEntityManager().getTransaction().begin(); - beanFailure.addTask(user.getUserId(), task); - super.getEntityManager().getTransaction().commit(); - } catch (Exception e) { - super.getEntityManager().getTransaction().rollback(); - throw e; - } - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testUpdateTaskPersistenceError() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - task.setStatus(TaskStatus.COMPLETED); - beanFailure.updateTask(user.getUserId(), task); - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = IllegalArgumentException.class) - public void testUpdateTaskIAE() throws Exception { - taskService.updateTask(user.getUserId(), null); - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testUpdateTaskPermisionError() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - task.setStatus(TaskStatus.COMPLETED); - taskService.updateTask(user.getUserId() + 1000, task); - } - - /** - *

- * Tests the method: {@link JPATaskService#updateTask(long, Task)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = NotificationException.class) - public void testUpdateTaskNotificationError() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - task.setStatus(TaskStatus.COMPLETED); - NotificationService notificationService = Mockito.mock(NotificationService.class); - Mockito.doThrow(NotificationException.class).when(notificationService).notifyTaskStatusChange( - Mockito.anyLong(), Mockito.any(TaskStatus.class), Mockito.any(Task.class)); - beanFailure.setNotificationService(notificationService); - try { - super.getEntityManager().clear(); - super.getEntityManager().getTransaction().begin(); - beanFailure.updateTask(user.getUserId(), task); - super.getEntityManager().getTransaction().commit(); - } catch (Exception e) { - super.getEntityManager().getTransaction().rollback(); - throw e; - } - } - - /** - *

- * Tests the method: {@link JPATaskService#getTask(long, long)}. - *

- * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetTaskPermisionError() throws Exception { - Task task = createTask(TaskStatus.IN_PROGRESS); - long taskId = task.getId(); - taskService.getTask(user.getUserId() + 1000, taskId); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/MockJPATestService.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/MockJPATestService.java deleted file mode 100644 index a4b8e9357..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/MockJPATestService.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import javax.persistence.EntityManager; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - - -/** - *

- * This class is a mock up class for testing the abstract class: BaseJPAService. - *

- * @author TCSDEVELOPER - * @version 1.0 - */ -public class MockJPATestService extends BaseJPAService implements MockTestService { - - /** - *

- * Gets the entity manager for unit tests. - *

- * @return the entity manager. - */ - public EntityManager getTestEntityManager() { - return super.getEntityManager(); - } - - /** - *

- * Gets the notification service for unit tests. - *

- * @return the notification service for unit tests. - */ - public NotificationService getTestNotificationService() { - return super.getNotificationService(); - } - - /** - *

- * Get the log for unit tests. - *

- * @return the log for unit tests. - */ - public Log getTestLog() { - return super.getLog(); - } - - /** - *

- * Get the user service for unit tests. - *

- * @return the user service for unit tests. - */ - public UserService getTestUserService() { - return super.getUserService(); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/MockTestService.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/MockTestService.java deleted file mode 100644 index 80c6813df..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/MockTestService.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import javax.persistence.EntityManager; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - -/** - *

- * A mock spring bean interface for unit tests. - *

- * @author TCSDEVELOPER - * @version 1.0 - * - */ -public interface MockTestService { - /** - *

- * Gets the entity manager for unit tests. - *

- * @return the entity manager. - */ - public EntityManager getTestEntityManager(); - - /** - *

- * Gets the notification service for unit tests. - *

- * @return the notification service for unit tests. - */ - public NotificationService getTestNotificationService(); - - /** - *

- * Get the log for unit tests. - *

- * @return the log for unit tests. - */ - public Log getTestLog(); - - /** - *

- * Get the user service for unit tests. - *

- * @return the user service for unit tests. - */ - public UserService getTestUserService(); -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/ServiceHelperTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/ServiceHelperTests.java deleted file mode 100644 index e5deaa618..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/impl/ServiceHelperTests.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import javax.persistence.EntityManager; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.EntityNotFoundException; -import com.topcoder.direct.services.project.task.PermissionException; -import com.topcoder.direct.services.project.task.PersistenceException; -import com.topcoder.direct.services.project.task.TaskManagementConfigurationException; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserService; -import com.topcoder.util.log.Log; - -/** - *

- * All unit tests for ServiceHelper. - *

- * - * @author TCSDEVELOPER - * @version 1.0 - * - */ -public class ServiceHelperTests extends BaseUnitTests { - - /** - *

- * Represents the logger for unit tests. - *

- */ - private Log log; - - /** - *

- * Represents the entity manager for unit tests. - *

- */ - private EntityManager entityManager; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ServiceHelperTests.class); - } - - - /** - *

- * Sets up the test environment. - *

- * @throws Exception to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - log = (Log) super.getApplicationContext().getBean("logBean"); - entityManager = super.getEntityManager(); - } - - /** - *

- * Accuracy test for the method logEntrance(Logger logger, String signature, String[] paramNames, - * Object[] params).
- * The result should be correct. - *

- */ - @Test - public void testLogEntrance1() { - ServiceHelper.logEntrance(log, "signature", new String[] {"p1", "p2"}, new Object[] {"v1", new Integer(12)}); - } - - /** - *

- * Accuracy test for the method logEntrance(Logger logger, String signature, String[] paramNames, - * Object[] params).
- * The result should be correct. - *

- */ - @Test - public void testLogEntrance2() { - ServiceHelper.logEntrance(log, "signature", null, null); - } - - /** - *

- * Accuracy test for the method logEntrance(Logger logger, String signature, String[] paramNames, - * Object[] params).
- * The result should be correct. - *

- */ - @Test - public void testLogEntrance3() { - ServiceHelper.logEntrance(null, "signature", null, null); - } - - /** - *

- * Accuracy test for the method - * logExit(Logger logger, String signature).
- * The result should be correct. - *

- */ - @Test - public void testLogExit1() { - ServiceHelper.logExit(log, "signature"); - } - - /** - *

- * Accuracy test for the method - * logExit(Logger logger, String signature, T obj).
- * The result should be correct. - *

- */ - @Test - public void testLogExit2() { - ServiceHelper.logExit(log, "signature", "return value"); - } - - /** - *

- * Accuracy test for the method - * logExit(Logger logger, String signature, T obj, boolean lazyFetch).
- * The result should be correct. - *

- */ - @Test - public void testLogExit3() { - ServiceHelper.logExit(log, "signature", "abc", false); - } - - /** - *

- * Accuracy test for the method logException(Logger logger, String signature, T exception).
- * The result should be correct. - *

- * - * @throws Exception - * to JUnit. - */ - @Test - public void testLogException1() throws Exception { - Throwable e = new Exception("Test"); - - ServiceHelper.logException(log, "signature", e); - } - - /** - *

- * Accuracy test for the method logException(Logger logger, String signature, T exception).
- * The result should be correct. - *

- * - * @throws Exception - * to JUnit. - */ - @Test - public void testLogException2() throws Exception { - log = null; - Throwable e = new Exception("Test"); - - ServiceHelper.logException(log, "signature", e); - } - - - /** - *

- * Tests failure of checkState(boolean isInvalid, String message) method with - * isInvalid is true.
- * TaskManagementConfigurationException is expected. - *

- */ - @Test(expected = TaskManagementConfigurationException.class) - public void testCheckState_Invalid() { - ServiceHelper.checkState(true, "message"); - } - - /** - *

- * Tests accuracy of checkState(boolean isInvalid, String message) method.
- * Result should be correct. - *

- */ - @Test - public void testCheckState() { - ServiceHelper.checkState(false, "message"); - - // Good - } - - /** - *

- * Tests accuracy of checkNull(Logger logger, String signature, Object value, String name) - * method.
- * Result should be correct. - *

- */ - @Test - public void testCheckNull() { - Object value = new Object(); - - ServiceHelper.checkNull(log, "signature", value, "name"); - - // Good - } - - /** - *

- * Tests failure of checkNullOrEmpty(Logger logger, String signature, String, String) method - * with value is null.
- * IllegalArgumentException is expected. - *

- */ - @Test(expected = IllegalArgumentException.class) - public void testCheckNullOrEmpty_Null() { - ServiceHelper.checkNullOrEmpty(log, "signature", null, "name"); - } - - /** - *

- * Tests failure of checkNullOrEmpty(Logger logger, String signature, String, String) method - * with value is empty.
- * IllegalArgumentException is expected. - *

- */ - @Test(expected = IllegalArgumentException.class) - public void testCheckNullOrEmpty_Empty() { - ServiceHelper.checkNullOrEmpty(log, "signature", "", "name"); - } - - /** - *

- * Tests failure of checkNullOrEmpty(Logger logger, String signature, String, String) method - * with value is trimmed empty.
- * IllegalArgumentException is expected. - *

- */ - @Test(expected = IllegalArgumentException.class) - public void testCheckNullOrEmpty_TrimmedEmpty() { - ServiceHelper.checkNullOrEmpty(log, "signature", " \t ", "name"); - } - - /** - *

- * Tests accuracy of checkNullOrEmpty(Logger logger, String signature, String, String) - * method.
- * Result should be correct. - *

- */ - @Test - public void testCheckNullOrEmpty() { - ServiceHelper.checkNullOrEmpty(log, "signature", "str", "name"); - - // Good - } - - - /** - *

- * Tests the method: {@link ServiceHelper#queryListResult(Log, String, EntityManager, String, Object[])}. - *

- * Accuracy test to check if the list result can be retrieved. - */ - @Test - public void testQueryListResult() { - super.createUsers(); - String query = "select u from UserDTO u"; - List users = ServiceHelper.queryListResult(log, "test", entityManager, query, null); - assertTrue("users can be retrieve.", users.size() > 0); - } - - /** - *

- * Tests the method: {@link ServiceHelper#querySingleResult(Log, String, EntityManager, String, Object[], Class)}. - *

- * Null should be return if the entity not found. - * @throws Exception to JUnit. - */ - @Test - public void testQuerySingleResultNotFound() throws Exception { - String query = "select u from UserDTO u where u.userId = ?1"; - UserDTO dto = ServiceHelper.querySingleResult( - log, "test", entityManager, query, new Object[] {1L}, UserDTO.class); - assertNull("should be null.", dto); - } - - /** - *

- * Tests the method: {@link ServiceHelper#querySingleResult(Log, String, EntityManager, String, Object[], Class)}. - *

- * Exception should be thrown if more than one result can get. - * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testQuerySingleResultMoreThanOne() throws Exception { - super.createUsers(); - String query = "select u from UserDTO u"; - ServiceHelper.querySingleResult( - log, "test", entityManager, query, null, UserDTO.class); - } - - /** - *

- * Tests the method: {@link ServiceHelper#querySingleResult(Log, String, EntityManager, String, Object[], Class)}. - *

- * If the type is invalid, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = PersistenceException.class) - public void testQuerySingleResultInvalidType() throws Exception { - User user = super.createUsers().get(0); - String query = "select u from UserDTO u where u.userId = ?1"; - ServiceHelper.querySingleResult( - log, "test", entityManager, query, new Object[] {user.getUserId()}, String.class); - } - - /** - *

- * Tests the method: {@link ServiceHelper#querySingleResult(Log, String, EntityManager, String, Object[], Class)}. - *

- * - * Accuracy test to check if the result can be retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testQuerySingleResultAccuracy() throws Exception { - User user = super.createUsers().get(0); - String query = "select u from UserDTO u where u.userId = ?1"; - UserDTO dto = ServiceHelper.querySingleResult( - log, "test", entityManager, query, new Object[] {user.getUserId()}, UserDTO.class); - assertEquals("should has the same handle.", user.getHandle(), dto.getHandle()); - } - - /** - *

- * Tests the method: {@link ServiceHelper#queryRecordNum(Log, String, EntityManager, String, Object[])}. - *

- * Accuracy to check if the records are correct. - * @throws Exception to JUnit. - */ - @Test - public void testQueryRecordNum() throws Exception { - String query = "select count(t) from Task t"; - int result = ServiceHelper.queryRecordNum(log, "test", entityManager, query, null); - assertEquals("should be zero.", 0, result); - } - - /** - *

- * Tests the method: {@link ServiceHelper#existsProject(Log, String, EntityManager, long)}. - *

- * Accuracy to check if the project exists. - * @throws Exception to JUnit. - */ - @Test - public void testExistsProject() throws Exception { - ContestDTO contest = new ContestDTO(); - contest.setContestId(123); - contest.setContestName("abc"); - persist(contest); - ServiceHelper.existsProject(log, "test", entityManager, contest.getContestId()); - // good - } - - /** - *

- * Tests the method: {@link ServiceHelper#existsProject(Log, String, EntityManager, long)}. - *

- * Exception should throw if no projects. - * @throws Exception to JUnit. - */ - @Test (expected = EntityNotFoundException.class) - public void testExistsProjectNotFound() throws Exception { - ServiceHelper.existsProject(log, "test", entityManager, 123); - // good - } - - /** - *

- * Tests the method: {@link ServiceHelper#getUserHandle(Log, String, UserService, long)}. - *

- * If the user does not exist, exception should be thrown. - * @throws Exception to JUnit. - */ - @Test (expected = PermissionException.class) - public void testGetUserHandleNotExist() throws Exception { - UserService userService = (UserService) super.getApplicationContext().getBean("mockUserService"); - ServiceHelper.getUserHandle(log, "test", userService, 888); - } - - /** - *

- * Tests the method: {@link ServiceHelper#getUserHandle(Log, String, UserService, long)}. - *

- * Accuracy test to check if the user handle can be retrieved. - * @throws Exception to JUnit. - */ - @Test - public void testGetUserHandle() throws Exception { - User user = super.createUsers().get(0); - UserService userService = (UserService) super.getApplicationContext().getBean("mockUserService"); - String handle = ServiceHelper.getUserHandle(log, "test", userService, user.getUserId()); - assertEquals("should be equal.", user.getHandle(), handle); - } - - /** - *

- * Tests the method: {@link ServiceHelper#flush(Log, String, EntityManager)}. - *

- * @throws Exception to JUnit. - */ - @Test - public void testFlush() throws Exception { - UserDTO userDTO = new UserDTO(); - userDTO.setHandle("abc"); - userDTO.setUserId(123); - entityManager.getTransaction().begin(); - entityManager.persist(userDTO); - // should flush to database - ServiceHelper.flush(log, "testFlush", entityManager); - entityManager.getTransaction().commit(); - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/AuditableEntityUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/AuditableEntityUnitTests.java deleted file mode 100644 index e2849e908..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/AuditableEntityUnitTests.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.Date; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link AuditableEntity} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class AuditableEntityUnitTests { - /** - *

- * Represents the AuditableEntity instance used in tests. - *

- */ - private AuditableEntity instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(AuditableEntityUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new MockAuditableEntity(); - } - - /** - *

- * AuditableEntity should be subclass of IdentifiableEntity. - *

- */ - @Test - public void testInheritance() { - assertTrue("AuditableEntity should be subclass of IdentifiableEntity.", - AuditableEntity.class.getSuperclass() == IdentifiableEntity.class); - } - - /** - *

- * Accuracy test for the constructor AuditableEntity().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new MockAuditableEntity(); - - assertNull("'createdDate' should be correct.", TestsHelper.getField(instance, "createdDate")); - assertNull("'createdBy' should be correct.", TestsHelper.getField(instance, "createdBy")); - assertNull("'lastModifiedDate' should be correct.", TestsHelper.getField(instance, "lastModifiedDate")); - assertNull("'lastModifiedBy' should be correct.", TestsHelper.getField(instance, "lastModifiedBy")); - } - - - /** - *

- * Accuracy test for the method getCreatedDate().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getCreatedDate() { - Date value = new Date(); - instance.setCreatedDate(value); - - assertSame("'getCreatedDate' should be correct.", - value, instance.getCreatedDate()); - } - - /** - *

- * Accuracy test for the method setCreatedDate(Date createdDate).
- * The value should be properly set. - *

- */ - @Test - public void test_setCreatedDate() { - Date value = new Date(); - instance.setCreatedDate(value); - - assertSame("'setCreatedDate' should be correct.", - value, TestsHelper.getField(instance, "createdDate")); - } - - /** - *

- * Accuracy test for the method getCreatedBy().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getCreatedBy() { - String value = "new_value"; - instance.setCreatedBy(value); - - assertEquals("'getCreatedBy' should be correct.", - value, instance.getCreatedBy()); - } - - /** - *

- * Accuracy test for the method setCreatedBy(String createdBy).
- * The value should be properly set. - *

- */ - @Test - public void test_setCreatedBy() { - String value = "new_value"; - instance.setCreatedBy(value); - - assertEquals("'setCreatedBy' should be correct.", - value, TestsHelper.getField(instance, "createdBy")); - } - - /** - *

- * Accuracy test for the method getLastModifiedDate().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getLastModifiedDate() { - Date value = new Date(); - instance.setLastModifiedDate(value); - - assertSame("'getLastModifiedDate' should be correct.", - value, instance.getLastModifiedDate()); - } - - /** - *

- * Accuracy test for the method setLastModifiedDate(Date lastModifiedDate).
- * The value should be properly set. - *

- */ - @Test - public void test_setLastModifiedDate() { - Date value = new Date(); - instance.setLastModifiedDate(value); - - assertSame("'setLastModifiedDate' should be correct.", - value, TestsHelper.getField(instance, "lastModifiedDate")); - } - - /** - *

- * Accuracy test for the method getLastModifiedBy().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getLastModifiedBy() { - String value = "new_value"; - instance.setLastModifiedBy(value); - - assertEquals("'getLastModifiedBy' should be correct.", - value, instance.getLastModifiedBy()); - } - - /** - *

- * Accuracy test for the method setLastModifiedBy(String lastModifiedBy).
- * The value should be properly set. - *

- */ - @Test - public void test_setLastModifiedBy() { - String value = "new_value"; - instance.setLastModifiedBy(value); - - assertEquals("'setLastModifiedBy' should be correct.", - value, TestsHelper.getField(instance, "lastModifiedBy")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/BaseTaskEntityUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/BaseTaskEntityUnitTests.java deleted file mode 100644 index 7fd23a3ac..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/BaseTaskEntityUnitTests.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link BaseTaskEntity} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class BaseTaskEntityUnitTests { - /** - *

- * Represents the BaseTaskEntity instance used in tests. - *

- */ - private BaseTaskEntity instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(BaseTaskEntityUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new MockBaseTaskEntity(); - } - - /** - *

- * BaseTaskEntity should be subclass of AuditableEntity. - *

- */ - @Test - public void testInheritance() { - assertTrue("BaseTaskEntity should be subclass of AuditableEntity.", - BaseTaskEntity.class.getSuperclass() == AuditableEntity.class); - } - - /** - *

- * Accuracy test for the constructor BaseTaskEntity().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new MockBaseTaskEntity(); - - assertNull("'name' should be correct.", TestsHelper.getField(instance, "name")); - assertNull("'notes' should be correct.", TestsHelper.getField(instance, "notes")); - assertNull("'associatedToProjectMilestones' should be correct.", - TestsHelper.getField(instance, "associatedToProjectMilestones")); - assertNull("'associatedToContests' should be correct.", TestsHelper.getField(instance, "associatedToContests")); - } - - - /** - *

- * Accuracy test for the method getName().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getName() { - String value = "new_value"; - instance.setName(value); - - assertEquals("'getName' should be correct.", - value, instance.getName()); - } - - /** - *

- * Accuracy test for the method setName(String name).
- * The value should be properly set. - *

- */ - @Test - public void test_setName() { - String value = "new_value"; - instance.setName(value); - - assertEquals("'setName' should be correct.", - value, TestsHelper.getField(instance, "name")); - } - - /** - *

- * Accuracy test for the method getNotes().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getNotes() { - String value = "new_value"; - instance.setNotes(value); - - assertEquals("'getNotes' should be correct.", - value, instance.getNotes()); - } - - /** - *

- * Accuracy test for the method setNotes(String notes).
- * The value should be properly set. - *

- */ - @Test - public void test_setNotes() { - String value = "new_value"; - instance.setNotes(value); - - assertEquals("'setNotes' should be correct.", - value, TestsHelper.getField(instance, "notes")); - } - - /** - *

- * Accuracy test for the method getAssociatedToProjectMilestones().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAssociatedToProjectMilestones() { - List value = new ArrayList(); - instance.setAssociatedToProjectMilestones(value); - - assertSame("'getAssociatedToProjectMilestones' should be correct.", - value, instance.getAssociatedToProjectMilestones()); - } - - /** - *

- * Accuracy test for the method setAssociatedToProjectMilestones(List<MilestoneDTO> - * associatedToProjectMilestones).
- * The value should be properly set. - *

- */ - @Test - public void test_setAssociatedToProjectMilestones() { - List value = new ArrayList(); - instance.setAssociatedToProjectMilestones(value); - - assertSame("'setAssociatedToProjectMilestones' should be correct.", - value, TestsHelper.getField(instance, "associatedToProjectMilestones")); - } - - /** - *

- * Accuracy test for the method getAssociatedToContests().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAssociatedToContests() { - List value = new ArrayList(); - instance.setAssociatedToContests(value); - - assertSame("'getAssociatedToContests' should be correct.", - value, instance.getAssociatedToContests()); - } - - /** - *

- * Accuracy test for the method setAssociatedToContests(List<ContestDTO> - * associatedToContests).
- * The value should be properly set. - *

- */ - @Test - public void test_setAssociatedToContests() { - List value = new ArrayList(); - instance.setAssociatedToContests(value); - - assertSame("'setAssociatedToContests' should be correct.", - value, TestsHelper.getField(instance, "associatedToContests")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/ContestDTOUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/ContestDTOUnitTests.java deleted file mode 100644 index c6d97ce07..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/ContestDTOUnitTests.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link ContestDTO} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class ContestDTOUnitTests { - /** - *

- * Represents the ContestDTO instance used in tests. - *

- */ - private ContestDTO instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(ContestDTOUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new ContestDTO(); - } - - /** - *

- * Accuracy test for the constructor ContestDTO().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new ContestDTO(); - - assertEquals("'contestId' should be correct.", 0L, TestsHelper.getField(instance, "contestId")); - assertNull("'contestName' should be correct.", TestsHelper.getField(instance, "contestName")); - } - - - /** - *

- * Accuracy test for the method getContestId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getContestId() { - long value = 1L; - instance.setContestId(value); - - assertEquals("'getContestId' should be correct.", - value, instance.getContestId()); - } - - /** - *

- * Accuracy test for the method setContestId(long contestId).
- * The value should be properly set. - *

- */ - @Test - public void test_setContestId() { - long value = 1L; - instance.setContestId(value); - - assertEquals("'setContestId' should be correct.", - value, TestsHelper.getField(instance, "contestId")); - } - - /** - *

- * Accuracy test for the method getContestName().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getContestName() { - String value = "new_value"; - instance.setContestName(value); - - assertEquals("'getContestName' should be correct.", - value, instance.getContestName()); - } - - /** - *

- * Accuracy test for the method setContestName(String contestName).
- * The value should be properly set. - *

- */ - @Test - public void test_setContestName() { - String value = "new_value"; - instance.setContestName(value); - - assertEquals("'setContestName' should be correct.", - value, TestsHelper.getField(instance, "contestName")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/IdentifiableEntityUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/IdentifiableEntityUnitTests.java deleted file mode 100644 index aa342f0a3..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/IdentifiableEntityUnitTests.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link IdentifiableEntity} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class IdentifiableEntityUnitTests { - /** - *

- * Represents the IdentifiableEntity instance used in tests. - *

- */ - private IdentifiableEntity instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(IdentifiableEntityUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new MockIdentifiableEntity(); - } - - /** - *

- * Accuracy test for the constructor IdentifiableEntity().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new MockIdentifiableEntity(); - - assertEquals("'id' should be correct.", 0L, TestsHelper.getField(instance, "id")); - } - - - /** - *

- * Accuracy test for the method getId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getId() { - long value = 1L; - instance.setId(value); - - assertEquals("'getId' should be correct.", - value, instance.getId()); - } - - /** - *

- * Accuracy test for the method setId(long id).
- * The value should be properly set. - *

- */ - @Test - public void test_setId() { - long value = 1L; - instance.setId(value); - - assertEquals("'setId' should be correct.", - value, TestsHelper.getField(instance, "id")); - } - - /** - *

- * Accuracy test for the method equals(Object obj).
- * The result should be correct. - *

- */ - @Test - public void test_equals_True1() { - instance.setId(1); - - Object obj = instance; - - assertTrue("'equals' should be correct.", instance.equals(obj)); - } - - /** - *

- * Accuracy test for the method equals(Object obj).
- * The result should be correct. - *

- */ - @Test - public void test_equals_True2() { - instance.setId(1); - - IdentifiableEntity obj = new MockIdentifiableEntity(); - obj.setId(1); - - assertTrue("'equals' should be correct.", instance.equals(obj)); - } - - /** - *

- * Accuracy test for the method equals(Object obj).
- * The result should be correct. - *

- */ - @Test - public void test_equals_False1() { - instance.setId(1); - - IdentifiableEntity obj = null; - - assertFalse("'equals' should be correct.", instance.equals(obj)); - } - - /** - *

- * Accuracy test for the method equals(Object obj).
- * The result should be correct. - *

- */ - @Test - public void test_equals_False2() { - instance.setId(1); - - IdentifiableEntity obj = new MockAuditableEntity(); - obj.setId(1); - - assertFalse("'equals' should be correct.", instance.equals(obj)); - } - - /** - *

- * Accuracy test for the method equals(Object obj).
- * The result should be correct. - *

- */ - @Test - public void test_equals_False3() { - instance.setId(1); - - IdentifiableEntity obj = new MockIdentifiableEntity(); - obj.setId(2); - - assertFalse("'equals' should be correct.", instance.equals(obj)); - } - - /** - *

- * Accuracy test for the method equals(Object obj).
- * The result should be correct. - *

- */ - @Test - public void test_equals_False4() { - instance.setId(1); - - Object obj = new Object(); - - assertFalse("'equals' should be correct.", instance.equals(obj)); - } - - /** - *

- * Accuracy test for the method hashCode().
- * The result should be correct. - *

- */ - @Test - public void test_hashCode_1() { - instance.setId(1); - - IdentifiableEntity obj = new MockIdentifiableEntity(); - obj.setId(1); - - assertTrue("'hashCode' should be correct.", obj.hashCode() == instance.hashCode()); - } - - /** - *

- * Accuracy test for the method hashCode().
- * The result should be correct. - *

- */ - @Test - public void test_hashCode_2() { - instance.setId(1); - - IdentifiableEntity obj = new MockIdentifiableEntity(); - obj.setId(2); - - assertFalse("'hashCode' should be correct.", obj.hashCode() == instance.hashCode()); - } - - /** - *

- * Accuracy test for the method hashCode().
- * The result should be correct. - *

- */ - @Test - public void test_hashCode_3() { - instance.setId(1); - - IdentifiableEntity obj = new MockAuditableEntity(); - obj.setId(1); - - assertFalse("'hashCode' should be correct.", obj.hashCode() == instance.hashCode()); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MilestoneDTOUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MilestoneDTOUnitTests.java deleted file mode 100644 index d9b3dbb9f..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MilestoneDTOUnitTests.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link MilestoneDTO} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class MilestoneDTOUnitTests { - /** - *

- * Represents the MilestoneDTO instance used in tests. - *

- */ - private MilestoneDTO instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(MilestoneDTOUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new MilestoneDTO(); - } - - /** - *

- * Accuracy test for the constructor MilestoneDTO().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new MilestoneDTO(); - - assertEquals("'milestoneId' should be correct.", 0L, TestsHelper.getField(instance, "milestoneId")); - assertNull("'milestoneName' should be correct.", TestsHelper.getField(instance, "milestoneName")); - } - - - /** - *

- * Accuracy test for the method getMilestoneId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getMilestoneId() { - long value = 1L; - instance.setMilestoneId(value); - - assertEquals("'getMilestoneId' should be correct.", - value, instance.getMilestoneId()); - } - - /** - *

- * Accuracy test for the method setMilestoneId(long milestoneId).
- * The value should be properly set. - *

- */ - @Test - public void test_setMilestoneId() { - long value = 1L; - instance.setMilestoneId(value); - - assertEquals("'setMilestoneId' should be correct.", - value, TestsHelper.getField(instance, "milestoneId")); - } - - /** - *

- * Accuracy test for the method getMilestoneName().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getMilestoneName() { - String value = "new_value"; - instance.setMilestoneName(value); - - assertEquals("'getMilestoneName' should be correct.", - value, instance.getMilestoneName()); - } - - /** - *

- * Accuracy test for the method setMilestoneName(String milestoneName).
- * The value should be properly set. - *

- */ - @Test - public void test_setMilestoneName() { - String value = "new_value"; - instance.setMilestoneName(value); - - assertEquals("'setMilestoneName' should be correct.", - value, TestsHelper.getField(instance, "milestoneName")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockAuditableEntity.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockAuditableEntity.java deleted file mode 100644 index e77a1249c..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockAuditableEntity.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - - -/** - *

- * A mockup class of abstract class AuditableEntity. Used for testing. - *

- * - * @author sparemax - * @version 1.0 - */ -@SuppressWarnings("serial") -public class MockAuditableEntity extends AuditableEntity { - /** - * Creates an instance of MockAuditableEntity. - */ - public MockAuditableEntity() { - // Empty - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockBaseTaskEntity.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockBaseTaskEntity.java deleted file mode 100644 index 0f8db86a3..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockBaseTaskEntity.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - - -/** - *

- * A mockup class of abstract class BaseTaskEntity. Used for testing. - *

- * - * @author sparemax - * @version 1.0 - */ -@SuppressWarnings("serial") -public class MockBaseTaskEntity extends BaseTaskEntity { - /** - * Creates an instance of MockBaseTaskEntity. - */ - public MockBaseTaskEntity() { - // Empty - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockIdentifiableEntity.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockIdentifiableEntity.java deleted file mode 100644 index 827626bc5..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/MockIdentifiableEntity.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - - -/** - *

- * A mockup class of abstract class IdentifiableEntity. Used for testing. - *

- * - * @author sparemax - * @version 1.0 - */ -@SuppressWarnings("serial") -public class MockIdentifiableEntity extends IdentifiableEntity { - /** - * Creates an instance of MockIdentifiableEntity. - */ - public MockIdentifiableEntity() { - // Empty - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskAttachmentUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskAttachmentUnitTests.java deleted file mode 100644 index f90d6ea36..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskAttachmentUnitTests.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link TaskAttachment} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskAttachmentUnitTests { - /** - *

- * Represents the TaskAttachment instance used in tests. - *

- */ - private TaskAttachment instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskAttachmentUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new TaskAttachment(); - } - - /** - *

- * TaskAttachment should be subclass of AuditableEntity. - *

- */ - @Test - public void testInheritance() { - assertTrue("TaskAttachment should be subclass of AuditableEntity.", - TaskAttachment.class.getSuperclass() == AuditableEntity.class); - } - - /** - *

- * Accuracy test for the constructor TaskAttachment().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new TaskAttachment(); - - assertNull("'fileName' should be correct.", TestsHelper.getField(instance, "fileName")); - assertNull("'mimeType' should be correct.", TestsHelper.getField(instance, "mimeType")); - assertEquals("'taskId' should be correct.", 0L, TestsHelper.getField(instance, "taskId")); - } - - - /** - *

- * Accuracy test for the method getFileName().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getFileName() { - String value = "new_value"; - instance.setFileName(value); - - assertEquals("'getFileName' should be correct.", - value, instance.getFileName()); - } - - /** - *

- * Accuracy test for the method setFileName(String fileName).
- * The value should be properly set. - *

- */ - @Test - public void test_setFileName() { - String value = "new_value"; - instance.setFileName(value); - - assertEquals("'setFileName' should be correct.", - value, TestsHelper.getField(instance, "fileName")); - } - - /** - *

- * Accuracy test for the method getMimeType().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getMimeType() { - String value = "new_value"; - instance.setMimeType(value); - - assertEquals("'getMimeType' should be correct.", - value, instance.getMimeType()); - } - - /** - *

- * Accuracy test for the method setMimeType(String mimeType).
- * The value should be properly set. - *

- */ - @Test - public void test_setMimeType() { - String value = "new_value"; - instance.setMimeType(value); - - assertEquals("'setMimeType' should be correct.", - value, TestsHelper.getField(instance, "mimeType")); - } - - /** - *

- * Accuracy test for the method getTaskId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getTaskId() { - long value = 1L; - instance.setTaskId(value); - - assertEquals("'getTaskId' should be correct.", - value, instance.getTaskId()); - } - - /** - *

- * Accuracy test for the method setTaskId(long taskId).
- * The value should be properly set. - *

- */ - @Test - public void test_setTaskId() { - long value = 1L; - instance.setTaskId(value); - - assertEquals("'setTaskId' should be correct.", - value, TestsHelper.getField(instance, "taskId")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskFilterUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskFilterUnitTests.java deleted file mode 100644 index bd5966b2d..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskFilterUnitTests.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link TaskFilter} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskFilterUnitTests { - /** - *

- * Represents the TaskFilter instance used in tests. - *

- */ - private TaskFilter instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskFilterUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new TaskFilter(); - } - - /** - *

- * Accuracy test for the constructor TaskFilter().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new TaskFilter(); - - assertNull("'name' should be correct.", TestsHelper.getField(instance, "name")); - assertNull("'assigneeId' should be correct.", TestsHelper.getField(instance, "assigneeId")); - assertNull("'dueDateFrom' should be correct.", TestsHelper.getField(instance, "dueDateFrom")); - assertNull("'dueDateTo' should be correct.", TestsHelper.getField(instance, "dueDateTo")); - assertNull("'priorities' should be correct.", TestsHelper.getField(instance, "priorities")); - assertNull("'statuses' should be correct.", TestsHelper.getField(instance, "statuses")); - assertNull("'associatedToProjectMilestoneIds' should be correct.", - TestsHelper.getField(instance, "associatedToProjectMilestoneIds")); - assertNull("'associatedToContestIds' should be correct.", - TestsHelper.getField(instance, "associatedToContestIds")); - assertNull("'projectIds' should be correct.", TestsHelper.getField(instance, "projectIds")); - assertNull("'isProjectActive' should be correct.", TestsHelper.getField(instance, "isProjectActive")); - } - - - /** - *

- * Accuracy test for the method getName().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getName() { - String value = "new_value"; - instance.setName(value); - - assertEquals("'getName' should be correct.", - value, instance.getName()); - } - - /** - *

- * Accuracy test for the method setName(String name).
- * The value should be properly set. - *

- */ - @Test - public void test_setName() { - String value = "new_value"; - instance.setName(value); - - assertEquals("'setName' should be correct.", - value, TestsHelper.getField(instance, "name")); - } - - /** - *

- * Accuracy test for the method getAssigneeId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAssigneeId() { - Long value = 1L; - instance.setAssigneeId(value); - - assertEquals("'getAssigneeId' should be correct.", - value, instance.getAssigneeId()); - } - - /** - *

- * Accuracy test for the method setAssigneeId(Long assigneeId).
- * The value should be properly set. - *

- */ - @Test - public void test_setAssigneeId() { - Long value = 1L; - instance.setAssigneeId(value); - - assertEquals("'setAssigneeId' should be correct.", - value, TestsHelper.getField(instance, "assigneeId")); - } - - /** - *

- * Accuracy test for the method getDueDateFrom().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getDueDateFrom() { - Date value = new Date(); - instance.setDueDateFrom(value); - - assertSame("'getDueDateFrom' should be correct.", - value, instance.getDueDateFrom()); - } - - /** - *

- * Accuracy test for the method setDueDateFrom(Date dueDateFrom).
- * The value should be properly set. - *

- */ - @Test - public void test_setDueDateFrom() { - Date value = new Date(); - instance.setDueDateFrom(value); - - assertSame("'setDueDateFrom' should be correct.", - value, TestsHelper.getField(instance, "dueDateFrom")); - } - - /** - *

- * Accuracy test for the method getDueDateTo().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getDueDateTo() { - Date value = new Date(); - instance.setDueDateTo(value); - - assertSame("'getDueDateTo' should be correct.", - value, instance.getDueDateTo()); - } - - /** - *

- * Accuracy test for the method setDueDateTo(Date dueDateTo).
- * The value should be properly set. - *

- */ - @Test - public void test_setDueDateTo() { - Date value = new Date(); - instance.setDueDateTo(value); - - assertSame("'setDueDateTo' should be correct.", - value, TestsHelper.getField(instance, "dueDateTo")); - } - - /** - *

- * Accuracy test for the method getPriorities().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getPriorities() { - List value = new ArrayList(); - instance.setPriorities(value); - - assertSame("'getPriorities' should be correct.", - value, instance.getPriorities()); - } - - /** - *

- * Accuracy test for the method setPriorities(List<TaskPriority> priorities).
- * The value should be properly set. - *

- */ - @Test - public void test_setPriorities() { - List value = new ArrayList(); - instance.setPriorities(value); - - assertSame("'setPriorities' should be correct.", - value, TestsHelper.getField(instance, "priorities")); - } - - /** - *

- * Accuracy test for the method getStatuses().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getStatuses() { - List value = new ArrayList(); - instance.setStatuses(value); - - assertSame("'getStatuses' should be correct.", - value, instance.getStatuses()); - } - - /** - *

- * Accuracy test for the method setStatuses(List<TaskStatus> statuses).
- * The value should be properly set. - *

- */ - @Test - public void test_setStatuses() { - List value = new ArrayList(); - instance.setStatuses(value); - - assertSame("'setStatuses' should be correct.", - value, TestsHelper.getField(instance, "statuses")); - } - - /** - *

- * Accuracy test for the method getAssociatedToProjectMilestoneIds().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAssociatedToProjectMilestoneIds() { - List value = new ArrayList(); - instance.setAssociatedToProjectMilestoneIds(value); - - assertSame("'getAssociatedToProjectMilestoneIds' should be correct.", - value, instance.getAssociatedToProjectMilestoneIds()); - } - - /** - *

- * Accuracy test for the method setAssociatedToProjectMilestoneIds(List<Long> - * associatedToProjectMilestoneIds).
- * The value should be properly set. - *

- */ - @Test - public void test_setAssociatedToProjectMilestoneIds() { - List value = new ArrayList(); - instance.setAssociatedToProjectMilestoneIds(value); - - assertSame("'setAssociatedToProjectMilestoneIds' should be correct.", - value, TestsHelper.getField(instance, "associatedToProjectMilestoneIds")); - } - - /** - *

- * Accuracy test for the method getAssociatedToContestIds().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAssociatedToContestIds() { - List value = new ArrayList(); - instance.setAssociatedToContestIds(value); - - assertSame("'getAssociatedToContestIds' should be correct.", - value, instance.getAssociatedToContestIds()); - } - - /** - *

- * Accuracy test for the method setAssociatedToContestIds(List<Long> associatedToContestIds).
- * The value should be properly set. - *

- */ - @Test - public void test_setAssociatedToContestIds() { - List value = new ArrayList(); - instance.setAssociatedToContestIds(value); - - assertSame("'setAssociatedToContestIds' should be correct.", - value, TestsHelper.getField(instance, "associatedToContestIds")); - } - - /** - *

- * Accuracy test for the method getProjectIds().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getProjectIds() { - List value = new ArrayList(); - instance.setProjectIds(value); - - assertSame("'getProjectIds' should be correct.", - value, instance.getProjectIds()); - } - - /** - *

- * Accuracy test for the method setProjectIds(List<Long> projectIds).
- * The value should be properly set. - *

- */ - @Test - public void test_setProjectIds() { - List value = new ArrayList(); - instance.setProjectIds(value); - - assertSame("'setProjectIds' should be correct.", - value, TestsHelper.getField(instance, "projectIds")); - } - - /** - *

- * Accuracy test for the method getProjectActive().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getProjectActive() { - Boolean value = true; - instance.setProjectActive(value); - - assertEquals("'getProjectActive' should be correct.", - value, instance.getProjectActive()); - } - - /** - *

- * Accuracy test for the method setProjectActive(Boolean isProjectActive).
- * The value should be properly set. - *

- */ - @Test - public void test_setProjectActive() { - Boolean value = true; - instance.setProjectActive(value); - - assertEquals("'setProjectActive' should be correct.", - value, TestsHelper.getField(instance, "isProjectActive")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskListUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskListUnitTests.java deleted file mode 100644 index 30af47051..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskListUnitTests.java +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link TaskList} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskListUnitTests { - /** - *

- * Represents the TaskList instance used in tests. - *

- */ - private TaskList instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskListUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new TaskList(); - } - - /** - *

- * TaskList should be subclass of BaseTaskEntity. - *

- */ - @Test - public void testInheritance() { - assertTrue("TaskList should be subclass of BaseTaskEntity.", - TaskList.class.getSuperclass() == BaseTaskEntity.class); - } - - /** - *

- * Accuracy test for the constructor TaskList().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new TaskList(); - - assertNull("'permittedUsers' should be correct.", TestsHelper.getField(instance, "permittedUsers")); - assertEquals("'projectId' should be correct.", 0L, TestsHelper.getField(instance, "projectId")); - assertEquals("'numberOfCompletedTasks' should be correct.", - 0, TestsHelper.getField(instance, "numberOfCompletedTasks")); - assertEquals("'numberOfAllTasks' should be correct.", 0, TestsHelper.getField(instance, "numberOfAllTasks")); - assertNull("'tasks' should be correct.", TestsHelper.getField(instance, "tasks")); - assertFalse("'isActive' should be correct.", (Boolean) TestsHelper.getField(instance, "isActive")); - assertFalse("'isDefault' should be correct.", (Boolean) TestsHelper.getField(instance, "isDefault")); - } - - - /** - *

- * Accuracy test for the method getPermittedUsers().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getPermittedUsers() { - List value = new ArrayList(); - instance.setPermittedUsers(value); - - assertSame("'getPermittedUsers' should be correct.", - value, instance.getPermittedUsers()); - } - - /** - *

- * Accuracy test for the method setPermittedUsers(List<UserDTO> permittedUsers).
- * The value should be properly set. - *

- */ - @Test - public void test_setPermittedUsers() { - List value = new ArrayList(); - instance.setPermittedUsers(value); - - assertSame("'setPermittedUsers' should be correct.", - value, TestsHelper.getField(instance, "permittedUsers")); - } - - /** - *

- * Accuracy test for the method getProjectId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getProjectId() { - long value = 1L; - instance.setProjectId(value); - - assertEquals("'getProjectId' should be correct.", - value, instance.getProjectId()); - } - - /** - *

- * Accuracy test for the method setProjectId(long projectId).
- * The value should be properly set. - *

- */ - @Test - public void test_setProjectId() { - long value = 1L; - instance.setProjectId(value); - - assertEquals("'setProjectId' should be correct.", - value, TestsHelper.getField(instance, "projectId")); - } - - /** - *

- * Accuracy test for the method getNumberOfCompletedTasks().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getNumberOfCompletedTasks() { - int value = 1; - instance.setNumberOfCompletedTasks(value); - - assertEquals("'getNumberOfCompletedTasks' should be correct.", - value, instance.getNumberOfCompletedTasks()); - } - - /** - *

- * Accuracy test for the method setNumberOfCompletedTasks(int numberOfCompletedTasks).
- * The value should be properly set. - *

- */ - @Test - public void test_setNumberOfCompletedTasks() { - int value = 1; - instance.setNumberOfCompletedTasks(value); - - assertEquals("'setNumberOfCompletedTasks' should be correct.", - value, TestsHelper.getField(instance, "numberOfCompletedTasks")); - } - - /** - *

- * Accuracy test for the method getNumberOfAllTasks().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getNumberOfAllTasks() { - int value = 1; - instance.setNumberOfAllTasks(value); - - assertEquals("'getNumberOfAllTasks' should be correct.", - value, instance.getNumberOfAllTasks()); - } - - /** - *

- * Accuracy test for the method setNumberOfAllTasks(int numberOfAllTasks).
- * The value should be properly set. - *

- */ - @Test - public void test_setNumberOfAllTasks() { - int value = 1; - instance.setNumberOfAllTasks(value); - - assertEquals("'setNumberOfAllTasks' should be correct.", - value, TestsHelper.getField(instance, "numberOfAllTasks")); - } - - /** - *

- * Accuracy test for the method getTasks().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getTasks() { - List value = new ArrayList(); - instance.setTasks(value); - - assertSame("'getTasks' should be correct.", - value, instance.getTasks()); - } - - /** - *

- * Accuracy test for the method setTasks(List<Task> tasks).
- * The value should be properly set. - *

- */ - @Test - public void test_setTasks() { - List value = new ArrayList(); - instance.setTasks(value); - - assertSame("'setTasks' should be correct.", - value, TestsHelper.getField(instance, "tasks")); - } - - /** - *

- * Accuracy test for the method isActive().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_isActive() { - boolean value = true; - instance.setActive(value); - - assertTrue("'isActive' should be correct.", instance.isActive()); - } - - /** - *

- * Accuracy test for the method setActive(boolean isActive).
- * The value should be properly set. - *

- */ - @Test - public void test_setActive() { - boolean value = true; - instance.setActive(value); - - assertTrue("'setActive' should be correct.", - (Boolean) TestsHelper.getField(instance, "isActive")); - } - - /** - *

- * Accuracy test for the method isDefault().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_isDefault() { - boolean value = true; - instance.setDefault(value); - - assertTrue("'isDefault' should be correct.", instance.isDefault()); - } - - /** - *

- * Accuracy test for the method setDefault(boolean isDefault).
- * The value should be properly set. - *

- */ - @Test - public void test_setDefault() { - boolean value = true; - instance.setDefault(value); - - assertTrue("'setDefault' should be correct.", - (Boolean) TestsHelper.getField(instance, "isDefault")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskPriorityUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskPriorityUnitTests.java deleted file mode 100644 index 3f2c22600..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskPriorityUnitTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Test; - -/** - *

- * Unit tests for {@link TaskPriority} enumeration. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskPriorityUnitTests { - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskPriorityUnitTests.class); - } - - /** - *

- * Accuracy test for the constant HIGH.
- * The value should be correct. - *

- */ - @Test - public void test_HIGH() { - assertEquals("'HIGH' should be correct.", "HIGH", TaskPriority.HIGH.toString()); - } - - /** - *

- * Accuracy test for the constant LOW.
- * The value should be correct. - *

- */ - @Test - public void test_LOW() { - assertEquals("'LOW' should be correct.", "LOW", TaskPriority.LOW.toString()); - } - - /** - *

- * Accuracy test for the constant NORMAL.
- * The value should be correct. - *

- */ - @Test - public void test_NORMAL() { - assertEquals("'NORMAL' should be correct.", "NORMAL", TaskPriority.NORMAL.toString()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskStatusUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskStatusUnitTests.java deleted file mode 100644 index 94fb32896..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskStatusUnitTests.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Test; - -/** - *

- * Unit tests for {@link TaskStatus} enumeration. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskStatusUnitTests { - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskStatusUnitTests.class); - } - - /** - *

- * Accuracy test for the constant NOT_STARTED.
- * The value should be correct. - *

- */ - @Test - public void test_NOT_STARTED() { - assertEquals("'NOT_STARTED' should be correct.", "NOT_STARTED", TaskStatus.NOT_STARTED.toString()); - } - - /** - *

- * Accuracy test for the constant IN_PROGRESS.
- * The value should be correct. - *

- */ - @Test - public void test_IN_PROGRESS() { - assertEquals("'IN_PROGRESS' should be correct.", "IN_PROGRESS", TaskStatus.IN_PROGRESS.toString()); - } - - /** - *

- * Accuracy test for the constant WAIT_ON_DEPENDENCY.
- * The value should be correct. - *

- */ - @Test - public void test_WAIT_ON_DEPENDENCY() { - assertEquals("'WAIT_ON_DEPENDENCY' should be correct.", "WAIT_ON_DEPENDENCY", - TaskStatus.WAIT_ON_DEPENDENCY.toString()); - } - - /** - *

- * Accuracy test for the constant COMPLETED.
- * The value should be correct. - *

- */ - @Test - public void test_COMPLETED() { - assertEquals("'COMPLETED' should be correct.", "COMPLETED", TaskStatus.COMPLETED.toString()); - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskUnitTests.java deleted file mode 100644 index 015879dac..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/TaskUnitTests.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link Task} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class TaskUnitTests { - /** - *

- * Represents the Task instance used in tests. - *

- */ - private Task instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TaskUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new Task(); - } - - /** - *

- * TaskList should be subclass of BaseTaskEntity. - *

- */ - @Test - public void testInheritance() { - assertTrue("TaskList should be subclass of BaseTaskEntity.", - TaskList.class.getSuperclass() == BaseTaskEntity.class); - } - - /** - *

- * Accuracy test for the constructor Task().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new Task(); - - assertNull("'startDate' should be correct.", TestsHelper.getField(instance, "startDate")); - assertNull("'dueDate' should be correct.", TestsHelper.getField(instance, "dueDate")); - assertNull("'assignees' should be correct.", TestsHelper.getField(instance, "assignees")); - assertNull("'priority' should be correct.", TestsHelper.getField(instance, "priority")); - assertNull("'attachments' should be correct.", TestsHelper.getField(instance, "attachments")); - assertNull("'status' should be correct.", TestsHelper.getField(instance, "status")); - assertEquals("'taskListId' should be correct.", 0L, TestsHelper.getField(instance, "taskListId")); - } - - - /** - *

- * Accuracy test for the method getStartDate().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getStartDate() { - Date value = new Date(); - instance.setStartDate(value); - - assertSame("'getStartDate' should be correct.", - value, instance.getStartDate()); - } - - /** - *

- * Accuracy test for the method setStartDate(Date startDate).
- * The value should be properly set. - *

- */ - @Test - public void test_setStartDate() { - Date value = new Date(); - instance.setStartDate(value); - - assertSame("'setStartDate' should be correct.", - value, TestsHelper.getField(instance, "startDate")); - } - - /** - *

- * Accuracy test for the method getDueDate().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getDueDate() { - Date value = new Date(); - instance.setDueDate(value); - - assertSame("'getDueDate' should be correct.", - value, instance.getDueDate()); - } - - /** - *

- * Accuracy test for the method setDueDate(Date dueDate).
- * The value should be properly set. - *

- */ - @Test - public void test_setDueDate() { - Date value = new Date(); - instance.setDueDate(value); - - assertSame("'setDueDate' should be correct.", - value, TestsHelper.getField(instance, "dueDate")); - } - - /** - *

- * Accuracy test for the method getAssignees().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAssignees() { - List value = new ArrayList(); - instance.setAssignees(value); - - assertSame("'getAssignees' should be correct.", - value, instance.getAssignees()); - } - - /** - *

- * Accuracy test for the method setAssignees(List<UserDTO> assignees).
- * The value should be properly set. - *

- */ - @Test - public void test_setAssignees() { - List value = new ArrayList(); - instance.setAssignees(value); - - assertSame("'setAssignees' should be correct.", - value, TestsHelper.getField(instance, "assignees")); - } - - /** - *

- * Accuracy test for the method getPriority().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getPriority() { - TaskPriority value = TaskPriority.HIGH; - instance.setPriority(value); - - assertEquals("'getPriority' should be correct.", - value, instance.getPriority()); - } - - /** - *

- * Accuracy test for the method setPriority(TaskPriority priority).
- * The value should be properly set. - *

- */ - @Test - public void test_setPriority() { - TaskPriority value = TaskPriority.HIGH; - instance.setPriority(value); - - assertEquals("'setPriority' should be correct.", - value, TestsHelper.getField(instance, "priority")); - } - - /** - *

- * Accuracy test for the method getAttachments().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getAttachments() { - List value = new ArrayList(); - instance.setAttachments(value); - - assertSame("'getAttachments' should be correct.", - value, instance.getAttachments()); - } - - /** - *

- * Accuracy test for the method setAttachments(List<TaskAttachment> attachments).
- * The value should be properly set. - *

- */ - @Test - public void test_setAttachments() { - List value = new ArrayList(); - instance.setAttachments(value); - - assertSame("'setAttachments' should be correct.", - value, TestsHelper.getField(instance, "attachments")); - } - - /** - *

- * Accuracy test for the method getStatus().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getStatus() { - TaskStatus value = TaskStatus.COMPLETED; - instance.setStatus(value); - - assertEquals("'getStatus' should be correct.", - value, instance.getStatus()); - } - - /** - *

- * Accuracy test for the method setStatus(TaskStatus status).
- * The value should be properly set. - *

- */ - @Test - public void test_setStatus() { - TaskStatus value = TaskStatus.COMPLETED; - instance.setStatus(value); - - assertEquals("'setStatus' should be correct.", - value, TestsHelper.getField(instance, "status")); - } - - /** - *

- * Accuracy test for the method getTaskListId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getTaskListId() { - long value = 1L; - instance.setTaskListId(value); - - assertEquals("'getTaskListId' should be correct.", - value, instance.getTaskListId()); - } - - /** - *

- * Accuracy test for the method setTaskListId(long taskListId).
- * The value should be properly set. - *

- */ - @Test - public void test_setTaskListId() { - long value = 1L; - instance.setTaskListId(value); - - assertEquals("'setTaskListId' should be correct.", - value, TestsHelper.getField(instance, "taskListId")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/UserDTOUnitTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/UserDTOUnitTests.java deleted file mode 100644 index f084cf977..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/model/UserDTOUnitTests.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import junit.framework.JUnit4TestAdapter; - -import org.junit.Before; -import org.junit.Test; - -import com.topcoder.direct.services.project.task.TestsHelper; - -/** - *

- * Unit tests for {@link UserDTO} class. - *

- * - * @author sparemax - * @version 1.0 - */ -public class UserDTOUnitTests { - /** - *

- * Represents the UserDTO instance used in tests. - *

- */ - private UserDTO instance; - - /** - *

- * Adapter for earlier versions of JUnit. - *

- * - * @return a test suite. - */ - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(UserDTOUnitTests.class); - } - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Before - public void setUp() throws Exception { - instance = new UserDTO(); - } - - /** - *

- * Accuracy test for the constructor UserDTO().
- * Instance should be correctly created. - *

- */ - @Test - public void testCtor() { - instance = new UserDTO(); - - assertEquals("'userId' should be correct.", 0L, TestsHelper.getField(instance, "userId")); - assertNull("'handle' should be correct.", TestsHelper.getField(instance, "handle")); - } - - - /** - *

- * Accuracy test for the method getUserId().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getUserId() { - long value = 1L; - instance.setUserId(value); - - assertEquals("'getUserId' should be correct.", - value, instance.getUserId()); - } - - /** - *

- * Accuracy test for the method setUserId(long userId).
- * The value should be properly set. - *

- */ - @Test - public void test_setUserId() { - long value = 1L; - instance.setUserId(value); - - assertEquals("'setUserId' should be correct.", - value, TestsHelper.getField(instance, "userId")); - } - - /** - *

- * Accuracy test for the method getHandle().
- * The value should be properly retrieved. - *

- */ - @Test - public void test_getHandle() { - String value = "new_value"; - instance.setHandle(value); - - assertEquals("'getHandle' should be correct.", - value, instance.getHandle()); - } - - /** - *

- * Accuracy test for the method setHandle(String handle).
- * The value should be properly set. - *

- */ - @Test - public void test_setHandle() { - String value = "new_value"; - instance.setHandle(value); - - assertEquals("'setHandle' should be correct.", - value, TestsHelper.getField(instance, "handle")); - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/EmailEngineNotificationServiceStressTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/EmailEngineNotificationServiceStressTests.java deleted file mode 100644 index 0d7d3fd87..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/EmailEngineNotificationServiceStressTests.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.stresstests; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.junit.After; -import org.junit.Before; -import org.springframework.context.support.FileSystemXmlApplicationContext; - -import com.topcoder.direct.services.project.task.impl.EmailEngineNotificationService; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; - -/** - *

- * Stress test cases for EmailEngineNotificationService. - *

- * - * @author lqz - * @version 1.0 - */ -public class EmailEngineNotificationServiceStressTests extends TestCase { - /** - *

- * This constant represents the test count used for testing. - *

- */ - private static final int NUMBER = 10; - - /** - *

- * This constant represents the current time used for testing. - *

- */ - private long current = -1; - - /** - *

- * EmailEngineNotificationService instance for testing. - *

- */ - private EmailEngineNotificationService impl; - - /** - * the error. - */ - private static Throwable error; - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - impl = (EmailEngineNotificationService) new FileSystemXmlApplicationContext("test_files/stress/spring.xml").getBean("notificationService"); - error = null; - } - - /** - *

- * Cleans up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Override - @After - public void tearDown() throws Exception { - impl = null; - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(EmailEngineNotificationServiceStressTests.class); - } - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskCreation() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_notifyTaskCreation() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - Task task = new Task(); - task.setName("name"); - task.setPriority(TaskPriority.HIGH); - task.setStatus(TaskStatus.NOT_STARTED); - List assignees = new ArrayList(); - UserDTO dto = new UserDTO(); - dto.setHandle("user"+NUMBER); - dto.setUserId(NUMBER); - assignees.add(dto ); - task.setAssignees(assignees ); - impl.notifyTaskCreation(100, task ); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("EmailEngineNotificationService#notifyTaskCreation", NUMBER); - } - - - /** - *

- * Tests EmailEngineNotificationService#notifyTaskStatusChange() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_notifyTaskStatusChange() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - Task task = new Task(); - task.setName("name"); - task.setPriority(TaskPriority.HIGH); - task.setStatus(TaskStatus.NOT_STARTED); - task.setCreatedBy("user1"); - List assignees = new ArrayList(); - UserDTO dto = new UserDTO(); - dto.setHandle("user"+NUMBER); - dto.setUserId(NUMBER); - assignees.add(dto ); - task.setAssignees(assignees ); - - Task newtask = new Task(); - newtask.setName("name"); - newtask.setCreatedBy("user1"); - newtask.setPriority(TaskPriority.HIGH); - newtask.setStatus(TaskStatus.COMPLETED); - newtask.setAssignees(assignees ); - impl.notifyTaskStatusChange(100, TaskStatus.IN_PROGRESS, newtask ); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("EmailEngineNotificationService#notifyTaskStatusChange", NUMBER); - } - /** - *

- * Starts to count time. - *

- */ - private void start() { - current = System.currentTimeMillis(); - } - - /** - *

- * Prints test result. - *

- * - * @param name - * the test name - * @param count - * the run count - */ - private void printResult(String name, long count) { - System.out.println("The test [" + name + "] run " + count - + " times, took time: " - + (System.currentTimeMillis() - current) + " ms"); - } - - /** - *

- * Blocks the execution of the current thread until all work thread ends - * their execution - *

- * - * @param executorService - * the ExecutorService instance - * - * @throws Exception - * to JUnit - */ - private static void awaitTermination(ExecutorService executorService) - throws Throwable { - executorService.shutdown(); - - while (!executorService.isTerminated()) { - executorService.awaitTermination(30, TimeUnit.SECONDS); - } - - if (error != null) { - throw error; - } - } -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/JPATaskListServiceStressTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/JPATaskListServiceStressTests.java deleted file mode 100644 index f687b4bb4..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/JPATaskListServiceStressTests.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.stresstests; - -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.junit.After; -import org.junit.Before; -import org.springframework.context.support.FileSystemXmlApplicationContext; - -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskStatus; - -/** - *

- * Stress test cases for JPATaskListService. - *

- * - * @author lqz - * @version 1.0 - */ -public class JPATaskListServiceStressTests extends TestCase { - /** - *

- * This constant represents the test count used for testing. - *

- */ - private static final int NUMBER = 1; - - /** - *

- * This constant represents the current time used for testing. - *

- */ - private long current = -1; - - /** - *

- * JPATaskListService instance for testing. - *

- */ - private TaskListService impl; - - /** - * the error. - */ - private static Throwable error; - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - impl = (TaskListService) new FileSystemXmlApplicationContext("test_files/stress/spring.xml").getBean("taskListService"); - error = null; - StressHelper.clearDB(); - StressHelper.prepareDB(); - } - - /** - *

- * Cleans up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Override - @After - public void tearDown() throws Exception { - impl = null; - StressHelper.clearDB(); - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(JPATaskListServiceStressTests.class); - } - - /** - *

- * Tests JPATaskListService#curd() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_curd() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - TaskList taskList = new TaskList(); - taskList.setProjectId(1); - taskList.setName("name1"); - taskList.setNotes("notes1"); - impl.addTaskList(1, taskList); - taskList.setNotes("notes2"); - impl.updateTaskList(1, taskList); - TaskList ret = impl.getTaskList(1, taskList.getId()); - assertEquals("the result is wrong", "notes2", ret.getNotes()); - impl.deleteTaskList(1, taskList.getId()); - ret= impl.getTaskList(1, taskList.getId()); - assertEquals("the result is wrong", null, ret); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskListService#curd", NUMBER); - } - /** - *

- * Tests JPATaskListService#getDefaultTaskList() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_getDefaultTaskList() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - TaskList ret= impl.getDefaultTaskList(1, 1); - assertEquals("the result is wrong", "Project Tasks List", ret.getName()); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskListService#getDefaultTaskList", NUMBER); - } - /** - *

- * Tests JPATaskListService#resolveTaskList() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_resolveTaskList() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - impl.resolveTaskList(1, 1); - - TaskList ret = impl.getTaskList(1, 1); - assertEquals("the result is wrong", "tasklist1", ret.getName()); - assertEquals("the result is wrong", false, ret.isActive()); - assertEquals("the result is wrong", TaskStatus.COMPLETED, ret.getTasks().get(0).getStatus()); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskListService#getDefaultTaskList", NUMBER); - } - - /** - *

- * Tests JPATaskListService#getTaskListsWithTasks() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_getTaskListsWithTasks() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - List ret = impl.getTaskListsWithTasks(1, null); - - assertEquals("the result is wrong", 1, ret.size()); - - - TaskFilter filter = new TaskFilter(); - filter.setName("task1"); - ret = impl.getTaskListsWithTasks(1, filter ); - - assertEquals("the result is wrong", 1, ret.size()); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskListService#getDefaultTaskList", NUMBER); - } - /** - *

- * Starts to count time. - *

- */ - private void start() { - current = System.currentTimeMillis(); - } - - /** - *

- * Prints test result. - *

- * - * @param name - * the test name - * @param count - * the run count - */ - private void printResult(String name, long count) { - System.out.println("The test [" + name + "] run " + count - + " times, took time: " - + (System.currentTimeMillis() - current) + " ms"); - } - - /** - *

- * Blocks the execution of the current thread until all work thread ends - * their execution - *

- * - * @param executorService - * the ExecutorService instance - * - * @throws Exception - * to JUnit - */ - private static void awaitTermination(ExecutorService executorService) - throws Throwable { - executorService.shutdown(); - - while (!executorService.isTerminated()) { - executorService.awaitTermination(30, TimeUnit.SECONDS); - - if (error != null) { - throw error; - } - - } -} -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/JPATaskServiceStressTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/JPATaskServiceStressTests.java deleted file mode 100644 index f9319021e..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/JPATaskServiceStressTests.java +++ /dev/null @@ -1,541 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.stresstests; - -import java.io.FileInputStream; -import java.io.InputStream; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.SortedMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -import org.junit.After; -import org.junit.Before; -import org.springframework.context.support.FileSystemXmlApplicationContext; - -import com.topcoder.direct.services.project.task.TaskService; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; - -/** - *

- * Stress test cases for JPATaskService. - *

- * - * @author lqz - * @version 1.0 - */ -public class JPATaskServiceStressTests extends TestCase { - /** - *

- * This constant represents the test count used for testing. - *

- */ - private static final int NUMBER = 1; - - /** - *

- * This constant represents the current time used for testing. - *

- */ - private long current = -1; - - /** - *

- * JPATaskService instance for testing. - *

- */ - private TaskService impl; - - /** - * the error. - */ - private static Throwable error; - - /** - *

- * Sets up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Override - @Before - public void setUp() throws Exception { - impl = (TaskService) new FileSystemXmlApplicationContext("test_files/stress/spring.xml").getBean("taskService"); - error = null; - StressHelper.clearDB(); - StressHelper.prepareDB(); - } - - /** - *

- * Cleans up the unit tests. - *

- * - * @throws Exception - * to JUnit. - */ - @Override - @After - public void tearDown() throws Exception { - impl = null; - StressHelper.clearDB(); - } - - /** - *

- * Return all tests. - *

- * - * @return all tests - */ - public static Test suite() { - return new TestSuite(JPATaskServiceStressTests.class); - } - - - - - /** - *

- * Tests JPATaskService#groupTasksByPriority() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_groupTasksByPriority() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - List taskLists = getTaskLists(); - SortedMap> ret = impl.groupTasksByPriority(taskLists ); - assertEquals("the result is wrong", 2, ret.size()); - assertEquals("the result is wrong", 5, ret.get(TaskPriority.HIGH).size()); - assertEquals("the result is wrong", 5, ret.get(TaskPriority.LOW).size()); - - assertEquals("the result is wrong", TaskPriority.HIGH, ret.get(TaskPriority.HIGH).get(0).getPriority()); - assertEquals("the result is wrong", TaskPriority.HIGH, ret.get(TaskPriority.HIGH).get(1).getPriority()); - assertEquals("the result is wrong", TaskPriority.HIGH, ret.get(TaskPriority.HIGH).get(2).getPriority()); - assertEquals("the result is wrong", TaskPriority.HIGH, ret.get(TaskPriority.HIGH).get(3).getPriority()); - assertEquals("the result is wrong", TaskPriority.HIGH, ret.get(TaskPriority.HIGH).get(4).getPriority()); - - assertEquals("the result is wrong", TaskPriority.LOW, ret.get(TaskPriority.LOW).get(0).getPriority()); - assertEquals("the result is wrong", TaskPriority.LOW, ret.get(TaskPriority.LOW).get(1).getPriority()); - assertEquals("the result is wrong", TaskPriority.LOW, ret.get(TaskPriority.LOW).get(2).getPriority()); - assertEquals("the result is wrong", TaskPriority.LOW, ret.get(TaskPriority.LOW).get(3).getPriority()); - assertEquals("the result is wrong", TaskPriority.LOW, ret.get(TaskPriority.LOW).get(4).getPriority()); - - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#groupTasksByPriority", NUMBER); - } - /** - *

- * Tests JPATaskService#groupTasksByDueDate() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_groupTasksByDueDate() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - List taskLists = getTaskLists(); - SortedMap> ret = impl.groupTasksByDueDate(taskLists ); - assertEquals("the result is wrong", 2, ret.size()); - assertEquals("the result is wrong", 5, ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).size()); - assertEquals("the result is wrong", 5, ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).size()); - - assertEquals("the result is wrong", new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(0).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(1).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(2).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(3).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(4).getDueDate()); - - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(0).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(1).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(2).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(3).getDueDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(4).getDueDate()); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#groupTasksByDueDate", NUMBER); - } - /** - *

- * Tests JPATaskService#groupTasksByStartDate() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_groupTasksByStartDate() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - List taskLists = getTaskLists(); - SortedMap> ret = impl.groupTasksByStartDate(taskLists ); - assertEquals("the result is wrong", 3, ret.size()); - - assertEquals("the result is wrong", 4, ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).size()); - assertEquals("the result is wrong", 4, ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).size()); - assertEquals("the result is wrong", 2, ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130402")).size()); - - assertEquals("the result is wrong", new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(0).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(1).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(2).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130400"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130400")).get(3).getStartDate()); - - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(0).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(1).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(2).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130401"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130401")).get(3).getStartDate()); - - - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130402"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130402")).get(0).getStartDate()); - assertEquals("the result is wrong",new SimpleDateFormat("yyyyMMdd").parse("20130402"), ret.get(new SimpleDateFormat("yyyyMMdd").parse("20130402")).get(1).getStartDate()); - - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#groupTasksByStartDate", NUMBER); - } - /** - *

- * Tests JPATaskService#groupTasksByStatus() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_groupTasksByStatus() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - List taskLists = getTaskLists(); - SortedMap> ret = impl.groupTasksByStatus(taskLists ); - assertEquals("the result is wrong", 2, ret.size()); - assertEquals("the result is wrong", 5, ret.get(TaskStatus.COMPLETED).size()); - assertEquals("the result is wrong", 5, ret.get(TaskStatus.IN_PROGRESS).size()); - - assertEquals("the result is wrong", TaskStatus.COMPLETED, ret.get(TaskStatus.COMPLETED).get(0).getStatus()); - assertEquals("the result is wrong", TaskStatus.COMPLETED, ret.get(TaskStatus.COMPLETED).get(1).getStatus()); - assertEquals("the result is wrong", TaskStatus.COMPLETED, ret.get(TaskStatus.COMPLETED).get(2).getStatus()); - assertEquals("the result is wrong", TaskStatus.COMPLETED, ret.get(TaskStatus.COMPLETED).get(3).getStatus()); - assertEquals("the result is wrong", TaskStatus.COMPLETED, ret.get(TaskStatus.COMPLETED).get(4).getStatus()); - - assertEquals("the result is wrong", TaskStatus.IN_PROGRESS, ret.get(TaskStatus.IN_PROGRESS).get(0).getStatus()); - assertEquals("the result is wrong", TaskStatus.IN_PROGRESS, ret.get(TaskStatus.IN_PROGRESS).get(1).getStatus()); - assertEquals("the result is wrong", TaskStatus.IN_PROGRESS, ret.get(TaskStatus.IN_PROGRESS).get(2).getStatus()); - assertEquals("the result is wrong", TaskStatus.IN_PROGRESS, ret.get(TaskStatus.IN_PROGRESS).get(3).getStatus()); - assertEquals("the result is wrong", TaskStatus.IN_PROGRESS, ret.get(TaskStatus.IN_PROGRESS).get(4).getStatus()); - - - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#groupTasksByStatus", NUMBER); - } - /** - *

- * Tests JPATaskService#groupTasksByAssignee() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_groupTasksByAssignee() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - List taskLists = getTaskLists(); - SortedMap> ret = impl.groupTasksByAssignee(taskLists ); - assertEquals("the result is wrong", 2, ret.size()); - Iterator> it = ret.values().iterator(); - List list1 = it.next(); - List list2 = it.next(); - assertEquals("the result is wrong", 5,list1.size()); - assertEquals("the result is wrong", 5,list2.size()); - - assertEquals("the result is wrong", 0, list1.get(0).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 0, list1.get(1).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 0, list1.get(2).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 0, list1.get(3).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 0, list1.get(4).getAssignees().get(0).getUserId()); - - assertEquals("the result is wrong", 1, list2.get(0).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 1, list2.get(1).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 1, list2.get(2).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 1, list2.get(3).getAssignees().get(0).getUserId()); - assertEquals("the result is wrong", 1, list2.get(4).getAssignees().get(0).getUserId()); - - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#groupTasksByAssignee", NUMBER); - } - - - - /** - *

- * Tests JPATaskService#curd() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_curd() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - Task task = new Task(); - task.setName("task1"); - task.setNotes("notes1"); - task.setTaskListId(1); - task.setPriority(TaskPriority.HIGH); - task.setStatus(TaskStatus.COMPLETED); - impl.addTask(1, task); - task.setNotes("notes2"); - impl.updateTask(1, task); - Task ret = impl.getTask(1, task.getId()); - assertEquals("the result is wrong", "notes2", ret.getNotes()); - impl.deleteTask(1, task.getId()); - ret= impl.getTask(1, task.getId()); - assertEquals("the result is wrong", null, ret); - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#curd", NUMBER); - } - /** - *

- * Tests JPATaskService#attachmentCURD() for stress purpose. - *

- * - * @throws Exception - * to JUnit - */ - public void test_attachmentCURD() throws Throwable { - start(); - ExecutorService executorService = Executors.newFixedThreadPool(NUMBER); - - for (int i = 0; i < NUMBER; i++) { - executorService.submit(new Runnable() { - /** - *

- * The testing thread running the process method. - *

- */ - public void run() { - try { - TaskAttachment attachment = new TaskAttachment(); - attachment.setFileName("1.jpeg"); - attachment.setMimeType("jpeg"); - attachment.setTaskId(1); - impl.addTaskAttachment(1, attachment , new FileInputStream("test_files/stress/1.jpeg")); - - InputStream at = impl.getTaskAttachmentContent(1, attachment.getId()); - assertEquals("the result is wrong", at.available(), 20201); - - impl.deleteTaskAttachment(1, attachment.getId()); - at = impl.getTaskAttachmentContent(1, attachment.getId()); - assertNull("the result is wrong", at); - - } catch (Throwable e) { - error = e; - } - } - }); - } - - awaitTermination(executorService); - - printResult("JPATaskService#attachmentCURD", NUMBER); - } - private List getTaskLists() throws ParseException { - ArrayList tasklist = new ArrayList(); - TaskList list1 = new TaskList(); - List tasks = new ArrayList(); - for (int i = 0; i < 10; i++) { - Task task1 = new Task(); - task1.setName("task"+i); - task1.setPriority(i % 2== 0 ? TaskPriority.HIGH : TaskPriority.LOW); - task1.setStatus(i % 2== 0 ? TaskStatus.COMPLETED : TaskStatus.IN_PROGRESS); - task1.setStartDate(new SimpleDateFormat("yyyyMMdd").parse("2013040"+(i/4))); - task1.setDueDate(new SimpleDateFormat("yyyyMMdd").parse("2013040"+(i/5))); - task1.setCreatedDate(new SimpleDateFormat("yyyyMMdd").parse("2013040"+i)); - List assignees = new ArrayList(); - UserDTO dto1 = new UserDTO(); - dto1.setUserId(i / 5); - dto1.setHandle("user" + (i/5)); - assignees.add(dto1 ); - task1.setAssignees(assignees ); - tasks.add(task1 ); - } - list1.setTasks(tasks ); - tasklist.add(list1 ); - return tasklist; - } - /** - *

- * Starts to count time. - *

- */ - private void start() { - current = System.currentTimeMillis(); - } - - /** - *

- * Prints test result. - *

- * - * @param name - * the test name - * @param count - * the run count - */ - private void printResult(String name, long count) { - System.out.println("The test [" + name + "] run " + count - + " times, took time: " - + (System.currentTimeMillis() - current) + " ms"); - } - - /** - *

- * Blocks the execution of the current thread until all work thread ends - * their execution - *

- * - * @param executorService - * the ExecutorService instance - * - * @throws Exception - * to JUnit - */ - private static void awaitTermination(ExecutorService executorService) - throws Throwable { - executorService.shutdown(); - - while (!executorService.isTerminated()) { - executorService.awaitTermination(30, TimeUnit.SECONDS); - - if (error != null) { - throw error; - } - - } -} -} \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/StressHelper.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/StressHelper.java deleted file mode 100644 index 5dc2965b8..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/StressHelper.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.stresstests; - -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; -import java.lang.reflect.Field; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.Statement; -import java.util.Properties; - -import junit.framework.TestCase; - -/** - *

- * This test case aggregates all stress unit test cases. - *

- * - * @author lqz - * @version 1.0 - */ -public class StressHelper extends TestCase { - private static Connection connection; - - /** - * Clear the database. - * - * @param connection - * the connection. - * - * @throws Exception - * to JUnit. - */ - protected static void clearDB( ) throws Exception { - executeSQL(getConnection(), "test_files/stress/clear.sql"); - } - - /** - * Clear the database. - * - * @param connection - * the connection. - * - * @throws Exception - * to JUnit. - */ - protected static void prepareDB( ) throws Exception { - executeSQL(getConnection(), "test_files/stress/data.sql"); - } - - /** - * Clear the database. - * - * @param connection - * the connection. - * - * @throws Exception - * to JUnit. - */ - protected static Connection getConnection() throws Exception { - if (connection == null) { - - Properties p = new Properties(); - FileInputStream in = new FileInputStream("test_files/stress/database.properties"); - p.load(in); - in.close(); - Class.forName(p.getProperty("DatabaseDriver")); - return DriverManager.getConnection(p.getProperty("DatabaseUrl"), p.getProperty("username"), p - .getProperty("password")); - } - return connection; - } - /** - * Executes the SQL statements from file. - * - * @param connection - * the connection. - * @param file - * the file. - * - * @throws Exception - * to JUnit. - */ - private static void executeSQL(Connection connection, String file) throws Exception { - String[] values = readFile(file).split(";"); - - Statement statement = connection.createStatement(); - try { - - for (int i = 0; i < values.length; i++) { - String sql = values[i].trim(); - if ((sql.length() != 0) && (!sql.startsWith("#"))) { - statement.executeUpdate(sql); - } - } - } finally { - statement.close(); - } - } - - /** - * Reads file to a string. - * - * @param fileName - * the name of the file to read. - * - * @return a string represents the content. - * - * @throws IOException - * if any IO error occurs. - */ - private static String readFile(String fileName) throws IOException { - Reader reader = new FileReader(fileName); - - try { - StringBuilder sb = new StringBuilder(); - char[] buffer = new char[1024]; - int k = 0; - while ((k = reader.read(buffer)) != -1) { - sb.append(buffer, 0, k); - } - return sb.toString().replace("\r\n", "\n"); - } finally { - try { - reader.close(); - } catch (IOException ioe) { - // Ignore - } - } - } - - - /** - *

- * Gets value for field of given object. - *

- * - * @param obj - * the given object. - * @param field - * the field name. - * - * @return the field value. - */ - public static Object getField(Object obj, String field) { - Object value = null; - try { - Field declaredField = null; - try { - declaredField = obj.getClass().getDeclaredField(field); - } catch (NoSuchFieldException e) { - // Ignore - } - if (declaredField == null) { - try { - declaredField = obj.getClass().getSuperclass().getDeclaredField(field); - } catch (NoSuchFieldException e) { - // Ignore - } - } - - if (declaredField == null) { - declaredField = obj.getClass().getSuperclass().getSuperclass().getDeclaredField(field); - } - - declaredField.setAccessible(true); - - try { - value = declaredField.get(obj); - } finally { - declaredField.setAccessible(false); - } - } catch (IllegalAccessException e) { - // Ignore - } catch (NoSuchFieldException e) { - // Ignore - } - - return value; - } -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/StressTests.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/StressTests.java deleted file mode 100644 index 635ef2175..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/StressTests.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.stresstests; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -/** - * This is the stress tests for this component. - * - * @author TCSDEVELOPER - * @version 1.0 - */ -public class StressTests extends TestCase { - /** - *

- * All unit test cases. - *

- * - * @return The test suite. - */ - public static Test suite() { - final TestSuite suite = new TestSuite(); - - suite.addTestSuite(EmailEngineNotificationServiceStressTests.class); - suite.addTestSuite(JPATaskListServiceStressTests.class); - suite.addTestSuite(JPATaskServiceStressTests.class); - return suite; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/UserServiceStressMock.java b/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/UserServiceStressMock.java deleted file mode 100644 index 94b813e36..000000000 --- a/components/topcoder_cockpit_task_management_services/src/java/tests/com/topcoder/direct/services/project/task/stresstests/UserServiceStressMock.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.project.task.stresstests; - -import java.util.Date; -import java.util.List; - -import com.topcoder.service.user.User; -import com.topcoder.service.user.UserInfo; -import com.topcoder.service.user.UserService; -import com.topcoder.service.user.UserServiceException; - -/** - *

- * Stress mock of UserService. - *

- * - * @author lqz - * @version 1.0 - */ -public class UserServiceStressMock implements UserService { - - - public void activateUser(String arg0) throws UserServiceException { - - } - - - public void addUserTerm(String arg0, long arg1, Date arg2) - throws UserServiceException { - // TODO Auto-generated method stub - - } - - - public void addUserTerm(long arg0, long arg1, Date arg2) - throws UserServiceException { - // TODO Auto-generated method stub - - } - - - public void addUserToGroups(String arg0, long[] arg1) - throws UserServiceException { - // TODO Auto-generated method stub - - } - - - public void addUserToGroups(long arg0, long[] arg1) - throws UserServiceException { - // TODO Auto-generated method stub - - } - - - public boolean checkUserTerm(long arg0, long arg1) - throws UserServiceException { - // TODO Auto-generated method stub - return false; - } - - - public String getEmailAddress(long arg0) throws UserServiceException { - return "email"+arg0+"@sohu.com"; - } - - - public String getEmailAddress(String arg0) throws UserServiceException { - return "email"+arg0+"@sohu.com"; - } - - - public User getUser(long arg0) throws UserServiceException { - User user = new User(); - user.setUserId(arg0); - user.setHandle("user"+arg0); - user.setEmailAddress("email"+arg0+"@sohu.com"); - return user ; - } - - - public User getUserByEmail(String arg0) throws UserServiceException { - return null; - } - - - public String getUserHandle(long arg0) throws UserServiceException { - return "user"+arg0; - } - - - public long getUserId(String arg0) throws UserServiceException { - return 0; - } - - - public UserInfo getUserInfo(String arg0) throws UserServiceException { - return null; - } - - - public boolean isAdmin(String arg0) throws UserServiceException { - // TODO Auto-generated method stub - return false; - } - - - public long registerUser(User arg0) throws UserServiceException { - // TODO Auto-generated method stub - return 0; - } - - - public void removeUserFromGroups(String arg0, long[] arg1) - throws UserServiceException { - // TODO Auto-generated method stub - - } - - - public void removeUserTerm(String arg0, long arg1) - throws UserServiceException { - // TODO Auto-generated method stub - - } - - - public List searchUser(String arg0) throws UserServiceException { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/components/topcoder_cockpit_task_management_services/test_files/DevNullSmtp.jar b/components/topcoder_cockpit_task_management_services/test_files/DevNullSmtp.jar deleted file mode 100644 index 70ee8553d..000000000 Binary files a/components/topcoder_cockpit_task_management_services/test_files/DevNullSmtp.jar and /dev/null differ diff --git a/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/applicationContext.xml b/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/applicationContext.xml deleted file mode 100644 index 36ba487cf..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/applicationContext.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - java:TCS_CATALOG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.util.log.LogManager.getLog - - - - com.topcoder.task.logger - - - - - - - - - - - - - - - task_log - - - - \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/persistence.xml b/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/persistence.xml deleted file mode 100644 index 4e4f7742e..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/persistence.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - org.hibernate.ejb.HibernatePersistence - META-INF/task/task_orm.xml - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/task_orm.xml b/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/task_orm.xml deleted file mode 100644 index 3cef8f976..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/META-INF/task/task_orm.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.direct.services.project.task.model.TaskStatus - - - - - com.topcoder.direct.services.project.task.model.TaskPriority - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/README b/components/topcoder_cockpit_task_management_services/test_files/README deleted file mode 100644 index 82a439873..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/README +++ /dev/null @@ -1,36 +0,0 @@ -=================== enhancement ================ -1. -resolveTaskList(long userId, long taskListId) - -In this method, the designer's code: -oldTask = entityManager.find(...); - -He finds the oldTask from the database, but this is not necessary, -we only need to save the oldTaskStatus, which can be directly retrieve from the task.getStatus(); - - -================= Steps to run the unit tests ========== - -1. -put spring, hiberate and other dependencies (the build-dependencies.xml may help) to your classpath. -2. -I have provided the mock_user_service.jar and the cockpit_modules.jar in reflib, -add them to the class path too. -3. -run create.sql in your database, make sure that delete all your existing tables before running the script. -4. -I use the devnullsmtp.jar (provided in test_files) as the smtp server. -use jar -jar devnullsmtp.jar to start the server before running the unit tests. -And you can save the receiving emails to a directory in the devnull stmp server to manully check the emails. -5. -Modifies the configurations for your own in: -a). test_files/jdbc.properties -b). test_files/com/topcoder/message/email/EmailEngine.xml - -NOTE, I have success run my tests both in the spring 2.5.6 and hibernate 3.4(JPA1), -and also the spring 3.1 and hibernate 3.5.6 (JPA2). -But failed in spring 2.5.6 (JPA1) and hibernate 3.5.6(JPA2), you can try. - -============== CS has been updated ============ - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/attachmentDirectory/1 b/components/topcoder_cockpit_task_management_services/test_files/accuracy/attachmentDirectory/1 deleted file mode 100644 index b6fc4c620..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/attachmentDirectory/1 +++ /dev/null @@ -1 +0,0 @@ -hello \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/clearUpDataBase.sql b/components/topcoder_cockpit_task_management_services/test_files/accuracy/clearUpDataBase.sql deleted file mode 100644 index 7d3c6af46..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/clearUpDataBase.sql +++ /dev/null @@ -1,15 +0,0 @@ -delete from direct_project_task_contest_xref; -delete from direct_project_task_milestone_xref; -delete from direct_project_task_list_contest_xref; -delete from direct_project_task_list_milestone_xref; -delete from project_milestone_owner; -delete from direct_project_task_attachment; -delete from direct_project_task_assignee; -delete from direct_project_task_list_permitted_user; -delete from direct_project_task; -delete from project_milestone; -delete from direct_project_task_list; -delete from project; -delete from direct_project_task_status; -delete from direct_project_task_priority; -delete from user; \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/initDataBase.sql b/components/topcoder_cockpit_task_management_services/test_files/accuracy/initDataBase.sql deleted file mode 100644 index 6339f6cf1..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/initDataBase.sql +++ /dev/null @@ -1,19 +0,0 @@ -insert into direct_project_task_status (direct_project_task_status_id, name) values (0, 'NOT_STARTED'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (1, 'IN_PROGRESS'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (2, 'WAIT_ON_DEPENDENCY'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (3, 'COMPLETED'); - -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (0, 'HIGH'); -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (1, 'LOW'); -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (2, 'NORMAL'); - -INSERT INTO project(project_id, project_name) VALUES(1, 'project1'); -INSERT INTO project(project_id, project_name) VALUES(2, 'project2'); - - -INSERT INTO user (user_id, email_address,handle) VALUES(1, '1@tc.com', 'u1'); -INSERT INTO user (user_id, email_address,handle) VALUES(2, '2@tc.com', 'u2'); - -insert into direct_project_task_list (create_date, create_user, modify_date, modify_user, name, notes, project_id, is_active, is_default, direct_project_task_list_id) values (current, 'u1', null,null,'n0','n1', 1, 1, 1, 1); -insert into direct_project_task_list_permitted_user(direct_project_task_list_id, user_id) values (1, 1); -insert into direct_project_task_list_permitted_user(direct_project_task_list_id, user_id) values (1, 2); \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/statuschangebody.txt b/components/topcoder_cockpit_task_management_services/test_files/accuracy/statuschangebody.txt deleted file mode 100644 index 36d1dafe1..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/statuschangebody.txt +++ /dev/null @@ -1,11 +0,0 @@ - - -

-Task status has been changed. - -Task name is %TASK_NAME% - -Updated task status is %UPDATED_TASK_STATUS% -

- - diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/statuschangesubject.txt b/components/topcoder_cockpit_task_management_services/test_files/accuracy/statuschangesubject.txt deleted file mode 100644 index c458a4c41..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/statuschangesubject.txt +++ /dev/null @@ -1 +0,0 @@ -Task "%TASK_NAME%" status has been changed. \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/taskcreationbody.txt b/components/topcoder_cockpit_task_management_services/test_files/accuracy/taskcreationbody.txt deleted file mode 100644 index d65ddf9ef..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/taskcreationbody.txt +++ /dev/null @@ -1,29 +0,0 @@ - - -

-Task has been created. - -Task name is %TASK_NAME% - -Task notes are\: -%TASK_NOTES% - -Task start date is %TASK_START_DATE% - -Task due date is %TASK_DUE_DATE% - -Task status is %TASK_STATUS% - -Task priority is %TASK_PRIORITY% - -Task assignees are\: -

    -%loop:TASK_ASSIGNEES% -
  • -<%USER_ID%>%USER_HANDLE% -
  • -%endloop% -
-

- - diff --git a/components/topcoder_cockpit_task_management_services/test_files/accuracy/taskcreationsubject.txt b/components/topcoder_cockpit_task_management_services/test_files/accuracy/taskcreationsubject.txt deleted file mode 100644 index 240422dc6..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/accuracy/taskcreationsubject.txt +++ /dev/null @@ -1 +0,0 @@ -Task "%TASK_NAME%" has been creation. \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/clear.sql b/components/topcoder_cockpit_task_management_services/test_files/clear.sql deleted file mode 100644 index 41e9064dc..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/clear.sql +++ /dev/null @@ -1,18 +0,0 @@ - -delete from direct_project_task_contest_xref; -delete from direct_project_task_milestone_xref; -delete from direct_project_task_list_contest_xref; -delete from direct_project_task_list_milestone_xref; -delete from project_milestone_owner; -delete from direct_project_task_attachment; -delete from direct_project_task_assignee; -delete from direct_project_task_list_permitted_user; -delete from direct_project_task; -delete from project_milestone; -delete from direct_project_task_list; -delete from project; - -delete from direct_project_task_status; -delete from direct_project_task_priority; - -delete from user; \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/com/topcoder/message/email/EmailEngine.xml b/components/topcoder_cockpit_task_management_services/test_files/com/topcoder/message/email/EmailEngine.xml deleted file mode 100644 index 6f56d845d..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/com/topcoder/message/email/EmailEngine.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - 192.168.1.88 - - - 25 - - - test - - - test - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/com/topcoder/util/config/ConfigManager.properties b/components/topcoder_cockpit_task_management_services/test_files/com/topcoder/util/config/ConfigManager.properties deleted file mode 100644 index 8c509ec82..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/com/topcoder/util/config/ConfigManager.properties +++ /dev/null @@ -1,15 +0,0 @@ -# use this file to place a list of pre-load namespaces -com.topcoder.util.config.ConfigManager=com/topcoder/util/config/ConfigManager.properties - -# for properties file -# com.topcoder.foo.SampleProperties=com/topcoder/util/config/SampleProperties.properties - -# for xml file -# com.topcoder.foo.SampleXML=com/topcoder/util/config/SampleXML.xml - -# for multiple namespace xml file -# Component A=com/topcoder/util/config/SampleMultiXML.xml -# Component B=com/topcoder/util/config/SampleMultiXML.xml - -# for pluggable config file -# com.topcoder.foo.SamplePluggable=com/topcoder/util/config/SamplePluggable.config diff --git a/components/topcoder_cockpit_task_management_services/test_files/create.sql b/components/topcoder_cockpit_task_management_services/test_files/create.sql deleted file mode 100644 index a24b310a9..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/create.sql +++ /dev/null @@ -1,276 +0,0 @@ - - -CREATE TABLE user ( - user_id SERIAL NOT NULL, - email_address VARCHAR(64), - handle VARCHAR(64) -); - -alter table user add constraint primary key - (user_id) - constraint pk_user; - -CREATE TABLE project ( - project_id SERIAL NOT NULL, - project_name VARCHAR(80) not null -); - -alter table project add constraint primary key - (project_id) - constraint pk_project; - -create table project_milestone ( - project_milestone_id Serial NOT NULL, - name VARCHAR(80) not null -); - -alter table project_milestone add constraint primary key - (project_milestone_id) - constraint pk_project_milestone; - -create table project_milestone_owner ( - project_milestone_owner_id Serial NOT NULL, - user_id INT NOT NULL, - user_handle VARCHAR(45) NOT NULL, - project_milestone_id INT NOT NULL -); - -alter table project_milestone_owner add constraint primary key - (project_milestone_owner_id) - constraint pk_project_milestone_owner; - -create table direct_project_task_list ( - direct_project_task_list_id Serial NOT NULL, - project_id INT NOT NULL, - name VARCHAR(80) NOT NULL, - notes VARCHAR(250), - create_date DATETIME YEAR TO FRACTION NOT NULL, - create_user VARCHAR(64) NOT NULL, - modify_date DATETIME YEAR TO FRACTION, - modify_user VARCHAR(64), - is_active CHAR DEFAULT 'Y' NOT NULL, - is_default CHAR DEFAULT 'N' NOT NULL -); - -alter table direct_project_task_list add constraint primary key - (direct_project_task_list_id) - constraint pk_direct_project_task_list; - - -create table direct_project_task_list_permitted_user ( - direct_project_task_list_id INT NOT NULL, - user_id INT NOT NULL -); - -alter table direct_project_task_list_permitted_user add constraint primary key - (direct_project_task_list_id, user_id) - constraint pk_direct_project_task_list_permitted_user; - - -create table direct_project_task_status ( - direct_project_task_status_id int NOT NULL, - name VARCHAR(64) NOT NULL -); - -alter table direct_project_task_status add constraint primary key - (direct_project_task_status_id) - constraint pk_direct_project_task_status_id; - -create table direct_project_task_priority ( - direct_project_task_priority_id int NOT NULL, - name VARCHAR(64) NOT NULL -); - -alter table direct_project_task_priority add constraint primary key - (direct_project_task_priority_id) - constraint pk_direct_project_task_priority; - - -create table direct_project_task ( - direct_project_task_id Serial NOT NULL, - direct_project_task_list_id INT NOT NULL, - name VARCHAR(80) NOT NULL, - notes VARCHAR(250), - create_date DATETIME YEAR TO FRACTION NOT NULL, - create_user VARCHAR(64) NOT NULL, - modify_date DATETIME YEAR TO FRACTION, - modify_user VARCHAR(64), - start_date DATETIME YEAR TO FRACTION, - due_date DATETIME YEAR TO FRACTION, - status INT NOT NULL, - priority INT NOT NULL -); - -alter table direct_project_task add constraint primary key - (direct_project_task_id) - constraint pk_direct_project_task; - -create table direct_project_task_attachment ( - direct_project_task_attachment_id Serial NOT NULL, - direct_project_task_id INT NOT NULL, - file_name VARCHAR(64) NOT NULL, - mime_type VARCHAR(64) NOT NULL, - create_date DATETIME YEAR TO FRACTION NOT NULL, - create_user VARCHAR(64) NOT NULL, - modify_date DATETIME YEAR TO FRACTION, - modify_user VARCHAR(64) -); - -alter table direct_project_task_attachment add constraint primary key - (direct_project_task_attachment_id) - constraint pk_direct_project_task_attachment; - -create table direct_project_task_contest_xref ( - direct_project_task_id INT NOT NULL, - project_id INT NOT NULL -); - -alter table direct_project_task_contest_xref add constraint primary key - (direct_project_task_id, project_id) - constraint pk_direct_project_task_contest_xref; - -create table direct_project_task_assignee ( - direct_project_task_id INT NOT NULL, - user_id INT NOT NULL -); - -alter table direct_project_task_assignee add constraint primary key - (direct_project_task_id, user_id) - constraint pk_direct_project_task_assignee; - - -create table direct_project_task_milestone_xref ( - direct_project_task_id INT NOT NULL, - project_milestone_id INT NOT NULL -); - -alter table direct_project_task_milestone_xref add constraint primary key - (direct_project_task_id, project_milestone_id) - constraint pk_direct_project_task_milestone_xref; - - -create table direct_project_task_list_contest_xref ( - direct_project_task_list_id INT NOT NULL, - project_id INT NOT NULL -); - -alter table direct_project_task_list_contest_xref add constraint primary key - (direct_project_task_list_id, project_id) - constraint pk_direct_project_task_list_contest_xref; - -create table direct_project_task_list_milestone_xref ( - direct_project_task_list_id INT NOT NULL, - project_milestone_id INT NOT NULL -); - -alter table direct_project_task_list_milestone_xref add constraint primary key - (direct_project_task_list_id, project_milestone_id) - constraint pk_direct_project_task_list_milestone_xref; - - - -alter table direct_project_task_list add constraint foreign key - (project_id) - references project - (project_id) - constraint fk_task_list_to_direct_project; - -alter table direct_project_task_list_permitted_user add constraint foreign key - (user_id) - references user - (user_id) - constraint fk_task_list_permitted_user_to_user; - -alter table direct_project_task_list_permitted_user add constraint foreign key - (direct_project_task_list_id) - references direct_project_task_list - (direct_project_task_list_id) - constraint fk_task_list_permitted_user_to_task_list; - -alter table direct_project_task add constraint foreign key - (direct_project_task_list_id) - references direct_project_task_list - (direct_project_task_list_id) - constraint fk_task_to_task_list; - -alter table direct_project_task add constraint foreign key - (status) - references direct_project_task_status - (direct_project_task_status_id) - constraint fk_task_to_task_status; - -alter table direct_project_task add constraint foreign key - (priority) - references direct_project_task_priority - (direct_project_task_priority_id) - constraint fk_task_to_task_priority; - -alter table direct_project_task_attachment add constraint foreign key - (direct_project_task_id) - references direct_project_task - (direct_project_task_id) - constraint fk_task_attachment_to_task; - -alter table direct_project_task_contest_xref add constraint foreign key - (direct_project_task_id) - references direct_project_task - (direct_project_task_id) - constraint fk_task_contest_xref_to_task; - -alter table direct_project_task_contest_xref add constraint foreign key - (project_id) - references project - (project_id) - constraint fk_task_contest_xref_to_project; - -alter table direct_project_task_assignee add constraint foreign key - (direct_project_task_id) - references direct_project_task - (direct_project_task_id) - constraint fk_task_assignee_to_task; - -alter table direct_project_task_assignee add constraint foreign key - (user_id) - references user - (user_id) - constraint fk_task_assignee_to_user; - -alter table direct_project_task_milestone_xref add constraint foreign key - (direct_project_task_id) - references direct_project_task - (direct_project_task_id) - constraint fk_task_milestone_xref_to_task; - -alter table direct_project_task_milestone_xref add constraint foreign key - (project_milestone_id) - references project_milestone - (project_milestone_id) - constraint fk_task_milestone_xref_to_project; - - -alter table direct_project_task_list_contest_xref add constraint foreign key - (project_id) - references project - (project_id) - constraint fk_task_list_contest_xref_to_project; - -alter table direct_project_task_list_contest_xref add constraint foreign key - (direct_project_task_list_id) - references direct_project_task_list - (direct_project_task_list_id) - constraint fk_task_list_context_xref_to_task_list; - -alter table direct_project_task_list_milestone_xref add constraint foreign key - (project_milestone_id) - references project_milestone - (project_milestone_id) - constraint fk_task_list_milestone_xref_to_project; - -alter table direct_project_task_list_milestone_xref add constraint foreign key - (direct_project_task_list_id) - references direct_project_task_list - (direct_project_task_list_id) - constraint fk_task_list_milestone_xref_to_task_list; - -alter table direct_project_task lock mode(row); -alter table direct_project_task_list lock mode(row); \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/create_body_template.txt b/components/topcoder_cockpit_task_management_services/test_files/create_body_template.txt deleted file mode 100644 index 25b743888..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/create_body_template.txt +++ /dev/null @@ -1,39 +0,0 @@ - - -

-Task has been created. -

-Task name is %TASK_NAME% - -

-Task notes are\: -

-

-%TASK_NOTES% -

-

-Task start date is %TASK_START_DATE% -

-

-Task due date is %TASK_DUE_DATE% -

-

-Task status is %TASK_STATUS% -

-

-Task priority is %TASK_PRIORITY% -

-

-Task assignees are\: -

-

-

-

- - diff --git a/components/topcoder_cockpit_task_management_services/test_files/enums.sql b/components/topcoder_cockpit_task_management_services/test_files/enums.sql deleted file mode 100644 index 2994154b0..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/enums.sql +++ /dev/null @@ -1,8 +0,0 @@ -insert into direct_project_task_status (direct_project_task_status_id, name) values (0, 'NOT_STARTED'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (1, 'IN_PROGRESS'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (2, 'WAIT_ON_DEPENDENCY'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (3, 'COMPLETED'); - -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (0, 'HIGH'); -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (1, 'LOW'); -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (2, 'NORMAL'); diff --git a/components/topcoder_cockpit_task_management_services/test_files/jdbc.properties b/components/topcoder_cockpit_task_management_services/test_files/jdbc.properties deleted file mode 100644 index e855c23a3..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/jdbc.properties +++ /dev/null @@ -1,5 +0,0 @@ -datasource.driver=com.informix.jdbc.IfxDriver -datasource.url=jdbc:informix-sqli://127.0.0.1:2021/test:INFORMIXSERVER=informixoltp_tcp -datasource.username=informix -datasource.password=topcoder -hibernate.dialect=org.hibernate.dialect.InformixDialect \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/log4j.properties b/components/topcoder_cockpit_task_management_services/test_files/log4j.properties deleted file mode 100644 index a8617e8e2..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/log4j.properties +++ /dev/null @@ -1,18 +0,0 @@ -# Log levels -log4j.rootLogger=DEBUG, stdout - -log4j.logger.org.springframework=INFO - -# Console appender configuration -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -# Pattern to output the caller's file name and line number. -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d -%-4r [%t] %-5p %c %x - %m%n - -log4j.logger.org.hibernate=WARN -# Changing the log level to DEBUG will result in Hibernate generated -# SQL to be logged. -log4j.logger.org.hibernate.SQL=WARN -# Changing the log level to DEBUG will result in the PreparedStatement -# bound variable values to be logged. -log4j.logger.org.hibernate.type=WARN \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/spring.xml b/components/topcoder_cockpit_task_management_services/test_files/spring.xml deleted file mode 100644 index 579a182f9..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/spring.xml +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - test_log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/status_body_template.txt b/components/topcoder_cockpit_task_management_services/test_files/status_body_template.txt deleted file mode 100644 index 5fc1dc8d7..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/status_body_template.txt +++ /dev/null @@ -1,12 +0,0 @@ - - -

-Task status has been changed. -

-

-Task name is %TASK_NAME% -

-

-Updated task status is %UPDATED_TASK_STATUS% -

- diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/1.jpeg b/components/topcoder_cockpit_task_management_services/test_files/stress/1.jpeg deleted file mode 100644 index 4addeaf82..000000000 Binary files a/components/topcoder_cockpit_task_management_services/test_files/stress/1.jpeg and /dev/null differ diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/META-INF/orm.xml b/components/topcoder_cockpit_task_management_services/test_files/stress/META-INF/orm.xml deleted file mode 100644 index 3cef8f976..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/META-INF/orm.xml +++ /dev/null @@ -1,155 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - com.topcoder.direct.services.project.task.model.TaskStatus - - - - - com.topcoder.direct.services.project.task.model.TaskPriority - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/META-INF/persistence.xml b/components/topcoder_cockpit_task_management_services/test_files/stress/META-INF/persistence.xml deleted file mode 100644 index cdef407bf..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/META-INF/persistence.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - META-INF/orm.xml - - \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/clear.sql b/components/topcoder_cockpit_task_management_services/test_files/stress/clear.sql deleted file mode 100644 index 41e9064dc..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/clear.sql +++ /dev/null @@ -1,18 +0,0 @@ - -delete from direct_project_task_contest_xref; -delete from direct_project_task_milestone_xref; -delete from direct_project_task_list_contest_xref; -delete from direct_project_task_list_milestone_xref; -delete from project_milestone_owner; -delete from direct_project_task_attachment; -delete from direct_project_task_assignee; -delete from direct_project_task_list_permitted_user; -delete from direct_project_task; -delete from project_milestone; -delete from direct_project_task_list; -delete from project; - -delete from direct_project_task_status; -delete from direct_project_task_priority; - -delete from user; \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/data.sql b/components/topcoder_cockpit_task_management_services/test_files/stress/data.sql deleted file mode 100644 index c74341031..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/data.sql +++ /dev/null @@ -1,41 +0,0 @@ -insert into direct_project_task_status (direct_project_task_status_id, name) values (0, 'NOT_STARTED'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (1, 'IN_PROGRESS'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (2, 'WAIT_ON_DEPENDENCY'); -insert into direct_project_task_status (direct_project_task_status_id, name) values (3, 'COMPLETED'); - -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (0, 'HIGH'); -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (1, 'LOW'); -insert into direct_project_task_priority (direct_project_task_priority_id, name) values (2, 'NORMAL'); - -insert into user (user_id, email_address, handle) values (1, 'user1@sohu.com', 'user1'); -insert into user (user_id, email_address, handle) values (2, 'user1@sohu.com', 'user2'); -insert into user (user_id, email_address, handle) values (3,'user1@sohu.com', 'user3'); -insert into user (user_id, email_address, handle) values (4,'user1@sohu.com', 'user4'); -insert into project (project_id, project_name) values (1, 'project 1' ); -insert into project (project_id, project_name) values (2, 'project 2' ); -insert into project (project_id, project_name) values (3, 'project 3' ); -insert into project (project_id, project_name) values (4, 'project 4' ); -insert into project_milestone (project_milestone_id, name) values (1, 'milston name 1' ); -insert into project_milestone (project_milestone_id, name) values (2, 'milston name 2' ); -insert into project_milestone (project_milestone_id, name) values (3, 'milston name 3' ); -insert into project_milestone (project_milestone_id, name) values (4, 'milston name 4' ); -insert into direct_project_task_list(direct_project_task_list_id, project_id,name,notes,create_date,create_user,is_active,is_default) values (1, 1, 'tasklist1', 'note1', current, 'user1', 'T', 'T'); -insert into direct_project_task_list(direct_project_task_list_id, project_id,name,notes,create_date,create_user,is_active,is_default) values (2, 2, 'tasklist2', 'note2', current, 'user2', 'T', 'T'); -insert into direct_project_task_list(direct_project_task_list_id, project_id,name,notes,create_date,create_user,is_active,is_default) values (3, 3, 'tasklist3', 'note3', current, 'user3', 'T', 'T'); -insert into direct_project_task_list(direct_project_task_list_id, project_id,name,notes,create_date,create_user,is_active,is_default) values (4, 4, 'tasklist4', 'note4', current, 'user4', 'T', 'T'); -insert into direct_project_task(direct_project_task_id, direct_project_task_list_id, name,create_date,create_user,status,priority) values (1,1, 'task1', current, 'user1', 1,1); -insert into direct_project_task(direct_project_task_id, direct_project_task_list_id, name,create_date,create_user,status,priority) values (2,2, 'task2', current, 'user2', 1,1); -insert into direct_project_task(direct_project_task_id, direct_project_task_list_id, name,create_date,create_user,status,priority) values (3,3, 'task3', current, 'user3', 1,1); -insert into direct_project_task(direct_project_task_id, direct_project_task_list_id, name,create_date,create_user,status,priority) values (4,4, 'task4', current, 'user4', 1,1); -insert into direct_project_task_contest_xref(direct_project_task_id, project_id) values (1,1); -insert into direct_project_task_contest_xref(direct_project_task_id, project_id) values (2,2); -insert into direct_project_task_contest_xref(direct_project_task_id, project_id) values (3,3); -insert into direct_project_task_contest_xref(direct_project_task_id, project_id) values (4,4); -insert into direct_project_task_list_contest_xref(direct_project_task_list_id, project_id) values (1,1); -insert into direct_project_task_list_contest_xref(direct_project_task_list_id, project_id) values (2,2); -insert into direct_project_task_list_contest_xref(direct_project_task_list_id, project_id) values (3,3); -insert into direct_project_task_list_contest_xref(direct_project_task_list_id, project_id) values (4,4); -insert into direct_project_task_list_permitted_user(direct_project_task_list_id, user_id) values (1,1); -insert into direct_project_task_list_permitted_user(direct_project_task_list_id, user_id) values (2,2); -insert into direct_project_task_list_permitted_user(direct_project_task_list_id, user_id) values (3,3); -insert into direct_project_task_list_permitted_user(direct_project_task_list_id, user_id) values (4,4); diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/database.properties b/components/topcoder_cockpit_task_management_services/test_files/stress/database.properties deleted file mode 100644 index 087cb6c38..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/database.properties +++ /dev/null @@ -1,5 +0,0 @@ -# database connection parameters -DatabaseDriver=com.informix.jdbc.IfxDriver -DatabaseUrl=jdbc:informix-sqli://127.0.0.1:2021/test:INFORMIXSERVER=informixoltp_tcp -username=informix -password=topcoder diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/spring.xml b/components/topcoder_cockpit_task_management_services/test_files/stress/spring.xml deleted file mode 100644 index 18f822b86..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/spring.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - test_log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/template/create_body.txt b/components/topcoder_cockpit_task_management_services/test_files/stress/template/create_body.txt deleted file mode 100644 index 758fb9e25..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/template/create_body.txt +++ /dev/null @@ -1,38 +0,0 @@ - - -

-Task has been created. -

-Task name is %TASK_NAME% - -

-Task notes are\: -

-

-%TASK_NOTES% -

-

-Task start date is %TASK_START_DATE% -

-

-Task due date is %TASK_DUE_DATE% -

-

-Task status is %TASK_STATUS% -

-

-Task priority is %TASK_PRIORITY% -

-

-Task assignees are\: -

-

-

    -%loop:TASK_ASSIGNEES% -
  • -
  • -%endloop% -
-

- - diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/template/create_sub.txt b/components/topcoder_cockpit_task_management_services/test_files/stress/template/create_sub.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/template/status_body.txt b/components/topcoder_cockpit_task_management_services/test_files/stress/template/status_body.txt deleted file mode 100644 index 5a49dac14..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/template/status_body.txt +++ /dev/null @@ -1,12 +0,0 @@ - - -

-Task status has been changed. -

-

-Task name is %TASK_NAME% -

-

-Updated task status is %UPDATED_TASK_STATUS% -

- \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/stress/template/status_sub.txt b/components/topcoder_cockpit_task_management_services/test_files/stress/template/status_sub.txt deleted file mode 100644 index 3dbe32dc2..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/stress/template/status_sub.txt +++ /dev/null @@ -1 +0,0 @@ -Task status has been changed. \ No newline at end of file diff --git a/components/topcoder_cockpit_task_management_services/test_files/test.properties b/components/topcoder_cockpit_task_management_services/test_files/test.properties deleted file mode 100644 index 26efdf3a3..000000000 --- a/components/topcoder_cockpit_task_management_services/test_files/test.properties +++ /dev/null @@ -1 +0,0 @@ -user.emailaddress=test@126.com \ No newline at end of file diff --git a/conf/email_templates/create_task_email_template.txt b/conf/email_templates/create_task_email_template.txt deleted file mode 100644 index 139f3440c..000000000 --- a/conf/email_templates/create_task_email_template.txt +++ /dev/null @@ -1,241 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
&nbsp;
- -
- - - - - - - - - - - - - - - -
- -
- -
- -
&nbsp; &nbsp;
- - - -
- -
- -
- - - - - -
- -
&nbsp;
- -
- - - - - - - - - - - - - - - -
- - - - - - - - - -
Topcoder Direct Alert\: Task Created
- -
- - - - - - - -
Hello,

- - - - A task has been created in your project\: %PROJECT_NAME% and assigned to you. - -

- - Name\: %TASK_NAME%
- - Notes\: - -

%TASK_NOTES%


- - Start Date\: %TASK_START_DATE%
- - Due Date\: %TASK_DUE_DATE%
- - Status\: %TASK_STATUS%
- - Priority\: %TASK_PRIORITY%
- - Assignees\: - -

- -

    - - %loop:TASK_ASSIGNEES% - -
  • - - %USER_HANDLE% - -
  • - - %endloop% - -
- -

- - - -
- - - -
- - - -
- - - - - - - - - - - -
- -
- -
- - TopCoder, Inc. - -95 Glastonbury Blvd. - -Glastonbury, CT 06033 U.S.A. - -
- -Contact Us
- - - -
- - - -
- - - -
- - - - - - - - diff --git a/conf/email_templates/update_task_status_email_template.txt b/conf/email_templates/update_task_status_email_template.txt deleted file mode 100644 index b4dd8133a..000000000 --- a/conf/email_templates/update_task_status_email_template.txt +++ /dev/null @@ -1,240 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
&nbsp;
- -
- - - - - - - - - - - - - - - -
- -
- -
- -
&nbsp; &nbsp;
- - - -
- -
- -
- - - - - -
- -
&nbsp;
- -
- - - - - - - - - - - - - - - -
- - - - - - - - - -
TopCoder Cockpit Alert\: Task Status Changed
- -
- - - - - - - -
Hello,

- - - - Status of task %TASK_NAME% has been changed to\: %UPDATED_TASK_STATUS% in your project\: %PROJECT_NAME%. - -

- - Notes\: - -

%TASK_NOTES%


- - Start Date\: %TASK_START_DATE%
- - Due Date\: %TASK_DUE_DATE%
- - Status\: %TASK_STATUS%
- - Priority\: %TASK_PRIORITY%
- - Assignees\: - -

- -

    - - %loop:TASK_ASSIGNEES% - -
  • - - %USER_HANDLE% - -
  • - - %endloop% - -
- -

- - - -
- - - -
- - - -
- - - - - - - - - - - -
- -
- -
- - TopCoder, Inc. - -95 Glastonbury Blvd. - -Glastonbury, CT 06033 U.S.A. - -
- -Contact Us
- - - -
- - - -
- - - -
- - - - - - - - - diff --git a/conf/token.properties b/conf/token.properties index 831cde1c8..34120513d 100644 --- a/conf/token.properties +++ b/conf/token.properties @@ -255,15 +255,6 @@ j####################################################### @assetUploadBasePath@=/tmp/assetupload @assetUploadTempFileRoot@=/tmp/assetuploadtemp -################## -# Project Tasks # -################## -@taskEmailSender@=donotreply@topcoder.com -@taskCreationEmailSubjectTemplateText@=(%PROJECT_NAME%) Task created and assigned to you\\: %TASK_NAME% -@taskCreationEmailBodyTemplatePath@=email_templates/create_task_email_template.txt -@taskStatusChangeEmailSubjectTemplateText@=(%PROJECT_NAME%) Task status changed to %UPDATED_TASK_STATUS%\\: %TASK_NAME% -@taskStatusChangeEmailBodyTemplatePath@=email_templates/update_task_status_email_template.txt - #OAuth settings. @oauth.authorizationURL@=https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=%s @oauth.callBackActionUrl@=https://cockpit.cloud.topcoder.com/direct/marathonmatch/callBack.action diff --git a/conf/web/WEB-INF/applicationContext.xml b/conf/web/WEB-INF/applicationContext.xml index 53632717f..977283f02 100644 --- a/conf/web/WEB-INF/applicationContext.xml +++ b/conf/web/WEB-INF/applicationContext.xml @@ -1482,45 +1482,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/conf/web/WEB-INF/struts.xml b/conf/web/WEB-INF/struts.xml index bdca16dd3..5425c67e2 100644 --- a/conf/web/WEB-INF/struts.xml +++ b/conf/web/WEB-INF/struts.xml @@ -565,71 +565,6 @@ /WEB-INF/contest-view.jsp - - - /WEB-INF/task/project/projectTasks.jsp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /WEB-INF/contest-draft-batch-edit.jsp diff --git a/conf/web/WEB-INF/web.xml b/conf/web/WEB-INF/web.xml index db6bb23ce..8b6690aba 100644 --- a/conf/web/WEB-INF/web.xml +++ b/conf/web/WEB-INF/web.xml @@ -12,7 +12,6 @@ contextConfigLocation classpath:/META-INF/asset/applicationContext.xml - classpath:/META-INF/task/applicationContext.xml WEB-INF/securityGroupsApplicationContext.xml WEB-INF/applicationContext.xml diff --git a/src/java/main/com/topcoder/direct/services/view/action/task/BaseTaskAction.java b/src/java/main/com/topcoder/direct/services/view/action/task/BaseTaskAction.java deleted file mode 100644 index dede4364d..000000000 --- a/src/java/main/com/topcoder/direct/services/view/action/task/BaseTaskAction.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.view.action.task; - -import com.topcoder.direct.services.project.task.NotificationService; -import com.topcoder.direct.services.project.task.TaskListService; -import com.topcoder.direct.services.project.task.TaskService; -import com.topcoder.direct.services.view.action.BaseDirectStrutsAction; - -/** - *

- * Base Action for all the tasks actions. - *

- * - * @author TCSASSEMBLER - * @version 1.0 (Module Assembly TC - Cockpit Tasks Management Services Setup and Quick Add Task) - */ -public abstract class BaseTaskAction extends BaseDirectStrutsAction { - - /** - * The task notification service. - */ - private NotificationService taskNotificationService; - - /** - * The task service. - */ - private TaskService taskService; - - /** - * The task list service. - */ - private TaskListService taskListService; - - /** - * Gets the task notification service. - * - * @return the task notification service. - */ - public NotificationService getTaskNotificationService() { - return taskNotificationService; - } - - /** - * Sets the task notification service. - * - * @param taskNotificationService the task notification service. - */ - public void setTaskNotificationService(NotificationService taskNotificationService) { - this.taskNotificationService = taskNotificationService; - } - - /** - * Gets the task service. - * - * @return the task service. - */ - public TaskService getTaskService() { - return taskService; - } - - /** - * Sets the task service. - * - * @param taskService the task service. - */ - public void setTaskService(TaskService taskService) { - this.taskService = taskService; - } - - /** - * Gets the task list service. - * - * @return the task list service. - */ - public TaskListService getTaskListService() { - return taskListService; - } - - /** - * Sets the task list service. - * - * @param taskListService the task list service. - */ - public void setTaskListService(TaskListService taskListService) { - this.taskListService = taskListService; - } -} diff --git a/src/java/main/com/topcoder/direct/services/view/action/task/project/ProjectTaskViewAction.java b/src/java/main/com/topcoder/direct/services/view/action/task/project/ProjectTaskViewAction.java deleted file mode 100644 index cdaf4a0c6..000000000 --- a/src/java/main/com/topcoder/direct/services/view/action/task/project/ProjectTaskViewAction.java +++ /dev/null @@ -1,1431 +0,0 @@ -/* - * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.view.action.task.project; - -import com.topcoder.direct.services.project.metadata.entities.dao.DirectProjectMetadata; -import com.topcoder.direct.services.project.milestone.model.Milestone; -import com.topcoder.direct.services.project.milestone.model.MilestoneStatus; -import com.topcoder.direct.services.project.milestone.model.SortOrder; -import com.topcoder.direct.services.project.task.model.ContestDTO; -import com.topcoder.direct.services.project.task.model.MilestoneDTO; -import com.topcoder.direct.services.project.task.model.Task; -import com.topcoder.direct.services.project.task.model.TaskAttachment; -import com.topcoder.direct.services.project.task.model.TaskFilter; -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.project.task.model.TaskPriority; -import com.topcoder.direct.services.project.task.model.TaskStatus; -import com.topcoder.direct.services.project.task.model.UserDTO; -import com.topcoder.direct.services.view.action.FormAction; -import com.topcoder.direct.services.view.action.task.BaseTaskAction; -import com.topcoder.direct.services.view.dto.CommonDTO; -import com.topcoder.direct.services.view.dto.contest.TypedContestBriefDTO; -import com.topcoder.direct.services.view.dto.copilot.CopilotBriefDTO; -import com.topcoder.direct.services.view.dto.project.ProjectBriefDTO; -import com.topcoder.direct.services.view.dto.project.ProjectContestsListDTO; -import com.topcoder.direct.services.view.dto.task.project.TaskDTO; -import com.topcoder.direct.services.view.dto.task.project.TaskFilterDTO; -import com.topcoder.direct.services.view.dto.task.project.TaskGroupDTO; -import com.topcoder.direct.services.view.form.ProjectIdForm; -import com.topcoder.direct.services.view.util.DataProvider; -import com.topcoder.direct.services.view.util.DirectUtils; -import com.topcoder.security.TCSubject; -import com.topcoder.service.permission.Permission; -import org.apache.commons.lang.StringEscapeUtils; -import org.codehaus.jackson.map.ObjectMapper; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.TransactionDefinition; -import org.springframework.transaction.TransactionStatus; -import org.springframework.transaction.support.DefaultTransactionDefinition; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Comparator; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.SortedMap; - -/** - *

- * The action for project tasks view. - *

- * - *

- * Version 1.1 Release Assembly - TC Cockpit Tasks Management Release 2 - *

    - *
  • Adds method {@link #addTaskList()}
  • - *
  • Adds method {@link #updateTaskList()}
  • - *
  • Adds method {@link #deleteTaskList()}
  • - *
  • Adds method {@link #resolveTaskList()}
  • - *
  • Adds method {@link #getTaskLists()}
  • - *
  • Adds method {@link #addNewTask()}
  • - *
  • Adds method {@link #updateTask()}
  • - *
  • Adds method {@link #getTask()}
  • - *
  • Adds method {@link #removeTask()}
  • - *
  • Adds method {@link #toggleTask()}
  • - *
- *

- * - *

- * Version 1.2 (TC - Cockpit Tasks Management Assembly 3) - *

    - *
  • Adds {@link #filter} and its getter and setter
  • - *
  • Adds {@link #group} and its getter and setter
  • - *
  • Updates {@link #getTaskLists()} to handle the task list filtering and grouping
  • - *
- *

- * - *

- * Version 1.3 (TopCoder Direct - Change Right Sidebar to pure Ajax) - * - Removes the statements to populate the right sidebar direct projects and project contests. It's changed to - * load these data via ajax instead after the page finishes loading. - *

- * - * @author GreatKevin, Veve - * @version 1.3 - */ -public class ProjectTaskViewAction extends BaseTaskAction implements FormAction { - - /** - * The MAX DAYS used by the date filtering to calculate a MIN or MAX date from now - * - * @since 1.2 - */ - private static final int MAX_DAYS = 365 * 50; - - /** - * All the task statuses. - */ - private static Map taskStatuses = new LinkedHashMap(); - - /** - * All the task priorities. - */ - private static Map taskPriorities = new LinkedHashMap(); - - /** - * The date format for the task start date and due date. - */ - private DateFormat taskDateFormat = new SimpleDateFormat("MM/dd/yyyy"); - - /** - * The simple format for the task start date and due date. - */ - private DateFormat taskDateSimpleFormat = new SimpleDateFormat("dd MMM"); - - /** - * The date format used to display the header of group by due date. - * - * @since 1.2 - */ - private DateFormat taskDueDateGroupFormat = new SimpleDateFormat("dd MMM yyyy"); - - /** - * The project ID form. - */ - private ProjectIdForm formData = new ProjectIdForm(); - - /** - * The task users. - */ - private Set taskUserIds = new HashSet(); - - /** - * The users for the permission chosen. - * - * @since 1.1 - */ - private Set taskPermissionUserIds = new HashSet(); - - /** - * The contests for the task / task list association. - * - * @since 1.1 - */ - private Map projectContests = new LinkedHashMap(); - - /** - * The milestones for the task / task list association. - * - * @since 1.1 - */ - private Map projectMilestones = new LinkedHashMap(); - - /** - * The common DTO used for store the right sidebar data. - * - * @since 1.1 - */ - private CommonDTO viewData = new CommonDTO(); - - /** - * The task list id. - * - * @since 1.1 - */ - private long taskListId; - - /** - * The new task. - */ - private TaskDTO task; - - /** - * The project task lists. - * - * @since 1.1 - */ - private List projectTaskLists; - - /** - * The task list instance. - * - * @since 1.1 - */ - private TaskList newTaskList; - - /** - * The Task Filter DTO used to store the task filters. - * - * @since 1.2 - */ - private TaskFilterDTO filter = new TaskFilterDTO(); - - /** - * The Task Group DTO used to store the task grouping type. - * - * @since 1.2 - */ - private TaskGroupDTO group = new TaskGroupDTO(); - - /** - * The transaction manager - */ - PlatformTransactionManager transactionManager; - - /** - * Static initializer - */ - static { - TaskStatus[] statuses = TaskStatus.values(); - - for (TaskStatus s : statuses) { - taskStatuses.put(s.getId(), s.getName()); - } - - TaskPriority[] priorities = TaskPriority.values(); - - for (TaskPriority p : priorities) { - taskPriorities.put(p.getId(), p.getName()); - } - } - - /** - * Gets the form data. - * - * @return the form data. - */ - public ProjectIdForm getFormData() { - return formData; - } - - /** - * Sets the form data. - * - * @param formData the form data. - */ - public void setFormData(ProjectIdForm formData) { - this.formData = formData; - } - - - /** - * Gets all the task statuses. - * - * @return all the task statuses. - */ - public Map getTaskStatuses() { - return taskStatuses; - } - - - /** - * Gets all the task priorities. - * - * @return all the task priorities. - */ - public Map getTaskPriorities() { - return taskPriorities; - } - - /** - * Gets all the task user ids. - * - * @return all the task user ids. - */ - public Set getTaskUserIds() { - return taskUserIds; - } - - /** - * Gets the new task. - * - * @return the new task. - */ - public TaskDTO getNewTask() { - return task; - } - - /** - * Sets the new task. - * - * @param newTask the new task. - */ - public void setNewTask(TaskDTO newTask) { - this.task = newTask; - } - - - /** - * Sets the task. - * - * @param task the task to set. - * @since 1.1 - */ - public void setTask(TaskDTO task) { - this.task = task; - } - - - /** - * Gets the task list. - * - * @return the task list. - * @since 1.1 - */ - public TaskList getNewTaskList() { - return newTaskList; - } - - /** - * Sets the task list. - * - * @param newTaskList the task list. - * @since 1.1 - */ - public void setNewTaskList(TaskList newTaskList) { - this.newTaskList = newTaskList; - } - - /** - * Gets the project task lists. - * - * @return the project task lists. - * @since 1.1 - */ - public List getProjectTaskLists() { - return projectTaskLists; - } - - /** - * Gets the users for the task list permission settings. - * - * @return the users for the task list permission settings. - * @since 1.1 - */ - public Set getTaskPermissionUserIds() { - return taskPermissionUserIds; - } - - /** - * Gets the project contests for setting task/task list association. - * - * @return the project contests for setting task/task list association. - * @since 1.1 - */ - public Map getProjectContests() { - return projectContests; - } - - /** - * Gets the project milestones for setting task/task list association. - * - * @return the project milestones for setting task/task list association. - * @since 1.1 - */ - public Map getProjectMilestones() { - return projectMilestones; - } - - /** - * Sets the task list id. - * - * @param taskListId the task list id. - * @since 1.1 - */ - public void setTaskListId(long taskListId) { - this.taskListId = taskListId; - } - - /** - * Sets the transaction manager. - * - * @param transactionManager the transaction manager. - * @since 1.1 - */ - public void setTransactionManager(PlatformTransactionManager transactionManager) { - this.transactionManager = transactionManager; - } - - /** - * Gets the task filter DTO. - * - * @return the task filter DTO. - * @since 1.2 - */ - public TaskFilterDTO getFilter() { - return filter; - } - - /** - * Sets the task filter DTO. - * - * @param filter the task filter DTO. - * @since 1.2 - */ - public void setFilter(TaskFilterDTO filter) { - this.filter = filter; - } - - /** - * Gets the task group DTO. - * - * @return the task group DTO. - * @since 1.2 - */ - public TaskGroupDTO getGroup() { - return group; - } - - /** - * Sets the task group DTO. - * - * @param group the task group DTO. - * @since 1.2 - */ - public void setGroup(TaskGroupDTO group) { - this.group = group; - } - - /** - * Gets the view data for right sidebar. - * - * @return the view data for right sidebar. - * @since 1.1 - */ - public CommonDTO getViewData() { - return viewData; - } - - /** - * Gets the view data for right sidebar. - * - * @param viewData the view data for right sidebar. - * @since 1.1 - */ - public void setViewData(CommonDTO viewData) { - this.viewData = viewData; - } - - /** - * The entry view action for the project tasks page. - * - * @throws Exception if there is any error. - */ - @Override - protected void executeAction() throws Exception { - getTaskListService().getDefaultTaskList(DirectUtils.getTCSubjectFromSession().getUserId(), - getFormData().getProjectId()); - setUpTaskAsignees(); - setupTaskPermissionUsers(); - setupProjectMilestones(); - setupProjectContests(); - - // right sidebar data - TCSubject currentUser = DirectUtils.getTCSubjectFromSession(); - final ProjectContestsListDTO projectContests = DataProvider.getProjectContests(currentUser.getUserId(), - getFormData().getProjectId()); - ProjectBriefDTO currentDirectProject; - - if (projectContests.getContests().size() > 0) { - currentDirectProject = projectContests.getContests().get(0).getContest().getProject(); - } else { - currentDirectProject = DirectUtils.getCurrentProjectBrief(getProjectServiceFacade(), - getFormData().getProjectId()); - } - - getSessionData().setCurrentProjectContext(currentDirectProject); - getSessionData().setCurrentSelectDirectProjectID(currentDirectProject.getId()); - } - - /** - * Handles the ajax request to get all the project task lists for the project. - * - * @return the result code. - * @since 1.1 - */ - public String getTaskLists() { - try { - - TCSubject currentUser = DirectUtils.getTCSubjectFromSession(); - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - - if(this.taskListId <= 0) { - // get all the task lists of the project - TaskFilter taskFilter; - if(getFilter() != null && getFilter().isApplyFilter()) { - taskFilter = getTaskFilterFromFilterDTO(getFilter()); - } else { - taskFilter = new TaskFilter(); - } - - taskFilter.setProjectIds(Arrays.asList(new Long[]{getFormData().getProjectId()})); - - // filter the task list out first - this.projectTaskLists = getTaskListService().getTaskLists(currentUser.getUserId(), - taskFilter); - - for(TaskList list : this.projectTaskLists) { - // apply filter to task if applyFilter flag is true - if(getFilter() != null && getFilter().isApplyFilter()) { - filterTasksInTaskList(list, taskFilter); - } - } - - if(getGroup() != null && getGroup().getGroupTypeId() == TaskGroupDTO.GROUP_BY_DUE_DATE) { - // group by due date - SortedMap> dateListSortedMap = getTaskService().groupTasksByDueDate(this.projectTaskLists); - List> result = new ArrayList>(); - - for(Date dueDateKey : dateListSortedMap.keySet()) { - Map resultEntry = new HashMap(); - resultEntry.put("dueDate", taskDueDateGroupFormat.format(dueDateKey)); - List> tasksGrouped = new ArrayList>(); - for(Task t : dateListSortedMap.get(dueDateKey)) { - - if(t.getStatus().equals(TaskStatus.COMPLETED)) { - continue; - } - - if(group.getGroupListId() > 0 && group.getGroupListId() != t.getTaskListId()) { - continue; - } - - tasksGrouped.add(m.convertValue(t, Map.class)); - } - resultEntry.put("tasks", tasksGrouped); - - if(tasksGrouped.size() == 0) { - // no include empty grouped task - continue; - } - - result.add(resultEntry); - } - setResult(result); - - } else { - Map>> result = new HashMap>>(); - List> taskListResult = new ArrayList>(); - result.put("tasks", taskListResult); - for (TaskList tl : projectTaskLists) { - taskListResult.add(m.convertValue(tl, Map.class)); - } - setResult(result); - } - - } else { - // get a specific task list - TaskList taskList = getTaskListService().getTaskList(currentUser.getUserId(), this.taskListId); - - if(getFilter().isApplyFilter()) { - filterTasksInTaskList(taskList, getTaskFilterFromFilterDTO(getFilter())); - } - - if(taskList == null) { - throw new IllegalArgumentException("The task list to retrieve does not exist"); - } - - setResult(m.convertValue(taskList, Map.class)); - } - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - - /** - * Handles the ajax request to add a new task list. - * - * @return the result code. - * @since 1.1 - */ - public String addTaskList() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - // set project id to the projectID in projectID form - getNewTaskList().setProjectId(getFormData().getProjectId()); - - // set task list to be active - getNewTaskList().setActive(true); - - if(getNewTaskList().getName() != null) { - // escape the task list name - getNewTaskList().setName(StringEscapeUtils.escapeHtml(getNewTaskList().getName())); - } - - - if(getNewTaskList().getNotes() != null) { - // escape the task list notes - getNewTaskList().setNotes(StringEscapeUtils.escapeHtml(getNewTaskList().getNotes())); - } - - TaskList taskList = getTaskListService().addTaskList(currentUserId, getNewTaskList()); - - taskList = getTaskListService().getTaskList(currentUserId, taskList.getProjectId()); - - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - Map result = m.convertValue(taskList, Map.class); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Handles the ajax request to update the task list. - * - * @return the result code. - * @since 1.1 - */ - public String updateTaskList() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - - TaskList taskListToUpdate = getTaskListService().getTaskList(currentUserId, getNewTaskList().getId()); - - if(taskListToUpdate == null) { - throw new IllegalArgumentException("The task list to update does not exist"); - } - - taskListToUpdate.setName(getNewTaskList().getName()); - taskListToUpdate.setNotes(getNewTaskList().getNotes()); - taskListToUpdate.setPermittedUsers(getNewTaskList().getPermittedUsers()); - - if (getNewTaskList().getAssociatedToContests() != null && getNewTaskList().getAssociatedToContests().size() > 0) { - taskListToUpdate.setAssociatedToContests(getNewTaskList().getAssociatedToContests()); - taskListToUpdate.setAssociatedToProjectMilestones(null); - } else if (getNewTaskList().getAssociatedToProjectMilestones() != null && getNewTaskList().getAssociatedToProjectMilestones().size() > 0) { - taskListToUpdate.setAssociatedToProjectMilestones(getNewTaskList().getAssociatedToProjectMilestones()); - taskListToUpdate.setAssociatedToContests(null); - } else { - taskListToUpdate.setAssociatedToContests(null); - taskListToUpdate.setAssociatedToProjectMilestones(null); - } - - getTaskListService().updateTaskList(currentUserId, taskListToUpdate); - - taskListToUpdate = getTaskListService().getTaskList(currentUserId, taskListToUpdate.getId()); - - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - Map result = m.convertValue(taskListToUpdate, Map.class); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Handles the ajax request to delete the task list. - * - * @return the result code. - * @since 1.1 - */ - public String deleteTaskList() { - - TransactionStatus status = null; - - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - DefaultTransactionDefinition def = new DefaultTransactionDefinition(); - def.setName(this.getClass().getName() + ".deleteTaskList"); - def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); - status = transactionManager.getTransaction(def); - - // get the task to delete first - TaskList taskList = getTaskListService().getTaskList(currentUserId, getNewTaskList().getId()); - - if (taskList == null) { - throw new IllegalArgumentException("The task list to delete does not exist"); - } - - // delete the tasks - List tasksToDelete = taskList.getTasks(); - for (Task t : tasksToDelete) { - for (TaskAttachment ta : t.getAttachments()) { - getTaskService().deleteTaskAttachment(currentUserId, ta.getId()); - } - getTaskService().deleteTask(currentUserId, t.getId()); - } - - // delete the task list finally - getTaskListService().deleteTaskList(currentUserId, getNewTaskList().getId()); - - // commit the transaction - transactionManager.commit(status); - - Map result = new HashMap(); - result.put("taskListDeletedId", getNewTaskList().getId()); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - - if (status != null && !status.isCompleted()) { - // roll back if there is exception - transactionManager.rollback(status); - } - - } - - return SUCCESS; - } - - /** - * Handles the ajax request to resolve the task list. - * - * @return the result code. - * @since 1.1 - */ - public String resolveTaskList() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - getTaskListService().resolveTaskList(currentUserId, getNewTaskList().getId()); - Map result = new HashMap(); - result.put("taskListResolvedId", getNewTaskList().getId()); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Helper methods to populate all the task users from managers and copilots - * - * @throws Exception if any error - */ - private void setUpTaskAsignees() throws Exception { - List allMetadata = getMetadataService().getProjectMetadataByProject(formData.getProjectId()); - - if (allMetadata != null && allMetadata.size() > 0) { - for (DirectProjectMetadata data : allMetadata) { - long keyId = data.getProjectMetadataKey().getId(); - String value = data.getMetadataValue(); - - if (value == null || value.trim().length() == 0) { - // value does not exist, continue - continue; - } - - if (keyId == 1L || keyId == 2L || keyId == 14L) { - // client manager || TopCoder Platform Managers || TopCoder Account Managers - taskUserIds.add(Long.parseLong(value)); - } - } - } - - List copilots = DataProvider.getCopilotProject( - DirectUtils.getTCSubjectFromSession().getUserId(), formData.getProjectId()).getCopilots(); - - if (copilots != null && copilots.size() > 0) { - for (CopilotBriefDTO copilot : copilots) { - taskUserIds.add(copilot.getUserId()); - } - } - } - - /** - * Helper method to setup the permission users. - * - * @throws Exception if any error. - * @since 1.1 - */ - private void setupTaskPermissionUsers() throws Exception { - final List projectPermissions = getPermissionServiceFacade().getPermissionsByProject( - DirectUtils.getTCSubjectFromSession(), getFormData().getProjectId()); - for(Permission p : projectPermissions) { - taskPermissionUserIds.add(p.getUserId()); - } - } - - /** - * Helper method to setup the project milestones. - * - * @throws Exception if any error. - * @since 1.1 - */ - private void setupProjectMilestones() throws Exception { - final List allMilestones = - this.getMilestoneService().getAll(getFormData().getProjectId(), Arrays.asList(MilestoneStatus.values()), - SortOrder.ASCENDING); - for(Milestone m : allMilestones) { - projectMilestones.put(m.getId(), m.getName()); - } - } - - /** - * Helper method to setup the project contests. - * - * @throws Exception if any error. - * @since 1.1 - */ - private void setupProjectContests() throws Exception { - List contests = DataProvider.getProjectTypedContests( - DirectUtils.getTCSubjectFromSession().getUserId(), - getFormData().getProjectId()); - for(TypedContestBriefDTO c : contests) { - projectContests.put(c.getId(), c.getTitle()); - } - } - - - /** - * The action operation to handle the ajax request to quickly create a new task. - * - * @return the action result code. - */ - public String addNewTask() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - Task task = getTaskService().addTask(currentUserId, createNewTaskFromDTO(getNewTask())); - - task = getTaskService().getTask(currentUserId, task.getId()); - - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - Map result = m.convertValue(task, Map.class); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Handles the ajax request to update the task. - * - * @return the result code. - * @since 1.1 - */ - public String updateTask() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - Task task = getTaskService().getTask(currentUserId, this.task.getId()); - - if(task == null) { - throw new IllegalArgumentException("The task to update does not exist"); - } - - task = updateTaskFromDTO(task, this.task); - - getTaskService().updateTask(currentUserId, task); - - // retrieve again for getting detailed data - task = getTaskService().getTask(currentUserId, task.getId()); - - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - Map result = m.convertValue(task, Map.class); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Handles the ajax request to toggle the task. - * - * @return the result code. - * @since 1.1 - */ - public String toggleTask() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - Task task = getTaskService().getTask(currentUserId, this.task.getId()); - - if(task == null) { - throw new IllegalArgumentException("The task to resolve does not exist"); - } - - if(task.getStatus() == TaskStatus.COMPLETED) { - // toggle a completed task, set to Not Start - task.setStatus(TaskStatus.NOT_STARTED); - } else { - task.setStatus(TaskStatus.COMPLETED); - } - - getTaskService().updateTask(currentUserId, task); - - // retrieve again for getting detailed data - task = getTaskService().getTask(currentUserId, task.getId()); - - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - Map result = m.convertValue(task, Map.class); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - - /** - * Handles the ajax request to remove the task. - * - * @return the result code. - * @since 1.1 - */ - public String removeTask() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - getTaskService().deleteTask(currentUserId, this.task.getId()); - - Map removedTask = new HashMap(); - removedTask.put("removedTaskId", String.valueOf(this.task.getId())); - - setResult(removedTask); - - } catch(Throwable e) { - if(getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Handles the ajax request to get the task. - * - * @return the result code. - * @since 1.1 - */ - public String getTask() { - try { - - long currentUserId = DirectUtils.getTCSubjectFromSession().getUserId(); - - Task task = getTaskService().getTask(currentUserId, this.task.getId()); - - ObjectMapper m = new ObjectMapper(); - m.setDateFormat(taskDateSimpleFormat); - Map result = m.convertValue(task, Map.class); - - setResult(result); - - } catch (Throwable e) { - if (getModel() != null) { - setResult(e); - } - } - - return SUCCESS; - } - - /** - * Helper method to populate the Task model from TaskDTO. - * - * @param task the task model - * @param taskDTO the TaskDTO - * @return the populated task model - * @throws Exception if any error. - * @since 1.1 - */ - private Task updateTaskFromDTO(Task task, TaskDTO taskDTO) throws Exception { - // update name - task.setName(StringEscapeUtils.escapeHtml(taskDTO.getName())); - - // update notes - if(taskDTO.getNotes() != null && taskDTO.getNotes().trim().length() > 0) { - // notes set, update notes - task.setNotes(StringEscapeUtils.escapeHtml(taskDTO.getNotes())); - } else { - // update to empty - task.setNotes(null); - } - - // update status - task.setStatus(TaskStatus.forId(taskDTO.getStatusId())); - - // update start date - if(taskDTO.getStartDate() != null && taskDTO.getStartDate().trim().length() > 0) { - task.setStartDate(taskDateFormat.parse(taskDTO.getStartDate())); - } else { - task.setStartDate(null); - } - - // update the task due date if exists - if (taskDTO.getDueDate() != null && taskDTO.getDueDate().trim().length() > 0) { - task.setDueDate(taskDateFormat.parse(taskDTO.getDueDate())); - } else { - task.setDueDate(null); - } - - // update the task assignee - if (taskDTO.getAssignUserIds() != null && taskDTO.getAssignUserIds().size() > 0) { - List users = new ArrayList(); - for (Long userId : taskDTO.getAssignUserIds()) { - UserDTO userDTO = new UserDTO(); - userDTO.setUserId(userId); - users.add(userDTO); - } - - task.setAssignees(users); - } - - // update priority - if(taskDTO.getPriorityId() >= 0) { - task.setPriority(TaskPriority.forId(taskDTO.getPriorityId())); - } - - // update the association - if (taskDTO.getAssociatedContestId() > 0) { - // associate task to contest - ContestDTO contest = new ContestDTO(); - contest.setContestId(taskDTO.getAssociatedContestId()); - task.setAssociatedToContests(Arrays.asList(new ContestDTO[]{contest})); - task.setAssociatedToProjectMilestones(null); - } else if (taskDTO.getAssociatedMilestoneId() > 0) { - // associate task to milestone - MilestoneDTO milestone = new MilestoneDTO(); - milestone.setMilestoneId(taskDTO.getAssociatedMilestoneId()); - task.setAssociatedToProjectMilestones(Arrays.asList(new MilestoneDTO[]{milestone})); - task.setAssociatedToContests(null); - } else { - task.setAssociatedToProjectMilestones(null); - task.setAssociatedToContests(null); - } - - return task; - } - - /** - * Helper method to convert a TaskDTO to Task model - * - * @param taskDTO the TaskDTO instance - * @return the converted Task instance - * @throws Exception if there is any error - */ - private Task createNewTaskFromDTO(TaskDTO taskDTO) throws Exception { - - Task task = new Task(); - - // set the name (escaped) - task.setName(StringEscapeUtils.escapeHtml(taskDTO.getName())); - - if(taskDTO.getNotes() != null && taskDTO.getNotes().trim().length() > 0) { - // set the notes (escaped) - task.setNotes(StringEscapeUtils.escapeHtml(taskDTO.getNotes())); - } else { - task.setNotes(null); - } - - // set the task list id - task.setTaskListId(taskDTO.getTaskListId()); - - // set the TaskStatus enum - task.setStatus(TaskStatus.forId(taskDTO.getStatusId())); - - // set the TaskPriority enum - if(taskDTO.getPriorityId() >= 0) { - task.setPriority(TaskPriority.forId(taskDTO.getPriorityId())); - } else { - // set default priority - NORMAL - task.setPriority(TaskPriority.NORMAL); - } - - // set the task assignee - if (taskDTO.getAssignUserIds() != null && taskDTO.getAssignUserIds().size() > 0) { - List users = new ArrayList(); - for (Long userId : taskDTO.getAssignUserIds()) { - UserDTO userDTO = new UserDTO(); - userDTO.setUserId(userId); - users.add(userDTO); - } - - task.setAssignees(users); - } - - // set the task start date if exists - if (taskDTO.getStartDate() != null && taskDTO.getStartDate().trim().length() > 0) { - task.setStartDate(taskDateFormat.parse(taskDTO.getStartDate())); - } else { - // not exist - task.setStartDate(null); - } - - // set the task due date if exists - if (taskDTO.getDueDate() != null && taskDTO.getDueDate().trim().length() > 0) { - task.setDueDate(taskDateFormat.parse(taskDTO.getDueDate())); - } else { - // not exist - task.setDueDate(null); - } - - // set the creation date - task.setCreatedDate(new Date()); - - if (taskDTO.getAssociatedContestId() > 0) { - // associate task to contest - ContestDTO contest = new ContestDTO(); - contest.setContestId(taskDTO.getAssociatedContestId()); - task.setAssociatedToContests(Arrays.asList(new ContestDTO[]{contest})); - } else if (taskDTO.getAssociatedMilestoneId() > 0) { - // associate task to milestone - MilestoneDTO milestone = new MilestoneDTO(); - milestone.setMilestoneId(taskDTO.getAssociatedMilestoneId()); - task.setAssociatedToProjectMilestones(Arrays.asList(new MilestoneDTO[]{milestone})); - } - - // set the created by - task.setCreatedBy(String.valueOf(DirectUtils.getTCSubjectFromSession().getUserId())); - - return task; - } - - /** - * The comparator to sort the task by creation order. - */ - private static class TaskComparatorByCreationDate implements Comparator { - public int compare(Task t1, Task t2) { - return t2.getCreatedDate().compareTo(t1.getCreatedDate()); - } - } - - /** - * Helper method to transfer a TaskFilterDTO to TaskFilter intance - * - * @param filterDTO the task filter DTO - * @return the TaskFilter instance - * @throws Exception if there is any error. - * @since 1.2 - */ - private TaskFilter getTaskFilterFromFilterDTO(TaskFilterDTO filterDTO) throws Exception { - TaskFilter filter = new TaskFilter(); - - // set task name filter - filter.setName(filterDTO.getName()); - - // set assignee id filter - filter.setAssigneeId(filterDTO.getAssigneeId()); - - // set date to filter - Date dueDateStart = null; - Date dueDateEnd = null; - - if (filterDTO.getDueType() == TaskFilterDTO.DUE_TODAY) { - dueDateStart = new Date(); - dueDateEnd = dueDateStart; - } else if (filterDTO.getDueType() == TaskFilterDTO.DUE_THIS_WEEK) { - Calendar currentDate = Calendar.getInstance(Locale.US); - int firstDayOfWeek = currentDate.getFirstDayOfWeek(); - - Calendar startDate = Calendar.getInstance(Locale.US); - startDate.setTime(currentDate.getTime()); - int days = (startDate.get(Calendar.DAY_OF_WEEK) + 7 - firstDayOfWeek) % 7; - startDate.add(Calendar.DATE, -days); - - Calendar endDate = Calendar.getInstance(Locale.US); - endDate.setTime(startDate.getTime()); - endDate.add(Calendar.DATE, 6); - dueDateStart = startDate.getTime(); - dueDateEnd = endDate.getTime(); - } else if (filterDTO.getDueType() == TaskFilterDTO.DUE_NEXT_WEEK || filterDTO.getDueType() == TaskFilterDTO.DUE_LATER) { - Calendar currentDate = Calendar.getInstance(Locale.US); - int firstDayOfWeek = currentDate.getFirstDayOfWeek(); - - Calendar startDate = Calendar.getInstance(Locale.US); - startDate.setTime(currentDate.getTime()); - startDate.add(Calendar.DATE, 7); - startDate.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); - - Calendar endDate = Calendar.getInstance(Locale.US); - endDate.setTime(currentDate.getTime()); - endDate.add(Calendar.DATE, 7); - endDate.set(Calendar.DAY_OF_WEEK, (firstDayOfWeek + 6)); - dueDateStart = startDate.getTime(); - dueDateEnd = endDate.getTime(); - - if (filterDTO.getDueType() == TaskFilterDTO.DUE_LATER) { - endDate.add(Calendar.DATE, 1); - dueDateStart = endDate.getTime(); - // set end to to 50 years from current time - currentDate.add(Calendar.DATE, MAX_DAYS); - dueDateEnd = currentDate.getTime(); - } - - } else if (filterDTO.getDueType() == TaskFilterDTO.DUE_PAST) { - Calendar startDate = Calendar.getInstance(Locale.US); - Calendar endDate = Calendar.getInstance(Locale.US); - endDate.setTime(startDate.getTime()); - startDate.add(Calendar.DATE, -MAX_DAYS); - endDate.add(Calendar.DATE, -1); - dueDateStart = startDate.getTime(); - dueDateEnd = endDate.getTime(); - } - - if((dueDateStart == null && dueDateEnd == null) && - (filterDTO.getDueDateFrom() != null && filterDTO.getDueDateFrom().trim().length() > 0 - || filterDTO.getDueDateTo() != null && filterDTO.getDueDateTo().trim().length() > 0)) { - // check date range only if there is no date due type chosen or date due type is ANYTIME - Calendar startDate = Calendar.getInstance(Locale.US); - Calendar endDate = Calendar.getInstance(Locale.US); - startDate.add(Calendar.DATE, -MAX_DAYS); - endDate.add(Calendar.DATE, MAX_DAYS); - dueDateStart = startDate.getTime(); - dueDateEnd = endDate.getTime(); - DateFormat dueDateFormat = new SimpleDateFormat("MM/dd/yyyy"); - if(filterDTO.getDueDateFrom() != null && filterDTO.getDueDateFrom().trim().length() > 0) { - dueDateStart = dueDateFormat.parse(filterDTO.getDueDateFrom()); - } - if(filterDTO.getDueDateTo() != null && filterDTO.getDueDateTo().trim().length() > 0) { - dueDateEnd = dueDateFormat.parse(filterDTO.getDueDateTo()); - } - - } - Calendar cal = Calendar.getInstance(Locale.US); - - // change the time part - if(dueDateStart != null) { - cal.setTime(dueDateStart); - cal.set(Calendar.HOUR_OF_DAY, 0); // set hour to midnight - cal.set(Calendar.MINUTE, 0); // set minute in hour - cal.set(Calendar.SECOND, 0); // set second in minute - cal.set(Calendar.MILLISECOND, 0); // set millis in second - dueDateStart = cal.getTime(); - } - - if(dueDateEnd != null) { - cal.setTime(dueDateEnd); - cal.set(Calendar.HOUR_OF_DAY, 23); // set hour to max - cal.set(Calendar.MINUTE, 59); // set minute to max - cal.set(Calendar.SECOND, 59); // set second to max - dueDateEnd = cal.getTime(); - } - - filter.setDueDateFrom(dueDateStart); - filter.setDueDateTo(dueDateEnd); - - // set priority - if(filterDTO.getPriorityIds() != null) { - List priorities = new ArrayList(); - for(long pid : filterDTO.getPriorityIds()) { - priorities.add(TaskPriority.forId(pid)); - } - filter.setPriorities(priorities); - } - - // set status - if(filterDTO.getStatusIds() != null) { - List statuses = new ArrayList(); - for(long sid: filterDTO.getStatusIds()) { - statuses.add(TaskStatus.forId(sid)); - } - filter.setStatuses(statuses); - } - - // set contest ids - filter.setAssociatedToContestIds(filterDTO.getContestIds()); - - // set milestone ids - filter.setAssociatedToProjectMilestoneIds(filterDTO.getMilestoneIds()); - - return filter; - } - - - /** - * Helper method to filter the tasks in the task list with the specified TaskFilter. - * - * @param list the task list - * @param filter the task filter - * @since 1.2 - */ - private void filterTasksInTaskList(TaskList list, TaskFilter filter) { - List filteredTasks = new ArrayList(); - List tasks = list.getTasks(); - - for(Task t : tasks) { - - // 1) NAME - if (filter.getName() != null && filter.getName().trim().length() > 0) { - if (t.getName().toLowerCase().indexOf(filter.getName().toLowerCase()) == -1) { - // do not contain the name, bypass - continue; - } - } - - - // 2) ASSIGNEE - if (filter.getAssigneeId() != null && filter.getAssigneeId() > 0) { - List assignees = t.getAssignees(); - boolean matched = false; - for (UserDTO ud : assignees) { - if (ud.getUserId() == filter.getAssigneeId()) { - matched = true; - break; - } - } - if (!matched) { - // no match, bypass - continue; - } - } - - - // 3) DUE - if (filter.getDueDateFrom() != null && filter.getDueDateTo() != null) { - if (t.getDueDate() == null) { - continue; - } - - if (t.getDueDate().before(filter.getDueDateFrom()) || t.getDueDate().after(filter.getDueDateTo())) { - continue; - } - } - - - // 4) PRIORITIES - if (filter.getPriorities() == null || filter.getPriorities().size() == 0) { - continue; - } else if (!filter.getPriorities().contains(t.getPriority())) { - continue; - } - - // 5) STATUS - if (filter.getStatuses() == null || filter.getStatuses().size() == 0) { - continue; - } else if (!filter.getStatuses().contains(t.getStatus())) { - continue; - } - - // 6) MILESTONE ASSOCIATION - if (filter.getAssociatedToProjectMilestoneIds() != null && filter.getAssociatedToProjectMilestoneIds().size() > 0) { - // do the filters - boolean matched = false; - for (MilestoneDTO md : t.getAssociatedToProjectMilestones()) { - if (filter.getAssociatedToProjectMilestoneIds().contains(md.getMilestoneId())) { - matched = true; - break; - } - } - - if (!matched) { - continue; - } - } - - // 7) CONTEST ASSOCIATION - if (filter.getAssociatedToContestIds() != null && filter.getAssociatedToContestIds().size() > 0) { - // do the filters - boolean matched = false; - for (ContestDTO cd : t.getAssociatedToContests()) { - if (filter.getAssociatedToContestIds().contains(cd.getContestId())) { - matched = true; - break; - } - } - - if (!matched) { - continue; - } - } - - // all matched - filteredTasks.add(t); - } - - list.setTasks(filteredTasks); - } -} diff --git a/src/java/main/com/topcoder/direct/services/view/dto/task/project/ProjectTaskViewDTO.java b/src/java/main/com/topcoder/direct/services/view/dto/task/project/ProjectTaskViewDTO.java deleted file mode 100644 index c42d59476..000000000 --- a/src/java/main/com/topcoder/direct/services/view/dto/task/project/ProjectTaskViewDTO.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.view.dto.task.project; - -import com.topcoder.direct.services.project.task.model.TaskList; -import com.topcoder.direct.services.view.dto.CommonDTO; - -/** - *

- * The DTO for Project Task View. - *

- * - * @author TCSASSEMBLER - * @version 1.0 (Module Assembly TC - Cockpit Tasks Management Services Setup and Quick Add Task) - */ -public class ProjectTaskViewDTO extends CommonDTO { - /** - * The default task list - */ - private TaskList defaultTaskList; - - /** - * Gets the default task list - * - * @return the default task list. - */ - public TaskList getDefaultTaskList() { - return defaultTaskList; - } - - /** - * Sets the default task list. - * - * @param defaultTaskList the default task list. - */ - public void setDefaultTaskList(TaskList defaultTaskList) { - this.defaultTaskList = defaultTaskList; - } -} diff --git a/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskDTO.java b/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskDTO.java deleted file mode 100644 index 387ca6808..000000000 --- a/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskDTO.java +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.view.dto.task.project; - -import java.io.Serializable; -import java.util.List; - -/** - *

- * The DTO to transfer the data for a task between front end and back end. - *

- * - * @author GreatKevin - * @version 1.1 - */ -public class TaskDTO implements Serializable { - - /** - * The constant to indicate a long field not set. - * @since 1.1 - */ - public static final long NOT_SET_LONG = -1000; - - /** - * The id of the task. - * @since 1.1 - */ - private long id; - - /** - * The name of the task. - */ - private String name; - - /** - * The notes of the task. - * @since 1.1 - */ - private String notes; - - /** - * The status id of the task. - */ - private long statusId; - - /** - * The id of the task list this task is in. - */ - private long taskListId; - - /** - * The start date of the task. - */ - private String startDate; - - /** - * The due date of the task. - */ - private String dueDate; - - /** - * The priority id of the task. - * @since 1.1 - */ - private long priorityId = NOT_SET_LONG; - - /** - * The associated milestone id of the task. - * @since 1.1 - */ - private long associatedMilestoneId = NOT_SET_LONG; - - /** - * The associated contest id of the task. - * @since 1.1 - */ - private long associatedContestId = NOT_SET_LONG; - - /** - * The user ids this task is assigned to. - */ - private List assignUserIds; - - /** - * Gets the id of the task. - * - * @return the id of the task. - * @since 1.1 - */ - public long getId() { - return id; - } - - /** - * Sets the id of the task. - * - * @param id the id of the task. - * @since 1.1 - */ - public void setId(long id) { - this.id = id; - } - - /** - * Gets the name of the task. - * - * @return the name of the task. - */ - public String getName() { - return name; - } - - /** - * Sets the name of the task. - * - * @param name the name of the task. - */ - public void setName(String name) { - this.name = name; - } - - /** - * Set the status id of the task. - * - * @return the status id of the task. - */ - public long getStatusId() { - return statusId; - } - - /** - * Sets the status id of the task. - * - * @param statusId the status id of the task. - */ - public void setStatusId(long statusId) { - this.statusId = statusId; - } - - /** - * Gets the id of the task list. - * - * @return the id of the task list. - */ - public long getTaskListId() { - return taskListId; - } - - /** - * Sets the id of the task list. - * - * @param taskListId the id of the task list. - */ - public void setTaskListId(long taskListId) { - this.taskListId = taskListId; - } - - /** - * Gets the start date. - * - * @return the start date. - */ - public String getStartDate() { - return startDate; - } - - /** - * Sets the start date. - * - * @param startDate the start date. - */ - public void setStartDate(String startDate) { - this.startDate = startDate; - } - - /** - * Gets the due date. - * - * @return the due date. - */ - public String getDueDate() { - return dueDate; - } - - /** - * Sets the due date. - * - * @param dueDate the due date. - */ - public void setDueDate(String dueDate) { - this.dueDate = dueDate; - } - - /** - * Gets the ids of the users the task is assigned to. - * - * @return the ids of the users the task is assigned to. - */ - public List getAssignUserIds() { - return assignUserIds; - } - - /** - * Sets the ids of the users the task is assigned to. - * - * @param assignUserIds the ids of the users the task is assigned to. - */ - public void setAssignUserIds(List assignUserIds) { - this.assignUserIds = assignUserIds; - } - - /** - * Gets the priority id. - * - * @return the priority id. - * @since 1.1 - */ - public long getPriorityId() { - return priorityId; - } - - /** - * Sets the priority id. - * - * @param priorityId the priority id. - * @since 1.1 - */ - public void setPriorityId(long priorityId) { - this.priorityId = priorityId; - } - - /** - * Gets the associated milestone id. - * - * @return the associated milestone id. - * @since 1.1 - */ - public long getAssociatedMilestoneId() { - return associatedMilestoneId; - } - - /** - * Sets the associated milestone id. - * - * @param associatedMilestoneId the associated milestone id. - * @since 1.1 - */ - public void setAssociatedMilestoneId(long associatedMilestoneId) { - this.associatedMilestoneId = associatedMilestoneId; - } - - /** - * Gets the associated contest id. - * - * @return the associated contest id. - * @since 1.1 - */ - public long getAssociatedContestId() { - return associatedContestId; - } - - /** - * Sets the associated contest id. - * - * @param associatedContestId the associated contest id. - * @since 1.1 - */ - public void setAssociatedContestId(long associatedContestId) { - this.associatedContestId = associatedContestId; - } - - /** - * Gets the notes. - * - * @return the notes. - * @since 1.1 - */ - public String getNotes() { - return notes; - } - - /** - * Sets the notes. - * - * @param notes the notes. - * @since 1.1 - */ - public void setNotes(String notes) { - this.notes = notes; - } -} diff --git a/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskFilterDTO.java b/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskFilterDTO.java deleted file mode 100644 index 426edad0f..000000000 --- a/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskFilterDTO.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.view.dto.task.project; - -import java.io.Serializable; -import java.util.List; - -/** - * This DTO class stores the all kinds of task filters. - * - * @version 1.0 (TC - Cockpit Tasks Management Assembly 3) - * @author TCSASSEMBLER - */ -public class TaskFilterDTO implements Serializable { - - /** - * The due type - anytime - */ - public static final int DUE_ANYTIME = 0; - - /** - * The due type - this week - */ - public static final int DUE_THIS_WEEK = 1; - - /** - * The due type - next week - */ - public static final int DUE_NEXT_WEEK = 2; - - /** - * The due type - later - */ - public static final int DUE_LATER = 3; - - /** - * The due type - past - */ - public static final int DUE_PAST = 4; - - /** - * The due type - today - */ - public static final int DUE_TODAY = 5; - - /** - * The task name used to filter. - */ - private String name; - - /** - * the assignee id used to filter. - */ - private Long assigneeId; - - /** - * The due type used to filter. - */ - private int dueType; - - /** - * The from date of the due date range. - */ - private String dueDateFrom; - - /** - * The to date of the due date range. - */ - private String dueDateTo; - - /** - * The priority ids used to filter. - */ - private List priorityIds; - - /** - * The status ids used to filter. - */ - private List statusIds; - - /** - * The milestone ids used to filter. - */ - private List milestoneIds; - - /** - * The contest ids used to filter. - */ - private List contestIds; - - /** - * The flag to indicate whether the filter is applied. - */ - private boolean applyFilter = false; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Long getAssigneeId() { - return assigneeId; - } - - public void setAssigneeId(Long assigneeId) { - this.assigneeId = assigneeId; - } - - public String getDueDateFrom() { - return dueDateFrom; - } - - public void setDueDateFrom(String dueDateFrom) { - this.dueDateFrom = dueDateFrom; - } - - public String getDueDateTo() { - return dueDateTo; - } - - public void setDueDateTo(String dueDateTo) { - this.dueDateTo = dueDateTo; - } - - public List getPriorityIds() { - return priorityIds; - } - - public void setPriorityIds(List priorityIds) { - this.priorityIds = priorityIds; - } - - public List getStatusIds() { - return statusIds; - } - - public void setStatusIds(List statusIds) { - this.statusIds = statusIds; - } - - public List getMilestoneIds() { - return milestoneIds; - } - - public void setMilestoneIds(List milestoneIds) { - this.milestoneIds = milestoneIds; - } - - public List getContestIds() { - return contestIds; - } - - public void setContestIds(List contestIds) { - this.contestIds = contestIds; - } - - public int getDueType() { - return dueType; - } - - public void setDueType(int dueType) { - this.dueType = dueType; - } - - public boolean isApplyFilter() { - return applyFilter; - } - - public void setApplyFilter(boolean applyFilter) { - this.applyFilter = applyFilter; - } -} diff --git a/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskGroupDTO.java b/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskGroupDTO.java deleted file mode 100644 index 450f947bf..000000000 --- a/src/java/main/com/topcoder/direct/services/view/dto/task/project/TaskGroupDTO.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - */ -package com.topcoder.direct.services.view.dto.task.project; - -/** - * This DTO class stores the task grouping information. - * - * @author TCSASSEMBLER - * @version 1.0 (TC - Cockpit Tasks Management Assembly 3) - */ -public class TaskGroupDTO { - - /** - * The group type - no grouping (default, group by task list) - */ - public static final int NO_GROUPING = 0; - - /** - * The group type - group by the due date. - */ - public static final int GROUP_BY_DUE_DATE = 1; - - /** - * The groupu type id, default to no grouping. - */ - private int groupTypeId = NO_GROUPING; - - /** - * The task list id the group is applied. 0 means all the task list - */ - private long groupListId = 0; - - /** - * Gets the group type id. - * - * @return the group type id. - */ - public int getGroupTypeId() { - return groupTypeId; - } - - /** - * Sets the group type id. - * - * @param groupTypeId the group type id. - */ - public void setGroupTypeId(int groupTypeId) { - this.groupTypeId = groupTypeId; - } - - /** - * Get the task list id the group wants to applied to. - * - * @return the task list id - */ - public long getGroupListId() { - return groupListId; - } - - /** - * Sets the task list id the group wants to apply to - * - * @param groupListId the task list id - */ - public void setGroupListId(long groupListId) { - this.groupListId = groupListId; - } -} diff --git a/src/web/WEB-INF/includes/modal/projectTaskModals.jsp b/src/web/WEB-INF/includes/modal/projectTaskModals.jsp deleted file mode 100644 index 01fe1ead0..000000000 --- a/src/web/WEB-INF/includes/modal/projectTaskModals.jsp +++ /dev/null @@ -1,674 +0,0 @@ -<%-- - - Author: GreatKevin - - Version: 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - - Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - - - - Description: modal windows used in the project tasks page - - - - Version 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - - - Updates modal to suppor task creation / update, task list creation / update. - - ---%> -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ include file="/WEB-INF/includes/taglibs.jsp" %> -
-
-
-
- ADD TASK - Close -
-
-
- -
-
-
-
    -
  • - - -
    - - -

    - Task name cannot be empty - 80 characters remaining -

    -
    -
  • -
  • - - -
    - - -

    - 250 characters remaining -

    -
    -
  • -
  • - - -
    - -
    -
  • -
  • - - -
    - -
    -
  • -
  • - - -
    - -
    -
  • -
  • - - -
    - -
    -
  • -
  • - - -
    -
    -
    Select - Users
    - -
    -
    -
  • -
  • - - -
    - -
    -
  • -
  • - - -
    -
    - - - -
    -
    - - - -
    -
    -
  • -
  • - - -
    -
    -
    -
    -
    -
    -
    - Attach Another File - -
    -
    -
    -
    -
    -
  • -
-
-
-
- ADD - CANCEL - -
-
-
- -
-
-
-
-
- -
- - -
-
-
-
-
- MESSAGE - Close -
-
-
- -
-
-

Task has been added.

-
-
- OK - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
- ADD TASK LIST - Close -
-
-
- -
-
-
    -
  • - - -
    - - -

    - Task list name cannot be empty - 80 characters remaining -

    -
    -
  • -
  • - - -
    - - -

    - 250 characters remaining -

    -
    -
  • -
  • - - -
    -
    - - -
    -
    -
  • -
  • - - -
    -

    Users with permission to this task list :

    - -
    -
    Select - Users
    - -
    -
    -
  • -
  • - - -
    -
    - - - -
    -
    - - - -
    -
    -
  • - -
-
-
- ADD - CANCEL - -
-
-
- -
-
-
-
-
- -
- - -
-
-
-
-
- MESSAGE - Close -
-
-
- -
-
-

Task list has been added.

-
-
- OK - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
- Edit TASK LIST - Close -
-
-
-
- -
-
    -
  • - - -
    - - -

    - Task list name cannot be empty - 80 characters remaining -

    -
    -
  • -
  • - - -
    - - -

    - 250 characters remaining -

    -
    -
  • -
  • - - -
    -
    - - -
    -
    -
  • -
  • - - -
    -

    Users with permission to this task list :

    - -
    -
    Select - Users
    - -
    -
    -
  • -
  • - - -
    -
    - - - -
    -
    - - - -
    -
    -
  • - -
-
- SAVE - CANCEL - -
-
-
-
- -
-
-
-
-
- -
- - -
-
-
-
-
- MESSAGE - Close -
-
-
- -
-
-

Changes have been saved.

-
-
- OK - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
-
- RESOLVE AND ARCHIVE TASK LIST - Close -
-
-
- -
-
-

Are you sure you want to resolve all tasks in the list and archive the list ?

-
-
- YES - NO - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
-
- MESSAGE - Close -
-
-
- -
-
-

Task List has been resolved and archived.

-
-
- OK - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
-
- DELETE TASK LIST - Close -
-
-
- -
-
-

Are you sure you want to delete the task list and all tasks in the list?

-
-
- YES - NO - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
-
- MESSAGE - Close -
-
-
- -
-
-

Task List has been deleted.

-
-
- OK - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
-
- DELETE TASK - Close -
-
-
- -
-
-

Are you sure you want to delete the task?

-
-
- YES - NO - -
-
-
- -
-
-
-
-
- -
-
- - -
-
-
-
-
- MESSAGE - Close -
-
-
- -
-
-

Task has been deleted.

-
-
- OK - -
-
-
- -
-
-
-
-
- -
-
- diff --git a/src/web/WEB-INF/includes/newHeader.jsp b/src/web/WEB-INF/includes/newHeader.jsp index 3b42c7c40..158915d0b 100644 --- a/src/web/WEB-INF/includes/newHeader.jsp +++ b/src/web/WEB-INF/includes/newHeader.jsp @@ -23,6 +23,9 @@ - Version 1.6 (Topcoder - Migrate Struts 2.3 to 2.5 For Direct App) - - Replace name attribute for s:set with var attribute - + - Version 1.7 (TOPCODER - REMOVE TASKS TAB IN DIRECT APP) + - - Remove tasks tab + - - Description: The new cockpit header and navigation. --%> <%@ page import="com.topcoder.direct.services.configs.ServerConfiguration" %> @@ -488,9 +491,6 @@ "> Assets -
  • class="active"> - "> Tasks -
  • class="active"> ">VM Management
  • diff --git a/src/web/WEB-INF/includes/oldHeader.jsp b/src/web/WEB-INF/includes/oldHeader.jsp index f179b7521..a978e33db 100644 --- a/src/web/WEB-INF/includes/oldHeader.jsp +++ b/src/web/WEB-INF/includes/oldHeader.jsp @@ -54,6 +54,8 @@ - Version 3.3 (Release Assembly - TC Cockpit Misc Bug Fixes) change notes: Make Game Plan tab clickable and link to game plan page - Version 3.4 (Topcoder - Migrate Struts 2.3 to 2.5 For Direct App) - - Replace name attribute for s:set with var attribute + - Version 3.5 (TOPCODER - REMOVE TASKS TAB IN DIRECT APP) + - - remove tasks tab --%> <%@ page import="com.topcoder.direct.services.configs.ServerConfiguration" %> <%@ page import="com.topcoder.direct.services.view.action.accounting.ClientInvoiceManageAction" %> @@ -639,10 +641,6 @@
  • class="on"> ">Files
  • - -
  • class="on"> - ">Tasks -
  • diff --git a/src/web/WEB-INF/includes/popups.jsp b/src/web/WEB-INF/includes/popups.jsp index 77a124fb4..6a036d30d 100644 --- a/src/web/WEB-INF/includes/popups.jsp +++ b/src/web/WEB-INF/includes/popups.jsp @@ -977,11 +977,6 @@ - - - - - diff --git a/src/web/WEB-INF/task/project/projectTasks.jsp b/src/web/WEB-INF/task/project/projectTasks.jsp deleted file mode 100644 index ef099381c..000000000 --- a/src/web/WEB-INF/task/project/projectTasks.jsp +++ /dev/null @@ -1,894 +0,0 @@ -<%-- - - Author: GreatKevin, TCSASSEMLBER - - - - Version: 1.4 - - Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. - - - - Description: This page renders the project tasks view. - - - - Version 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - - Updates to support task CRUD and task list CRUD - - - - Version 1.2 (TC - Cockpit Tasks Management Assembly 3) - - - Adds the task filtering - - - Adds the task grouping. - - - - Version 1.3 (Release Assembly - TopCoder Cockpit Navigation Update) - - - Move the beta notification out of the bread crumb area - - - - Version 1.4 (TC Direct Rebranding Assembly Project and Contest related pages) - - - Rebranding the project tasks page ---%> -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ include file="/WEB-INF/includes/taglibs.jsp" %> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    -
    -
    - - - -
    - - - -
    - -
    - -
    - " class="home">Dashboard - > - ">Projects > - > - Tasks -
    - -
    -

    - BETA ANNOUNCEMENT: - Welcome to the new Task Management area of Direct. You will see this new section under each of your projects. You are welcome to play around and begin using it, but please keep in - mind that some features are not implemented yet. For a full description of what is currently implemented, check out Platform Announcements. -

    -
    - - -
    -
    -

    ADD A TASK

    - More Details -
    -
    -
    -
    - -
    -
    - - - - <%----%> -
    -
    - - -
    -
    -
    -
    Assign to User
    - -
    -
    -
    - -
    -
    - ADD -
    -
    -
    -
    - - -
    -
    -

    Task name:

    -
    - -
    -

    Show to-dos assigned to:

    - -

    Show to-dos that are due

    - -

    Due Date

    -
    - - To - -
    -

    Priority:

    -
      -
    • -
    • -
    • -
    -

    Status:

    -
      -
    • -
    • -
    • -
    • -
    -

    Associated With Project Milestone

    -
    -
    Any Milestone
    - -
    -

    Associated With Challenges

    -
    -
    Any Challenge
    - -
    - Clear - Apply Filters -
    -
    -
    -
    -
    - -
    -
    -

    Task List

    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -

    0 out of 0 completed across 0 Task List

    -

    No Task on this project

    -
    - -
    - - - - - ADD A TASK LIST -
    -
    -
    -
    -
    -
    - - -
    -
    -
    -
    -
    -

    Project Tasks

    - Add New Task -
    -
    -
    -
    -
    -

    This is your default task list for this project, you can add tasks by clicking on “Add New Task” button, you can quickly add task by using the top section. “More details button” allows you to input other infomation about the task.

    -

    You can also create new task list by clicking on “Add a Task List” button.

    -

    Have questions or need help?

    - -
    -
    -
    -
    -
    - -<%--
    --%> -<%--
    --%> - <%--
    --%> - <%--
    --%> - <%--

    Project Tasks

    --%> - <%--Resolve--%> - <%--Delete--%> - <%--Edit--%> - <%--Add New Task--%> - <%--
    --%> - <%--
    --%> -<%--
    --%> -<%--
    --%> -<%--
    --%> - <%--<%–

    Associated with : Challenge Name 1, Project Milestone 1

    –%>--%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--

    0 out of Completed

    --%> - <%--
    --%> - <%--

    --%> -<%--
    --%> -<%----%> - -<%----%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--More Details--%> - <%--Delete--%> - <%--Edit--%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%----%> - <%----%> - <%--

    --%> - <%--
    --%> - - <%--
    --%> - <%--
    --%> - <%----%> - <%--

    ">

    --%> - <%--
    --%> - <%--
    --%> - <%----%> - <%--

    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%----%> - <%--

    --%> - <%--
    --%> - <%--Overdue--%> - <%--
    --%> - <%--
    --%> - <%----%> - <%--

    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%----%> - <%--
      --%> - - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%----%> - - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> - <%--
    --%> -<%--
    --%> - -<%--
    --%> - <%--

    This is your default task list for this project, you can add tasks by clicking on “Add New Task” button, you can quickly add task by using the top section. “More details button” allows you to input other infomation about the task.

    --%> - <%--

    You can also create new task list by clicking on “Add a Task List” button.

    --%> - <%--

    Have questions or need help?

    --%> - <%----%> -<%--
    --%> -<%--
    --%> -<%--
    --%> -<%--
    --%> -<%--
    --%> -<%----%> - - -
    - - - -
    - -
    - -
    -
    -
    -
    - Cancel - Save -
    -
    -
    - -
    -
    Select Users
    - -
    -
    -
    - - -
    -
    - - -
    -
    -
    -
    -
    - -
    -
    -
    -
    - Cancel - Save -
    -
    -
    -
    -
    - -
    -
    Select Users
    - -
    -
    -
    - - -
    -
    - - -
    -
    - -
    - - to - -
    -
    -
    - -
    - -
    - -
    -
    - -
    - -
    -
    -
    - - -
    -
    -
    - -
    -
    -
    -
    - -
    - -
    - - -
    -
    - - -
    - - - -
    - -
    - -
    -
    - - - - - - - - - - diff --git a/src/web/css/direct/projectTasks.css b/src/web/css/direct/projectTasks.css deleted file mode 100644 index 54f2ab02b..000000000 --- a/src/web/css/direct/projectTasks.css +++ /dev/null @@ -1,1560 +0,0 @@ -/* - * Copyright (C) 2013 - 2014 TopCoder Inc., All Rights Reserved. - * - * Used for the project tasks pages. - * - * @version 1.0 (Module Assembly TC - Cockpit Tasks Management Services Setup and Quick Add Task) - * @version 1.1 (Release Assembly - TC Cockpit Tasks Management Release 2) - * - Update the error label css - * @version 1.2 (TC Direct Rebranding Assembly Project and Contest related pages) - * - Rebranding the project tasks page - * - * @author GreatKevin, TCSASSEMBLER - */ -.taskPage #content{ - min-width: 1347px -} -.taskPage #mainContent{ - overflow: visible; -} -.taskPage #area1{ - z-index: 1; -} -.addTaskPanel{ - position: relative; - margin-top: 26px; - border:1px solid #f7f7f7; - background: #f1f1f1; - padding: 0 26px 0 16px; - z-index: 10; -} - .addTaskPanel .panelHeader{ - height: 62px; - overflow: hidden; - background: #f1f1f1; - } - .addTaskPanel .panelHeader h3{ - line-height: 61px; - border-bottom:1px solid #999999; - height: 61px; - overflow: hidden; - padding-left: 37px; - background: url(/images/icon-project.png) 0 center no-repeat; - color: #666666; - font-weight: bold; - font-size: 24px; - } - .addTaskPanel .panelHeader .jsAddTaskDetailedPopup{ - display: block; - position: absolute; - top: 9px; - right: 23px; - line-height: 45px; - height: 45px; - border-left: 1px solid #cccccc; - text-decoration: none; - font-size: 12px; - font-weight: normal; - color: #FF6700; - } - .addTaskPanel .panelHeader .jsAddTaskDetailedPopup span{ - display: block; - height: 34px; - padding: 9px 16px 0 45px; - text-decoration: none; - } - .addTaskPanel .panelHeader .jsAddTaskDetailedPopup span span{ - display: block; - height: 28px; - line-height: 29px; - background: url(/images/icon-task-more-details2.png) 0 center no-repeat; - padding: 0 0 0 37px; - } - .addTaskPanel .panelHeader .jsAddTaskDetailedPopup:hover{ - text-decoration: underline; - cursor: pointer; - } - .addTaskPanel .panelHeader .jsAddTaskDetailedPopup:hover span{ - cursor: pointer; - } - .addTaskPanel .panelContent{ - background-color: #f1f1f1; - border-top-width: 0; - padding: 15px 96px 15px 15px; - height: 24px; - position: relative; - } - .addTaskPanel .panelContent form{ - display: block; - height: 24px; - } - .addTaskPanel .col1{ - width: 22%; - min-width:207px; - } - .addTaskPanel .col2{ - width: 14%; - min-width:137px; - } - .addTaskPanel .col3{ - width: 24%; - min-width:222px; - } - .addTaskPanel .col4{ - width: 19%; - min-width:183px; - } - .addTaskPanel .col5{ - width: 18%; - min-width:170px; - } - .addTaskPanel input{ - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - font-size: 11px; - } - .addTaskPanel .textInput{ - padding: 4px 6px; - border-radius: 4px; - width: 179px; - margin-right: 14px; - color: #666666; - border: 1px solid #e7e7e7; - } - .addTaskPanel .focused{ - color: #666666; - } - .addTaskPanel select{ - color: #666666; - margin-top: 1px; - padding: 1px; - height: 21px; - } - .addTaskPanel #quickTaskStatus{ - width: 122px; - margin-right: 15px; - } - .addTaskPanel .task-date-pick{ - padding: 2px 5px; - border-radius: 4px; - width: 58px; - color: #666666; - border: 1px solid #e7e7e7; - } - .addTaskPanel .selected{ - color: #666666; - } - .addTaskPanel .dp-choose-date{ - margin-left: 3px; - margin-right: 15px; - } - .addTaskPanel .taskMultiSelector { - width: 168px; - margin-right: 15px; - } - .addTaskPanel .corner{ - background: url(/images/gray-corners-custom.png) 0 0 no-repeat; - display: block; - position: absolute; - width: 4px; - height: 4px; - overflow: hidden; - } - .addTaskPanel #quickAssignTask{ - width: 170px; - } - .addTaskPanel .quickAddTaskBtn{ - position: absolute; - background: url(/images/button-left-plus.png) 0 0 no-repeat; - top: 15px; - right: 15px; - margin: 0; - padding-left: 27px; - height: 24px; - line-height: 24px; - display: inline-block; - width: auto; - } - .addTaskPanel .quickAddTaskBtn span{ - background: url(/images/button-right.png) 100% 0 no-repeat; - padding: 0 6px; - height: 24px; - font-size: 13px; - color: #fffffe; - overflow: hidden; - text-decoration: none; - line-height: 24px; - display: inline-block; - width: auto; - } - .addTaskPanel .quickAddTaskBtn:hover{ - background-position: 0 -24px; - } - .addTaskPanel .quickAddTaskBtn:hover span{ - background-position: 100% -24px; - } -.taskMultiSelector { - position: relative; -} - .taskMultiSelector .trigger{ - margin-right: 24px; - cursor: pointer; - } - .taskMultiSelector .trigger .msValue, .taskMultiSelector .trigger .msValue:hover{ - display: block; - height: 24px; - line-height: 24px; - font-size: 11px; - color: #666666; - overflow: hidden; - padding-left: 7px; - /*background: url(/images/task-multi-selector.png) 0 0 no-repeat;*/ - text-decoration: none; - } - .taskMultiSelector .trigger .selectorArrow{ - display: block; - height: 24px; - width: 24px; - background: url(/images/task-multi-selector.png) 100% -48px no-repeat; - position: absolute; - top: 0; - right: 0; - } - .taskMultiSelector .trigger .hidden{ - display: none; - } - .taskMultiSelector .dropDown{ - display: none; - position: absolute; - top: 23px; - left: 0; - border: 1px solid #e7e7e7; - background-color: #ffffff; - } - .taskMultiSelectorOpen .dropDown ul{ - padding: 7px 0 6px 0; - overflow-y: auto; - overflow-x: hidden; - max-height: 120px; - border-bottom: 1px solid #dddddd; - position: relative; - list-style-type: none; - } - .taskMultiSelectorOpen .dropDown ul li{ - padding: 5px 0 3px 32px; - font-size: 11px; - line-height: 16px!important; - position: relative; - list-style-type: none; - min-height: 16px!important; - } - .taskMultiSelectorOpen .dropDown ul li input{ - position: absolute; - top: 6px; - left: 12px; - width: 13px; - height: 13px; - } - .taskMultiSelectorOpen .dropDown ul li label{ - display: inline-block; - line-height: 16px!important; - font-size: 11px; - cursor: pointer; - padding: 0; - } - .taskMultiSelectorOpen .dropDown .btnWrapper{ - height: 24px; - padding: 7px 0; - background-color: #f1f1f1; - text-align: center; - } - .taskMultiSelectorOpen .dropDown .btnWrapper a span{ - padding: 0 26px 0 22px; - } - - .taskMultiSelectorOpen .dropDown{ - display: block; - } - - .taskMultiSelectorOpen .trigger span{ - background-position: 0 -24px; - } - .taskMultiSelectorOpen .trigger .selectorArrow{ - background-position: 100% -72px; - } - .dropDown .buttonRed1{ - height: 21px; - line-height: 21px; - background: #00aeff; - border-bottom: 3px solid #0096ff; - border-radius: 4px; - behavior: url(/css/PIE.htc); - color: #ffffff; - - } - .dropDown .buttonRed1 span{ - background: none; - } - .dropDown .buttonRed1:hover{ - border-bottom: 3px solid #00aeff; - - } -.taskListContainer{ - padding: 20px 0 0 343px; - min-height: 540px; - position: relative; - z-index: 9; -} - .taskListContainer ul, .taskListContainer ul li{ - list-style-type: none; - } - .taskListContainer .taskListFilter{ - width: 272px; - position: absolute; - top: 20px; - left: 0; - border: 1px solid #e7e7e7; - background-color: #f1f1f1; - padding: 28px 22px 60px 22px; - font-size: 11px; - } - .taskListFilter .fieldLabel{ - padding: 6px 1px; - line-height: 12px; - font-size: 11px; - font-weight: bold; - color: #666666; - } - .taskListFilter .searchTaskByName{ - background: url("/images/filter-panel/search_icon.png") no-repeat scroll 98% 3px #FFFFFF; - height: 22px; - border: 1px solid #c2c2c2; - height: 20px; - width: 270px; - margin-bottom: 13px; - } - .taskListFilter .searchTaskByName input{ - border-width: 0; - width: 234px; - padding: 1px 0 0 6px; - } - .taskListFilter select{ - color: #666666; - margin-top: 1px; - padding: 1px; - height: 21px; - width: 272px; - margin-bottom: 12px; - } -.dueDateFilter{ - margin-bottom: 14px; - height: 22px; -} - .dueDateFilter input{ - width: 97px; - border: 1px solid #e7e7e7; - border-radius: 4px; - padding: 3px 0; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - font-size: 11px; - color: #666666; - } - .dueDateFilter .dp-choose-date{ - margin: 0 0 0 2px; - } - .dueDateFilter span.fLeft{ - display: block; - width: 21px; - line-height: 22px; - text-align: center; - } - .taskListFilter #filterByPriority{ - margin-bottom: 9px; - } - .taskListFilter #filterByPriority li{ - padding: 2px 0 3px 1px; - height: 17px; - } - .priorityLabel { - background-image: url(/images/icon-task-priority.png); - background-repeat: no-repeat; - padding-left: 24px; - height: 18px; - line-height: 18px; - display: inline-block; - cursor: pointer; - } - .taskListFilter #filterByPriority input { - height:12px; - width: 12px; - margin-right: 6px; - vertical-align: text-top; - } - .priorityHigh{ - background-position: 0 0; - } - .priorityNormal{ - background-position: 0 -17px; - } - .priorityLow{ - background-position: 0 -34px; - } - .taskListFilter #filterByStatus{ - margin-bottom: 2px; - } - .taskListFilter #filterByStatus li{ - height: 12px; - line-height: 12px; - padding: 0 0 10px 1px; - } - .taskListFilter #filterByStatus li input{ - height:12px; - width: 12px; - margin-right: 6px; - vertical-align: text-top; - } - .taskListFilter #filterByStatus li label{ - display: inline-block; - cursor: pointer; - } - .taskListFilter #filerByPM{ - z-index: 10; - margin-bottom: 10px; - } - .taskListFilter #filerByContest{ - z-index: 9; - } -.taskListControlPanel { - height: 119px; - border: 1px solid #e7e7e7; - position: relative; - background: #f1f1f1; - padding: 0 16px 6px 16px; - margin-bottom: 20px; -} - .taskListControlPanel h2{ - height: 62px; - line-height: 62px; - padding: 0 0 0 44px; - color: #666666; - font-size: 24px; - font-weight: bold; - border-bottom: 1px solid #999999; - background: url(/images/icon-task-list.png) 8px 10px no-repeat; - } - .taskListControlPanel .taskListSummary{ - position: absolute; - top: 12px; - right: 45px; - } - .taskListControlPanel .taskListSummary .emptyTxt{ - line-height: 34px; - font-size: 11px; - color: #666666; - white-space: nowrap; - } - .taskListControlPanel .taskListSummary .summaryTxt{ - line-height: 26px; - font-size: 11px; - color: #666666; - white-space: nowrap; - text-indent: 2px; - } -.progressBarBg { - width: 237px; - height: 18px; - border: 1px solid #d9d9d9; - position: relative; -} - .progressBarBg .progressBar { - width: auto; - height: 18px; - float: left; - display: inline; - overflow: hidden; - position: absolute; - } - .progressBarBg .progressBarLeft { - width: auto; - float: left; - display: inline; - padding-left: 4px; - background: #00aeff; - } - .progressBarBg .progressBarRight { - width: auto; - float: left; - display: inline; - padding-right: 4px; - background: #00aeff; - } - .progressBarBg .progressBarMid { - width: 10px; - float: left; - display: inline; - height: 18px; - background: #00aeff; - } -.smallProgressBarBg { - width: 158px; - height: 18px; - border:1px solid #e7e7e7; - background: #fff; - position: relative; -} - .smallProgressBarBg .smallProgressBar { - width: auto; - height: 18px; - float: left; - display: inline; - overflow: hidden; - } - .smallProgressBarBg .smallProgressBarLeft { - width: auto; - float: left; - display: inline; - padding-left: 3px; - background-position: 0 0; - background-repeat: no-repeat; - background:#00aeff; - } - .smallProgressBarBg .smallProgressBarRight { - width: auto; - float: left; - display: inline; - padding-right: 3px; - background: #00aeff; - } - .smallProgressBarBg .smallProgressBarMid { - width: 10px; - float: left; - display: inline; - height: 18px; - background: #00aeff; - } - .taskListControlPanel .taskListControlArea{ - padding: 14px 1px 0 2px; - height: 24px; - border-top: 1px solid #ffffff; - } - .taskListControlPanel .taskListControlArea label{ - font-size: 12px; - color: #666666; - font-weight: bold; - line-height: 24px; - } - .taskListControlPanel .taskListControlArea select { - color: #666666; - height: 21px; - width: 150px; - font-size: 11px; - padding: 1px; - margin: 2px 20px 0 12px; - } - .taskListControlPanel .taskListControlArea .addTaskList { - margin: 0; - } - .taskListControlPanel .taskListControlArea .addTaskList span{ - padding: 0 6px; - position: relative; - } - .taskListControlPanel .taskListControlArea .addTaskList span i{ - position: absolute; - display: block; - width: 9px; - height: 10px; - background: url(/images/icon-project-task.png) 0 -80px no-repeat; - top: 8px; - left: 9px; - } -.taskListPanel{ - margin-bottom: 20px; - position: relative; -} - .taskListPanel .taskListPanelHeader{ - height: 47px; - padding: 0 0 0 10px; - background: #f1f1f1; - } - .taskListPanel .taskListPanelHeaderRight{ - height: 47px; - padding: 0 10px 0 0; - background: #f1f1f1; - } - .taskListPanel .taskListPanelHeaderInner{ - height: 47px; - padding: 0 45px 0 10px; - background: #f1f1f1; - } - .taskListPanel .taskListPanelHeaderInner h3{ - padding: 5px 0 0 37px; - color: #666666; - font-size: 18px; - font-weight: bold; - line-height: 40px; - background: url(/images/icon-task-list.png) 5px -100px no-repeat; - } - .taskListPanel .taskListPanelHeaderInner h3.defaultList { - background-position: 5px -60px; - } - .taskListPanel .taskListPanelHeaderInner a{ - margin: 10px 0 0 19px; - } - .taskListPanel .taskListPanelHeaderInner .hide{ - display: none; - } -.buttonGray { - display: block; - font-size: 11px; - -webkit-text-size-adjust: none; - font-weight: normal; - text-align: left; - padding:0 4px; - font-family: "Source Sans Pro", Arial, Helvetica, sans-serif; - text-decoration: none; - white-space: nowrap; - overflow: hidden; - - height: 25px; - line-height: 25px; - background: #fff; - border: 1px solid #e7e7e7; - border-radius: 2px; - behavior: url(/css/PIE.htc); - color: #666666; - -} - .buttonGray span { - height: 25px; - line-height: 25px; - display: block; - position: relative; - } -.buttonGray:hover { - background:#ebebeb; -} -.buttonGray:active{ - background:#ff8b03; - border:1px solid #ff8b04; - color: #fffffe; -} - .buttonGray:hover span { - } - .taskListPanel .taskListPanelHeaderInner .buttonGray span i{ - background-image: url("/images/icon-project-task.png"); - background-repeat: no-repeat ; - display: block; - position: absolute; - width: 20px; - height: 25px; - top: 0; - } - .addNewTaskToList span{ - padding: 0 10px 0 27px; - } - .addNewTaskToList span i, - .addNewTaskToList:hover span i{ - background-position: 0 -115px; - left: 6px; - } - .addNewTaskToList:active span i{ - background-position: 0 -588px; - } - .editTaskList span { - padding: 0 24px 0 41px; - } - .editTaskList span i, - .editTaskList:hover span i{ - background-position: 0 -152px; - left: 20px; - } - .editTaskList:active span i{ - background-position: 0 -623px; - } - .deleteTaskList span{ - padding: 0 17px 0 35px; - } - .deleteTaskList span i, - .deleteTaskList:hover span i{ - background-position: 0 -194px; - left: 14px; - } - .deleteTaskList:active span i{ - background-position: 0 -662px; - - } - .resolveTaskList span{ - padding: 0 14px 0 29px; - } - .resolveTaskList span i, - .resolveTaskList:hover span i{ - background-position: 0 -233px; - left: 11px; - } - .resolveTaskList:active span i{ - background-position: 0 -711px; - } - .taskListContent{ - border: 1px solid #e7e7e7; - border-top-width: 0; - padding: 15px 26px 17px; - } - .taskListContent .emptyHint{ - padding-top: 6px; - line-height: 20px; - font-size: 14px; - color: #666666; - } - .taskListContent .emptyHint p{ - padding-bottom: 8px; - } - .taskListContent .emptyHint h4{ - line-height: 22px; - padding-bottom: 3px; - font-size: 14px; - font-weight: bold; - color: #666666; - } - .taskListContent .emptyHint .linkswrapper{ - line-height: 13px; - font-size: 12px; - color: #666666; - } - .taskListContent .emptyHint .linkswrapper a{ - color: #ed0000; - text-decoration: none; - } - .taskListContent .emptyHint .linkswrapper a:hover{ - text-decoration: underline; - } - - .taskListContent .taskListInfo{ - line-height: 15px; - padding-bottom: 5px; - position: relative; - color: #666666; - } - .taskListContent .taskListInfo .associatedInfo{ - font-size: 12px; - line-height: 15px; - padding: 0 250px 13px 0; - } - .taskListContent .taskListInfo .associatedInfo a{ - text-decoration: underline; - color: #f90; - } - .taskListContent .taskListInfo .associatedInfo a:hover{ - text-decoration: none; - cursor: pointer; - } - .taskListContent .taskListInfo .taskListProgress{ - position: absolute; - top: 0; - right: 0; - } - .taskListContent .taskListInfo .taskListProgress p{ - font-size: 11px; - line-height: 18px; - padding-right: 10px; - white-space: nowrap; - } - .taskListContent .taskListInfo .taksListBrief{ - color: #666666; - font-size: 11px; - line-height: 16px; - - } -.taskItem { - border: 1px solid #e5e5e5; - margin-top: 15px; -} -.clearLeftFix{ - clear: left; - display: block; - height: 2px; - overflow: hidden; -} -.taskItemHeader{ - background-color: #f1f1f1; - height: 40px; -} - .taskItemHeader .checkBoxWrapper { - height: 18px; - padding: 11px 0 0 16px; - color: #666666; - font-size: 12px; - font-weight: bold; - max-width: 500px; - overflow: hidden; - white-space: nowrap; - } - .taskItemHeader .checkBoxWrapper input { - vertical-align: text-top; - width: 12px; - height: 12px; - margin-right: 7px; - } -.taskItemLink { - line-height: 18px; - display: inline-block; - color: #f90; - padding: 0 13px 0 21px; - margin: 11px 0 0 10px; - font-size: 11px; - text-decoration: none; - background-image: url("../../images/icon-project-task.png"); - background-repeat: no-repeat; -} -.taskItemLink:hover { - text-decoration: underline; -} -.taskEditLink { - background-position: 0 -156px; -} -.taskDeleteLink { - background-image: url("../../images/trash-icon.png"); -} -.taskMoreDetailsLink { - background-position: 0 -276px; -} -.taskCancelSave { - background-position: 2px -555px; - padding-left: 17px; -} -.taskEditSave { - background-position: 0 -515px; - padding-left: 17px; - -} -.taskItemContent{ - padding: 8px 0 15px 15px; - min-height: 52px; - overflow: hidden; -} -.taskItemContent label{ - display: block; - line-height: 21px; - font-size: 12px; - padding-top: 2px; -} -.taskItemContent p{ - font-size: 11px; -} -.taskItemContent .leftCol{ - width: 57%; - float: left; -} -.taskItemContent .rightCol{ - width: 42%; - float: left; -} -.taskItemContent .col1{ - width: 25%; - float: left; - height: 41px; -} -.taskItemContent .col2{ - width: 34%; - height: 41px; - float: left; -} -.taskItemContent .col3{ - width: 18%; - height: 41px; - float: left; -} -.taskItemContent .col4{ - width: 21%; - height: 41px; - float: left; - position: relative; -} -.taskItemContent .col4 div{ - width: 40px; - padding: 0 0 0 6px; - height: 41px; -} -.taskItemContent .col5{ - width: 94%; - padding: 9px 25px 0 0; - float: left; - clear: left; - display: none; -} -.taskItemContent .col7{ - clear: left; - display: none; -} -.taskItemDetailed .col5, .taskItemDetailed .col7{ - display: block; -} -.statusTextGray{ - font-weight: bold; - color: #666666; -} -.statusTextBlue{ - font-weight: bold; - color: #00aeff; -} -.statusTextGreen{ - font-weight: bold; - color: #80b728; -} -.statusTextRed{ - font-weight: bold; - color: #ff0000; -} -.dateTxt, .noteTxt{ - color: #666666; -} -.overDueAlert{ - display: none; - font-size: 11px; - font-weight: bold; - color: #e70000; - position: absolute; - line-height: 18px; - bottom: -18px; - left: 0; -} -.taskItemContent .isOverdue div{ - background-color: #e70000; -} -.taskItemContent .isOverdue label, .taskItemContent .isOverdue p{ - color: #ffffff; -} -.taskItemContent .isOverdue .overDueAlert{ - display: block; -} -.taskAttachmentUl{ - padding-bottom: 1px; - overflow: hidden; -} - .taskAttachmentUl li{ - width: 142px; - height: 22px; - padding-bottom: 4px; - float: left; - overflow: hidden; - margin-right: 11px; - } - .taskAttachmentUl li a, .editTaskAttachment li a.taskAttachment { - padding-left: 21px; - color: #f90; - display: inline-block; - text-decoration: none; - font-size: 11px; - background-image: url("/images/icon-project-task.png"); - background-repeat: no-repeat; - line-height: 22px; - } - .taskAttachmentUl li a:hover, .editTaskAttachment li a.taskAttachment:hover{ - text-decoration: underline; - } -.typeZip{ - background-position: 0 -317px; -} -.typePdf{ - background-position: 0 -357px; -} -.typeDoc{ - background-position: 0 -397px; -} -.taskAssociateUl{ - overflow: hidden; -} - .taskAssociateUl li{ - height: 16px; - display: block; - } - .taskAssociateUl li a{ - display: inline-block; - font-size: 11px; - color: #666666; - line-height: 16px; - float: left; - text-decoration: underline; - } - .taskAssociateUl li a:hover{ - text-decoration: none; - } -.completedTaskTogger { - overflow: hidden; - padding: 15px 9px 0 16px; - height: 23px; - line-height: 23px; -} -.completedTasksNum{ - height: 23px; - line-height: 23px; - padding: 0 0 0 38px; - font-size: 12px; - font-weight: bold; - background: url("/images/icon-project-task-complete.png") 0 center no-repeat; -} -.showCompletedTasks{ - padding: 2px 0 0 0; - line-height: 12px; - color: #ff8a00; - font-size: 14px; -} -.completedTaskTogger .showCompletedTasks{ - - text-decoration: underline; -} -.showCompletedTasks:hover{ - text-decoration: none; -} -.completedTaskList{ - margin-bottom: 0 -} -.completedTaskListTogger{ - height: 40px; - border: 1px solid #e7e7e7; - padding: 0 0 0 10px; - background: #f1f1f1; -} -.completedTaskListToggerRight{ - height: 40px; - padding: 0 10px 0 0; - background: #f1f1f1; -} -.completedTaskListToggerInner{ - height: 40px; - padding: 0 6px 0 0; - background: #f1f1f1; -} -.completedTaskListNum { - line-height: 23px; - height: 23px; - color: #666666; - margin: 8px 0 0 6px; - font-size: 14px; - font-weight: bold; - padding: 0 0 0 27px; - background: url("../../images/icon-project-task-complete.png") 0 center no-repeat; -} -.showCompletedTaskLists { - color: #f90; - line-height: 16px; - margin: 12px 0 0 0; - font-size: 12px; - text-decoration: none; -} -.showCompletedTaskLists:hover { - text-decoration: underline; -} -.completedTaskListsShowed{ - background-position: 0 -240px; -} - .completedTaskListsShowed .completedTaskListToggerRight{ - background-position: 100% -280px - } -.completedTaskList .taskListPanelHeader{ - background-position: 0 -321px; - height: 39px; -} -.completedTaskList .taskListPanelHeaderRight{ - background-position: 100% -361px; - height: 39px; -} -.completedTaskList .taskListPanelHeaderInner{ - height: 39px; - background-position: 0 -41px; -} - .completedTaskList .taskListPanelHeaderInner h3 { - line-height: 39px; - } - .completedTaskList .taskListPanelHeaderInner a { - margin: 7px 0 0 5px; - } -.completedItem .priorityLabel { - text-decoration: line-through; -} -.completedTaskList .corner{ - display: none; -} -.singlePt .completedTaskListTogger { - display: none; -} -.singlePt .completedTaskList .taskListPanelHeader{ - background-position: 0 0; - height: 40px; -} -.singlePt .completedTaskList .taskListPanelHeaderRight{ - background-position: 100% -80px; - height: 40px; -} -.singlePt .completedTaskList .taskListPanelHeaderInner{ - height: 40px; - background-position: 0 -40px; -} -.singlePt .completedTaskList .corner{ - display: block; -} -.groupByDueDate .taskListContent{ - padding: 15px 28px 16px; -} -.taskListPanel .taskListPanelHeaderInner h3.dateList { - background-image: none; - padding-left: 6px; -} -.taskListPanel .taskListPanelHeaderInner h3.dateList { - background-image: none; - padding-left: 6px; -} -.overDueList .taskListPanelHeader{ - padding-left: 105px; - background: url("/images/tabs5-overdue.png") 0 0 no-repeat; -} - -/*Modal*/ -#new-modal .outLay .modalHeader .modalHeaderCenter{ - height: 36px; - line-height: 36px; - color: #666666; - background: #f1f1f1; - border-bottom: 1px solid #e7e7e7; - padding: 4px 0 0 14px; -} -.popups .taskForm{ - border-top: 1px solid #CCCCCC; - padding: 20px 50px 0 50px; - list-style-type: none; - font-size: 11px; -} -.popups .taskForm li{ - padding-bottom: 12px; - list-style-type: none; - clear: both; - min-height: 25px; -} -.popups .taskForm li .fieldName{ - float: left; - width: 120px; - font-size: 12px; - line-height: 25px; -} -.popups .taskForm li div.right{ - float: left; - width: 418px; -} -.taskPage .popups input.text { - border: 1px solid #e7e7e7; - color: #666666; - padding: 4px 6px; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - background-image: none; - height: 15px; - width: 405px; - line-height: 14px; -} -.taskPage .popups input.fileInput { - color: #666666; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - height: 25px; - width: 360px; -} -.taskPage .popups input.invalid { - border: 1px solid #FF0000; - background-color: #FFE1E0; -} -.taskPage .popups input.task-date-pick{ - width: 116px; -} -.taskPage .popups .dp-choose-date{ - margin: 2px 0 0 6px; -} -.taskPage .popups .taskMultiSelector { - width: 168px; -} -.popups .taskForm div.right .fieldNote{ - text-align: right; - color: #999999; - line-height: 20px; -} -.popups .taskForm div.right .rightRow{ - min-height: 25px; - padding-bottom: 6px; -} -.popups .taskForm div.right .errorMessage{ - display: none; - float: left; -} -.taskPage .popups textarea { - border: 1px solid #e7e7e7; - padding: 4px 6px; - border-radius: 4px; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - line-height: 14px; - resize: none; - overflow: auto; - width: 405px; - height: 59px; - font-size: 11px; - color: #666666; -} -.taskPage .popups select { - color: #666666; - height: 21px; - margin-top: 1px; - padding: 1px; - width: 156px; -} -.taskPage .popups .selectDisabled select { - color: #999999; -} -.taskPage .popups .buttonArea{ - clear: both; -} -/* Add project task modal*/ -#addProjectTaskModal{ - width: 647px; -} -#addProjectTaskModal .fixedHeightTaskFormWrapper{ - height: 570px; -} -#addProjectTaskModal .fixedHeightTaskFormWrapper ul{ - max-height: 550px; - overflow-y: auto; - -} -#addProjectTaskModal .fixedHeightTaskFormWrapper ul li{ - width: 539px; -} -#addProjectTaskModal .tasknameField, #addProjectTaskListModal .taskListNameRow{ - height: 58px; - padding-bottom: 0; -} -#addProjectTaskModal .noteField, #addProjectTaskListModal .taskListNoteRow{ - height: 84px; - padding-bottom: 0; - position: relative; -} -#addProjectTaskModal .noteField .fieldNote, #addProjectTaskListModal .taskListNoteRow .fieldNote{ - position: absolute; - bottom: -5px; - right: 0; -} -#addProjectTaskModal .buttonArea{ - padding-left: 215px; -} -#addProjectTaskModal .buttonArea a.button6 { - margin-right: 30px; - width: 90px; - text-align: center; -} -.associateField input{ - vertical-align: text-top; - width: 12px; - height: 12px; -} -.associateField .chxLbl{ - display: inline-block; - width: 110px; - cursor: pointer; - padding-left: 4px; - font-size: 12px; -} -.newTaskAddFile:hover{ - text-decoration: none; -} -/* Add project task list modal*/ -#addProjectTaskSuccessModal, #addProjectTaskListSuccessModal, #editProjectTaskListSuccessModal, #resolveTaskListSuccessModal{ - width: 288px; -} -#addProjectTaskSuccessModal .modalBody .confirmInfo, #addProjectTaskListSuccessModal .modalBody .confirmInfo, #editProjectTaskListSuccessModal .modalBody .confirmInfo { - background: url("/images/modal-success2.png") 15px 31px no-repeat; - list-style: none outside none; - margin: 0; - min-height: 16px; - padding: 42px 0 42px 72px; - line-height: 16px; -} -#resolveTaskListSuccessModal .modalBody .confirmInfo { - background: url("/images/modal-success2.png") 15px 31px no-repeat; - list-style: none outside none; - margin: 0; - min-height: 16px; - padding: 33px 25px 29px 72px; - line-height: 20px; -} -#addProjectTaskSuccessModal .buttonArea .button6, #addProjectTaskListSuccessModal .buttonArea .button6, #editProjectTaskListSuccessModal .buttonArea .button6, #resolveTaskListSuccessModal .buttonArea .button6 { - width: 48px; -} - -#addProjectTaskListModal, #editProjectTaskListModal{ - width: 647px; -} -.popups .taskForm div.right .radioRow{ - min-height: 20px; - padding-top: 5px; -} -.radioRow input{ - vertical-align: text-top; - width: 12px; - height: 12px; -} -.radioRow label{ - display: inline-block; - cursor: pointer; - padding-left: 4px; - margin-right: 44px; - font-size: 12px; -} -#addProjectTaskListModal .permissionRow, #editProjectTaskListModal .permissionRow{ - height: 50px; -} -#addProjectTaskListModal .buttonArea, #editProjectTaskListModal .buttonArea{ - padding-left: 215px; -} -#addProjectTaskListModal .buttonArea a.button6, #editProjectTaskListModal .buttonArea a.button6 { - margin-right: 30px; - width: 90px; - text-align: center; -} - -/*Resolve modal*/ -#resolveTaskListModal{ - width: 368px; -} -#resolveTaskListModal .modalBody .confirmInfo { - background: url("/images/modal-confirmation.png") 16px 31px no-repeat; - list-style: none outside none; - margin: 0; - padding: 33px 25px 29px 78px; - line-height: 20px; -} -#resolveTaskListModal .buttonArea{ - padding-left: 116px; -} -#resolveTaskListModal .buttonArea .button6 { - width: 48px; - float: left; - margin-right: 32px; -} -#resolveTaskListModal .buttonArea .button6 span.right { - padding: 0px 10px; - text-align: center; -} -/*Delete task list / Delete task modal*/ -#deleteTaskListModal, #deleteTaskModal{ - width: 368px; -} -#deleteTaskListModal .modalBody .confirmInfo, #deleteTaskModal .modalBody .confirmInfo { - background: url("/images/modal-delete.png") 25px 26px no-repeat; - list-style: none outside none; - margin: 0; - padding: 28px 25px 34px 88px; - line-height: 20px; - min-height: 36px; -} -#deleteTaskListModal .buttonArea, #deleteTaskModal .buttonArea{ - padding-left: 116px; -} -#deleteTaskListModal .buttonArea .button6, #deleteTaskModal .buttonArea .button6 { - width: 48px; - float: left; - margin-right: 32px; -} -#deleteTaskListModal .buttonArea .button6 span.right, #deleteTaskModal .buttonArea .button6 span.right { - padding: 0px 10px; - text-align: center; -} -#deleteTaskListSuccessModal, #deleteTaskSuccessModal{ - width: 288px; -} -#deleteTaskListSuccessModal .modalBody .confirmInfo, #deleteTaskSuccessModal .modalBody .confirmInfo { - background: url("/images/modal-delete-success.png") 35px 26px no-repeat; - list-style: none outside none; - margin: 0; - min-height: 16px; - padding: 38px 0 48px 92px; - line-height: 16px; -} - -#deleteTaskListSuccessModal .buttonArea .button6, #deleteTaskSuccessModal .buttonArea .button6 { - width: 48px; -} -#deleteTaskListSuccessModal .buttonArea .button6 span.right, #deleteTaskSuccessModal .buttonArea .button6 span.right { - padding: 0px 10px; - text-align: center; -} - -/*Edit Task*/ -.editTaskItem{ - z-index: 100; - font-size: 11px; -} -.editTaskItem .taskItemContent{ - overflow: visible; -} -.editTaskItem .taskItemHeader .inputWrapper { - padding: 11px 0 0 15px; -} -.editTaskItem .taskItemHeader .inputWrapper input{ - border: 1px solid #e7e7e7; - color: #666666; - padding: 2px 6px; - width: 417px; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - font-size: 11px; - display: block; -} -.quickEditTaskItem .taskItemContent{ - height: 50px; -} -.quickEditCol1{ - width: 26%; - float: left; -} - .quickEditCol1 .taskMultiSelector { - width: 170px; - } -.quickEditCol2{ - width: 26%; - float: left; -} - .editTaskItem select { - color: #666666; - height: 21px; - margin-top: 1px; - padding: 1px; - width: 170px; - } -.quickEditCol3{ - width: 20%; - float: left; -} -.quickEditTaskItem .quickEditCol3 .task-date-pick { - border: 1px solid #e7e7e7; - color: #666666; - padding: 2px 5px; - width: 56px; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - font-size: 11px; -} -.editColLeft{ - width: 57%; - float: left; -} -.editColLeft .editCol1-l{ - width: 39%; - float: left; - height: 64px; - clear: left; -} -.editColLeft .editCol1-r{ - width: 56%; - margin-left: 4%; - float: left; - height: 64px; -} -.editColLeft .editCol1-w{ - width: 100%; - clear: left; -} -.editColLeft .editCol1-w .editCol1-l, .editColLeft .editCol1-w .editCol1-r{ - height: 61px; -} -.editColLeft .editCol1-w .editCol1-l select, .editColLeft .editCol1-w .editCol1-r select{ - margin-top: 10px; -} -.editColLeft .selectDisabled select{ - color: #999999; -} -.editColRight{ - width: 42%; - float: left; -} -.editTaskItem label { - line-height: 22px; -} -.editTaskItem label.chxLbl { - line-height: 12px; - font-size: 11px; -} -.editTaskItem .taskMultiSelector { - width: 170px; -} -.editTaskItem .task-date-pick { - border: 1px solid #e7e7e7; - color: #666666; - padding: 2px 2px; - width: 59px; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - font-size: 11px; -} -.editTaskItem .dp-choose-date { - margin: 0 0 0 5px; -} -.editTaskItem .dueDateWrapper span.fLeft{ - width: 29px; - text-align: center; - display: inline-block; - line-height: 24px; -} -.editTaskItem textarea { - border: 1px solid #e7e7e7; - padding: 4px 6px; - font-family: "Source Sans Pro", Arial,Helvetica,sans-serif; - line-height: 14px; - resize: none; - overflow: auto; - width: 92%; - height: 59px; - font-size: 11px; - color: #666666; -} -.editTaskAttachment li{ - width: 240px; - display: block; - height: 22px; - padding-bottom: 4px; - margin-right: 11px; -} -.editTaskAttachment li a.taskAttachment { - max-width: 160px; - overflow: hidden; - float: left; -} -.editTaskAttachment li a.removeFile { - float: right; - line-height: 22px; - color: #ff0000; -} -.editTaskAttachment li a.removeFile:hover { - text-decoration: none; -} -.editTaskItem .newFileList{ - width: 264px; - padding: 12px 0 8px 0; -} -.editTaskItem .newFileList input{ - width: 264px; -} -.editTaskItem .newFileList .rightRow{ - padding: 0 0 6px 0; -} - -#addProjectTaskSuccessModal .buttonArea .button6, #addProjectTaskListSuccessModal .buttonArea .button6, #editProjectTaskListSuccessModal .buttonArea .button6, #resolveTaskListSuccessModal .buttonArea .button6 { - background: #00aeff; - border-bottom: 3px solid #0096ff; -} - -#addProjectTaskSuccessModal .buttonArea .button6:hover, -#addProjectTaskListSuccessModal .buttonArea .button6:hover, - #editProjectTaskListSuccessModal .buttonArea .button6:hover, - #resolveTaskListSuccessModal .buttonArea .button6:hover { -{ - border-bottom: 3px solid #00aeff; - -} - -#addProjectTaskModal .buttonArea a.closeNewProjectTask { - background: #ff8a00; - border-bottom: 3px solid #ff6700; -} -#addProjectTaskModal .buttonArea a.closeNewProjectTask:hover{ - border-bottom: 3px solid #ff8a00; - -} diff --git a/src/web/css/direct/screen.css b/src/web/css/direct/screen.css index 6bc8bd21f..f90481881 100644 --- a/src/web/css/direct/screen.css +++ b/src/web/css/direct/screen.css @@ -3551,14 +3551,6 @@ a.saveSetting:hover, .modalBody .buttonArea a.saveSetting:hover{ border-bottom: 3px solid #81bc02; } -#addProjectTaskModal .buttonArea a.closeNewProjectTask { - background: #ff8a00; - border-bottom: 3px solid #ff6700; -} -#addProjectTaskModal .buttonArea a.closeNewProjectTask:hover{ - border-bottom: 3px solid #ff8a00; - -} .btnApply{ padding:0 24px; diff --git a/src/web/images/icon-project-task-complete.png b/src/web/images/icon-project-task-complete.png deleted file mode 100644 index fbb0b644c..000000000 Binary files a/src/web/images/icon-project-task-complete.png and /dev/null differ diff --git a/src/web/images/icon-project.png b/src/web/images/icon-project.png deleted file mode 100644 index 973192d63..000000000 Binary files a/src/web/images/icon-project.png and /dev/null differ diff --git a/src/web/images/icon-task-list.png b/src/web/images/icon-task-list.png deleted file mode 100644 index f0603fc4d..000000000 Binary files a/src/web/images/icon-task-list.png and /dev/null differ diff --git a/src/web/images/icon-task-more-details.png b/src/web/images/icon-task-more-details.png deleted file mode 100644 index 92d1488d2..000000000 Binary files a/src/web/images/icon-task-more-details.png and /dev/null differ diff --git a/src/web/images/icon-task-more-details2.png b/src/web/images/icon-task-more-details2.png deleted file mode 100644 index bf5994b02..000000000 Binary files a/src/web/images/icon-task-more-details2.png and /dev/null differ diff --git a/src/web/images/icon-task-priority.png b/src/web/images/icon-task-priority.png deleted file mode 100644 index 07d2f2632..000000000 Binary files a/src/web/images/icon-task-priority.png and /dev/null differ diff --git a/src/web/images/modal-delete-success.png b/src/web/images/modal-delete-success.png deleted file mode 100644 index 423b25963..000000000 Binary files a/src/web/images/modal-delete-success.png and /dev/null differ diff --git a/src/web/images/modal-delete.png b/src/web/images/modal-delete.png deleted file mode 100644 index 8bb005fc7..000000000 Binary files a/src/web/images/modal-delete.png and /dev/null differ diff --git a/src/web/images/modal-success2.png b/src/web/images/modal-success2.png deleted file mode 100644 index 24ac7ee2d..000000000 Binary files a/src/web/images/modal-success2.png and /dev/null differ diff --git a/src/web/images/tabs5-overdue.png b/src/web/images/tabs5-overdue.png deleted file mode 100644 index 4e1a6eb4e..000000000 Binary files a/src/web/images/tabs5-overdue.png and /dev/null differ diff --git a/src/web/images/trash-icon.png b/src/web/images/trash-icon.png deleted file mode 100644 index 1869681d5..000000000 Binary files a/src/web/images/trash-icon.png and /dev/null differ diff --git a/src/web/scripts/dashboard.js b/src/web/scripts/dashboard.js index f4be60ba5..ba8877d9d 100644 --- a/src/web/scripts/dashboard.js +++ b/src/web/scripts/dashboard.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2011 - 2014 TopCoder Inc., All Rights Reserved. + * Copyright (C) 2011 - 2017 TopCoder Inc., All Rights Reserved. * * The JS script for dashboard. * @@ -135,9 +135,12 @@ * Version 3.3 (TopCoder Direct - Change Right Sidebar to pure Ajax) * - Refactor right sidebar scripts into the separate js file rightSidebar.js * + * Version 3.4 (TOPCODER - REMOVE TASKS TAB IN DIRECT APP) + * - Remove unused code of "tasks tab" related + * * @author tangzx, Blues, GreatKevin, isv, GreatKevin, xjtufreeman, - * @author bugbuka, notpad, GreatKevin, Ghost_141, Veve, GreatKevin, Veve - * @version 3.3 + * @author bugbuka, notpad, GreatKevin, Ghost_141, Veve, GreatKevin, Veve, TCCODER + * @version 3.4 */ var mouse_is_inside; @@ -2693,72 +2696,6 @@ $(document).ready(function(){ }); }) -// Multiply selector element functionality -// Moved from projectTasks.js -$(document).ready(function () { - - // binds on document click function which close currently opened selector - function selectorClose(selector) { - var hideFunction = function (event) { - if (event.type != 'click' && $(event.target).closest(".taskMultiSelectorOpen").filter(selector).length) { - return; - } - $(document).unbind('mousedown', hideFunction); - $('.btnWrapper a', selector).unbind('click', hideFunction); - selector.removeClass("taskMultiSelectorOpen"); - buildSelectorLabel(selector); - }; - $(document).bind('mousedown', hideFunction); - $('.btnWrapper a', selector).click(hideFunction); - } - - // builds selector caption and title - function buildSelectorLabel(selector) { - var label = []; - $('input:checked', selector).next('label').each(function () { - var inner = this.innerHTML; - var text = this.innerHTML; - if($(inner).is("a")) { - text = $(inner).text(); - } - label.push(text); - }); - - var displayTxt = label.join(', '); - if (displayTxt == "") { - displayTxt = $(".trigger label", selector).text(); - } - $(".trigger .msValue", selector).text(displayTxt).attr("title", displayTxt); - } - - // handles selector label changes - $('.taskMultiSelector').live('changelabel', function () { - buildSelectorLabel(this); - }); - - $('.taskMultiSelector .trigger').live('click', function () { - var wrapper = $(this).parent(); - if (wrapper.hasClass('disabled')) { - return; - } - var wrapperWidth = wrapper.width(); - if (wrapper.not('.taskMultiSelectorOpen')) selectorClose(wrapper); - wrapper.addClass("taskMultiSelectorOpen"); - $('.dropDown', wrapper).width(wrapperWidth - 2); - }); - - $('.taskMultiSelector li label').live('click',function () { - var li = $(this).parent(); - $("input", li).trigger("click"); - }).live('change', function () { - - // handles selector item label changes - if ($(this).prev(':checked').length) { - buildSelectorLabel($(this).closest('.taskMultiSelector')); - } - }); -}); - var userRecentProjects; $(document).ready(function () { diff --git a/src/web/scripts/projectTasks.js b/src/web/scripts/projectTasks.js deleted file mode 100644 index 2938a5465..000000000 --- a/src/web/scripts/projectTasks.js +++ /dev/null @@ -1,1530 +0,0 @@ -/* - * Copyright (C) 2013 TopCoder Inc., All Rights Reserved. - * - * Javascript for for the project tasks pages. - * - * - Version 1.1 (Module Assembly - TopCoder Cockpit Project Planner) - * Refactor the multiple selection drop down to dashboard.js - * - * - Version 1.2 (Release Assembly - TC Cockpit Tasks Management Release 2) - * - Add methods to suppor task CRUD and task list CRUD. - * - * - Version 1.3 (TC - Cockpit Tasks Management Assembly 3) - * - Adds the task filtering feature - * - Adds the task group by due date feature - * - * @version 1.3 - * @author GreatKevin - */ -var quickTaskNameHint = "Task Name"; - -var userLinksCache = {}; - -var statusMap = { - "NOT_STARTED": {id: 0, name: "Not Started"}, - "IN_PROGRESS": {id: 1, name: "In Progress"}, - "WAIT_ON_DEPENDENCY": {id: 2, name: "Wait On Dependency"}, - "COMPLETED": {id: 3, name: "Completed"} -} - -var priorityMap = { - "HIGH": {id: 0, name: "High"}, - "LOW": {id: 1, name: "Low"}, - "NORMAL": {id: 2, name: "Normal"} -} - -var taskValidationRules = { - rules: { - name: { - required: true, - maxlength:80 - }, - notes: { - maxlength: 250 - } - }, - messages: { - name: { - required: "Task Name cannot be empty", - maxlength: "Task name cannot exceeds 80 characters" - }, - notes: { - maxlength: "Notes cannot exceeds 250 characters" - } - } -}; - -var taskListValidationRules = { - rules: { - name: { - required: true, - maxlength:80 - }, - notes: { - maxlength: 250 - } - }, - messages: { - name: { - required: "Task List Name cannot be empty", - maxlength: "Task List name cannot exceeds 80 characters" - }, - notes: { - maxlength: "Notes cannot exceeds 250 characters" - } - } -}; - - - -var localVM = {}; - -var filterApplied = false; - -if($.views) { - $.views.helpers({ - getUserLink: getUserLink, - getStatusId: getStatusId, - getStatusName: getStatusName, - getPriorityName: getPriorityName - }); -} - -function getUserLink(userId) { - return userLinksCache[userId]; -} - -function getStatusId(enumName) { - return statusMap[enumName].id; -} - -function getStatusName(enumName) { - return statusMap[enumName].name; -} - -function getPriorityId(enumName) { - return priorityMap[enumName].id; -} - -function getPriorityName(enumName) { - return priorityMap[enumName].name; -} - -function buildFilterRequest() { - var filters = {}; - var _filterPanel = $(".taskListFilter"); - - var name = $(".searchBox", _filterPanel).val(); - var assignee = $("#filterAssignedTo").val(); - var dueType = $("#filterDueType").val(); - var dueDateFrom = $("#filterStartDate").val(); - var dueDateTo = $("#filterDueDate").val(); - var priorityIds = []; - $("input[name=priorityFilter]:checked").each(function(){ - priorityIds.push($(this).val()); - }); - var statusIds = []; - $("input[name=statusFilter]:checked").each(function(){ - statusIds.push($(this).val()); - }); - var milestoneIds = []; - $("input[name=milestoneFilter]:checked").each(function(){ - milestoneIds.push($(this).val()); - }); - var contestIds = []; - $("input[name=contestFilter]:checked").each(function(){ - contestIds.push($(this).val()); - }); - - if(name.length > 0) { - filters.name = name; - } - - if(assignee && assignee > 0) { - filters.assigneeId = assignee; - } - - filters.dueType = dueType; - - if(dueType == 0) { - if(dueDateFrom && dueDateFrom.length > 0) { - filters.dueDateFrom = dueDateFrom; - } - if(dueDateTo && dueDateTo.length > 0) { - filters.dueDateTo = dueDateTo; - } - } - - filters.priorityIds = priorityIds; - filters.statusIds = statusIds; - - if(milestoneIds.length > 0) { - filters.milestoneIds = milestoneIds; - } - - if(contestIds.length > 0) { - filters.contestIds = contestIds; - } - - filters.applyFilter = true; - - return filters; -} - -function resetAssociationInput(item, name) { - var selector = item.find("select[name='" + name + "']"); - selector.find("option").removeAttr('selected'); - var wrapper = selector.parent(); - wrapper.addClass("selectDisabled"); - selector.attr('disabled', 'disabled'); - wrapper.find("input[type=checkbox]").removeAttr("checked"); -} - -function loadTaskList(taskListId, callBackFunction) { - var taskListPanel = $("#taskList" + taskListId); - - var request; - if(filterApplied == true) { - request = {formData:{projectId:tcDirectProjectId}, taskListId:taskListId, filter: buildFilterRequest()}; - } else { - request = {formData:{projectId:tcDirectProjectId}, taskListId:taskListId}; - } - - $.ajax({ - type: 'POST', - url: ctx + "/getTaskLists", - data: request, - cache: false, - dataType: 'json', - success: function (jsonResult) { - handleJsonResult(jsonResult, - function (result) { - result['isDefault'] = result['default']; // fix ie8 default keyword issue in template - taskListPanel.html($($("#taskListTemplate").render(result)).html()); - - displayProgress(); - taskListPanel.find(".completedItem").hide(); - - if(callBackFunction) { - callBackFunction(); - } - - localVM[result.id] = result; - updateCompletedStat(); - }, - function (errorMessage) { - showServerError(errorMessage); - }); - } - }); -} - -function updateCompletedStat() { - var completedTasksNum = 0; - var totalTaskNum = 0; - var totalTaskListNum = 0; - $("#switchTaskList option:gt(0)").remove(); - - $.each(localVM, function (key, value) { - completedTasksNum += value.completedTasks.length; - totalTaskNum += value.tasks.length; - totalTaskListNum ++; - if(value.active) { - $("#switchTaskList").append($('