1515 */
1616package com .marklogic .hub ;
1717
18- import static org .custommonkey .xmlunit .XMLAssert .assertXMLEqual ;
19- import static org .junit .jupiter .api .Assertions .assertEquals ;
20- import static org .junit .jupiter .api .Assertions .assertFalse ;
21- import static org .junit .jupiter .api .Assertions .assertNotEquals ;
22- import static org .junit .jupiter .api .Assertions .assertTrue ;
23-
24- import java .io .IOException ;
25- import java .nio .file .Files ;
26- import java .nio .file .Path ;
27- import java .nio .file .Paths ;
28- import java .util .ArrayList ;
29- import java .util .Arrays ;
30- import java .util .HashMap ;
31- import java .util .Iterator ;
32- import java .util .List ;
33- import java .util .Map ;
34- import java .util .Map .Entry ;
35- import java .util .Vector ;
36- import java .util .concurrent .TimeUnit ;
37-
38- import org .custommonkey .xmlunit .XMLUnit ;
39- import org .junit .jupiter .api .AfterAll ;
40- import org .junit .jupiter .api .BeforeAll ;
41- import org .junit .jupiter .api .BeforeEach ;
42- import org .junit .jupiter .api .DynamicTest ;
43- import org .junit .jupiter .api .TestFactory ;
44- import org .junit .platform .runner .JUnitPlatform ;
45- import org .junit .runner .RunWith ;
46- import org .w3c .dom .Document ;
47-
4818import com .fasterxml .jackson .core .JsonProcessingException ;
4919import com .fasterxml .jackson .databind .JsonNode ;
5020import com .fasterxml .jackson .databind .ObjectMapper ;
5828import com .marklogic .client .io .DocumentMetadataHandle ;
5929import com .marklogic .client .io .JacksonHandle ;
6030import com .marklogic .client .io .StringHandle ;
61- import com .marklogic .hub .flow .CodeFormat ;
62- import com .marklogic .hub .flow .DataFormat ;
63- import com .marklogic .hub .flow .Flow ;
64- import com .marklogic .hub .flow .FlowRunner ;
65- import com .marklogic .hub .flow .FlowType ;
31+ import com .marklogic .hub .flow .*;
6632import com .marklogic .hub .mapping .Mapping ;
6733import com .marklogic .hub .scaffold .Scaffolding ;
6834import com .marklogic .hub .util .FileUtil ;
6935import com .marklogic .hub .util .Installer ;
36+ import org .custommonkey .xmlunit .XMLUnit ;
37+ import org .junit .jupiter .api .*;
38+ import org .junit .platform .runner .JUnitPlatform ;
39+ import org .junit .runner .RunWith ;
40+ import org .w3c .dom .Document ;
41+
42+ import java .io .IOException ;
43+ import java .nio .file .Files ;
44+ import java .nio .file .Path ;
45+ import java .nio .file .Paths ;
46+ import java .util .*;
47+ import java .util .Map .Entry ;
48+ import java .util .concurrent .TimeUnit ;
49+
50+ import static org .custommonkey .xmlunit .XMLAssert .assertXMLEqual ;
51+ import static org .junit .jupiter .api .Assertions .*;
7052
7153
7254@ RunWith (JUnitPlatform .class )
@@ -83,7 +65,7 @@ public class MappingE2E extends HubTestBase {
8365 private String installDocError ;
8466 private List <String > modelProperties ;
8567 private Scaffolding scaffolding ;
86-
68+
8769 @ BeforeAll
8870 public static void setup () {
8971 XMLUnit .setIgnoreWhitespace (true );
@@ -167,7 +149,7 @@ public List<DynamicTest> generateTests() {
167149 }));
168150 }
169151 });
170-
152+
171153 for (String mapping : getMappings ()) {
172154 allCombos ((codeFormat , dataFormat , flowType , useEs ) -> {
173155 if (useEs && flowType .equals (FlowType .HARMONIZE )) {
@@ -187,35 +169,35 @@ public List<DynamicTest> generateTests() {
187169 testHarmonizeFlow (prefix , codeFormat , dataFormat , useEs , options , flowRunnerClient , HubConfig .DEFAULT_FINAL_NAME , finalCounts , true , mapping , 1 );
188170 }
189171 testHarmonizeFlow (prefix , codeFormat , dataFormat , useEs , options , flowRunnerClient , HubConfig .DEFAULT_FINAL_NAME , finalCounts , true , mapping , version );
190-
191- }));
172+
173+ }));
192174 }
193175 });
194176 }
195177 return tests ;
196178 }
197-
179+
198180 private List <String > getMappings () {
199181 Path mappingDir = getHubAdminConfig ().getHubMappingsDir ();
200182 List <String > allMappings = new ArrayList <>();
201183 try {
202- Files .walk (mappingDir ).filter (f ->Files .isDirectory (f )).forEach (f -> allMappings .add (f .getFileName ().toString ()));
203-
184+ Files .walk (mappingDir ).filter (f ->Files .isDirectory (f )).forEach (f -> allMappings .add (f .getFileName ().toString ()));
185+
204186 } catch (IOException e ) {
205187 throw new RuntimeException (e );
206188 }
207189 //remove "mappings" form the list
208190 allMappings .remove (0 );
209191 return allMappings ;
210192 }
211-
193+
212194 private String getFlowName (String prefix , CodeFormat codeFormat , DataFormat dataFormat , FlowType flowType , String mapping , int version ) {
213195 return prefix + "-" + flowType .toString () + "-" + codeFormat .toString () + "-" + dataFormat .toString () + "-" + mapping +"-" +version ;
214196 }
215197
216198 private void createFlow (String prefix , CodeFormat codeFormat , DataFormat dataFormat , FlowType flowType , boolean useEs , String mapping , int version , CreateFlowListener listener ) {
217199 if (useEs && flowType .equals (FlowType .HARMONIZE )) {
218- String flowName = getFlowName (prefix , codeFormat , dataFormat , flowType , mapping , version );
200+ String flowName = getFlowName (prefix , codeFormat , dataFormat , flowType , mapping , version );
219201 Path entityDir = projectDir .resolve ("plugins" ).resolve ("entities" ).resolve (ENTITY );
220202 Path flowDir = entityDir .resolve (flowType .toString ()).resolve (flowName );
221203
@@ -243,7 +225,7 @@ private void createMappings() {
243225 //properties.put("twoProp","empid,fullname");
244226 properties .put ("threeProp" ,"empid,fullname,monthlysalary" );
245227 properties .put ("nonExistingProp" , "fakeprop1" );
246-
228+
247229
248230 for (Entry <String ,String > sourceContext : sourceContexts .entrySet ()) {
249231 for (Entry <String ,String > property : properties .entrySet ()) {
@@ -256,17 +238,17 @@ private void createMappings() {
256238 createMapping ("nonExistentPath" , "//test1/validtest/" ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" , "empid,fullname,monthlysalary" .split ("," ));
257239 createMapping ("inCorrectPath" , "//invalidtestns/" ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" , "empid,fullname,monthlysalary" .split ("," ));
258240 createMapping ("empty-sourceContext" , null ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" , "empid,fullname,monthlysalary" .split ("," ));
259-
241+
260242 createMapping ("default-without-sourcedFrom" , "/" ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" , "empid,fullname,monthlysalary" .split ("," ));
261243 createMapping ("default-no-properties" , "//*:validtest/*:" ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" , new String [1 ]);
262244 createMapping ("default-diffCanonicalProp" , "//*:validtest/*:" ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" ,"empid,fullname,monthlysalary" .split ("," ));
263-
245+
264246 createMapping ("diff-entity-validPath" , "//*:validtest/*:" ,"http://marklogic.com/example/Schema-0.0.1/fakeentity" , "empid,fullname,monthlysalary" .split ("," ));
265247 //Create another version of existing mapping
266248 createMapping ("validPath1-threeProp" , "//*:validtest/*:" ,"http://marklogic.com/example/Schema-0.0.1/e2eentity" , true , "empid,fullname,monthlysalary" .split ("," ));
267249 allMappings .addAll (Arrays .asList ("nonExistentPath,inCorrectPath,empty-sourceContext,default-without-sourcedFrom,default-no-properties,default-diffCanonicalProp,diff-entity-validPath" .split ("," )));
268-
269- installUserModules (getHubAdminConfig (), true );
250+
251+ installUserModules (getHubAdminConfig (), true );
270252 }
271253
272254 private void createMapping (String name , String sourceContext , String targetEntityType , String ... properties ) {
@@ -310,7 +292,7 @@ else if(name.contains("without-sourcedFrom")) {
310292 testMap .setProperties (mappingProperties );
311293 }
312294 mappingManager .saveMapping (testMap , incrementVersion );
313- }
295+ }
314296
315297 private void copyFile (String srcDir , Path dstDir ) {
316298 FileUtil .copy (getResourceStream (srcDir ), dstDir .toFile ());
@@ -358,7 +340,7 @@ private void installDocs(String flowName, DataFormat dataFormat, String collecti
358340 assertEquals (0 , getStagingDocCount (collection ));
359341 }
360342 }
361-
343+
362344 private Tuple <FlowRunner , JobTicket > runHarmonizeFlow (
363345 String flowName , DataFormat dataFormat ,
364346 Vector <String > completed , Vector <String > failed ,
@@ -438,9 +420,9 @@ private void testHarmonizeFlow(
438420 if (destDb .equals (HubConfig .DEFAULT_STAGING_NAME )) {
439421 mgr = stagingDocMgr ;
440422 }
441-
423+
442424 String filename = null ;
443-
425+
444426 if (flowName .contains ("validPath" )) {
445427 filename = "mapping/final-es" ;
446428 if (flowName .contains ("extranodes" )) {
@@ -453,7 +435,7 @@ private void testHarmonizeFlow(
453435 else {
454436 filename = "mapping/final-es-empty" ;
455437 }
456-
438+
457439 if (flowName .contains ("nonExistingProp" )) {
458440 filename = "mapping/final-es-empty" ;
459441 }
@@ -487,6 +469,6 @@ private void testHarmonizeFlow(
487469 else {
488470 assertNotEquals (TEST_SIZE , getFinalDocCount ());
489471 tuple .x .awaitCompletion ();
490- }
472+ }
491473 }
492- }
474+ }
0 commit comments