File tree 4 files changed +30
-3
lines changed
main/java/org/contextmapper/discovery
test/java/org/contextmapper/discovery
strategies/boundedcontexts
4 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 19
19
import org .contextmapper .discovery .cml .ContextMapToCMLConverter ;
20
20
import org .contextmapper .discovery .model .ContextMap ;
21
21
import org .contextmapper .dsl .ContextMappingDSLStandaloneSetup ;
22
- import org .contextmapper .dsl .contextMappingDSL .ContextMappingDSLFactory ;
23
22
import org .contextmapper .dsl .contextMappingDSL .ContextMappingModel ;
24
23
import org .eclipse .emf .common .util .URI ;
25
24
import org .eclipse .emf .ecore .resource .Resource ;
@@ -39,6 +38,8 @@ public class ContextMapSerializer {
39
38
public void serializeContextMap (ContextMap contextMap , File cmlFile ) throws IOException {
40
39
if (!FilenameUtils .getExtension (cmlFile .toString ()).equals ("cml" ))
41
40
throw new IllegalArgumentException ("The CML file must end with the file extension '*.cml'!" );
41
+ if (contextMap .getBoundedContexts ().size () <= 0 )
42
+ throw new IllegalArgumentException ("The Context Map must at least contain one Bounded Context to be serialized!" );
42
43
43
44
ContextMappingDSLStandaloneSetup .doSetup ();
44
45
Resource resource = new ResourceSetImpl ().createResource (URI .createURI (cmlFile .toURI ().toString ()));
Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ public ContextMappingModel convert(org.contextmapper.discovery.model.ContextMap
36
36
model .setMap (contextMap );
37
37
38
38
for (org .contextmapper .discovery .model .BoundedContext boundedContext : inputMap .getBoundedContexts ()) {
39
- model .getBoundedContexts ().add (convert (boundedContext ));
39
+ BoundedContext bc = convert (boundedContext );
40
+ model .getBoundedContexts ().add (bc );
41
+ contextMap .getBoundedContexts ().add (bc );
40
42
}
41
43
42
44
for (Relationship relationship : inputMap .getRelationships ()) {
Original file line number Diff line number Diff line change 19
19
import org .contextmapper .discovery .strategies .boundedcontexts .SpringBootBoundedContextDiscoveryStrategy ;
20
20
import org .contextmapper .discovery .strategies .names .SeparatorToCamelCaseBoundedContextNameMappingStrategy ;
21
21
import org .contextmapper .discovery .strategies .relationships .DockerComposeRelationshipDiscoveryStrategy ;
22
+ import org .junit .jupiter .api .Assertions ;
22
23
import org .junit .jupiter .api .BeforeEach ;
23
24
import org .junit .jupiter .api .Test ;
24
25
@@ -68,4 +69,28 @@ public void canSaveDiscoveredModelAsCMLFile() throws IOException {
68
69
assertTrue (new File (TEST_CML_FILE ).exists ());
69
70
}
70
71
72
+ @ Test
73
+ public void cannotSerializeOtherThanCMLFile () {
74
+ // given
75
+ ContextMapDiscoverer discoverer = new ContextMapDiscoverer ()
76
+ .usingBoundedContextDiscoveryStrategies (
77
+ new SpringBootBoundedContextDiscoveryStrategy ("test.microservice.spring.boot" ));
78
+
79
+ // when, then
80
+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
81
+ new ContextMapSerializer ().serializeContextMap (discoverer .discoverContextMap (), new File ("test.ext" ));
82
+ });
83
+ }
84
+
85
+ @ Test
86
+ public void cannotSerializeEmptyContextMap () {
87
+ // given
88
+ ContextMap contextMap = new ContextMap ();
89
+
90
+ // when, then
91
+ Assertions .assertThrows (IllegalArgumentException .class , () -> {
92
+ new ContextMapSerializer ().serializeContextMap (contextMap , new File ("test.cml" ));
93
+ });
94
+ }
95
+
71
96
}
Original file line number Diff line number Diff line change 17
17
18
18
import org .contextmapper .discovery .ContextMapDiscoverer ;
19
19
import org .contextmapper .discovery .model .BoundedContext ;
20
- import org .contextmapper .discovery .strategies .boundedcontexts .SpringBootBoundedContextDiscoveryStrategy ;
21
20
import org .junit .jupiter .api .Test ;
22
21
23
22
import java .util .Set ;
You can’t perform that action at this time.
0 commit comments