mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-24 13:57:33 +00:00
Add tests for each new command
This commit is contained in:
parent
d39bfbc3b5
commit
234cb3adea
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2024, Arnaud Roques
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: https://plantuml.com
|
* Project Info: https://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* https://plantuml.com/patreon (only 1$ per month!)
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
* https://plantuml.com/paypal
|
* https://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.cheneer.command;
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
@ -59,7 +59,7 @@ public class CommandAssociate extends SingleLineCommand2<ChenEerDiagram> {
|
|||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
protected static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
@ -61,7 +61,7 @@ public class CommandCreateAttribute extends SingleLineCommand2<ChenEerDiagram> {
|
|||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
protected static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
RegexLeaf.spaceZeroOrMore(),
|
RegexLeaf.spaceZeroOrMore(),
|
||||||
new RegexOptional( // Copied from CommandCreatePackageBlock
|
new RegexOptional( // Copied from CommandCreatePackageBlock
|
||||||
|
@ -58,7 +58,7 @@ public class CommandCreateEntity extends SingleLineCommand2<ChenEerDiagram> {
|
|||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
protected static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("TYPE", "(entity|relationship)"), //
|
new RegexLeaf("TYPE", "(entity|relationship)"), //
|
||||||
RegexLeaf.spaceOneOrMore(), //
|
RegexLeaf.spaceOneOrMore(), //
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2024, Arnaud Roques
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: https://plantuml.com
|
* Project Info: https://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* https://plantuml.com/patreon (only 1$ per month!)
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
* https://plantuml.com/paypal
|
* https://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.cheneer.command;
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
@ -50,7 +50,7 @@ public class CommandEndGroup extends SingleLineCommand2<ChenEerDiagram> {
|
|||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
static IRegex getRegexConcat() {
|
protected static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandEndGroup.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandEndGroup.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("\\}"), //
|
new RegexLeaf("\\}"), //
|
||||||
RegexLeaf.end()); //
|
RegexLeaf.end()); //
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2024, Arnaud Roques
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: https://plantuml.com
|
* Project Info: https://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* https://plantuml.com/patreon (only 1$ per month!)
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
* https://plantuml.com/paypal
|
* https://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.cheneer.command;
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
@ -63,7 +63,7 @@ public class CommandMultiSubclass extends SingleLineCommand2<ChenEerDiagram> {
|
|||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
protected static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("SUPERCLASS", "([\\w-]+)"), //
|
new RegexLeaf("SUPERCLASS", "([\\w-]+)"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2024, Arnaud Roques
|
* (C) Copyright 2009-2024, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: https://plantuml.com
|
* Project Info: https://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* https://plantuml.com/patreon (only 1$ per month!)
|
* https://plantuml.com/patreon (only 1$ per month!)
|
||||||
* https://plantuml.com/paypal
|
* https://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.cheneer.command;
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
@ -58,7 +58,7 @@ public class CommandSimpleSubclass extends SingleLineCommand2<ChenEerDiagram> {
|
|||||||
super(getRegexConcat());
|
super(getRegexConcat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IRegex getRegexConcat() {
|
protected static IRegex getRegexConcat() {
|
||||||
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
return RegexConcat.build(CommandCreateEntity.class.getName(), RegexLeaf.start(), //
|
||||||
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
new RegexLeaf("NAME1", "([\\w-]+)"), //
|
||||||
RegexLeaf.spaceZeroOrMore(), //
|
RegexLeaf.spaceZeroOrMore(), //
|
||||||
|
@ -0,0 +1,126 @@
|
|||||||
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.abel.Link;
|
||||||
|
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||||
|
import net.sourceforge.plantuml.command.Command;
|
||||||
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
|
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||||
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
|
import net.sourceforge.plantuml.utils.BlocLines;
|
||||||
|
|
||||||
|
public class CommandAssociateTest {
|
||||||
|
|
||||||
|
private final Command<ChenEerDiagram> command = new CommandAssociate();
|
||||||
|
|
||||||
|
private final ChenEerDiagram diagram = new ChenEerDiagram(UmlSource.create(List.of(), false), null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parse() {
|
||||||
|
IRegex regex = CommandAssociate.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 -- E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("CARDINALITY", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseWithCompulsoryParticipation() {
|
||||||
|
IRegex regex = CommandAssociate.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 == E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("=");
|
||||||
|
assertThat(matcher.get("CARDINALITY", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseWithCardinality() {
|
||||||
|
IRegex regex = CommandAssociate.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 -N- E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("CARDINALITY", 0)).isEqualTo("N");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseCardinalityRange() {
|
||||||
|
IRegex regex = CommandAssociate.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 -(1, n)- E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("CARDINALITY", 0)).isEqualTo("(1, n)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_execute() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 -- E2");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(1);
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link.getLabel().toString()).isEqualTo("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeWithCompulsoryParticipation() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 == E2");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(1);
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link.getType().getStyle().getStroke3().getThickness()).isEqualTo(2);
|
||||||
|
assertThat(link.getLabel().toString()).isEqualTo("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeWithCardinality() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 -N- E2");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(1);
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link.getLabel().toString()).isEqualTo("[N]");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,173 @@
|
|||||||
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.abel.Entity;
|
||||||
|
import net.sourceforge.plantuml.abel.Link;
|
||||||
|
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||||
|
import net.sourceforge.plantuml.command.Command;
|
||||||
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
|
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||||
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
|
import net.sourceforge.plantuml.utils.BlocLines;
|
||||||
|
|
||||||
|
public class CommandCreateAttributeTest {
|
||||||
|
|
||||||
|
private final Command<ChenEerDiagram> command = new CommandCreateAttribute();
|
||||||
|
|
||||||
|
private final ChenEerDiagram diagram = new ChenEerDiagram(UmlSource.create(List.of(), false), null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parse() {
|
||||||
|
IRegex regex = CommandCreateAttribute.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("attr");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("attr");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isNull();
|
||||||
|
assertThat(matcher.get("COMPOSITE", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseWithType() {
|
||||||
|
IRegex regex = CommandCreateAttribute.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("attr : String");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("attr : String");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isNull();
|
||||||
|
assertThat(matcher.get("COMPOSITE", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseComposite() {
|
||||||
|
IRegex regex = CommandCreateAttribute.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("attr{");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("attr");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isNull();
|
||||||
|
assertThat(matcher.get("COMPOSITE", 0)).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseWithDisplay() {
|
||||||
|
IRegex regex = CommandCreateAttribute.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("\"My Attribute\" as attr");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isEqualTo("My Attribute");
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("attr");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isNull();
|
||||||
|
assertThat(matcher.get("COMPOSITE", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseWithStereo() {
|
||||||
|
IRegex regex = CommandCreateAttribute.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("attr<<red>>");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("attr");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isEqualTo("<<red>>");
|
||||||
|
assertThat(matcher.get("COMPOSITE", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_execute() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("\"Attribute\" as attr<<stereo>>");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Entity entity = diagram.quarkInContext(true, "E").getData();
|
||||||
|
assertThat(entity).isNotNull();
|
||||||
|
|
||||||
|
Entity attribute = diagram.quarkInContext(true, "E/attr").getData();
|
||||||
|
assertThat(attribute).isNotNull();
|
||||||
|
assertThat(attribute.getDisplay().toString()).isEqualTo("[Attribute]");
|
||||||
|
assertThat(attribute.getStereotype().toString()).isEqualTo("<<stereo>>");
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(1);
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link).isNotNull();
|
||||||
|
assertThat(link.getEntity1()).isSameAs(attribute);
|
||||||
|
assertThat(link.getEntity2()).isSameAs(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeNested() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E {"));
|
||||||
|
|
||||||
|
CommandExecutionResult result1 = command.execute(diagram, BlocLines.singleString("attr1{"));
|
||||||
|
CommandExecutionResult result2 = command.execute(diagram, BlocLines.singleString("attr2"));
|
||||||
|
|
||||||
|
assertThat(result1).matches(CommandExecutionResult::isOk);
|
||||||
|
assertThat(result2).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Entity entity = diagram.quarkInContext(true, "E").getData();
|
||||||
|
assertThat(entity).isNotNull();
|
||||||
|
|
||||||
|
Entity attribute1 = diagram.quarkInContext(true, "E/attr1").getData();
|
||||||
|
assertThat(attribute1).isNotNull();
|
||||||
|
assertThat(attribute1.getDisplay().toString()).isEqualTo("[attr1]");
|
||||||
|
|
||||||
|
Entity attribute2 = diagram.quarkInContext(true, "E/attr1/attr2").getData();
|
||||||
|
assertThat(attribute2).isNotNull();
|
||||||
|
assertThat(attribute2.getDisplay().toString()).isEqualTo("[attr2]");
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(2);
|
||||||
|
Link link1 = diagram.getLinks().get(0);
|
||||||
|
assertThat(link1).isNotNull();
|
||||||
|
assertThat(link1.getEntity1()).isSameAs(attribute1);
|
||||||
|
assertThat(link1.getEntity2()).isSameAs(entity);
|
||||||
|
Link link2 = diagram.getLinks().get(1);
|
||||||
|
assertThat(link2).isNotNull();
|
||||||
|
assertThat(link2.getEntity1()).isSameAs(attribute2);
|
||||||
|
assertThat(link2.getEntity2()).isSameAs(attribute1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeNonNested() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E {"));
|
||||||
|
|
||||||
|
CommandExecutionResult result1 = command.execute(diagram, BlocLines.singleString("attr1"));
|
||||||
|
CommandExecutionResult result2 = command.execute(diagram, BlocLines.singleString("attr2"));
|
||||||
|
|
||||||
|
assertThat(result1).matches(CommandExecutionResult::isOk);
|
||||||
|
assertThat(result2).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Entity entity = diagram.quarkInContext(true, "E").getData();
|
||||||
|
assertThat(entity).isNotNull();
|
||||||
|
|
||||||
|
Entity attribute1 = diagram.quarkInContext(true, "E/attr1").getData();
|
||||||
|
assertThat(attribute1).isNotNull();
|
||||||
|
assertThat(attribute1.getDisplay().toString()).isEqualTo("[attr1]");
|
||||||
|
|
||||||
|
Entity attribute2 = diagram.quarkInContext(true, "E/attr2").getData();
|
||||||
|
assertThat(attribute2).isNotNull();
|
||||||
|
assertThat(attribute2.getDisplay().toString()).isEqualTo("[attr2]");
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(2);
|
||||||
|
Link link1 = diagram.getLinks().get(0);
|
||||||
|
assertThat(link1).isNotNull();
|
||||||
|
assertThat(link1.getEntity1()).isSameAs(attribute1);
|
||||||
|
assertThat(link1.getEntity2()).isSameAs(entity);
|
||||||
|
Link link2 = diagram.getLinks().get(1);
|
||||||
|
assertThat(link2).isNotNull();
|
||||||
|
assertThat(link2.getEntity1()).isSameAs(attribute2);
|
||||||
|
assertThat(link2.getEntity2()).isSameAs(entity);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,123 @@
|
|||||||
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.abel.Entity;
|
||||||
|
import net.sourceforge.plantuml.abel.LeafType;
|
||||||
|
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||||
|
import net.sourceforge.plantuml.command.Command;
|
||||||
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
|
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||||
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
|
import net.sourceforge.plantuml.utils.BlocLines;
|
||||||
|
|
||||||
|
public class CommandCreateEntityTest {
|
||||||
|
|
||||||
|
private final Command<ChenEerDiagram> command = new CommandCreateEntity();
|
||||||
|
|
||||||
|
private final ChenEerDiagram diagram = new ChenEerDiagram(UmlSource.create(List.of(), false), null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseEntity() {
|
||||||
|
IRegex regex = CommandCreateEntity.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("entity Bus_123 {");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("TYPE", 0)).isEqualTo("entity");
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("Bus_123");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseRelationship() {
|
||||||
|
IRegex regex = CommandCreateEntity.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("relationship Drives {");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("TYPE", 0)).isEqualTo("relationship");
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("Drives");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseInvalid() {
|
||||||
|
IRegex regex = CommandCreateEntity.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("class MyClass {");
|
||||||
|
|
||||||
|
assertThat(matcher).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseEntityWithStereo() {
|
||||||
|
IRegex regex = CommandCreateEntity.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("entity Bus_123 <<red>> {");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("TYPE", 0)).isEqualTo("entity");
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isNull();
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("Bus_123");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isEqualTo("<<red>>");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseEntityWithDisplayName() {
|
||||||
|
IRegex regex = CommandCreateEntity.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("entity \"Red Bus :)\" as Bus_123 <<red>> {");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("TYPE", 0)).isEqualTo("entity");
|
||||||
|
assertThat(matcher.get("DISPLAY", 0)).isEqualTo("Red Bus :)");
|
||||||
|
assertThat(matcher.get("CODE", 0)).isEqualTo("Bus_123");
|
||||||
|
assertThat(matcher.get("STEREO", 0)).isEqualTo("<<red>>");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeWithEntity() throws NoSuchColorException {
|
||||||
|
BlocLines lines = BlocLines.singleString("entity \"display\" as code <<stereo>> {");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Entity entity = diagram.quarkInContext(true, "code").getData();
|
||||||
|
assertThat(entity).isNotNull();
|
||||||
|
assertThat(entity.getLeafType()).isEqualTo(LeafType.CHEN_ENTITY);
|
||||||
|
assertThat(entity.getDisplay().toString()).isEqualTo("[display]");
|
||||||
|
assertThat(entity.getStereotype().toString()).isEqualTo("<<stereo>>");
|
||||||
|
|
||||||
|
assertThat(diagram.peekOwner()).isSameAs(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeWithRelationship() throws NoSuchColorException {
|
||||||
|
BlocLines lines = BlocLines.singleString("relationship \"display\" as code <<stereo>> {");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Entity entity = diagram.quarkInContext(true, "code").getData();
|
||||||
|
assertThat(entity).isNotNull();
|
||||||
|
assertThat(entity.getLeafType()).isEqualTo(LeafType.CHEN_RELATIONSHIP);
|
||||||
|
assertThat(entity.getDisplay().toString()).isEqualTo("[display]");
|
||||||
|
assertThat(entity.getStereotype().toString()).isEqualTo("<<stereo>>");
|
||||||
|
|
||||||
|
assertThat(diagram.peekOwner()).isSameAs(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeWithEntityWhenAlreadyExists() throws NoSuchColorException {
|
||||||
|
BlocLines lines = BlocLines.singleString("entity \"display\" as code <<stereo>> {");
|
||||||
|
command.execute(diagram, lines);
|
||||||
|
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.Spy;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||||
|
import net.sourceforge.plantuml.command.Command;
|
||||||
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
|
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||||
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
|
import net.sourceforge.plantuml.utils.BlocLines;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
public class CommandEndGroupTest {
|
||||||
|
|
||||||
|
private final Command<ChenEerDiagram> command = new CommandEndGroup();
|
||||||
|
|
||||||
|
@Spy
|
||||||
|
private final ChenEerDiagram diagram = new ChenEerDiagram(UmlSource.create(List.of(), false), null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parse() {
|
||||||
|
IRegex regex = CommandEndGroup.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("}");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_execute() throws NoSuchColorException {
|
||||||
|
diagram.pushOwner(null);
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("}");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Mockito.verify(diagram).popOwner();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,214 @@
|
|||||||
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.abel.Link;
|
||||||
|
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||||
|
import net.sourceforge.plantuml.command.Command;
|
||||||
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
|
import net.sourceforge.plantuml.decoration.LinkMiddleDecor;
|
||||||
|
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||||
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
|
import net.sourceforge.plantuml.utils.BlocLines;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandMultiSubclassTest {
|
||||||
|
|
||||||
|
private final Command<ChenEerDiagram> command = new CommandMultiSubclass();
|
||||||
|
|
||||||
|
private final ChenEerDiagram diagram = new ChenEerDiagram(UmlSource.create(List.of(), false), null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parse() {
|
||||||
|
IRegex regex = CommandMultiSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 ->- d { E2, E3, E4 }");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("SUPERCLASS", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("SUBCLASSES", 0)).isEqualTo(" E2, E3, E4 ");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("SYMBOL", 0)).isEqualTo("d");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseWithCompulsoryParticipation() {
|
||||||
|
IRegex regex = CommandMultiSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 =>= d { E2, E3, E4 }");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("SUPERCLASS", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("SUBCLASSES", 0)).isEqualTo(" E2, E3, E4 ");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("=");
|
||||||
|
assertThat(matcher.get("SYMBOL", 0)).isEqualTo("d");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseOverlapping() {
|
||||||
|
IRegex regex = CommandMultiSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 ->- o { E2, E3, E4 }");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("SUPERCLASS", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("SUBCLASSES", 0)).isEqualTo(" E2, E3, E4 ");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("SYMBOL", 0)).isEqualTo("o");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseCategory() {
|
||||||
|
IRegex regex = CommandMultiSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 ->- U { E2, E3, E4 }");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("SUPERCLASS", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("SUBCLASSES", 0)).isEqualTo(" E2, E3, E4 ");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("SYMBOL", 0)).isEqualTo("U");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeOverlappingSubclasses() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E3 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E4 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 ->- o { E2, E3, E4 }");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(4);
|
||||||
|
Link link1 = diagram.getLinks().get(0);
|
||||||
|
assertThat(link1.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link1.getEntity2().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link1.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link1.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
Link link2 = diagram.getLinks().get(1);
|
||||||
|
assertThat(link2.getEntity1().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link2.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link2.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link2.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
Link link3 = diagram.getLinks().get(2);
|
||||||
|
assertThat(link3.getEntity1().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link3.getEntity2().getName()).isEqualTo("E3");
|
||||||
|
assertThat(link3.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link3.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
Link link4 = diagram.getLinks().get(3);
|
||||||
|
assertThat(link4.getEntity1().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link4.getEntity2().getName()).isEqualTo("E4");
|
||||||
|
assertThat(link4.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link4.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeOverlappingSubclassesWithCompulsaryParticipation() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E3 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E4 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 =>= o { E2, E3, E4 }");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(4);
|
||||||
|
Link link1 = diagram.getLinks().get(0);
|
||||||
|
assertThat(link1.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link1.getEntity2().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link1.getType().getStyle().getStroke3().getThickness()).isEqualTo(2);
|
||||||
|
assertThat(link1.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
Link link2 = diagram.getLinks().get(1);
|
||||||
|
assertThat(link2.getEntity1().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link2.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link2.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link2.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
Link link3 = diagram.getLinks().get(2);
|
||||||
|
assertThat(link3.getEntity1().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link3.getEntity2().getName()).isEqualTo("E3");
|
||||||
|
assertThat(link3.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link3.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
Link link4 = diagram.getLinks().get(3);
|
||||||
|
assertThat(link4.getEntity1().getName()).isEqualTo("E1/o E2, E3, E4 /center");
|
||||||
|
assertThat(link4.getEntity2().getName()).isEqualTo("E4");
|
||||||
|
assertThat(link4.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link4.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeCategories() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E3 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E4 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 ->- U { E2, E3, E4 }");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(4);
|
||||||
|
Link link1 = diagram.getLinks().get(0);
|
||||||
|
assertThat(link1.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link1.getEntity2().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link1.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link1.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
Link link2 = diagram.getLinks().get(1);
|
||||||
|
assertThat(link2.getEntity1().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link2.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link2.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link2.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
Link link3 = diagram.getLinks().get(2);
|
||||||
|
assertThat(link3.getEntity1().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link3.getEntity2().getName()).isEqualTo("E3");
|
||||||
|
assertThat(link3.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link3.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
Link link4 = diagram.getLinks().get(3);
|
||||||
|
assertThat(link4.getEntity1().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link4.getEntity2().getName()).isEqualTo("E4");
|
||||||
|
assertThat(link4.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link4.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeCategoriesWithCompulsaryParticipation() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E3 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E4 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 =>= U { E2, E3, E4 }");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
assertThat(diagram.getLinks().size()).isEqualTo(4);
|
||||||
|
Link link1 = diagram.getLinks().get(0);
|
||||||
|
assertThat(link1.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link1.getEntity2().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link1.getType().getStyle().getStroke3().getThickness()).isEqualTo(2);
|
||||||
|
assertThat(link1.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
Link link2 = diagram.getLinks().get(1);
|
||||||
|
assertThat(link2.getEntity1().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link2.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link2.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link2.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
Link link3 = diagram.getLinks().get(2);
|
||||||
|
assertThat(link3.getEntity1().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link3.getEntity2().getName()).isEqualTo("E3");
|
||||||
|
assertThat(link3.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link3.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
Link link4 = diagram.getLinks().get(3);
|
||||||
|
assertThat(link4.getEntity1().getName()).isEqualTo("E1/U E2, E3, E4 /center");
|
||||||
|
assertThat(link4.getEntity2().getName()).isEqualTo("E4");
|
||||||
|
assertThat(link4.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link4.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.NONE);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
package net.sourceforge.plantuml.cheneer.command;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import net.sourceforge.plantuml.abel.Link;
|
||||||
|
import net.sourceforge.plantuml.cheneer.ChenEerDiagram;
|
||||||
|
import net.sourceforge.plantuml.command.Command;
|
||||||
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
||||||
|
import net.sourceforge.plantuml.core.UmlSource;
|
||||||
|
import net.sourceforge.plantuml.decoration.LinkMiddleDecor;
|
||||||
|
import net.sourceforge.plantuml.klimt.color.NoSuchColorException;
|
||||||
|
import net.sourceforge.plantuml.regex.IRegex;
|
||||||
|
import net.sourceforge.plantuml.regex.RegexResult;
|
||||||
|
import net.sourceforge.plantuml.utils.BlocLines;
|
||||||
|
|
||||||
|
public class CommandSimpleSubclassTest {
|
||||||
|
|
||||||
|
private final Command<ChenEerDiagram> command = new CommandSimpleSubclass();
|
||||||
|
|
||||||
|
private final ChenEerDiagram diagram = new ChenEerDiagram(UmlSource.create(List.of(), false), null);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseSubset() {
|
||||||
|
IRegex regex = CommandSimpleSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 -<- E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("DIRECTION", 0)).isEqualTo("<");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseSubsetWithCompulsoryParticipation() {
|
||||||
|
IRegex regex = CommandSimpleSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 =<= E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("=");
|
||||||
|
assertThat(matcher.get("DIRECTION", 0)).isEqualTo("<");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_parseSuperset() {
|
||||||
|
IRegex regex = CommandSimpleSubclass.getRegexConcat();
|
||||||
|
RegexResult matcher = regex.matcher("E1 ->- E2");
|
||||||
|
|
||||||
|
assertThat(matcher).isNotNull();
|
||||||
|
assertThat(matcher.get("NAME1", 0)).isEqualTo("E1");
|
||||||
|
assertThat(matcher.get("NAME2", 0)).isEqualTo("E2");
|
||||||
|
assertThat(matcher.get("PARTICIPATION", 0)).isEqualTo("-");
|
||||||
|
assertThat(matcher.get("DIRECTION", 0)).isEqualTo(">");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeSubset() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 -<- E2");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUBSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeSubsetWithCompulsoryParticipation() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 =<= E2");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link.getType().getStyle().getStroke3().getThickness()).isEqualTo(2);
|
||||||
|
assertThat(link.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUBSET);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test_executeSuperset() throws NoSuchColorException {
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E1 {"));
|
||||||
|
new CommandCreateEntity().execute(diagram, BlocLines.singleString("entity E2 {"));
|
||||||
|
|
||||||
|
BlocLines lines = BlocLines.singleString("E1 ->- E2");
|
||||||
|
CommandExecutionResult result = command.execute(diagram, lines);
|
||||||
|
|
||||||
|
assertThat(result).matches(CommandExecutionResult::isOk);
|
||||||
|
|
||||||
|
Link link = diagram.getLinks().get(0);
|
||||||
|
assertThat(link.getEntity1().getName()).isEqualTo("E1");
|
||||||
|
assertThat(link.getEntity2().getName()).isEqualTo("E2");
|
||||||
|
assertThat(link.getType().getStyle().getStroke3().getThickness()).isEqualTo(1);
|
||||||
|
assertThat(link.getType().getMiddleDecor()).isEqualTo(LinkMiddleDecor.SUPERSET);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user