Skip to content

Commit dfae78e

Browse files
authored
Adjust PlantUML component diagram labels (Customer/Supplier) (#154)
1 parent c5da88e commit dfae78e

File tree

2 files changed

+69
-11
lines changed

2 files changed

+69
-11
lines changed

org.contextmapper.dsl.tests/src/org/contextmapper/dsl/tests/generators/plantuml/PlantUMLComponentDiagramCreatorTest.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ public void canCreateCustomerSupplierRelationship() {
294294
assertTrue(plantUML.contains("component [myContext1]" + System.lineSeparator()));
295295
assertTrue(plantUML.contains("component [myContext2]" + System.lineSeparator()));
296296
assertTrue(plantUML.contains("interface \"Customer-Supplier (SOAP)\" as myContext2_to_myContext1" + System.lineSeparator()));
297-
assertTrue(plantUML.contains("[myContext1] --> myContext2_to_myContext1 : OPEN_HOST_SERVICE" + System.lineSeparator()));
298-
assertTrue(plantUML.contains("myContext2_to_myContext1 <.. [myContext2] : use via ANTICORRUPTION_LAYER" + System.lineSeparator()));
297+
assertTrue(plantUML.contains("[myContext1] --> myContext2_to_myContext1 : Supplier of OPEN_HOST_SERVICE" + System.lineSeparator()));
298+
assertTrue(plantUML.contains("myContext2_to_myContext1 <.. [myContext2] : Customer via ANTICORRUPTION_LAYER" + System.lineSeparator()));
299299
}
300300

301301
@Test
@@ -314,7 +314,7 @@ public void canCreateCustomerSupplierRelationshipWithName() {
314314
relationship.setImplementationTechnology("SOAP");
315315
relationship.setName("MyCS");
316316
relationship.getUpstreamRoles().add(UpstreamRole.OPEN_HOST_SERVICE);
317-
relationship.getDownstreamRoles().add(DownstreamRole.ANTICORRUPTION_LAYER);
317+
relationship.getDownstreamRoles().add(DownstreamRole.CONFORMIST);
318318
contextMap.getRelationships().add(relationship);
319319

320320
// when
@@ -324,8 +324,8 @@ public void canCreateCustomerSupplierRelationshipWithName() {
324324
assertTrue(plantUML.contains("component [myContext1]" + System.lineSeparator()));
325325
assertTrue(plantUML.contains("component [myContext2]" + System.lineSeparator()));
326326
assertTrue(plantUML.contains("interface \"MyCS (SOAP)\" as MyCS" + System.lineSeparator()));
327-
assertTrue(plantUML.contains("[myContext1] --> MyCS : OPEN_HOST_SERVICE" + System.lineSeparator()));
328-
assertTrue(plantUML.contains("MyCS <.. [myContext2] : use via ANTICORRUPTION_LAYER" + System.lineSeparator()));
327+
assertTrue(plantUML.contains("[myContext1] --> MyCS : Supplier of OPEN_HOST_SERVICE" + System.lineSeparator()));
328+
assertTrue(plantUML.contains("MyCS <.. [myContext2] : Customer as CONFORMIST" + System.lineSeparator()));
329329
}
330330

331331
@Test
@@ -351,7 +351,7 @@ public void canCreateUpstreamDownstreamRelationshipWithoutNameAndTechnology() {
351351
assertTrue(plantUML.contains("component [myContext2]" + System.lineSeparator()));
352352
assertTrue(plantUML.contains("interface \"Upstream-Downstream\" as myContext2_to_myContext1" + System.lineSeparator()));
353353
assertTrue(plantUML.contains("[myContext1] --> myContext2_to_myContext1" + System.lineSeparator()));
354-
assertTrue(plantUML.contains("myContext2_to_myContext1 <.. [myContext2] : use " + System.lineSeparator()));
354+
assertTrue(plantUML.contains("myContext2_to_myContext1 <.. [myContext2] : consume" + System.lineSeparator()));
355355
}
356356

357357
@Test
@@ -390,6 +390,43 @@ public void canAddExposedAggregatesToServiceUsageLabel() {
390390
assertTrue(plantUML1.contains("myContext2_to_myContext1 <.. [myContext2] : use Aggregate ExposedAggregate1 " + System.lineSeparator()));
391391
assertTrue(plantUML2.contains("myContext2_to_myContext1 <.. [myContext2] : use Aggregates ExposedAggregate1, ExposedAggregate2 " + System.lineSeparator()));
392392
}
393+
394+
@Test
395+
public void canAddExposedAggregatesToCustomerSupplierUsageLabel() {
396+
// given
397+
ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
398+
BoundedContext boundedContext1 = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
399+
boundedContext1.setName("myContext1");
400+
Aggregate aggregate1 = ContextMappingDSLFactory.eINSTANCE.createAggregate();
401+
aggregate1.setName("ExposedAggregate1");
402+
Aggregate aggregate2 = ContextMappingDSLFactory.eINSTANCE.createAggregate();
403+
aggregate2.setName("ExposedAggregate2");
404+
boundedContext1.getAggregates().add(aggregate1);
405+
boundedContext1.getAggregates().add(aggregate2);
406+
BoundedContext boundedContext2 = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
407+
boundedContext2.setName("myContext2");
408+
contextMap.getBoundedContexts().add(boundedContext1);
409+
contextMap.getBoundedContexts().add(boundedContext2);
410+
UpstreamDownstreamRelationship relationship = ContextMappingDSLFactory.eINSTANCE.createCustomerSupplierRelationship();
411+
relationship.setUpstream(boundedContext1);
412+
relationship.setDownstream(boundedContext2);
413+
relationship.getUpstreamExposedAggregates().add(aggregate1);
414+
contextMap.getRelationships().add(relationship);
415+
416+
// when
417+
String plantUML1 = this.creator.createDiagram(contextMap);
418+
relationship.getUpstreamExposedAggregates().add(aggregate2);
419+
this.creator = new PlantUMLComponentDiagramCreator();
420+
String plantUML2 = this.creator.createDiagram(contextMap);
421+
422+
// then
423+
assertTrue(plantUML1.contains("component [myContext1]" + System.lineSeparator()));
424+
assertTrue(plantUML1.contains("component [myContext2]" + System.lineSeparator()));
425+
assertTrue(plantUML1.contains("interface \"Customer-Supplier\" as myContext2_to_myContext1" + System.lineSeparator()));
426+
assertTrue(plantUML1.contains("[myContext1] --> myContext2_to_myContext1 : Supplier" + System.lineSeparator()));
427+
assertTrue(plantUML1.contains("myContext2_to_myContext1 <.. [myContext2] : Customer of Aggregate ExposedAggregate1 " + System.lineSeparator()));
428+
assertTrue(plantUML2.contains("myContext2_to_myContext1 <.. [myContext2] : Customer of Aggregates ExposedAggregate1, ExposedAggregate2 " + System.lineSeparator()));
429+
}
393430

394431
@Test
395432
public void createsNoteIfDiagramIsEmpty() {

org.contextmapper.dsl/src/org/contextmapper/dsl/generator/plantuml/PlantUMLComponentDiagramCreator.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ private void printUpstreamDownstreamRelationship(UpstreamDownstreamRelationship
8181
UpstreamDownstreamRelationship upDownRelationship = (UpstreamDownstreamRelationship) relationship;
8282
String interfaceId = getUniqueInterfaceId(upDownRelationship.getName(), upDownRelationship.getUpstream().getName(), upDownRelationship.getDownstream().getName());
8383
printInterface(getRelationshipLabel(relationship), interfaceId);
84-
printInterfaceExposure(upDownRelationship.getUpstream().getName(), interfaceId, upstreamRolesToArray(upDownRelationship.getUpstreamRoles()));
84+
if (upDownRelationship instanceof CustomerSupplierRelationship)
85+
printCustomerSupplierInterfaceExposure(upDownRelationship.getUpstream().getName(), interfaceId, upstreamRolesToArray(upDownRelationship.getUpstreamRoles()));
86+
else
87+
printUpstreamDownstreamInterfaceExposure(upDownRelationship.getUpstream().getName(), interfaceId, upstreamRolesToArray(upDownRelationship.getUpstreamRoles()));
8588
printInterfaceUsage(interfaceId, upDownRelationship);
8689
linebreak();
8790
}
@@ -121,23 +124,41 @@ private void printInterface(String interfaceName, String identifier) {
121124
}
122125

123126
private void printInterfaceUsage(String interfaceId, UpstreamDownstreamRelationship relationship) {
124-
sb.append(interfaceId).append(" <.. ").append("[" + relationship.getDownstream().getName() + "]").append(" : ").append("use ");
125-
if (!relationship.getUpstreamExposedAggregates().isEmpty())
127+
String downstreamRoleString = downstreamRoleToString(relationship.getDownstreamRoles());
128+
sb.append(interfaceId).append(" <.. ").append("[" + relationship.getDownstream().getName() + "]").append(" : ");
129+
if (relationship instanceof CustomerSupplierRelationship) {
130+
sb.append("Customer ");
131+
} else if (relationship.getUpstreamExposedAggregates().isEmpty() && "".equals(downstreamRoleString)) {
132+
sb.append("consume");
133+
} else {
134+
sb.append("use ");
135+
}
136+
if (!relationship.getUpstreamExposedAggregates().isEmpty()) {
137+
if (relationship instanceof CustomerSupplierRelationship)
138+
sb.append("of ");
126139
sb.append(relationship.getUpstreamExposedAggregates().size() > 1 ? "Aggregates " : "Aggregate ")
127140
.append(aggregatesToCommaSeparatedString(relationship.getUpstreamExposedAggregates())).append(" ");
128-
String downstreamRoleString = downstreamRoleToString(relationship.getDownstreamRoles());
141+
}
129142
if (!"".equals(downstreamRoleString))
130143
sb.append(downstreamRoleString);
131144
linebreak();
132145
}
133146

134-
private void printInterfaceExposure(String component, String interfaceId, String[] roles) {
147+
private void printUpstreamDownstreamInterfaceExposure(String component, String interfaceId, String[] roles) {
135148
sb.append("[" + component + "]").append(" --> ").append(interfaceId);
136149
if (roles.length > 0)
137150
sb.append(" : ").append(String.join(", ", roles));
138151
linebreak();
139152
}
140153

154+
private void printCustomerSupplierInterfaceExposure(String component, String interfaceId, String[] roles) {
155+
sb.append("[" + component + "]").append(" --> ").append(interfaceId);
156+
sb.append(" : Supplier");
157+
if (roles.length > 0)
158+
sb.append(" of ").append(String.join(", ", roles));
159+
linebreak();
160+
}
161+
141162
private String[] upstreamRolesToArray(EList<UpstreamRole> roles) {
142163
return roles.stream().map(role -> role.getName()).collect(Collectors.toList()).toArray(new String[roles.size()]);
143164
}

0 commit comments

Comments
 (0)