package test.pete.metrics.portability;

import static org.junit.Assert.assertEquals;

import java.nio.file.Paths;

import org.junit.Before;
import org.junit.Test;

import pete.metrics.portability.PortabilityAnalyzer;
import pete.reporting.ReportEntry;
import bpp.domain.PortabilityLevel;
import bpp.domain.metrics.ActivityPortabilityMetric;
import bpp.domain.metrics.BasicPortabilityMetric;
import bpp.domain.metrics.ServiceCommunicationPortabilityMetric;
import bpp.domain.metrics.WeightedElementsPortabilityMetric;

public class PortabilityAnalyzerTests {

	private PortabilityAnalyzer sut;

	@Before
	public void setUp() {
		sut = new PortabilityAnalyzer();
	}

	@Test
	public void testBasicFile() {
		ReportEntry result = sut.analyzeFile(
				Paths.get("src/test/resources/portability/Invoke-Empty.bpel"))
				.get(0);

		assertClassification(result, PortabilityLevel.LIMITED_PORTABILITY);
		assertNumberOfElements(result, 17);
		assertBasicPortability(result, 0.941);
		assertWeightedPortability(result, 0.963);
		assertActivityPortability(result, 0.875);
		assertServicePortability(result, 0.791);
	}

	private void assertNumberOfElements(ReportEntry entry, int numberOfElements) {
		assertEquals(Integer.parseInt(entry.getVariableValue("N")),
				numberOfElements);
	}

	private void assertClassification(ReportEntry entry,
			PortabilityLevel expected) {
		assertEquals(entry.getVariableValue("class"), expected.toString());
	}

	private void assertBasicPortability(ReportEntry entry, double expected) {
		assertEquals(Double.parseDouble(entry
				.getVariableValue(BasicPortabilityMetric.getLabel())),
				expected, 0.001);
	}

	private void assertWeightedPortability(ReportEntry entry, double expected) {
		assertEquals(
				Double.parseDouble(entry
						.getVariableValue(WeightedElementsPortabilityMetric
								.getLabel())), expected, 0.001);
	}

	private void assertActivityPortability(ReportEntry entry, double expected) {
		assertEquals(Double.parseDouble(entry
				.getVariableValue(ActivityPortabilityMetric.getLabel())),
				expected, 0.001);
	}

	private void assertServicePortability(ReportEntry entry, double expected) {
		assertEquals(Double.parseDouble(entry
				.getVariableValue(ServiceCommunicationPortabilityMetric
						.getLabel())), expected, 0.001);
	}
}

@@ -1371,16 +1371,37 @@
 tEquals(
+expected.toString(), 
 entry.ge
@@ -1427,29 +1427,8 @@
 ss%22)
-, expected.toString()
 );%0A%09
@@ -1512,32 +1512,42 @@
 %0A%09%09assertEquals(
+expected, 
 Double.parseDoub
@@ -1609,38 +1609,24 @@
 etLabel())),
-%0A%09%09%09%09expected,
  0.001);%0A%09%7D%0A
@@ -1719,16 +1719,25 @@
 tEquals(
+expected,
 %0A%09%09%09%09Dou
@@ -1834,34 +1834,24 @@
 etLabel())),
- expected,
  0.001);%0A%09%7D%0A
@@ -1936,32 +1936,42 @@
 %0A%09%09assertEquals(
+expected, 
 Double.parseDoub
@@ -2044,22 +2044,8 @@
 ))),
-%0A%09%09%09%09expected,
  0.0
@@ -2145,16 +2145,26 @@
 tEquals(
+expected, 
 Double.p
@@ -2236,24 +2236,24 @@
 ilityMetric%0A
+
 %09%09%09%09%09%09.getLa
@@ -2264,18 +2264,8 @@
 ))),
- expected,
  0.0

Use correct sorting of expected/actual