Commit 5586383f authored by Manuel Schrick's avatar Manuel Schrick
Browse files

removed old user tests

parent 68e6d56f
package de.monticore.lang.montiarc.svggenerator.templatetests;
import de.monticore.lang.montiarc.svggenerator.LogConfig;
import de.monticore.lang.montiarc.svggenerator.TemplateBuilder;
import de.monticore.lang.montiarc.svggenerator.TestingUtilities;
import de.monticore.lang.montiarc.svggenerator.ViewModel.*;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.LayoutPosition;
import freemarker.template.Configuration;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import static org.junit.Assert.assertEquals;
// de.monticore.lang.montiarc.svggenerator.templatetests
// montiarc-core-features
//
// Created by Sven Titgemeyer on 08/03/2017.
// Copyright (c) 2017 Sven Titgemeyer. All rights reserved.
//
public class TemplateTest {
private static String expectedFiles = "src/test/resources/templateTestResources/";
@BeforeClass
public static void init(){
LogConfig.init();
}
@Test
public void testDependency() {
//Test if Freemarker is correctly included
Configuration cfg = new Configuration(Configuration.VERSION_2_3_20);
Assert.assertNotNull("Assert if freemarker configuration is available", cfg);
}
@Test
public void testPortTemplate() throws IOException {
PortTemplate unused = new PortTemplate(); // Not used. Just for test coverage
PortViewModel viewModel = new PortViewModel();
viewModel.portname = "TestPortName";
viewModel.anchor = "TestPortAnchor";
viewModel.x = 100;
viewModel.y = 200;
viewModel.angle = 45;
viewModel.layoutPosition = LayoutPosition.UNDEFINED;
viewModel.isIncoming = true;
viewModel.isOutgoing = false;
viewModel.isInternal = false;
StringBuilder sb = new StringBuilder();
// TESTS WITH UNDEFINED LAYOUTPOSITION
viewModel.isIncoming = true;
viewModel.isOutgoing = false;
viewModel.isInternal = false;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate1.svg"), sb.toString());
sb.setLength(0);
viewModel.isIncoming = false;
viewModel.isOutgoing = true;
viewModel.isInternal = false;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate2.svg"), sb.toString());
sb.setLength(0);
viewModel.isIncoming = true;
viewModel.isOutgoing = false;
viewModel.isInternal = true;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate3.svg"), sb.toString());
sb.setLength(0);
viewModel.isIncoming = false;
viewModel.isOutgoing = true;
viewModel.isInternal = true;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate4.svg"), sb.toString());
sb.setLength(0);
viewModel.layoutPosition = LayoutPosition.LEFT;
// TESTS WITH DEFINED LAYOUTPOSITION
sb.setLength(0);
viewModel.isIncoming = true;
viewModel.isOutgoing = false;
viewModel.isInternal = false;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate5.svg"), sb.toString());
sb.setLength(0);
viewModel.isIncoming = false;
viewModel.isOutgoing = true;
viewModel.isInternal = false;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate6.svg"), sb.toString());
sb.setLength(0);
viewModel.isIncoming = true;
viewModel.isOutgoing = false;
viewModel.isInternal = true;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate7.svg"), sb.toString());
sb.setLength(0);
viewModel.isIncoming = false;
viewModel.isOutgoing = true;
viewModel.isInternal = true;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate8.svg"), sb.toString());
sb.setLength(0);
viewModel.portname = "ThisIsAVeryLongPortNameWithALotOfDifferentLetters";
viewModel.layoutPosition = LayoutPosition.UNDEFINED;
viewModel.isInternal = true;
PortTemplate.drawPortDescription(sb, viewModel);
assertEquals(TestingUtilities.readFile(expectedFiles + "portTemplate9.svg"), sb.toString());
}
@Test
public void testArrowHeadsTemplate() throws IOException {
// setup a component view model
HashSet<String> colors = new HashSet<>();
colors.add("42,42,42");
colors.add("1,2,3");
colors.add("123,321,312");
ConnectorViewModel viewModel = new ConnectorViewModel();
viewModel.colorset = colors;
// load expected component from file
String expectedComponent = TestingUtilities.readFile
(expectedFiles + "arrowHeads.svg");
// Build component using template builder
TemplateBuilder templateBuilder = new TemplateBuilder();
String component = templateBuilder.build("arrowHeads.ftl", viewModel.hashMap());
// compare results
assertEquals(component, expectedComponent);
}
@Test
public void testPortDefineTemplate() throws IOException {
// setup a component view model
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("portWidth", 20);
hashMap.put("portHeight", 40);
// load expected component from file
String expectedComponent = TestingUtilities.readFile
(expectedFiles + "portDefine.svg");
// Build component using template builder
TemplateBuilder templateBuilder = new TemplateBuilder();
String component = templateBuilder.build("portDefine.ftl", hashMap);
// compare results
assertEquals(component, expectedComponent);
}
@Test
public void testLineDrawing() {
// setup line view model
LineViewModel viewModel = getLineViewModel(false);
// load expected line from file
String expectedLine = TestingUtilities.readFile(expectedFiles + "line.svg");
// Build line using template builder
TemplateBuilder templateBuilder = new TemplateBuilder();
String line = templateBuilder.build("line.ftl", viewModel.hashMap());
// compare results
assertEquals(line, expectedLine);
}
@Test
public void testLineWithArrowDrawing() {
// setup line view model
LineViewModel viewModel = getLineViewModel(true);
// load expected line from file
String expectedLine = TestingUtilities.readFile(expectedFiles + "lineWithArrow.svg");
// Build line using template builder
TemplateBuilder templateBuilder = new TemplateBuilder();
String line = templateBuilder.build("line.ftl", viewModel.hashMap());
// compare results
assertEquals(line, expectedLine);
}
private LineViewModel getLineViewModel(boolean isEnd){
LineViewModel viewModel = new LineViewModel();
viewModel.x = 0;
viewModel.y = 1;
viewModel.xx = 2;
viewModel.yy = 3;
viewModel.red = 4;
viewModel.green = 5;
viewModel.blue = 6;
viewModel.linewidth = 7;
viewModel.isEnd = isEnd;
return viewModel;
}
}
package de.monticore.lang.montiarc.svggenerator.userTests;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.svggenerator.LogConfig;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.LayoutSymbol;
import org.junit.Assert;
import org.junit.BeforeClass;
// de.monticore.lang.montiarc.svggenerator.userTests
// montiarc-core-features
//
// Created by Sven Titgemeyer on 05/01/2017.
// Copyright (c) 2017 Sven Titgemeyer. All rights reserved.
//
public class TestCaseFelixWehnert extends AbstractUserTest{
@Override
public void testFirstMontiArcModel() throws Exception {
//calculate the layout
ExpandedComponentInstanceSymbol inst = super.getCalculatedLayoutModel
("testFelixWehnert.firstExample");
//get the components
ExpandedComponentInstanceSymbol[] components = inst.getSubComponents().toArray(new
ExpandedComponentInstanceSymbol[inst.getSubComponents().size()]);
//Look up each element and check if the grid position is correct
for(ExpandedComponentInstanceSymbol component : components){
//there should be exactly one layout symbol per component
Assert.assertEquals(component.<LayoutSymbol>getTags(LayoutSymbol.KIND).size(), 1);
LayoutSymbol layoutSymbol = component.<LayoutSymbol>getTags(LayoutSymbol.KIND).iterator()
.next();
if(component.getName().equals("component1")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 0);
} else {
Assert.fail("There should be no component with that name");
}
}
System.out.println("First test is completed.");
}
@Override
public void testSecondMontiArcModel() throws Exception {
//calculate the layout
ExpandedComponentInstanceSymbol inst = super.getCalculatedLayoutModel
("testFelixWehnert.secondExample");
//get the components
ExpandedComponentInstanceSymbol[] components = inst.getSubComponents().toArray(new
ExpandedComponentInstanceSymbol[inst.getSubComponents().size()]);
//Look up each element and check if the grid position is correct
for(ExpandedComponentInstanceSymbol ignored : components){
Assert.fail("There must be no component");
}
System.out.println("Second test is completed.");
}
@Override
public void testThirdMontiArcModel() throws Exception {
//calculate the layout
ExpandedComponentInstanceSymbol inst = super.getCalculatedLayoutModel
("testFelixWehnert.thirdExample");
//get the components
ExpandedComponentInstanceSymbol[] components = inst.getSubComponents().toArray(new
ExpandedComponentInstanceSymbol[inst.getSubComponents().size()]);
//Go through the all components of the scheme
for (ExpandedComponentInstanceSymbol component : components) {
Assert.assertEquals(component.<LayoutSymbol>getTags(LayoutSymbol.KIND).size(), 1);
LayoutSymbol layoutSymbol = component.<LayoutSymbol>getTags(LayoutSymbol.KIND).iterator().next();
//Change this part, now it's time to check different parameters of components
if (component.getName().equals("component1")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 0);
} else if (component.getName().equals("component2")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 1);
}else if (component.getName().equals("component3")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 2);
}else if (component.getName().equals("component4")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 3);
}else if (component.getName().equals("component5")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 4);
}else if (component.getName().equals("component6")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 5);
}else if (component.getName().equals("component7")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 6);
}else if (component.getName().equals("component8")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 7);
}else if (component.getName().equals("component9")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 8);
}else if (component.getName().equals("component10")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 9);
}else if (component.getName().equals("component11")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 10);
}else if (component.getName().equals("component12")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 11);
}else if (component.getName().equals("component13")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 12);
}else if (component.getName().equals("component14")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 13);
}else if (component.getName().equals("component15")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 14);
} else {
Assert.fail("Unexpected component");
}
}
System.out.println("Third test is completed.");
}
@Override
public void testFourthMontiArcModel() throws Exception {
//calculate the layout
ExpandedComponentInstanceSymbol inst = super.getCalculatedLayoutModel
("testFelixWehnert.fourthExample");
//get the components
ExpandedComponentInstanceSymbol[] components = inst.getSubComponents().toArray(new
ExpandedComponentInstanceSymbol[inst.getSubComponents().size()]);
//Go through the all components of the scheme
for (ExpandedComponentInstanceSymbol component : components) {
Assert.assertEquals(component.<LayoutSymbol>getTags(LayoutSymbol.KIND).size(), 1);
LayoutSymbol layoutSymbol = component.<LayoutSymbol>getTags(LayoutSymbol.KIND).iterator().next();
//Change this part, now it's time to check different parameters of components
if (component.getName().equals("component1")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 0);
} else if (component.getName().equals("component2")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 1);
}else if (component.getName().equals("component3")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 2);
}else if (component.getName().equals("component4")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 3);
}else if (component.getName().equals("component5")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 4);
}else if (component.getName().equals("component6")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 5);
}else if (component.getName().equals("component7")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 6);
}else if (component.getName().equals("component8")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 7);
}else if (component.getName().equals("component9")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 8);
}else if (component.getName().equals("component10")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 9);
}else if (component.getName().equals("component11")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 10);
}else if (component.getName().equals("component12")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 11);
}else if (component.getName().equals("component13")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 12);
}else if (component.getName().equals("component14")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 13);
}else if (component.getName().equals("component15")) {
Assert.assertEquals(layoutSymbol.getColumn(), 0);
Assert.assertEquals(layoutSymbol.getRow(), 14);
} else {
Assert.fail("Unexpected component");
}
}
System.out.println("Fourth test is completed.");
}
@Override
public void testFifthMontiArcModel() {
System.out.println("Fifth test is completed.");
}
}
package de.monticore.lang.montiarc.svggenerator.userTests;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.montiarc.svggenerator.calculators.symbols.LayoutSymbol;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by hanna on 11.01.17.
*/
public class TestCaseHannaFranzen extends AbstractUserNoMethodsTest {
/*
* testVerticalAlignmentCrossingConnectors:
* This tests has a look at a model with four elements of which 2x two are connected.
* It is tested if the connected components have the same row, respectively.
* So, the expected out put would be something like:
* _ _
* |1|--->|4|
* _ _
* |2|--->|3|
*
* This avoids output like:
* _ _
* |1| |3|
* \ ^
* \/
* /\
* _ / v _
* |2| |4|
*
* The test is written flexibly such that it tests if there is an incoming connection,
* and if so, if one of the connected elements is in the same row.
*/
@Test
public void testVerticalAlignmentCrossingConnectors() throws Exception {
ExpandedComponentInstanceSymbol inst =
super.getCalculatedLayoutModel("testHannaFranzenWithTags.firstExample");
//get the components in an array
ExpandedComponentInstanceSymbol[] components = inst.getSubComponents().toArray(new
ExpandedComponentInstanceSymbol[inst.getSubComponents().size()]);
//Look up the positions of each component
LayoutSymbol layoutSymbol1 = null;
LayoutSymbol layoutSymbol2 = null;
LayoutSymbol layoutSymbol3 = null;
LayoutSymbol layoutSymbol4 = null;
for(ExpandedComponentInstanceSymbol component : components){
//there should be exactly one layout symbol per component
Assert.assertEquals(component.<LayoutSymbol>getTags(LayoutSymbol.KIND).size(), 1);
LayoutSymbol layoutSymbol = component.<LayoutSymbol>getTags(LayoutSymbol.KIND).iterator()
.next();
if(component.getName().equals("component1")){
layoutSymbol1 = layoutSymbol;
} else if(component.getName().equals("component2")){
layoutSymbol2 = layoutSymbol;
} else if(component.getName().equals("component3")){
layoutSymbol3 = layoutSymbol;
} else if(component.getName().equals("component4")){
layoutSymbol4= layoutSymbol;
}else{
Assert.fail("There should be no component with that name");
}
}
//check if the rows of components A&D, B&C are the same (which is the expected value)
Assert.assertEquals(layoutSymbol1.getRow(), layoutSymbol3.getRow());
Assert.assertEquals(layoutSymbol2.getRow(), layoutSymbol4.getRow());
System.out.println("Test crossing of connectors executed, no crossing could be detected");
}
/*
* Test if for a component with 3 predecessors (and no additional components),
* there is one predecessor on the same row as the common postdecessor.
* This should prevent any wrong index incrementation errors that might occur during
* the vertical order assignment algorithm.
*/
@Test
public void testPredecessor() throws Exception {
ExpandedComponentInstanceSymbol inst =
super.getCalculatedLayoutModel("testHannaFranzenWithTags.thirdExample");
//get the components in an array
ExpandedComponentInstanceSymbol[] components = inst.getSubComponents().toArray(new
ExpandedComponentInstanceSymbol[inst.getSubComponents().size()]);