// Path: core/src/main/java/occi/config/OcciConfig.java
// public class OcciConfig extends XMLConfiguration {
// 	private static final long serialVersionUID = 1L;
// 	private static final Logger LOGGER = LoggerFactory
// 			.getLogger(OcciConfig.class);
// 	/**
// 	 * Instance of OcciConfig
// 	 */
// 	private static OcciConfig instance = null;
// 	private static ConfigurationFactory factory;
// 	/**
// 	 * Configuration for all occi properties
// 	 */
// 	public Configuration config;
// 
// 	private OcciConfig() {
// 		factory = new ConfigurationFactory();
// 		// load configuration file
// 		URL configURL = getClass().getResource("/conf/config.xml");
// 		factory.setConfigurationURL(configURL);
// 		try {
// 			// pick up configuration
// 			config = factory.getConfiguration();
// 		} catch (ConfigurationException e) {
// 			LOGGER.error("Failed to load config file.");
// 		}
// 	}
// 
// 	public static OcciConfig getInstance() {
// 		if (instance == null) {
// 			// create OcciConfig instance
// 			instance = new OcciConfig();
// 		}
// 		return instance;
// 	}
// 
// 	public static void main(String[] args) {
// 		new OcciConfig();
// 	}
// }
// 
// Path: http/src/main/java/occi/http/occiApi.java
// public class occiApi extends ServerResource {
// 	// initialize server component
// 	public static Component comp = new Component();
// 
// 	public static void main(String[] args) throws Exception {
// 		// load all logger properties
// 		if (new File("conf/log4j.properties").exists())
// 			PropertyConfigurator.configure("conf/log4j.properties");
// 		else
// 			PropertyConfigurator
// 					.configure("../core/src/main/resources/conf/log4jTest.properties");
// 		// Create the HTTP server and listen on port 8182
// 		comp.getServers().add(Protocol.HTTP,
// 				OcciConfig.getInstance().config.getInt("occi.server.port"));
// 
// 		comp.getDefaultHost().attach("/", OcciRestRoot.class);
// 		// Router for the Query/Discovery Interface.
// 		comp.getDefaultHost().attach("/-/", OcciRestQuery.class);
// 
// 		// Returns one single instance of a compute resource
// 		comp.getDefaultHost().attach("/compute", OcciRestCompute.class);
// 		comp.getDefaultHost().attach("/compute/{uuid}", OcciRestCompute.class);
// 
// 		// Returns all compute instances
// 		comp.getDefaultHost().attach("/compute/", OcciRestComputes.class);
// 
// 		// Router for storage instances
// 		comp.getDefaultHost().attach("/storage", OcciRestStorage.class);
// 
// 		// Returns all storage instances
// 		comp.getDefaultHost().attach("/storage/", OcciRestStorages.class);
// 
// 		// Router for storage instances
// 		comp.getDefaultHost().attach("/network", OcciRestNetwork.class);
// 		comp.getDefaultHost().attach("/network/{uuid}", OcciRestNetwork.class);
// 		comp.getDefaultHost().attach("/networkinterface",
// 				OcciRestNetworkInterface.class);
// 		comp.getDefaultHost().attach("/networkinterface/{uuid}",
// 				OcciRestNetworkInterface.class);
// 		// Returns all storage instances
// 		comp.getDefaultHost().attach("/network/", OcciRestNetworks.class);
// 		// Router for all available mixin instances. Returns mixin information.
// 		comp.getDefaultHost().attach("/{mixin}", OcciRestMixin.class);
// 		// start occi api
// 		comp.start();
// 	}
// }


import java.io.IOException;
import occi.config.OcciConfig;
import occi.http.occiApi;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
/**
 * Copyright (C) 2010-2011 Sebastian Heckmann, Sebastian Laag
 *
 * Contact Email: <sebastian.heckmann@udo.edu>, <sebastian.laag@udo.edu>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.occi.test;




/**
 * Test class to test the http root interface. Submits a HTTP GET request. Other
 * requests are not possible.
 * 
 * @author Sebastian Laag
 */
public class TestRestRoot {
	private ClientResource clientResource = new ClientResource(
			OcciConfig.getInstance().config.getString("occi.server.location"));

	@BeforeTest
	public void setUp() {
		try {
			// start occi api
			occiApi.main(null);
		} catch (Exception ex) {
			System.out.println("Failed to start occiApi: " + ex.getMessage());
		}
	}

