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.compile.impl.work;
 
Tests the net.officefloor.compile.work.WorkLoader.

Author(s):
Daniel Sagenschneider
 
 public class LoadWorkSpecificationTest extends OfficeFrameTestCase {

 
 	private final CompilerIssues issues = this.createMock(CompilerIssues.class);

 
 	private final WorkSourceSpecification specification = this
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see junit.framework.TestCase#setUp()
 	 */
 	protected void setUp() throws Exception {
 		MockWorkSource.reset(this.);
 	}

Ensures issue if fails to instantiate the net.officefloor.compile.spi.work.source.WorkSource.
 
 
 		final RuntimeException failure = new RuntimeException(
 				"instantiate failure");
 
 		// Record failure to instantiate
 		this.record_issue("Failed to instantiate "
 				+ MockWorkSource.class.getName() + " by default constructor",
 				failure);
 
 		// Attempt to obtain specification
 		this.loadSpecification(false);
 	}

Ensures issue if failure in obtaining the net.officefloor.compile.spi.work.source.WorkSourceSpecification .
 
 	public void testFailGetWorkSpecification() {
 
 		final Error failure = new Error("specification failure");
 
 		// Record failure to instantiate
 		this.record_issue("Failed to obtain WorkSourceSpecification from "
 				+ MockWorkSource.class.getName(), failure);
 
 		// Attempt to obtain specification
		this.loadSpecification(false);
	}

	public void testNoWorkSpecification() {
		// Record no specification returned
		this.record_issue("No WorkSourceSpecification returned from "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures issue if fails to obtain the net.officefloor.compile.spi.work.source.WorkSourceProperty instances.
	public void testFailGetWorkProperties() {
				"Fail to get work properties");
		// Record null work properties
				this..getProperties(), failure);
		this
						"Failed to obtain WorkSourceProperty instances from WorkSourceSpecification for "
MockWorkSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures considers null net.officefloor.compile.spi.work.source.WorkSourceProperty array as no properties.
	public void testNullWorkPropertiesArray() {
		// Record null work properties
				.getProperties(), null);
		// Attempt to obtain specification
	}

Ensures issue if element in net.officefloor.compile.spi.work.source.WorkSourceProperty array is null.
	public void testNullWorkPropertyElement() {
		// Record null work properties
				.getProperties(), new WorkSourceProperty[] { null });
		this
				.record_issue("WorkSourceProperty 0 is null from WorkSourceSpecification for "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

	public void testNullWorkPropertyName() {
		final WorkSourceProperty property = this
		// Record obtaining work properties
				.getProperties(), new WorkSourceProperty[] { property });
		this.recordReturn(propertyproperty.getName(), "");
		this
				.record_issue("WorkSourceProperty 0 provided blank name from WorkSourceSpecification for "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures issue if fails to get the net.officefloor.compile.spi.work.source.WorkSourceProperty name.
	public void testFailGetWorkPropertyName() {
		final RuntimeException failure = new RuntimeException(
				"Failed to get property name");
		final WorkSourceProperty property = this
		// Record obtaining work properties
				.getProperties(), new WorkSourceProperty[] { property });
		this.control(property).expectAndThrow(property.getName(), failure);
				"Failed to get name for WorkSourceProperty 0 from WorkSourceSpecification for "
MockWorkSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures issue if fails to get the net.officefloor.compile.spi.work.source.WorkSourceProperty label.
		final RuntimeException failure = new RuntimeException(
				"Failed to get property label");
		final WorkSourceProperty property = this
		// Record obtaining work properties
				.getProperties(), new WorkSourceProperty[] { property });
		this.recordReturn(propertyproperty.getName(), "NAME");
		this.control(property).expectAndThrow(property.getLabel(), failure);
		this
						"Failed to get label for WorkSourceProperty 0 (NAME) from WorkSourceSpecification for "
MockWorkSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

	public void testLoadWorkSpecification() {
		final WorkSourceProperty propertyWithLabel = this
		final WorkSourceProperty propertyWithoutLabel = this
		// Record obtaining work properties
				.getProperties(), new WorkSourceProperty[] { propertyWithLabel,
				propertyWithoutLabel });
		this.recordReturn(propertyWithLabelpropertyWithLabel.getName(),
				"NAME");
		this.recordReturn(propertyWithLabelpropertyWithLabel.getLabel(),
				"LABEL");
		this.recordReturn(propertyWithoutLabelpropertyWithoutLabel.getName(),
				"NO LABEL");
		this.recordReturn(propertyWithoutLabel,
				propertyWithoutLabel.getLabel(), null);
		// Attempt to obtain specification
		this.loadSpecification(true"NAME""LABEL""NO LABEL""NO LABEL");
	}

Records an issue.

Parameters:
issueDescription Description of the issue.
	private void record_issue(String issueDescription) {
				issueDescription);
	}

Records an issue.

Parameters:
issueDescription Description of the issue.
cause Cause of the issue.
	private void record_issue(String issueDescriptionThrowable cause) {
				issueDescriptioncause);
	}

Loads the net.officefloor.compile.spi.work.source.WorkSourceSpecification.

Parameters:
isExpectToLoad Flag indicating if expect to obtain the net.officefloor.compile.spi.work.source.WorkSourceSpecification.
propertyNames Expected net.officefloor.compile.properties.Property names for being returned.
	private void loadSpecification(boolean isExpectToLoad,
			String... propertyNameLabelPairs) {
		// Load the work specification
		OfficeFloorCompiler compiler = OfficeFloorCompiler
		compiler.setCompilerIssues(this.);
		WorkLoader workLoader = compiler.getWorkLoader();
		PropertyList propertyList = workLoader
		// Determine if expected to load
		if (isExpectToLoad) {
			assertNotNull("Expected to load specification"propertyList);
			// Ensure the properties are as expected
			PropertyListUtil.validatePropertyNameLabels(propertyList,
					propertyNameLabelPairs);
else {
			assertNull("Should not load specification"propertyList);
		}
	}

	public static class MockWorkSource implements WorkSource<Work> {

Failure to instantiate an instance.
		public static RuntimeException instantiateFailure = null;

		public static Error specificationFailure = null;

Resets the state for next test.

		public static void reset(WorkSourceSpecification specification) {
			. = specification;
		}

Default constructor.
		public MockWorkSource() {
			// Determine if fail to instantiate
			if ( != null) {
			}
		}
		/*
		 * ================ WorkSource ================================
		 */
			// Determine if failure to obtain
			if ( != null) {
			}
			// Return the specification
		}
		public void sourceWork(WorkTypeBuilder<WorkworkTypeBuilder,
				WorkSourceContext contextthrows Exception {
			fail("Should not be invoked for obtaining specification");
		}
	}
New to GrepCode? Check out our FAQ X