Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * OfficeFloor - http://www.officefloor.net
   * Copyright (C) 2005-2011 Daniel Sagenschneider
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package net.officefloor.model.impl.desk;
 
 
Tests adding a net.officefloor.model.desk.TaskModel.

Author(s):
Daniel Sagenschneider
 
 public class AddTaskTest extends AbstractDeskChangesTestCase {

 
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see
 	 * net.officefloor.compile.impl.desk.AbstractDeskOperationsTestCase#setUp()
 	 */
 	protected void setUp() throws Exception {
 		super.setUp();
 
 		// Obtain the work task model
 		this. = this..getWorks().get(0).getWorkTasks().get(0);
 	}

 
 	public void testWorkTaskNotOnDesk() {
 
 		// Create the work task not on the desk
 		WorkTaskModel workTask = new WorkTaskModel("NOT_ON_DESK");
 
 		// Validate not able to add task if work task not on desk
 		TaskType<?, ?, ?> taskType = this
 				.constructTaskType("NOT_ON_DESK"null);
 		Change<TaskModelchange = this..addTask("TASK"workTask,
 				taskType);
 		this.assertChange(changenull"Add task TASK"false,
 				"Work task NOT_ON_DESK not on desk");
 		assertNotNull("Must have target"change.getTarget());
 	}

Ensures can not apply change if the net.officefloor.model.desk.WorkTaskModel name does not match the net.officefloor.compile.work.TaskType name.
 
 	public void testWorkTaskNameMismatch() {
 
 		// Create a task type with mismatched name
 		TaskType<?, ?, ?> taskType = this.constructTaskType(
 				"MISMATCH_TASK_NAME"null);
 
 		// Validate not able to add task if work task name mismatch
 		Change<TaskModelchange = this..addTask("TASK",
 				this.taskType);
 		this
 				.assertChange(changenull"Add task TASK"false,
 						"Task type MISMATCH_TASK_NAME does not match work task WORK_TASK");
 		assertNotNull("Must have target"change.getTarget());
 	}

Ensure can add net.officefloor.model.desk.TaskModel that uses indexing.
 
	public void testAddTaskWithoutKeys() {
		// Create the task type
		TaskType<?, ?, ?> task = this.constructTaskType("WORK_TASK",
					public void construct(TaskTypeConstructor task) {
						task.addFlow(String.classnull);
						task.addFlow(Integer.classnull);
						// Should ignore objects
						task.addObject(Object.classnull);
					}
				});
		// Validate adding the task and reverting
		Change<TaskModelchange = this..addTask("TASK",
				this.task);
		this.assertChange(changenull"Add task TASK"true);
		change.apply();
		assertEquals("Ensure correct target"this..getTasks().get(0),
				change.getTarget());
	}

Ensure can add net.officefloor.model.desk.TaskModel that uses keys.
	public void testAddTaskWithKeys() {
		// Create the task type
		TaskType<?, ?, ?> task = this.constructTaskType("WORK_TASK",
					public void construct(TaskTypeConstructor task) {
						// Can not have argument types for flows
						task.addFlow(null.);
						task.addFlow(null.);
					}
				});
		// Validate adding the task and reverting
		Change<TaskModelchange = this..addTask("TASK",
				this.task);
		this.assertChange(changenull"Add task TASK"true);
	}

	private enum TaskFlowKeys {
		ONE, TWO
	}

	public void testAddTaskWithLabels() {
		// Create the task type
		TaskType<?, ?, ?> task = this.constructTaskType("WORK_TASK",
					public void construct(TaskTypeConstructor task) {
						task.addFlow(String.classnull).setLabel("FLOW_ONE");
						task.addFlow(Integer.classnull).setLabel("FLOW_TWO");
								"ESCALATION");
					}
				});
		// Validate adding the task and reverting
		Change<TaskModelchange = this..addTask("TASK",
				this.task);
		this.assertChange(changenull"Add task TASK"true);
	}

Ensure can add multiple net.officefloor.model.desk.TaskModel instances ensuring ordering of the net.officefloor.model.desk.TaskModel instances.
		// Create the task type
		TaskType<?, ?, ?> taskType = this.constructTaskType("WORK_TASK"null);
		// Create the changes to add the tasks
		Change<TaskModelchangeB = this..addTask("TASK_B",
				this.taskType);
		Change<TaskModelchangeA = this..addTask("TASK_A",
				this.taskType);
		Change<TaskModelchangeC = this..addTask("TASK_C",
				this.taskType);
		// Add the tasks and ensure ordering
		changeB.apply();
		changeA.apply();
		changeC.apply();
		// Revert
		changeC.revert();
		changeA.revert();
		changeB.revert();
	}
New to GrepCode? Check out our FAQ X