13
13
import com .boozallen .aiops .mda .generator .common .DataFlowStrategy ;
14
14
import com .boozallen .aiops .mda .generator .common .MachineLearningStrategy ;
15
15
import com .boozallen .aiops .mda .generator .common .PipelineContext ;
16
+ import com .boozallen .aiops .mda .metamodel .AissembleModelInstanceRepository ;
16
17
import com .boozallen .aiops .mda .util .TestMetamodelUtil ;
17
18
import com .boozallen .aiops .mda .metamodel .json .AissembleMdaJsonUtils ;
18
19
import io .cucumber .java .After ;
37
38
import java .nio .file .Files ;
38
39
import java .util .ArrayList ;
39
40
import java .util .List ;
41
+ import java .util .Map ;
40
42
import java .util .Random ;
41
43
import java .util .regex .Matcher ;
42
44
import java .util .regex .Pattern ;
43
45
import java .util .stream .Collectors ;
46
+ import org .technologybrewery .fermenter .mda .metamodel .ModelInstanceRepositoryManager ;
47
+ import org .technologybrewery .fermenter .mda .metamodel .ModelRepositoryConfiguration ;
48
+ import org .technologybrewery .fermenter .mda .metamodel .ModelInstanceUrl ;
44
49
45
50
import static org .junit .Assert .assertEquals ;
46
51
import static org .junit .Assert .assertFalse ;
@@ -56,6 +61,7 @@ public class PipelineSteps extends AbstractModelInstanceSteps {
56
61
public static final String DO_MODIFY_REGEX = "DO\\ s+MODIFY" ;
57
62
public static final String ABSTRACT_DATA_ACTION_IMPL_INHERIT_REGEX = "AbstractDataActionImpl\\ (AbstractDataAction\\ ):" ;
58
63
public static final String ABSTRACT_PIPELINE_STEP_INHERIT_REGEX = "AbstractPipelineStep\\ (AbstractDataActionImpl\\ )" ;
64
+ public static final String TEST_RECORD_RELATIONS = "test.record.relations" ;
59
65
60
66
protected Pipeline pipeline ;
61
67
protected Pipeline dataFLowPipeline ;
@@ -967,4 +973,110 @@ private List<Step> createStepForPySparkRDMSDataFlowPipeline() {
967
973
return steps ;
968
974
}
969
975
976
+
977
+ @ Given ("a valid data delivery pipeline with native inbound type" )
978
+ public void a_valid_data_delivery_pipeline_with_native_inbound_type () throws IOException {
979
+ RecordElement newRecordB = createNewRecordWithNameAndPackage ("RecordB" , RELATION_PACKAGE );
980
+ saveRecordToFile (newRecordB );
981
+
982
+ RecordElement nativeRecord = createNewRecordWithNameAndPackage ("RecordA" , TEST_RECORD_RELATIONS );
983
+
984
+ // Create relation from RecordA to RecordB
985
+ RelationElement recordRelation = new RelationElement ();
986
+ recordRelation .setName ("RecordB" );
987
+ recordRelation .setPackage (RELATION_PACKAGE );
988
+ recordRelation .setColumn ("FieldBParent" );
989
+ recordRelation .setDocumentation ("Some Documentation" );
990
+ recordRelation .setMultiplicity ("1-1" );
991
+
992
+ nativeRecord .addRelation (recordRelation );
993
+ saveRecordToFile (nativeRecord );
994
+
995
+ PipelineElement newPipeline = TestMetamodelUtil .createPipelineWithType ("nativeDataDelivery" , "com.boozallen.aiops.test" , "data-flow" , "versioned-streaming-spark-java" );
996
+
997
+ // Add steps to pipeline
998
+ StepElement step = new StepElement ();
999
+ step .setName ("inbound-step" );
1000
+ step .setType ("synchronous" );
1001
+
1002
+ PersistElement persist = new PersistElement ();
1003
+ persist .setType ("delta-lake" );
1004
+ step .setPersist (persist );
1005
+
1006
+ StepDataBindingElement inbound = new StepDataBindingElement ();
1007
+ inbound .setType ("native" );
1008
+ inbound .setChannelName ("unit-test-inbound" );
1009
+ inbound .setChannelType ("topic" );
1010
+
1011
+ // Add a record type to the inbound
1012
+ StepDataRecordTypeElement stepDataRecordTypeElement = new StepDataRecordTypeElement ();
1013
+ stepDataRecordTypeElement .setName ("RecordA" );
1014
+ stepDataRecordTypeElement .setPackage (TEST_RECORD_RELATIONS );
1015
+ inbound .setRecordType (stepDataRecordTypeElement );
1016
+ step .setInbound (inbound );
1017
+
1018
+ StepDataBindingElement outbound = new StepDataBindingElement ();
1019
+ outbound .setType ("messaging" );
1020
+ outbound .setChannelName ("unit-test-outbound" );
1021
+ outbound .setChannelType ("queue" );
1022
+ step .setOutbound (outbound );
1023
+
1024
+ for (int j = 0 ; j < RandomUtils .insecure ().randomInt (0 , 4 ); j ++) {
1025
+ ConfigurationItemElement configurationItem = new ConfigurationItemElement ();
1026
+ configurationItem .setKey (RandomStringUtils .insecure ().nextAlphanumeric (3 ));
1027
+ configurationItem .setValue (RandomStringUtils .insecure ().nextAlphanumeric (10 ));
1028
+ step .addConfigurationItem (configurationItem );
1029
+ }
1030
+
1031
+ newPipeline .addStep (step );
1032
+
1033
+ pipelineFile = savePipelineToFile (newPipeline );
1034
+ }
1035
+
1036
+ private RecordElement createNewRecordWithNameAndPackage (String name , String packageName ) {
1037
+ RecordElement newRecord = new RecordElement ();
1038
+ if (StringUtils .isNotBlank (name )) {
1039
+ newRecord .setName (name );
1040
+ }
1041
+
1042
+ if (StringUtils .isNotBlank (packageName )) {
1043
+ newRecord .setPackage (packageName );
1044
+ }
1045
+
1046
+ return newRecord ;
1047
+ }
1048
+
1049
+ @ Then ("the native inbound pipeline can be read with the associated record and relations" )
1050
+ public void the_native_inbound_pipeline_can_be_read () {
1051
+ primeRecordRepo ("example" );
1052
+
1053
+ pipeline = JsonUtils .readAndValidateJson (pipelineFile , PipelineElement .class );
1054
+ List <? extends Step > mySteps = pipeline .getSteps ();
1055
+
1056
+ for (Step mystep : mySteps ) {
1057
+ StepDataBinding myInbound = mystep .getInbound ();
1058
+ StepDataRecordType stepDataRecordType = myInbound .getRecordType ();
1059
+ Record myRecord = stepDataRecordType .getRecordType ();
1060
+
1061
+ assertTrue ("Record Relations was empty." , myRecord .getRelations () != null && !myRecord .getRelations ().isEmpty ());
1062
+ }
1063
+ }
1064
+
1065
+ /***
1066
+ * This method loads the metadataRepo for records. The default metadataRepo does
1067
+ * not set the correct ModelInstanceUrl, so calling this will prime the repo with the correct path.
1068
+ * @param artifactId The name of the project
1069
+ */
1070
+ protected void primeRecordRepo (String artifactId ) {
1071
+ ModelRepositoryConfiguration config = new ModelRepositoryConfiguration ();
1072
+ config .setArtifactId (artifactId );
1073
+ config .setBasePackage (BOOZ_ALLEN_PACKAGE );
1074
+ Map <String , ModelInstanceUrl > metadataUrlMap = config .getMetamodelInstanceLocations ();
1075
+ metadataUrlMap .put (artifactId ,
1076
+ new ModelInstanceUrl (artifactId , recordsDirectory .getParentFile ().toURI ().toString ()));
1077
+
1078
+ metadataRepo = new AissembleModelInstanceRepository (config );
1079
+ ModelInstanceRepositoryManager .setRepository (metadataRepo );
1080
+ metadataRepo .load ();
1081
+ }
970
1082
}
0 commit comments