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.managedobject;
 
Tests the net.officefloor.compile.managedobject.ManagedObjectLoader.

Author(s):
Daniel Sagenschneider
 
 
 	private final CompilerIssues issues = this.createMock(CompilerIssues.class);

 
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see junit.framework.TestCase#setUp()
 	 */
 	protected void setUp() throws Exception {
 		MockManagedObjectSource.reset(this.);
 	}

Ensures issue if fails to instantiate the net.officefloor.frame.spi.managedobject.source.ManagedObjectSource.
 
 
 		final RuntimeException failure = new RuntimeException(
 				"instantiate failure");
 
 		// Record failure to instantiate
 		this.record_issue("Failed to instantiate "
 				+ " by default constructor"failure);
 
 		// Attempt to obtain specification
 		this.loadSpecification(false);
 	}

 
 
 		final Error failure = new Error("specification failure");
 
 		// Record failure to instantiate
 				"Failed to obtain ManagedObjectSourceSpecification from "
 						+ MockManagedObjectSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		// Record no specification returned
		this.record_issue("No ManagedObjectSourceSpecification returned from "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures issue if fails to obtain the net.officefloor.frame.spi.managedobject.source.ManagedObjectSourceProperty instances.
				"Fail to get managed object source properties");
		// Record null properties
				this..getProperties(), failure);
				"Failed to obtain ManagedObjectSourceProperty instances from ManagedObjectSourceSpecification for "
MockManagedObjectSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		// Record null properties
		// Attempt to obtain specification
	}

		// Record null properties
				new ManagedObjectSourceProperty[] { null });
		this.record_issue("ManagedObjectSourceProperty 0 is null from ManagedObjectSourceSpecification for "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		final ManagedObjectSourceProperty property = this
		// Record obtaining properties
				new ManagedObjectSourceProperty[] { property });
		this.recordReturn(propertyproperty.getName(), "");
		this.record_issue("ManagedObjectSourceProperty 0 provided blank name from ManagedObjectSourceSpecification for "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		final RuntimeException failure = new RuntimeException(
				"Failed to get property name");
		final ManagedObjectSourceProperty property = this
		// Record obtaining properties
				new ManagedObjectSourceProperty[] { property });
		this.control(property).expectAndThrow(property.getName(), failure);
				"Failed to get name for ManagedObjectSourceProperty 0 from ManagedObjectSourceSpecification for "
MockManagedObjectSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		final RuntimeException failure = new RuntimeException(
				"Failed to get property label");
		final ManagedObjectSourceProperty property = this
		// Record obtaining properties
				new ManagedObjectSourceProperty[] { property });
		this.recordReturn(propertyproperty.getName(), "NAME");
		this.control(property).expectAndThrow(property.getLabel(), failure);
				"Failed to get label for ManagedObjectSourceProperty 0 (NAME) from ManagedObjectSourceSpecification for "
MockManagedObjectSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		final ManagedObjectSourceProperty propertyWithLabel = this
		final ManagedObjectSourceProperty propertyWithoutLabel = this
		// Record obtaining properties
				new ManagedObjectSourceProperty[] { 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) {
		this..addIssue(nullnull.null,
				issueDescription);
	}

Records an issue.

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

	private void loadSpecification(boolean isExpectToLoad,
			String... propertyNameLabelPairs) {
		// Load the managed object specification specification
		OfficeFloorCompiler compiler = OfficeFloorCompiler
		compiler.setCompilerIssues(this.);
		ManagedObjectLoader managedObjectLoader = compiler
		PropertyList propertyList = managedObjectLoader
		// 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 MockManagedObjectSource implements
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(ManagedObjectSourceSpecification specification) {
		}

Default constructor.
			// Determine if fail to instantiate
			if ( != null) {
			}
		}
		/*
		 * ================ ManagedObjectSource ================================
		 */
			// Determine if failure to obtain
			if ( != null) {
			}
			// Return the specification
		}
		public void init(ManagedObjectSourceContext<Nonecontext)
				throws Exception {
			fail("Should not be invoked for obtaining specification");
		}
			fail("Should not be invoked for obtaining specification");
			return null;
		}
		public void start(ManagedObjectExecuteContext<Nonecontext)
				throws Exception {
			fail("Should not be invoked for obtaining specification");
		}
		public void sourceManagedObject(ManagedObjectUser user) {
			fail("Should not be invoked for obtaining specification");
		}
		public void stop() {
			fail("Should not be invoked for obtaining specification");
		}
	}
New to GrepCode? Check out our FAQ X