package prope.executables;

import static org.junit.Assert.assertEquals;

import java.nio.file.Paths;
import java.util.List;

import org.junit.Test;

import prope.reporting.ReportEntry;

public class AnalysisWorkflowTests {
	
	private AnalysisWorkflow sut;
	
	private final String deployabilityResourcesPath = "src/test/resources/installability/deployment/";

	@Test(expected = IllegalArgumentException.class)
	public void testNonExistingDirectory() {
		sut = new AnalysisWorkflow(Paths.get("foobar"),
				AnalysisType.DEPLOYABILITY);
	}
	
	@Test
	public void deployabilityAnalysis(){
		sut = new AnalysisWorkflow(Paths.get(deployabilityResourcesPath + "xmlDescriptorWithText.zip"),
				AnalysisType.DEPLOYABILITY);
		
		List<ReportEntry> results = sut.start().getEntries();
		assertEquals(results.size(),1);
		
		ReportEntry entry = results.get(0);
		assertEquals(14, getDeploymentEffort(entry));
		assertEquals(2, getEffortOfPackageConstruction(entry));
		assertEquals(12, getDescriptorComplexity(entry));
	}

	private int getDeploymentEffort(ReportEntry entry) {
		if (entry != null) {
			return Integer.parseInt(entry.getVariableValue("DE"));
		} else {
			return 0;
		}
	}

	private int getEffortOfPackageConstruction(ReportEntry entry) {
		if (entry != null) {
			return Integer.parseInt(entry.getVariableValue("EPC"));
		} else {
			return 0;
		}
	}

	private int getDescriptorComplexity(ReportEntry entry) {
		if (entry != null) {
			return Integer.parseInt(entry.getVariableValue("DDS"));
		} else {
			return 0;
		}
	}
}

@@ -111,17 +111,106 @@
 ava.
-util.List
+text.NumberFormat;%0Aimport java.text.ParseException;%0Aimport java.util.List;%0Aimport java.util.Locale
 ;%0A%0Ai
@@ -440,16 +440,114 @@
 yment/%22;
+%0A%09%0A%09private final String installabilityResourcePath = %22src/test/resources/installability/server/%22;
 %0A%0A%09@Test
@@ -1709,10 +1709,549 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09@Test%0A%09public void installabilityAnalysis() throws ParseException %7B%0A%09%09sut = new AnalysisWorkflow(Paths.get(installabilityResourcePath + %22simple/%22),%0A%09%09%09%09AnalysisType.INSTALLABILITY);%0A%09%09%0A%09%09List%3CReportEntry%3E results = sut.start().getEntries();%0A%09%09assertEquals(results.size(),1);%0A%0A%09%09String ait = results.get(0).getVariableValue(%22AIT%22);%0A%09%09NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);%0A%09%09Number number = format.parse(ait);%0A%09%09double d = number.doubleValue();%0A%09%09assertEquals(%22AIT should be 22,00, but was %22 + d, 22, d, 0.1);%0A%09%7D%0A
 %7D%0A

Add integration test for installability analysis