Skip to content

Commit c14721d

Browse files
authored
MDSL generator fix: can handle multiple parameter references to empty domain objects (#171)
1 parent 67b2bf2 commit c14721d

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ContextMap {
2+
contains CustomerManagementContext, ContractManagementContext, JustAnotherContext
3+
4+
CustomerManagementContext -> ContractManagementContext {
5+
exposedAggregates = Customers
6+
implementationTechnology = "RESTful HTTP"
7+
}
8+
9+
// this relationship must be ignored, because it has no exposedAggregates
10+
CustomerManagementContext -> JustAnotherContext
11+
12+
// duplicate relationship should not change the result
13+
CustomerManagementContext -> ContractManagementContext {
14+
exposedAggregates = Customers
15+
}
16+
17+
}
18+
19+
BoundedContext ContractManagementContext
20+
21+
BoundedContext CustomerManagementContext {
22+
23+
Aggregate Customers {
24+
Entity Customer {
25+
aggregateRoot
26+
27+
def ReturnType updateCustomer(@Param1 param1, @Param2 param2);
28+
}
29+
Entity Param1
30+
Entity Param2
31+
}
32+
}
33+
34+
BoundedContext JustAnotherContext
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Generated from DDD Context Map.
2+
API description CustomerManagementContextAPI
3+
4+
5+
data type Param1 P // the type Param1 has not been specified or does not contain any attributes in CML
6+
data type Param2 P // the type Param2 has not been specified or does not contain any attributes in CML
7+
data type ReturnType P // the type ReturnType has not been specified or does not contain any attributes in CML
8+
data type updateCustomerParameter { "param1":Param1, "param2":Param2 }
9+
10+
11+
endpoint type CustomersAggregate
12+
exposes
13+
operation updateCustomer
14+
expecting
15+
payload updateCustomerParameter
16+
delivering
17+
payload ReturnType
18+
19+
20+
API provider CustomerManagementContextProvider
21+
offers CustomersAggregate
22+
at endpoint location "http://localhost:8000"
23+
via protocol "RESTful HTTP"
24+
25+
26+
API client ContractManagementContextClient
27+
consumes CustomersAggregate
28+
29+
IPA

org.contextmapper.dsl.tests/src/org/contextmapper/dsl/tests/generators/mdsl/MDSLAPIDescriptionCreatorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ void canHandleReferencesToEmptyDomainObjects() throws IOException {
193193
void canHandleDeepReferencesToEmptyDomainObjects() throws IOException {
194194
testCMLInputAndMDSLOutputFiles("mdsl-reference-to-empty-domain-object-2");
195195
}
196+
197+
@Test
198+
void canHandleMultipleParameterReferencesToEmptyDomainObjects() throws IOException {
199+
testCMLInputAndMDSLOutputFiles("mdsl-reference-to-empty-domain-object-3");
200+
}
196201

197202
private void testCMLInputAndMDSLOutputFiles(String baseFilename) throws IOException {
198203
testCMLInputAndMDSLOutputFiles(baseFilename, false);

org.contextmapper.dsl/src/org/contextmapper/dsl/generator/mdsl/MDSLModelCreator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ private DataTypeAttribute getDataTypeAttribute4DomainObject(DataType dataType, S
333333
}
334334
}
335335
mdslAttribute.addChildren(refAttributes);
336+
337+
// in case there are no attributes or refs, we need an abstract data type:
338+
if (!mdslAttribute.hasChildren())
339+
mdslAttribute.setType(mapAbstractDataType(simpleDomainObject.getName()));
336340
} else if (simpleDomainObject instanceof Enum) {
337341
mdslAttribute.setType(createEnumDataType((Enum) simpleDomainObject).getName());
338342
} else {

0 commit comments

Comments
 (0)