/*-
 * Copyright 2021 Hochschule für Technik Stuttgart
 *
 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
 *
 * 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.hft.stuttgart.ade.foodwaterenergycitygml4j;

import static org.junit.jupiter.api.Assertions.*;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import org.citygml4j.CityGMLContext;
import org.citygml4j.builder.jaxb.CityGMLBuilder;
import org.citygml4j.builder.jaxb.CityGMLBuilderException;
import org.citygml4j.model.citygml.ade.ADEComponent;
import org.citygml4j.model.citygml.ade.ADEException;
import org.citygml4j.model.citygml.ade.binding.ADEContext;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.citygml.core.CityModel;
import org.citygml4j.model.citygml.core.CityObjectMember;
import org.citygml4j.model.citygml.landuse.LandUse;
import org.citygml4j.model.gml.basicTypes.Code;
import org.citygml4j.model.gml.measures.Area;
import org.citygml4j.model.gml.measures.Scale;
import org.citygml4j.model.module.citygml.CityGMLVersion;
import org.citygml4j.xml.io.CityGMLInputFactory;
import org.citygml4j.xml.io.CityGMLOutputFactory;
import org.citygml4j.xml.io.reader.CityGMLReadException;
import org.citygml4j.xml.io.reader.CityGMLReader;
import org.citygml4j.xml.io.reader.FeatureReadMode;
import org.citygml4j.xml.io.writer.CityGMLWriteException;
import org.citygml4j.xml.io.writer.CityGMLWriter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import de.hft.stuttgart.ade.foodwaterenergycitygml4j.landuse.model.ConsistsOfFWESurvey;
import de.hft.stuttgart.ade.foodwaterenergycitygml4j.landuse.model.EnergySurvey;
import de.hft.stuttgart.ade.foodwaterenergycitygml4j.landuse.model.FoodSurvey;
import de.hft.stuttgart.ade.foodwaterenergycitygml4j.landuse.model.FoodWaterEnergy;
import de.hft.stuttgart.ade.foodwaterenergycitygml4j.landuse.model.LandUseSurvey;
import de.hft.stuttgart.ade.foodwaterenergycitygml4j.landuse.model.WaterSurvey;
import de.hft.stuttgart.ade.foodwaterenergycitygml4j.module.FoodWaterEnergyLandUseADEModule;

class FoodWaterEnergyLandUseTest {
	
	private String path;
	private String location;

	@BeforeEach
	void setUp() throws Exception {
		location = "src/test/resources/";
		String fileName= "FWELandUseSample.gml";
		path = location+fileName;
	}
	
	private CityModel readCityGml(InputStream input)
			throws ADEException, CityGMLBuilderException, CityGMLReadException {
		CityGMLContext context = CityGMLContext.getInstance();
		//register ADE module
		//context.registerADEContext(new FoodWaterEnergyADEContext());
		List<ADEContext> adeContexts = context.getADEContexts();
		if (adeContexts.isEmpty()) {
			for (ADEContext adeContext : ServiceLoader.load(ADEContext.class)) {
				context.registerADEContext(adeContext);
			}
		}
		CityGMLBuilder builder = context.createCityGMLBuilder();
		CityGMLInputFactory in = builder.createCityGMLInputFactory();
		in.setProperty(CityGMLInputFactory.USE_VALIDATION, true);
		in.setProperty(CityGMLInputFactory.FEATURE_READ_MODE, FeatureReadMode.NO_SPLIT);
		in.setValidationEventHandler(event -> {
			System.out.print(
					"[" + event.getLocator().getLineNumber() + "," + event.getLocator().getColumnNumber() + "] ");
			System.out.println(event.getMessage());
			throw new IllegalStateException(event.getLinkedException());
		});
		CityModel cityModel;
		try (CityGMLReader reader = in.createCityGMLReader("?", input)) {
			cityModel = (CityModel) reader.nextFeature();
		}
		return cityModel;
	}
	

	private CityModel readCityGml(File f)
			throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		return readCityGml(new FileInputStream(f));
	}	
	private CityModel readCityGml(String fileName)
			throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		return readCityGml(new File(fileName));
	}	

	/*
	 
	private CityModel readCityGml(byte[] bytes) throws ADEException, CityGMLBuilderException, CityGMLReadException {
		return readCityGml(new ByteArrayInputStream(bytes));
	}
	*/
	
	private byte[] writeCityGml(CityModel model) throws ADEException, CityGMLBuilderException, CityGMLWriteException {
		CityGMLContext context = CityGMLContext.getInstance();
		List<ADEContext> adeContexts = context.getADEContexts();
		if (adeContexts == null || adeContexts.isEmpty()) {
			for (ADEContext adeContext : ServiceLoader.load(ADEContext.class)) {
				context.registerADEContext(adeContext);
			}
		}
		CityGMLBuilder builder = context.createCityGMLBuilder();
		CityGMLOutputFactory outputFactory = builder.createCityGMLOutputFactory(CityGMLVersion.DEFAULT);
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		try (CityGMLWriter writer = outputFactory.createCityGMLWriter(out)) {
			writer.setIndentString("  ");
			writer.setPrefixes(CityGMLVersion.DEFAULT);
			writer.setPrefix("fwel", FoodWaterEnergyLandUseADEModule.NAMESPACE_URI);
			writer.setSchemaLocation(FoodWaterEnergyLandUseADEModule.NAMESPACE_URI,
					"http://transfer.hft-stuttgart.de/pages/in-source/fwe-ade/FWELanduse/v2.1.1/XSD");
			writer.setSchemaLocations(CityGMLVersion.DEFAULT);
			writer.write(model);
			return out.toByteArray();
		}
	}

	@Test
	void testForReadingCityObjectMember() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		assertEquals(1, listCityObjectMember.size());		
	}
	
	
	@Test
	void testForReadingLandUse() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		assertTrue(abstractCityObject instanceof LandUse);		
	}
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		int count = landUse.getGenericApplicationPropertyOfLandUse().size();
		assertEquals(1, count);
	}
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy_AreaName() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				FoodWaterEnergy foodWaterEnergy = (FoodWaterEnergy) component;
				assertTrue(foodWaterEnergy.getAreaName().equals("Test_Stuttgart_Ost"));
			}
		}
	}
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy_SystemName() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				FoodWaterEnergy foodWaterEnergy = (FoodWaterEnergy) component;
				assertTrue(foodWaterEnergy.getSystemName().equals("Test_Stuttgart_System"));
			}
		}
	}
	
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy_consistsOfFWEsurvey() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				FoodWaterEnergy foodWaterEnergy = (FoodWaterEnergy) component;
				assertNotNull(foodWaterEnergy.getConsistsOfFWESurvey());
			}
		}
	}
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy_consistsOfFWEsurvey_landUseSurvey() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				FoodWaterEnergy foodWaterEnergy = (FoodWaterEnergy) component;
				ConsistsOfFWESurvey consistsOfFWESurvey = foodWaterEnergy.getConsistsOfFWESurvey();
				assertEquals(1, consistsOfFWESurvey.getLandUseSurvey().size());
			}
		}
	}
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy_consistsOfFWEsurvey_landUseSurvey_FoodSurvey() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				FoodWaterEnergy foodWaterEnergy = (FoodWaterEnergy) component;
				ConsistsOfFWESurvey consistsOfFWESurvey = foodWaterEnergy.getConsistsOfFWESurvey();
				for(LandUseSurvey landUseSurvey : consistsOfFWESurvey.getLandUseSurvey()) {
					assertEquals(5.0,landUseSurvey.getBuildingFootprintArea().getValue());
					assertTrue(landUseSurvey.getBuildingFootprintArea().getUom().equals("m2"));
					assertNotNull(landUseSurvey.getFoodsurvey());
					if(landUseSurvey.getFoodsurvey() !=null) {
						FoodSurvey foodSurvey = landUseSurvey.getFoodsurvey();
						assertEquals(12.0,foodSurvey.getFoodConsumption().getValue());
						assertTrue(foodSurvey.getFoodConsumption().getUom().equals("no_idea"));
						assertTrue(foodSurvey.getFoodCategory().getValue().equals("no_idea_6"));
						assertTrue(foodSurvey.getFoodCategory().getCodeSpace().equals("codeSpace_no_idea"));
						assertEquals(122.0,foodSurvey.getFoodDemand().getValue());
						assertTrue(foodSurvey.getFoodDemand().getUom().equals("no_idea_2"));
						assertEquals(123.0,foodSurvey.getFoodProduction().getValue());
						assertTrue(foodSurvey.getFoodProduction().getUom().equals("no_idea_3"));
						assertEquals(124.0,foodSurvey.getFoodProductionEnergyDemand().getValue());
						assertTrue(foodSurvey.getFoodProductionEnergyDemand().getUom().equals("no_idea_4"));
						assertEquals(125.0,foodSurvey.getFoodProductionWaterDemand().getValue());
						assertTrue(foodSurvey.getFoodProductionWaterDemand().getUom().equals("no_idea_5"));
						
					}
				}
			}
		}
	}

	@Test
	void testForReadingLandUseADEFoodWaterEnergy_consistsOfFWEsurvey_landUseSurvey_WaterSurvey() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				ConsistsOfFWESurvey consistsOfFWESurvey = ((FoodWaterEnergy) component).getConsistsOfFWESurvey();
				for(LandUseSurvey landUseSurvey : consistsOfFWESurvey.getLandUseSurvey()) {
					assertEquals(5.0,landUseSurvey.getBuildingFootprintArea().getValue());
					assertTrue(landUseSurvey.getBuildingFootprintArea().getUom().equals("m2"));
					assertNotNull(landUseSurvey.getWatersurvey());
					if(landUseSurvey.getWatersurvey() !=null) {
						WaterSurvey waterSurvey = landUseSurvey.getWatersurvey();
						assertEquals(30.0,waterSurvey.getDomesticHotWaterDemand().getValue());
						assertTrue(waterSurvey.getDomesticHotWaterDemand().getUom().equals("l"));
						assertEquals(31.0,waterSurvey.getDomesticHotWaterEnergyDemand().getValue());
						assertTrue(waterSurvey.getDomesticHotWaterEnergyDemand().getUom().equals("l"));
						assertEquals(32.0,waterSurvey.getDomesticSolidWaste().getValue());
						assertTrue(waterSurvey.getDomesticSolidWaste().getUom().equals("l"));
						assertEquals(33.0,waterSurvey.getDomesticWaterDemand().getValue());
						assertTrue(waterSurvey.getDomesticWaterDemand().getUom().equals("l"));
						assertEquals(34.0,waterSurvey.getDomesticWaterWaste().getValue());
						assertTrue(waterSurvey.getDomesticWaterWaste().getUom().equals("l"));
						assertEquals(35.0,waterSurvey.getTotalDomesticWaste().getValue());
						assertTrue(waterSurvey.getTotalDomesticWaste().getUom().equals("l"));
					}
				}
			}
		}
	}
	
	@Test
	void testForReadingLandUseADEFoodWaterEnergy_consistsOfFWEsurvey_landUseSurvey_EnergySurvey() throws FileNotFoundException, ADEException, CityGMLBuilderException, CityGMLReadException {
		CityModel cityModel = readCityGml(path);
		List<CityObjectMember> listCityObjectMember = cityModel.getCityObjectMember();
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				ConsistsOfFWESurvey consistsOfFWESurvey = ((FoodWaterEnergy) component).getConsistsOfFWESurvey();
				for(LandUseSurvey landUseSurvey : consistsOfFWESurvey.getLandUseSurvey()) {
					assertEquals(5.0,landUseSurvey.getBuildingFootprintArea().getValue());
					assertTrue(landUseSurvey.getBuildingFootprintArea().getUom().equals("m2"));
					assertNotNull(landUseSurvey.getEnergySurvey());
					if(landUseSurvey.getEnergySurvey() !=null) {
						EnergySurvey energySurvey = landUseSurvey.getEnergySurvey();
						assertEquals(300.0,energySurvey.getSpaceCoolingDemand().getValue());
						assertTrue(energySurvey.getSpaceCoolingDemand().getUom().equals("J"));
						assertEquals(301.0,energySurvey.getSpaceHeatingDemand().getValue());
						assertTrue(energySurvey.getSpaceHeatingDemand().getUom().equals("J"));
						assertEquals(303.0,energySurvey.getElectricityPotentialFromPVBuildings().getValue());
						assertTrue(energySurvey.getElectricityPotentialFromPVBuildings().getUom().equals("J"));
						assertEquals(304.0,energySurvey.getBiomassPrimaryEnergyPotential().getValue());
						assertTrue(energySurvey.getBiomassPrimaryEnergyPotential().getUom().equals("J"));
						assertEquals(305.0,energySurvey.getBiomassToBioethanol().getValue());
						assertTrue(energySurvey.getBiomassToBioethanol().getUom().equals("J"));
						assertEquals(306.0,energySurvey.getBiomassToBiogas().getValue());
						assertTrue(energySurvey.getBiomassToBiogas().getUom().equals("J"));
						assertEquals(307.0,energySurvey.getBiomassToElectricityPotential().getValue());
						assertTrue(energySurvey.getBiomassToElectricityPotential().getUom().equals("J"));
						assertEquals(308.0,energySurvey.getBiomassToEnergyWoods().getValue());
						assertTrue(energySurvey.getBiomassToEnergyWoods().getUom().equals("J"));
						assertEquals(309.0,energySurvey.getBiomassToPlantOil().getValue());
						assertTrue(energySurvey.getBiomassToPlantOil().getUom().equals("J"));
						assertEquals(310.0,energySurvey.getBiomassToResidualSolidFuel().getValue());
						assertTrue(energySurvey.getBiomassToResidualSolidFuel().getUom().equals("J"));
						assertEquals(311.0,energySurvey.getBiomassToSolidFuel().getValue());
						assertTrue(energySurvey.getBiomassToSolidFuel().getUom().equals("J"));
						assertEquals(312.0,energySurvey.getBiomassToThermalPotential().getValue());
						assertTrue(energySurvey.getBiomassToThermalPotential().getUom().equals("J"));
						assertTrue(energySurvey.getVegetationCoverCategory().getCodeSpace().equals("Un_code"));
						assertTrue(energySurvey.getVegetationCoverCategory().getValue().equals("ndlep"));
						assertEquals(302.0,energySurvey.getResidentialElectricityDemand().getValue());
						assertTrue(energySurvey.getResidentialElectricityDemand().getUom().equals("J"));
						
					}
				}
			}
		}
	}
	
	@Test
	void testForWritingFWELandUse()
			throws ADEException, CityGMLBuilderException, CityGMLWriteException, CityGMLReadException {
		
		CityModel myCityModel = new CityModel();
		LandUse luse = new LandUse();
		luse.setId("FWEL_DEST007");
		luse.getGenericApplicationPropertyOfLandUse().add(getOrCreateDummyData());
		myCityModel.getCityObjectMember().add(new CityObjectMember(luse));
		
		byte[] gml = writeCityGml(myCityModel);
		System.out.println(new String(gml));
				
		List<CityObjectMember> listCityObjectMember = myCityModel.getCityObjectMember();
		assertEquals(1, listCityObjectMember.size());
		CityObjectMember cityObjectMember = listCityObjectMember.get(0);
		AbstractCityObject abstractCityObject = cityObjectMember.getCityObject();
		assertTrue(abstractCityObject instanceof LandUse);
		LandUse landUse = (LandUse) abstractCityObject;
		for(ADEComponent component : landUse.getGenericApplicationPropertyOfLandUse()) {
			if(component instanceof FoodWaterEnergy) {
				FoodWaterEnergy foodWaterEnergy = (FoodWaterEnergy) component;
				assertTrue(foodWaterEnergy.getAreaName().equals("Test_Stuttgart_Ost"));
				assertTrue(foodWaterEnergy.getSystemName().equals("Test_Stuttgart_System"));
				ConsistsOfFWESurvey consistsOfFWESurvey = foodWaterEnergy.getConsistsOfFWESurvey();
				assertEquals(1, consistsOfFWESurvey.getLandUseSurvey().size());
				for(LandUseSurvey landUseSurvey : consistsOfFWESurvey.getLandUseSurvey()) {
					assertEquals(5.0,landUseSurvey.getBuildingFootprintArea().getValue());
					assertTrue(landUseSurvey.getBuildingFootprintArea().getUom().equals("m2"));
					assertNotNull(landUseSurvey.getFoodsurvey());
					if(landUseSurvey.getFoodsurvey() !=null) {
						FoodSurvey foodSurvey = landUseSurvey.getFoodsurvey();
						assertEquals(12.0,foodSurvey.getFoodConsumption().getValue());
					}
					assertNotNull(landUseSurvey.getWatersurvey());
					if(landUseSurvey.getWatersurvey() !=null) {
						WaterSurvey waterSurvey = landUseSurvey.getWatersurvey();
						assertEquals(30.0,waterSurvey.getDomesticHotWaterDemand().getValue());
					}
					assertNotNull(landUseSurvey.getEnergySurvey());
					if(landUseSurvey.getEnergySurvey() !=null) {
						EnergySurvey energySurvey = landUseSurvey.getEnergySurvey();
						assertEquals(300.0,energySurvey.getSpaceCoolingDemand().getValue());
					}
					
				}
			}
		}	
	}
	
	private FoodWaterEnergy getOrCreateDummyData() {
		
		LandUseSurvey landUseSurvey = new LandUseSurvey();
		landUseSurvey.setId("landUseSurvey_001");
		landUseSurvey.setSurveyDescription("Test_SurveyDescription");
		
		Area surfaceArea = new Area();
		surfaceArea.setUom("m2");
		surfaceArea.setValue(12.5);
		landUseSurvey.setSurfaceArea(surfaceArea);
		landUseSurvey.setSurveyYear(1975);
		landUseSurvey.setSurveyYearVersion(0.1);
		landUseSurvey.setSurveyDescription("desc");
		
		Area buildingFootPrintArea = new Area();
		buildingFootPrintArea.setUom("m2");
		buildingFootPrintArea.setValue(5);
		landUseSurvey.setBuildingFootprintArea(buildingFootPrintArea);	
		landUseSurvey.setPopulation(15000);
		
		FoodSurvey foodSurvey = new FoodSurvey();
		foodSurvey.setId("foodSurvey_001");
		
		Scale consumption = new Scale();
		consumption.setUom("no_idea");
		consumption.setValue(12);
		foodSurvey.setFoodConsumption(consumption);
		Scale foodDemand = new Scale();
		foodDemand.setUom("no_idea_2");
		foodDemand.setValue(122);
		foodSurvey.setFoodDemand(foodDemand);
		Scale foodProduction = new Scale();
		foodProduction.setUom("no_idea_3");
		foodProduction.setValue(123);
		foodSurvey.setFoodProduction(foodProduction);
		Scale foodProductionEnergyDemand = new Scale();
		foodProductionEnergyDemand.setUom("no_idea_4");
		foodProductionEnergyDemand.setValue(124);
		foodSurvey.setFoodProductionEnergyDemand(foodProductionEnergyDemand);
		Scale foodProductionWaterDemand = new Scale();
		foodProductionWaterDemand.setUom("no_idea_5");
		foodProductionWaterDemand.setValue(125);
		foodSurvey.setFoodProductionWaterDemand(foodProductionWaterDemand);
		Code foodCategory = new Code();
		foodCategory.setCodeSpace("codeSpace_no_idea");
		foodCategory.setValue("no_idea_6");
		foodSurvey.setFoodCategory(foodCategory);
	
		
		WaterSurvey waterSurvey = new WaterSurvey();
		waterSurvey.setId("waterSurvey_001");
		Scale domesticHotWaterDemand = new Scale();
		domesticHotWaterDemand.setUom("l");
		domesticHotWaterDemand.setValue(30);
		waterSurvey.setDomesticHotWaterDemand(domesticHotWaterDemand);
		Scale domesticHotWaterEnergyDemand = new Scale();
		domesticHotWaterEnergyDemand.setUom("l");
		domesticHotWaterEnergyDemand.setValue(31);
		waterSurvey.setDomesticHotWaterEnergyDemand(domesticHotWaterEnergyDemand);
		Scale domesticSolidWaste = new Scale();
		domesticSolidWaste.setUom("l");
		domesticSolidWaste.setValue(32);
		waterSurvey.setDomesticSolidWaste(domesticSolidWaste);
		Scale domesticWaterDemand = new Scale();
		domesticWaterDemand.setUom("l");
		domesticWaterDemand.setValue(33);
		waterSurvey.setDomesticWaterDemand(domesticWaterDemand);
		Scale domesticWaterWaste = new Scale();
		domesticWaterWaste.setUom("l");
		domesticWaterWaste.setValue(34);
		waterSurvey.setDomesticWaterWaste(domesticWaterWaste);
		Scale totalDomesticWaste = new Scale();
		totalDomesticWaste.setUom("l");
		totalDomesticWaste.setValue(35);
		waterSurvey.setTotalDomesticWaste(totalDomesticWaste);
		
		EnergySurvey energySurvey = new EnergySurvey();
		energySurvey.setId("energySurvey_001");
		Scale spaceCoolingDemand = new Scale();
		spaceCoolingDemand.setUom("J");
		spaceCoolingDemand.setValue(300);
		energySurvey.setSpaceCoolingDemand(spaceCoolingDemand);
		Scale spaceHeatingDemand = new Scale();
		spaceHeatingDemand.setUom("J");
		spaceHeatingDemand.setValue(301);
		energySurvey.setSpaceHeatingDemand(spaceHeatingDemand);
		Scale residentialElectricityDemand = new Scale();
		residentialElectricityDemand.setUom("J");
		residentialElectricityDemand.setValue(302);
		energySurvey.setResidentialElectricityDemand(residentialElectricityDemand);
		Scale electricityPotentialFromPVBuildings = new Scale();
		electricityPotentialFromPVBuildings.setUom("J");
		electricityPotentialFromPVBuildings.setValue(303);
		energySurvey.setElectricityPotentialFromPVBuildings(electricityPotentialFromPVBuildings);
		Scale biomassPrimaryEnergyPotential = new Scale();
		biomassPrimaryEnergyPotential.setUom("J");
		biomassPrimaryEnergyPotential.setValue(304);
		energySurvey.setBiomassPrimaryEnergyPotential(biomassPrimaryEnergyPotential);
		Scale biomassToBioethanol = new Scale();
		biomassToBioethanol.setUom("J");
		biomassToBioethanol.setValue(305);
		energySurvey.setBiomassToBioethanol(biomassToBioethanol);
		Scale biomassToBiogas = new Scale();
		biomassToBiogas.setUom("J");
		biomassToBiogas.setValue(306);
		energySurvey.setBiomassToBiogas(biomassToBiogas);
		Scale biomassToElectricityPotential = new Scale();
		biomassToElectricityPotential.setUom("J");
		biomassToElectricityPotential.setValue(307);
		energySurvey.setBiomassToElectricityPotential(biomassToElectricityPotential);
		Scale biomassToEnergyWoods = new Scale();
		biomassToEnergyWoods.setUom("J");
		biomassToEnergyWoods.setValue(308);
		energySurvey.setBiomassToEnergyWoods(biomassToEnergyWoods);
		Scale biomassToPlantOil = new Scale();
		biomassToPlantOil.setUom("J");
		biomassToPlantOil.setValue(309);
		energySurvey.setBiomassToPlantOil(biomassToPlantOil);
		Scale biomassToResidualSolidFuel = new Scale();
		biomassToResidualSolidFuel.setUom("J");
		biomassToResidualSolidFuel.setValue(310);
		energySurvey.setBiomassToResidualSolidFuel(biomassToResidualSolidFuel);
		Scale biomassToSolidFuel = new Scale();
		biomassToSolidFuel.setUom("J");
		biomassToSolidFuel.setValue(311);
		energySurvey.setBiomassToSolidFuel(biomassToSolidFuel);
		Scale biomassToThermalPotential = new Scale();
		biomassToThermalPotential.setUom("J");
		biomassToThermalPotential.setValue(312);
		energySurvey.setBiomassToThermalPotential(biomassToThermalPotential);	
		Code vegetationCoverCategory = new Code();
		vegetationCoverCategory.setCodeSpace("Un_code");
		vegetationCoverCategory.setValue("ndlep");
		energySurvey.setVegetationCoverCategory(vegetationCoverCategory);
		
	
		landUseSurvey.setFoodsurvey(foodSurvey);
		landUseSurvey.setWatersurvey(waterSurvey);
		landUseSurvey.setEnergySurvey(energySurvey);
		
		ConsistsOfFWESurvey consistsOfFWESurvey = new ConsistsOfFWESurvey();
		List<LandUseSurvey> surveyList = new ArrayList<LandUseSurvey>();
		surveyList.add(landUseSurvey);
		consistsOfFWESurvey.setLandUseSurvey(surveyList);
	
		
		
		FoodWaterEnergy foodWaterEnergy = new FoodWaterEnergy();
		foodWaterEnergy.setId("foodWaterEnergy_001");
		foodWaterEnergy.setAreaName("Test_Stuttgart_Ost");
		foodWaterEnergy.setSystemName("Test_Stuttgart_System");
		foodWaterEnergy.setConsistsOfFWESurvey(consistsOfFWESurvey);
		
		return foodWaterEnergy;
		
	}
	
	
}
