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.repository.xml;
 
 import java.io.Reader;
 
Tests the XmlConfigurationContext.

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

Ensure can load the net.officefloor.model.repository.ConfigurationItem instances contained in the XML file without labels.
 
 	public void testXmlConfigurationWithoutLabels() throws Exception {
 
 		// Create the XML configuration context
 				"XmlConfigurationContextWithoutLabels.xml");
 
 		// Validate the first configuration item
 		ConfigurationItem one = context.getConfigurationItem("one");
 		this.validateConfigurationItem(one"one",
 				"<one name=\"value\">first</one>");
 
 		// Validate the second configuration item
 		ConfigurationItem two = context.getConfigurationItem("two");
 		this
 						"<two><element attribute=\"something\">another</element></two>");
 	}

Ensure can load the net.officefloor.model.repository.ConfigurationItem instances contained in the XML file with labels.
 
 	public void testXmlConfigurationWithLabels() throws Exception {
 
 		// Create the XML configuration context
 				"XmlConfigurationContextWithLabels.xml");
 
 		// Validate the first configuration item
 		ConfigurationItem one = context.getConfigurationItem("label-one");
 		this.validateConfigurationItem(one"label-one",
 				"<one name=\"value\">first</one>");
 
 		// Validate the second configuration item
 		ConfigurationItem two = context.getConfigurationItem("label-two");
 		this
 				.validateConfigurationItem(two"label-two",
 						"<two><element attribute=\"something\">another</element></two>");
 	}

Ensure that can do tag replacement before parsing the XML.
 
 	public void testXmlConfigurationTagReplace() throws Exception {
 
 		// Create the XML configuration context
 				"XmlConfigurationContextTagReplace.xml");
 
 		// Do tag replacement
 		context.addTag("TAG""VALUE");
 
 		// Validate the tag replacement
 		ConfigurationItem item = context.getConfigurationItem("tag");
 		this.validateConfigurationItem(item"tag""<tag>VALUE</tag>");
 	}

Validates the net.officefloor.model.repository.ConfigurationItem.

Parameters:
configurationItem net.officefloor.model.repository.ConfigurationItem to validate.
expectedLocation Expected location.
expectedContent Expected content.
Throws:
java.lang.Exception If fails to obtain net.officefloor.model.repository.ConfigurationItem details.
	private void validateConfigurationItem(ConfigurationItem configurationItem,
			String expectedLocationString expectedContentthrows Exception {
		// Ensure correct location
		assertEquals("Incorrect location"expectedLocationconfigurationItem
		// Obtain the configuration item content
		StringWriter writer = new StringWriter();
		Reader reader = new InputStreamReader(configurationItem
		for (int value = reader.read(); value != -1; value = reader.read()) {
			writer.write(value);
		}
		// Ensure the content matches
		String content = writer.toString();
		assertTextEquals("Incorrect content"expectedContentcontent.trim());
	}
New to GrepCode? Check out our FAQ X