package br.uem.din.architectureEvolution.helpers;

import static br.uem.din.architectureEvolution.helpers.ElementTypeNames.*;
import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;

import br.uem.din.architectureEvolution.helpers.ModelHelper;
import br.uem.din.architectureEvolution.helpers.ModelHelperFactory;

import com.sdmetrics.model.Model;
import com.sdmetrics.model.ModelElement;

public class ModelHelperTest {
	
	private static ModelHelper modelHelper;
	private static Model model;
	
	@BeforeClass
	public static void beforeClass() throws Exception{
		modelHelper = ModelHelperFactory.getModelHelper();
		model = modelHelper.getModel(modelHelper.findResource("br/uem/din/architectureEvolution/resources/AGMBusiness_Components.xmi"));
	}

	@Test
	public void getAllComponentsTest() {
		 
		List<ModelElement> allComponents = modelHelper.getAllComponents(model);
		
		assertCollectionSizeAndElementsType(allComponents, 2, COMPONENT);
	}
	
	@Test
	public void getAllClassesTest() {
		 
		List<ModelElement> allClasses = modelHelper.getAllClasses(model);
		
		assertCollectionSizeAndElementsType(allClasses, 18, CLASS);
	}
	
	@Test
	public void getAllInterfacesTest() {
		 
		List<ModelElement> allIntefraces = modelHelper.getAllInterfaces(model);
		
		assertCollectionSizeAndElementsType(allIntefraces, 1, INTERFACE);
	}
	
	@Test
	public void getAllCommentsTest(){
		
		List<ModelElement> allComments = modelHelper.getAllComments(model);
		assertCollectionSizeAndElementsType(allComments, 4, COMMENT);
	}
	
	@Test
	public void getAllGeneralizationsTest() {
		 
		List<ModelElement> allGeneralizations = modelHelper.getAllGeneralizations(model);
		assertCollectionSizeAndElementsType(allGeneralizations, 12, GENERALIZATION);
	}
	
	@Test
	public void getAllAbstractionsTest() {
		 
		List<ModelElement> allAbstractions = modelHelper.getAllAbstractions(model);
		
		assertCollectionSizeAndElementsType(allAbstractions, 1, ABSTRACTION);
	}
	
	@Test
	public void getAllAssociationsTest() {
		 
		List<ModelElement> allAssociations = modelHelper.getAllAssociations(model);
		
		assertCollectionSizeAndElementsType(allAssociations, 2, ASSOCIATION);
	}
	
	@Test
	public void getAllDependenciesTest() {
		 
		List<ModelElement> allDependencies = modelHelper.getAllDependencies(model);
		
		assertCollectionSizeAndElementsType(allDependencies, 3, DEPENDENCY);
	}	

	private void assertCollectionSizeAndElementsType(List<ModelElement> allElements, int expectedSize, String expectedType) {
		
		assertEquals(expectedSize, allElements.size());
		
		for (ModelElement element : allElements) {
			assertEquals(expectedType, element.getType().getName());
		}
	}

}