	/**
	 * Tests to submit a get request at the root resource.
	 * @throws IOException 
	 */
	@Test
	public void testGetRoot() throws IOException {
		// connect to Api
		clientResource.setReference(OcciConfig.getInstance().config
				.getString("occi.server.location"));
		Representation representation = null;
		try {
			// execute get request
			representation = clientResource.get();
			// checks whether representation is null
			Assert.assertNotNull(representation);
			System.out.println("representation.toString " + representation.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Tests to submit a post request at the root resource.
	 */
	@Test
// Path: core/src/main/java/occi/config/OcciConfig.java
// public class OcciConfig extends XMLConfiguration {
// 	private static final long serialVersionUID = 1L;
// 	private static final Logger LOGGER = LoggerFactory
// 			.getLogger(OcciConfig.class);
// 	/**
// 	 * Instance of OcciConfig
// 	 */
// 	private static OcciConfig instance = null;
// 	private static ConfigurationFactory factory;
// 	/**
// 	 * Configuration for all occi properties
// 	 */
// 	public Configuration config;
// 
// 	private OcciConfig() {
// 		factory = new ConfigurationFactory();
// 		// load configuration file
// 		URL configURL = getClass().getResource("/conf/config.xml");
// 		factory.setConfigurationURL(configURL);
// 		try {
// 			// pick up configuration
// 			config = factory.getConfiguration();
// 		} catch (ConfigurationException e) {
// 			LOGGER.error("Failed to load config file.");
// 		}
// 	}
// 
// 	public static OcciConfig getInstance() {
// 		if (instance == null) {
// 			// create OcciConfig instance
// 			instance = new OcciConfig();
// 		}
// 		return instance;
// 	}
// 
// 	public static void main(String[] args) {
// 		new OcciConfig();
// 	}
// }
// 
// Path: http/src/main/java/occi/http/occiApi.java
// public class occiApi extends ServerResource {
// 	// initialize server component
// 	public static Component comp = new Component();
// 
// 	public static void main(String[] args) throws Exception {
// 		// load all logger properties
// 		if (new File("conf/log4j.properties").exists())
// 			PropertyConfigurator.configure("conf/log4j.properties");
// 		else
// 			PropertyConfigurator
// 					.configure("../core/src/main/resources/conf/log4jTest.properties");
// 		// Create the HTTP server and listen on port 8182
// 		comp.getServers().add(Protocol.HTTP,
// 				OcciConfig.getInstance().config.getInt("occi.server.port"));
// 
// 		comp.getDefaultHost().attach("/", OcciRestRoot.class);
// 		// Router for the Query/Discovery Interface.
// 		comp.getDefaultHost().attach("/-/", OcciRestQuery.class);
// 
// 		// Returns one single instance of a compute resource
// 		comp.getDefaultHost().attach("/compute", OcciRestCompute.class);
// 		comp.getDefaultHost().attach("/compute/{uuid}", OcciRestCompute.class);
// 
// 		// Returns all compute instances
// 		comp.getDefaultHost().attach("/compute/", OcciRestComputes.class);
// 
// 		// Router for storage instances
// 		comp.getDefaultHost().attach("/storage", OcciRestStorage.class);
// 
// 		// Returns all storage instances
// 		comp.getDefaultHost().attach("/storage/", OcciRestStorages.class);
// 
// 		// Router for storage instances
// 		comp.getDefaultHost().attach("/network", OcciRestNetwork.class);
// 		comp.getDefaultHost().attach("/network/{uuid}", OcciRestNetwork.class);
// 		comp.getDefaultHost().attach("/networkinterface",
// 				OcciRestNetworkInterface.class);
// 		comp.getDefaultHost().attach("/networkinterface/{uuid}",
// 				OcciRestNetworkInterface.class);
// 		// Returns all storage instances
// 		comp.getDefaultHost().attach("/network/", OcciRestNetworks.class);
// 		// Router for all available mixin instances. Returns mixin information.
// 		comp.getDefaultHost().attach("/{mixin}", OcciRestMixin.class);
// 		// start occi api
// 		comp.start();
// 	}
// }


// Path: http/src/test/java/de/occi/test/TestRestRoot.java
import java.io.IOException;
import occi.config.OcciConfig;
import occi.http.occiApi;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

/**
 * Copyright (C) 2010-2011 Sebastian Heckmann, Sebastian Laag
 *
 * Contact Email: <sebastian.heckmann@udo.edu>, <sebastian.laag@udo.edu>
 *
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.gnu.org/licenses/lgpl-3.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.occi.test;




/**
 * Test class to test the http root interface. Submits a HTTP GET request. Other
 * requests are not possible.
 * 
 * @author Sebastian Laag
 */
public class TestRestRoot {
	private ClientResource clientResource = new ClientResource(
			OcciConfig.getInstance().config.getString("occi.server.location"));

	@BeforeTest
	public void setUp() {
		try {
			// start occi api
			occiApi.main(null);
		} catch (Exception ex) {
			System.out.println("Failed to start occiApi: " + ex.getMessage());
		}
	}

	/**
	 * Tests to submit a get request at the root resource.
	 * @throws IOException 
	 */
	@Test
	public void testGetRoot() throws IOException {
		// connect to Api
		clientResource.setReference(OcciConfig.getInstance().config
				.getString("occi.server.location"));
		Representation representation = null;
		try {
			// execute get request
			representation = clientResource.get();
			// checks whether representation is null
			Assert.assertNotNull(representation);
			System.out.println("representation.toString " + representation.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Tests to submit a post request at the root resource.
	 */
	@Test
	public void testPostRoot() {