package hu.elte.txtuml.export.cpp.wizardz;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

import java.io.File;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.junit.Test;

public class CompileTests {

	private static class Config {
		final String project;
		final String model;
		final String deployment;

		Config(String project, String model, String deployment) {
			this.project = project;
			this.model = model;
			this.deployment = deployment;
		}
	}

	private static final String pathToProjects = "../../../examples/demo/";

	private static final Config[] testProjects = {
			new Config("hu.elte.txtuml.examples.machine", "hu.elte.txtuml.examples.machine.model1",
					"hu.elte.txtuml.examples.machine.Machine1Configuration"),
			new Config("hu.elte.txtuml.examples.monitoring", "hu.elte.txtuml.examples.monitoring.model",
					"hu.elte.txtuml.examples.monitoring.MonitoringConfiguration"),
			new Config("hu.elte.txtuml.examples.producer_consumer", "hu.elte.txtuml.examples.producer_consumer.model",
					"hu.elte.txtuml.examples.producer_consumer.ProducerConsumerConfiguration"),
			new Config("hu.elte.txtuml.examples.train", "hu.elte.txtuml.examples.train.model",
					"hu.elte.txtuml.examples.train.TrainConfiguration"), };

	@Test
	public void exportTest() {
		for (Config config : testProjects) {
			TxtUMLToCppGovernor cppgen = new TxtUMLToCppGovernor(true);
			boolean runsOk = true;
			try {
				IProjectDescription desc = ResourcesPlugin.getWorkspace()
						.loadProjectDescription(new Path(pathToProjects + config.project + "/.project"));
				desc.setLocation(new Path(new File(pathToProjects + config.project).getAbsolutePath()));
				IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(desc.getName());
				project.create(desc, null);
				project.open(null);
				project.build(IncrementalProjectBuilder.CLEAN_BUILD, null);
				project.build(IncrementalProjectBuilder.FULL_BUILD, null);

				cppgen.uml2ToCpp(config.project, config.model, config.deployment, false);
			} catch (Exception e) {
				runsOk = false;
				e.printStackTrace();
			}
			assertThat(runsOk, is(true));
		}
	}
}

@@ -841,81 +841,35 @@
 ig(%22
-hu.elte.txtuml.examples.machine%22, %22hu.elte.txtuml.examples.
+machine%22, %22
 machine
+1.j
 .model
-1
 %22,%0A%09
@@ -877,142 +877,72 @@
 %09%09%09%22
-hu.elte.txtuml.examples.machine.Machine1Configuration%22),%0A%09%09%09new Config(%22hu.elte.txtuml.examples.monitoring%22, %22hu.elte.txtuml.examples.
+machine1.j.DefaultConfiguration%22),%0A%09%09%09new Config(%22monitoring%22, %22
 moni
@@ -948,16 +948,18 @@
 itoring.
+x.
 model%22,%0A
@@ -968,32 +968,8 @@
 %09%09%09%22
-hu.elte.txtuml.examples.
 moni
@@ -979,18 +979,17 @@
 ing.
-Monitoring
+x.Default
 Conf
@@ -1020,77 +1020,29 @@
 ig(%22
-hu.elte.txtuml.examples.producer_consumer%22, %22hu.elte.txtuml.examples.
+producer_consumer%22, %22
 prod
@@ -1055,16 +1055,18 @@
 onsumer.
+j.
 model%22,%0A
@@ -1075,32 +1075,8 @@
 %09%09%09%22
-hu.elte.txtuml.examples.
 prod
@@ -1093,24 +1093,17 @@
 mer.
-ProducerConsumer
+j.Default
 Conf
@@ -1134,71 +1134,25 @@
 ig(%22
-hu.elte.txtuml.examples.train%22, %22hu.elte.txtuml.examples.
+train%22, %22
 train.
+j.
 mode
@@ -1165,43 +1165,23 @@
 %09%09%09%22
-hu.elte.txtuml.examples.train.Train
+train.j.Default
 Conf

Update path of examples