-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add relationship name and implementation technology to provide enhanc…
…ed relationship labels (#4)
- Loading branch information
Showing
8 changed files
with
252 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/org/contextmapper/contextmap/generator/model/AbstractRelationship.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2020 The Context Mapper Project Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.contextmapper.contextmap.generator.model; | ||
|
||
/** | ||
* Represents a DDD relationship (that can have a name and an implementation technology). | ||
* | ||
* @author Stefan Kapferer | ||
*/ | ||
public abstract class AbstractRelationship implements Relationship { | ||
|
||
private String name = ""; | ||
private String implementationTechnology = ""; | ||
|
||
public AbstractRelationship setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public AbstractRelationship setImplementationTechnology(String implementationTechnology) { | ||
this.implementationTechnology = implementationTechnology; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String getImplementationTechnology() { | ||
return implementationTechnology; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/test/java/org/contextmapper/contextmap/generator/ContextMapGeneratorLabelsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* Copyright 2020 The Context Mapper Project Team | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.contextmapper.contextmap.generator; | ||
|
||
import guru.nidi.graphviz.engine.Format; | ||
import org.contextmapper.contextmap.generator.model.*; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import static org.contextmapper.contextmap.generator.model.DownstreamPatterns.ANTICORRUPTION_LAYER; | ||
import static org.contextmapper.contextmap.generator.model.DownstreamPatterns.CONFORMIST; | ||
import static org.contextmapper.contextmap.generator.model.UpstreamPatterns.OPEN_HOST_SERVICE; | ||
import static org.contextmapper.contextmap.generator.model.UpstreamPatterns.PUBLISHED_LANGUAGE; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ContextMapGeneratorLabelsTest { | ||
|
||
private void deleteFileIfExisting(String filename) { | ||
File file = new File(filename); | ||
if (file.exists()) | ||
file.delete(); | ||
} | ||
|
||
@Test | ||
public void canGenerateContextMapWithFullLabel() throws IOException { | ||
// given | ||
String filename = "./src-gen/FullLabelTest.png"; | ||
ContextMapGenerator generator = new ContextMapGenerator(); | ||
BoundedContext testContext1 = new BoundedContext("TestContext1"); | ||
BoundedContext testContext2 = new BoundedContext("TestContext2"); | ||
ContextMap contextMap = new ContextMap() | ||
.addBoundedContext(testContext1) | ||
.addBoundedContext(testContext2) | ||
.addRelationship(new Partnership(testContext1, testContext2) | ||
.setName("TestRelName") | ||
.setImplementationTechnology("Java")); | ||
|
||
// when | ||
deleteFileIfExisting(filename); | ||
assertFalse(new File(filename + ".png").exists()); | ||
generator.setLabelSpacingFactor(10) | ||
.generateContextMapGraphic(contextMap, Format.PNG, filename); | ||
|
||
// then | ||
assertTrue(new File(filename).exists()); | ||
} | ||
|
||
@Test | ||
public void canGenerateContextMapLabelWithNameAndTechnology() throws IOException { | ||
// given | ||
String filename = "./src-gen/NameAndTechnologyLabelTest.png"; | ||
ContextMapGenerator generator = new ContextMapGenerator(); | ||
BoundedContext testContext1 = new BoundedContext("TestContext1"); | ||
BoundedContext testContext2 = new BoundedContext("TestContext2"); | ||
ContextMap contextMap = new ContextMap() | ||
.addBoundedContext(testContext1) | ||
.addBoundedContext(testContext2) | ||
.addRelationship(new UpstreamDownstreamRelationship(testContext1, testContext2) | ||
.setName("TestRelName") | ||
.setImplementationTechnology("Java")); | ||
|
||
// when | ||
deleteFileIfExisting(filename); | ||
assertFalse(new File(filename + ".png").exists()); | ||
generator.setLabelSpacingFactor(10) | ||
.generateContextMapGraphic(contextMap, Format.PNG, filename); | ||
|
||
// then | ||
assertTrue(new File(filename).exists()); | ||
} | ||
|
||
@Test | ||
public void canGenerateContextMapLabelWithTypeAndTechnology() throws IOException { | ||
// given | ||
String filename = "./src-gen/TypeAndTechnologyLabelTest.png"; | ||
ContextMapGenerator generator = new ContextMapGenerator(); | ||
BoundedContext testContext1 = new BoundedContext("TestContext1"); | ||
BoundedContext testContext2 = new BoundedContext("TestContext2"); | ||
ContextMap contextMap = new ContextMap() | ||
.addBoundedContext(testContext1) | ||
.addBoundedContext(testContext2) | ||
.addRelationship(new SharedKernel(testContext1, testContext2) | ||
.setImplementationTechnology("Java Library")); | ||
|
||
// when | ||
deleteFileIfExisting(filename); | ||
assertFalse(new File(filename + ".png").exists()); | ||
generator.setLabelSpacingFactor(10) | ||
.generateContextMapGraphic(contextMap, Format.PNG, filename); | ||
|
||
// then | ||
assertTrue(new File(filename).exists()); | ||
} | ||
|
||
@Test | ||
public void canGenerateContextMapLabelWithNameOnly() throws IOException { | ||
// given | ||
String filename = "./src-gen/NameOnlyLabelTest.png"; | ||
ContextMapGenerator generator = new ContextMapGenerator(); | ||
BoundedContext testContext1 = new BoundedContext("TestContext1"); | ||
BoundedContext testContext2 = new BoundedContext("TestContext2"); | ||
ContextMap contextMap = new ContextMap() | ||
.addBoundedContext(testContext1) | ||
.addBoundedContext(testContext2) | ||
.addRelationship(new UpstreamDownstreamRelationship(testContext1, testContext2) | ||
.setName("MyUpDownRel")); | ||
|
||
// when | ||
deleteFileIfExisting(filename); | ||
assertFalse(new File(filename + ".png").exists()); | ||
generator.setLabelSpacingFactor(10) | ||
.generateContextMapGraphic(contextMap, Format.PNG, filename); | ||
|
||
// then | ||
assertTrue(new File(filename).exists()); | ||
} | ||
|
||
@Test | ||
public void canGenerateContextMapLabelWithImplementationTechnologyOnly() throws IOException { | ||
// given | ||
String filename = "./src-gen/ImplementationTechnologyOnlyLabelTest.png"; | ||
ContextMapGenerator generator = new ContextMapGenerator(); | ||
BoundedContext testContext1 = new BoundedContext("TestContext1"); | ||
BoundedContext testContext2 = new BoundedContext("TestContext2"); | ||
ContextMap contextMap = new ContextMap() | ||
.addBoundedContext(testContext1) | ||
.addBoundedContext(testContext2) | ||
.addRelationship(new UpstreamDownstreamRelationship(testContext1, testContext2) | ||
.setImplementationTechnology("RESTful HTTP")); | ||
|
||
// when | ||
deleteFileIfExisting(filename); | ||
assertFalse(new File(filename + ".png").exists()); | ||
generator.setLabelSpacingFactor(10) | ||
.generateContextMapGraphic(contextMap, Format.PNG, filename); | ||
|
||
// then | ||
assertTrue(new File(filename).exists()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters