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 the net.officefloor.model.desk.DeskChanges.

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

Ensure can add net.officefloor.model.desk.WorkModel that uses indexing.
 
 	public void testAddWorkWithoutKeys() {
 
 		// Create the work type to add
 		WorkType<?> work = this.constructWorkType(new WorkTypeConstructor() {
 			public void construct(WorkTypeContext context) {
 				// First task
 				TaskTypeConstructor taskOne = context.addTask("TASK_ONE");
 				taskOne.addObject(String.classnull);
 				taskOne.addObject(Integer.classnull);
 				taskOne.addFlow(String.classnull); // ignored for work-task
 				taskOne.addEscalation(Throwable.class); // ignored for work-task
 
 				// Second task (for labels)
 				TaskTypeConstructor taskTwo = context.addTask("TASK_TWO");
 				taskTwo.addObject(Object.classnull).setLabel("LABEL");
 			}
 		});
 
 		// Validate adding the work and reverting
 		Change<WorkModelchange = this.
 				.addWork("WORK""net.example.ExampleWorkSource",
 						new PropertyListImpl("name.one""value.one",
 								"name.two""value.two"), work);
 		this.assertChange(changenull"Add work WORK"true);
 		change.apply();
 		assertEquals("Ensure correct target"this..getWorks().get(0),
 				change.getTarget());
 	}

Ensure can add net.officefloor.model.desk.WorkModel that uses keys.
 
 	public void testAddWorkWithKeys() {
 
 		// Create the work type to add
 		WorkType<?> work = this.constructWorkType(new WorkTypeConstructor() {
 			public void construct(WorkTypeContext context) {
 				// First task
 				TaskTypeConstructor taskOne = context.addTask("TASK_ONE");
 				taskOne.addObject(String.class.);
 				taskOne.addObject(Integer.class.);
 				taskOne.addFlow(String.classnull); // ignored for work-task
 				taskOne.addEscalation(Throwable.class); // ignored for work-task
 
 				// Second task (for labels)
 				TaskTypeConstructor taskTwo = context.addTask("TASK_TWO");
 						"LABEL_ONE");
 						.setLabel("LABEL_TWO");
 			}
 		});
 
 		// Validate adding the work and reverting
 		Change<WorkModelchange = this..addWork("WORK",
 				"net.example.ExampleWorkSource"new PropertyListImpl("name",
						"value"), work);
		this.assertChange(changenull"Add work WORK"true);
	}

Keys identifying net.officefloor.compile.work.TaskObjectType instances.
	private enum TaskObjectKeys {
		ONE, TWO
	}

Ensure can add net.officefloor.model.desk.WorkModel specifying the tasks to be added.
		// Create the work type to add
			public void construct(WorkTypeContext context) {
				// Add many tasks
				context.addTask("TASK_ONE");
				context.addTask("TASK_TWO");
				context.addTask("TASK_THREE");
				context.addTask("TASK_FOUR");
			}
		});
		// Validate adding the work and reverting
		Change<WorkModelchange = this..addWork("WORK",
				"net.example.ExampleWorkSource"new PropertyListImpl(), work,
				"TASK_ONE""TASK_THREE");
		this.assertChange(changenull"Add work WORK"true);
	}

Ensure can add net.officefloor.model.desk.WorkModel and that the net.officefloor.model.desk.WorkTaskModel instances are ordered by the net.officefloor.frame.api.execute.Task name to make merging the XML files easier under SCM.
		// Create the work type to add
			public void construct(WorkTypeContext context) {
				// Add in wrong order
				context.addTask("D");
				context.addTask("A");
				context.addTask("C");
				context.addTask("B");
			}
		});
		// Validate adding the work and reverting
		Change<WorkModelchange = this..addWork("WORK",
				"net.example.ExampleWorkSource"new PropertyListImpl(), work);
		this.assertChange(changenull"Add work WORK"true);
	}

Ensure can add multiple net.officefloor.model.desk.WorkModel instances ensuring ordering of the net.officefloor.model.desk.WorkModel instances.
		// Create the work type
			public void construct(WorkTypeContext context) {
				context.addTask("TASK");
			}
		});
		// Add work multiple times
		Change<WorkModelchangeB = this..addWork("WORK_B",
				"net.example.ExampleWorkSource"new PropertyListImpl(), work);
		Change<WorkModelchangeA = this..addWork("WORK_A",
				"net.example.ExampleWorkSource"new PropertyListImpl(), work);
		Change<WorkModelchangeC = this..addWork("WORK_C",
				"net.example.ExampleWorkSource"new PropertyListImpl(), work);
		// Apply the changes
		changeB.apply();
		changeA.apply();
		changeC.apply();
		// Ensure can revert changes (undo)
		changeC.revert();
		changeA.revert();
		changeB.revert();
	}
New to GrepCode? Check out our FAQ X