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.office;
 
 
 
Tests the net.officefloor.model.office.OfficeRepository.

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

 
 	private final ModelRepository modelRepository = this
 
 	private final ConfigurationItem configurationItem = this
 
Ensures on retrieving a net.officefloor.model.office.OfficeModel that all net.officefloor.model.ConnectionModel instances are connected.
 
 	public void testRetrieveOffice() throws Exception {
 
 		// Create the raw office to be connected
 		OfficeModel office = new OfficeModel();
				"EXTERNAL_MANAGED_OBJECT"Connection.class.getName());
				"MANAGED_OBJECT""THREAD");
				"DEPENDENCY"Connection.class.getName());
				"MANAGED_OBJECT_SOURCE",
				"net.example.ExampleManagedObjectSource""java.lang.Object",
				"0");
				"INPUT_DEPENDENCY"Connection.class.getName());
				"FLOW"Integer.class.getName());
				"MO_TEAM");
		OfficeTeamModel team = new OfficeTeamModel("TEAM");
		office.addOfficeTeam(team);
				"ESCALATION");
		office.addOfficeEscalation(escalation);
		OfficeSectionModel section = new OfficeSectionModel("SECTION",
				"net.example.ExampleSectionSource""SECTION_LOCATION");
		office.addOfficeSection(section);
				"OBJECT"Connection.class.getName());
		section.addOfficeSectionObject(object);
				"RESPONSIBILITY");
		section.addOfficeSectionResponsibility(responsibility);
		AdministratorModel admin = new AdministratorModel("ADMINISTRATOR",
				"net.example.ExampleAdministratorSource""THREAD");
		DutyModel duty = new DutyModel("DUTY");
		admin.addDuty(duty);
		OfficeSectionModel targetSection = new OfficeSectionModel(
				"SECTION_TARGET""net.example.ExcampleSectionSource",
				"SECTION_LOCATION");
		office.addOfficeSection(targetSection);
				"INPUT"String.class.getName());
		targetSection.addOfficeSectionInput(targetInput);
		// responsibility -> team
				"TEAM");
		responsibility.setOfficeTeam(respToTeam);
		// section output -> section input
				"OUTPUT"String.class.getName(), false);
		section.addOfficeSectionOutput(output);
				"SECTION_TARGET""INPUT");
		output.setOfficeSectionInput(outputToInput);
		// section object -> external managed object
				"EXTERNAL_MANAGED_OBJECT");
		object.setExternalManagedObject(objectToExtMo);
		// section object -> office managed object
				"MANAGED_OBJECT");
		object.setOfficeManagedObject(objectToMo);
		// administrator -> team
				"TEAM");
		admin.setOfficeTeam(adminToTeam);
		// office task -> duty (setup)
		section.setOfficeSubSection(subSection);
				"SUB_SECTION");
		subSection.addOfficeSubSection(subSubSection);
		OfficeTaskModel officeTask = new OfficeTaskModel("TASK");
		subSubSection.addOfficeTask(officeTask);
		// office task -> pre duty
				"ADMINISTRATOR""DUTY");
		officeTask.addPreDuty(taskToPreDuty);
		// office task -> post duty
				"ADMINISTRATOR""DUTY");
		officeTask.addPostDuty(taskToPostDuty);
		// external managed object -> administrator
				"ADMINISTRATOR""1");
		extMo.addAdministrator(extMoToAdmin);
		// managed object -> administrator
				"ADMINISTRATOR""1");
		mo.addAdministrator(moToAdmin);
		// managed object -> managed object source
				"MANAGED_OBJECT_SOURCE");
		// mo flow -> section input
				"SECTION_TARGET""INPUT");
		moFlow.setOfficeSectionInput(flowToInput);
		// mo team -> team
				"TEAM");
		moTeam.setOfficeTeam(moTeamToTeam);
		// managed object dependency -> external managed object
				"EXTERNAL_MANAGED_OBJECT");
		dependency.setExternalManagedObject(dependencyToExtMo);
		// managed object dependency -> office managed object
				"MANAGED_OBJECT");
		dependency.setOfficeManagedObject(dependencyToMo);
		// input managed object dependency -> external managed object
				"EXTERNAL_MANAGED_OBJECT");
		inputDependency.setExternalManagedObject(inputDependencyToExtMo);
		// input managed object dependency -> office managed object
				"MANAGED_OBJECT");
		inputDependency.setOfficeManagedObject(inputDependencyToMo);
		// escalation -> section input
				"SECTION_TARGET""INPUT");
		escalation.setOfficeSectionInput(escalationToInput);
		// Record retrieving the office
				nullthis.), officenew AbstractMatcher() {
			public boolean matches(Object[] expectedObject[] actual) {
				assertTrue("Must be office model",
						actual[0] instanceof OfficeModel);
				assertEquals("Incorrect configuration item",
				return true;
			}
		});
		// Retrieve the office
		OfficeModel retrievedOffice = this.
		assertEquals("Incorrect office"officeretrievedOffice);
		// Ensure the responsibility team connected
		assertEquals("responsibility <- team"responsibilityrespToTeam
		assertEquals("responsibility -> team"teamrespToTeam.getOfficeTeam());
		// Ensure the outputs connected to inputs
		assertEquals("output <- input"outputoutputToInput
		assertEquals("output -> input"targetInputoutputToInput
		// Ensure the objects connected to external managed object
		assertEquals("object <- external managed object"objectobjectToExtMo
		assertEquals("object -> external managed object"extMoobjectToExtMo
		// Ensure the objects connect to office managed object
		assertEquals("object <- office managed object"objectobjectToMo
		assertEquals("object -> office managed object"moobjectToMo
		// Ensure managed object connected to its managed object source
		assertEquals("managed object <- managed object source"momoToMos
		assertEquals("managed object -> managed object source"mosmoToMos
		// Ensure managed object source flow connected to section input
		assertEquals("mos flow <- section input"moFlowflowToInput
		assertEquals("mos flow -> section input"targetInputflowToInput
		// Ensure managed object source team connected to office team
		assertEquals("mos team <- office team"moTeammoTeamToTeam
		assertEquals("mos team -> office team"teammoTeamToTeam
		// Ensure the administrator teams connected
		assertEquals("administrator <- team"adminadminToTeam
		assertEquals("administrator -> team"teamadminToTeam.getOfficeTeam());
		// Ensure the office task pre duties connected
		assertEquals("task <- pre duty"officeTasktaskToPreDuty
		assertEquals("task -> pre duty"dutytaskToPreDuty.getDuty());
		// Ensure the office task post duties connected
		assertEquals("task <- post duty"officeTasktaskToPostDuty
		assertEquals("task -> post duty"dutytaskToPostDuty.getDuty());
		// Ensure external managed object administration connected
		assertEquals("external managed object <- administrator"extMo,
				extMoToAdmin.getExternalManagedObject());
		assertEquals("external managed object -> administrator"admin,
				extMoToAdmin.getAdministrator());
		// Ensure managed object administration connected
		assertEquals("managed object <- administrator"momoToAdmin
		assertEquals("managed object -> administrator"adminmoToAdmin
		// Ensure dependency connected to external managed object
		assertEquals("dependency <- external mo"dependencydependencyToExtMo
		assertEquals("dependency -> external mo"extModependencyToExtMo
		// Ensure dependency connected to office managed object
		assertEquals("dependency <- managed object"dependencydependencyToMo
		assertEquals("dependency -> managed object"modependencyToMo
		// Ensure input dependency connected to external managed object
		assertEquals("input dependency <- external mo"inputDependency,
				inputDependencyToExtMo.getOfficeInputManagedObjectDependency());
		assertEquals("input dependency -> external mo"extMo,
				inputDependencyToExtMo.getExternalManagedObject());
		// Ensure input dependency connected to office managed object
		assertEquals("input dependency <- managed object"inputDependency,
		assertEquals("input dependency -> managed object"mo,
				inputDependencyToMo.getOfficeManagedObject());
		// Ensure escalation connected to section input
		assertEquals("escalation <- section input"escalation,
				escalationToInput.getOfficeEscalation());
		assertEquals("escalation -> section input"targetInput,
				escalationToInput.getOfficeSectionInput());
	}

Ensures on storing a net.officefloor.model.office.OfficeModel that all net.officefloor.model.ConnectionModel instances are readied for storing.
	public void testStoreOffice() throws Exception {
		// Create the office (without connections)
		OfficeModel office = new OfficeModel();
				"EXTERNAL_MANAGED_OBJECT"Connection.class.getName());
				"MANAGED_OBJECT""THREAD");
				"DEPENDENCY"Connection.class.getName());
				"MANAGED_OBJECT_SOURCE",
				"net.example.ExampleManagedObjectSource""java.lang.Object",
				"0");
				"INPUT_DEPENDENCY"Connection.class.getName());
				"FLOW"Integer.class.getName());
				"MO_TEAM");
				"ESCALATION");
		office.addOfficeEscalation(escalation);
		OfficeTeamModel team = new OfficeTeamModel("TEAM");
		office.addOfficeTeam(team);
		OfficeSectionModel section = new OfficeSectionModel("SECTION",
				"net.example.ExampleSectionSource""SECTION_LOCATION");
		office.addOfficeSection(section);
				"OBJECT"Connection.class.getName());
		section.addOfficeSectionObject(object);
				"RESPONSIBILITY");
		section.addOfficeSectionResponsibility(responsibility);
		AdministratorModel admin = new AdministratorModel("ADMINISTRATOR",
				"net.example.ExampleAdministratorSource""THREAD");
		DutyModel duty = new DutyModel("DUTY");
		admin.addDuty(duty);
		// responsibility -> team
		respToTeam.setOfficeSectionResponsibility(responsibility);
		respToTeam.setOfficeTeam(team);
		respToTeam.connect();
		// section output -> section input
				"OUTPUT"String.class.getName(), false);
		section.addOfficeSectionOutput(output);
		OfficeSectionModel targetSection = new OfficeSectionModel(
				"SECTION_TARGET""net.example.ExcampleSectionSource",
				"SECTION_LOCATION");
		office.addOfficeSection(targetSection);
				"INPUT"String.class.getName());
		targetSection.addOfficeSectionInput(targetInput);
		outputToInput.setOfficeSectionOutput(output);
		outputToInput.setOfficeSectionInput(targetInput);
		outputToInput.connect();
		// section object -> external managed object
		objectToExtMo.setOfficeSectionObject(object);
		objectToExtMo.setExternalManagedObject(extMo);
		objectToExtMo.connect();
		// section object -> office managed object
		objectToMo.setOfficeSectionObject(object);
		objectToMo.setOfficeManagedObject(mo);
		objectToMo.connect();
		// managed object -> managed object source
		moToMos.connect();
		// managed object source flow -> section input
		flowToInput.setOfficeSectionInput(targetInput);
		flowToInput.connect();
		// managed object source team -> office team
		moTeamToTeam.setOfficeTeam(team);
		moTeamToTeam.connect();
		// dependency -> external managed object
		dependencyToExtMo.setOfficeManagedObjectDependency(dependency);
		dependencyToExtMo.setExternalManagedObject(extMo);
		dependencyToExtMo.connect();
		// dependency -> office managed object
		dependencyToMo.setOfficeManagedObjectDependency(dependency);
		dependencyToMo.setOfficeManagedObject(mo);
		dependencyToMo.connect();
		// input dependency -> external managed object
		inputDependencyToExtMo
		inputDependencyToExtMo.setExternalManagedObject(extMo);
		inputDependencyToExtMo.connect();
		// input dependency -> office managed object
		inputDependencyToMo
		inputDependencyToMo.setOfficeManagedObject(mo);
		inputDependencyToMo.connect();
		// administrator -> team
		adminToTeam.setAdministrator(admin);
		adminToTeam.setOfficeTeam(team);
		adminToTeam.connect();
		// office task -> duty (setup)
		section.setOfficeSubSection(subSection);
				"SUB_SECTION");
		subSection.addOfficeSubSection(subSubSection);
		OfficeTaskModel officeTask = new OfficeTaskModel("TASK");
		subSubSection.addOfficeTask(officeTask);
		// office task -> pre duty
		taskToPreDuty.setOfficeTask(officeTask);
		taskToPreDuty.setDuty(duty);
		taskToPreDuty.connect();
		// office task -> post duty
		taskToPostDuty.setOfficeTask(officeTask);
		taskToPostDuty.setDuty(duty);
		taskToPostDuty.connect();
		// external managed object -> administrator
		extMoToAdmin.setExternalManagedObject(extMo);
		extMoToAdmin.setAdministrator(admin);
		extMoToAdmin.connect();
		// managed object -> administrator
		moToAdmin.setAdministrator(admin);
		moToAdmin.connect();
		// escalation -> section input
		escalationToInput.setOfficeEscalation(escalation);
		escalationToInput.setOfficeSectionInput(targetInput);
		escalationToInput.connect();
		// Record storing the office
		// Store the office
		// Ensure the connections have links to enable retrieving
		assertEquals("responsibility - team""TEAM"respToTeam
		assertEquals("output - input (section name)""SECTION_TARGET",
				outputToInput.getOfficeSectionName());
		assertEquals("output - input (input name)""INPUT"outputToInput
		assertEquals("object - external managed object",
				"EXTERNAL_MANAGED_OBJECT"objectToExtMo
		assertEquals("object - office managed object""MANAGED_OBJECT",
		assertEquals("managed object - managed object source",
				"MANAGED_OBJECT_SOURCE"moToMos
		assertEquals("managed object source flow - input (section name)",
				"SECTION_TARGET"flowToInput.getOfficeSectionName());
		assertEquals("managed object source flow - input (input name)",
				"INPUT"flowToInput.getOfficeSectionInputName());
		assertEquals("managed object source team - office team""TEAM",
				moTeamToTeam.getOfficeTeamName());
		assertEquals("dependency - external managed object",
				"EXTERNAL_MANAGED_OBJECT"dependencyToExtMo
		assertEquals("dependency - managed object""MANAGED_OBJECT",
				dependencyToMo.getOfficeManagedObjectName());
		assertEquals("input dependency - external managed object",
				"EXTERNAL_MANAGED_OBJECT"inputDependencyToExtMo
		assertEquals("input dependency - managed object""MANAGED_OBJECT",
				inputDependencyToMo.getOfficeManagedObjectName());
		assertEquals("administrator - team""TEAM"adminToTeam
		assertEquals("task - pre duty (administrator name)""ADMINISTRATOR",
				taskToPreDuty.getAdministratorName());
		assertEquals("task - pre duty (duty name)""DUTY"taskToPreDuty
		assertEquals("task - post duty (administrator name)""ADMINISTRATOR",
				taskToPostDuty.getAdministratorName());
		assertEquals("task - post duty (duty name)""DUTY"taskToPostDuty
		assertEquals("external managed object - administrator",
				"ADMINISTRATOR"extMoToAdmin.getAdministratorName());
		assertEquals("office managed object - administrator""ADMINISTRATOR",
		assertEquals("escalation - input (section name)""SECTION_TARGET",
				escalationToInput.getOfficeSectionName());
		assertEquals("escalation - input (input name""INPUT",
				escalationToInput.getOfficeSectionInputName());
	}
New to GrepCode? Check out our FAQ X