package archmapper.main.test;
import org.junit.Before;
import org.junit.Test;
import archmapper.main.model.MappingFileChecker;
import archmapper.main.model.archmapping.ComponentMapping;
import static org.junit.Assert.*;
public class MappingFileCheckerTest extends MappingTestBase {
protected MappingFileChecker checker;
@Before
public void loadFiles() {
super.loadFiles();
checker = new MappingFileChecker(architecture, archMapping, styleMapping);
}
@Test
public void testCheckInvalidNames() {
archMapping.getComponentMapping().get(0).setComponentName("abc");
checker.checkInvalidNamesInArchMapping();
assertEquals(1, checker.getArchMappingErrors().size());
checker.clearAllWarningsAndErrors();
assertEquals(0, checker.getAllWarningsAndErrors().size());
}
@Test
public void testInvalidImplementationArtifactTypeNames() {
checker.checkInvalidNamesInArchMapping();
// check that there were no errors before...
assertEquals(0, checker.getAllWarningsAndErrors().size());
// Inject a wrong type name
ComponentMapping compMapping = archMapping.getComponentMapping().get(0);
compMapping.getClassDefinition().get(0).setType("abc");
checker.checkInvalidNamesInArchMapping();
assertEquals(1, checker.getArchMappingErrors().size());
// wrong file name and interface name
compMapping.getFileDefinition().get(0).setType("abc");
compMapping.getInterfaceDefinition().get(0).setType("abc");
checker.clearAllWarningsAndErrors();
checker.checkInvalidNamesInArchMapping();
assertEquals(3, checker.getArchMappingErrors().size());
}
@Test
public void testWrongPortNamesChecking() {
archMapping.getComponentMapping().get(0).getPortMapping().get(0).setPortName("abc");
checker.checkInvalidNamesInArchMapping();
assertEquals(1, checker.getArchMappingErrors().size());
}
@Test
public void testOptionalTypeChecking() {
styleMapping.getComponentType("CompType2").getClassType("notUsedType").setOptional(false);
checker.checkIfNonOptionalTypesArePresent();
assertEquals(1, checker.getArchMappingErrors().size());
}
@Test
public void testInvalidStyleTypeChecking() {
styleMapping.getComponentType("CompType2").setTypeName("abc");
checker.checkUnusedTypesInStyleMapping();
assertEquals(1, checker.getStyleMappingWarnings().size());
checker.clearAllWarningsAndErrors();
styleMapping.getConnectorTypeMapping("ConnType").setTypeName("abc");
checker.checkUnusedTypesInStyleMapping();
assertEquals(2, checker.getStyleMappingWarnings().size());
checker.clearAllWarningsAndErrors();
styleMapping.getPortTypeMapping().get(0).setTypeName("abc");
styleMapping.getRoleTypeMapping().get(0).setTypeName("abc");
checker.checkUnusedTypesInStyleMapping();
assertEquals(4, checker.getStyleMappingWarnings().size());
}
@Test
public void testUnmappedComponentInArchMappingCheck() {
archMapping.getComponentMapping().get(0).setComponentName("abc");
checker.checkUnmappedComponentsInArchMapping();
assertEquals(1, checker.getArchMappingWarnings().size());
}
}