From db2ac7a4ee750f5c109af24e460581d85b1b186c Mon Sep 17 00:00:00 2001 From: Christos Tranoris <tranoris@ece.upatras.gr> Date: Wed, 14 Feb 2024 23:22:34 +0200 Subject: [PATCH] create test case for CREATION rule --- .../etsi/osl/osom/lcm/LCMRulesExecutor.java | 4 +- .../etsi/osl/osom/lcm/LcmBaseExecutor.java | 6 +- .../management/CreateReservedService.java | 1 + .../osl/osom/ProcessOrderIntegrationTest.java | 10 +- src/test/java/org/etsi/osl/osom/SCMocked.java | 32 +++++-- .../LcmCirrosRule1Test_CREATION.json | 31 ++++++ .../LcmRuleListSpecTest_CREATION.json | 9 ++ src/test/resources/cirros_2vnf_ns_RFS.json | 94 +++++++++++++++++++ 8 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 src/test/resources/LcmCirrosRule1Test_CREATION.json create mode 100644 src/test/resources/LcmRuleListSpecTest_CREATION.json diff --git a/src/main/java/org/etsi/osl/osom/lcm/LCMRulesExecutor.java b/src/main/java/org/etsi/osl/osom/lcm/LCMRulesExecutor.java index c9a4786..a157c1d 100644 --- a/src/main/java/org/etsi/osl/osom/lcm/LCMRulesExecutor.java +++ b/src/main/java/org/etsi/osl/osom/lcm/LCMRulesExecutor.java @@ -165,7 +165,7 @@ public class LCMRulesExecutor { ApplicationHome home = new ApplicationHome(LCMRulesExecutor.class); File classesJar = home.getSource(); - if ( classesJar.exists() ) { + if ( classesJar != null && classesJar.exists() ) { optionList.addAll(Arrays.asList("-classpath", classesJar.getAbsoluteFile().toString().replace("-exec", "") )); } logger.debug("classesJar = "+ classesJar); @@ -213,7 +213,7 @@ public class LCMRulesExecutor { URL[] classpath = new URL[] { temp.toUri().toURL() }; - if ( classesJar.exists() ) { + if ( classesJar != null && classesJar.exists() ) { classpath = new URL[] { temp.toUri().toURL(), classesJar.toURI().toURL() }; } logger.debug("classpath = "+ classpath.toString()); diff --git a/src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java b/src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java index c851b5d..7e7025a 100644 --- a/src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java +++ b/src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java @@ -396,8 +396,10 @@ public abstract class LcmBaseExecutor { System.out.println("============================================================================= \n"); - System.out.println("The value length is apayload= \n" + apayload.length()); - System.out.println("The value is apayload= \n" + apayload); + System.out.println("The value is apayload= \n" + apayload); + if (apayload!=null) { + System.out.println("The value length is apayload= \n" + apayload.length()); + } System.out.println("============================================================================= \n"); if (baseurl != null) { diff --git a/src/main/java/org/etsi/osl/osom/management/CreateReservedService.java b/src/main/java/org/etsi/osl/osom/management/CreateReservedService.java index 82516b5..d545ff9 100644 --- a/src/main/java/org/etsi/osl/osom/management/CreateReservedService.java +++ b/src/main/java/org/etsi/osl/osom/management/CreateReservedService.java @@ -313,6 +313,7 @@ public class CreateReservedService implements JavaDelegate { .value( new Any( initCharValues.get( c.getName() ), initCharValues.get( c.getName() ))) ; serviceToCreate.addServiceCharacteristicItem( helperCreateCharacteristicItem(c, orderCharacteristic ) ); characteristicFound = true; + continue; } } diff --git a/src/test/java/org/etsi/osl/osom/ProcessOrderIntegrationTest.java b/src/test/java/org/etsi/osl/osom/ProcessOrderIntegrationTest.java index 2ded0b1..7ef1c9d 100644 --- a/src/test/java/org/etsi/osl/osom/ProcessOrderIntegrationTest.java +++ b/src/test/java/org/etsi/osl/osom/ProcessOrderIntegrationTest.java @@ -181,7 +181,7 @@ public class ProcessOrderIntegrationTest { assertThat(spec).isInstanceOf(ServiceSpecification.class); assertThat(spec.getServiceSpecCharacteristic().size() ).isEqualTo(11); - assertThat(specCirros.getServiceSpecCharacteristic().size() ).isEqualTo(10); + assertThat(specCirros.getServiceSpecCharacteristic().size() ).isEqualTo(12); assertThat(sorder.getOrderItem().stream().findFirst().get().getService().getServiceCharacteristic().size() ).isEqualTo(2); assertThat(repositoryService.createProcessDefinitionQuery().count()).isEqualTo(15); @@ -224,15 +224,17 @@ public class ProcessOrderIntegrationTest { assertThat( aservice ).isNotNull(); assertThat( aservice.getServiceCharacteristic().size() ).isEqualTo(11); assertThat( aserviceCirros ).isNotNull(); - assertThat( aserviceCirros.getServiceCharacteristic().size() ).isEqualTo(10); + assertThat( aserviceCirros.getServiceCharacteristic().size() ).isEqualTo(12); assertThat( aservice.getServiceCharacteristicByName("Quality Class").getValue().getValue() ).isEqualTo( "1" ); assertThat( aservice.getServiceCharacteristicByName("cirros_2vnf_ns::OSM_CONFIG").getValue().getValue() ).contains( "eeeeeeee-8219-4580-9697-bf4a8f0a08f9" ); assertThat( aservice.getServiceCharacteristicByName("cirros_2vnf_ns::SSHKEY").getValue().getValue() ).isEqualTo( "MCKEYTESTINORDERExampleConcatSSHKEY_EnhancedByRule" ); //check that the cirros_2vnf_ns::SSHKEY value from the service order has been passed properly to the related RFS service assertThat( aserviceCirros.getServiceCharacteristicByName("OSM_CONFIG").getValue().getValue() ).contains( "eeeeeeee-8219-4580-9697-bf4a8f0a08f9" ); - assertThat( aserviceCirros.getServiceCharacteristicByName("SSHKEY").getValue().getValue() ).isEqualTo( "MCKEYTESTINORDERExampleConcatSSHKEY_EnhancedByRule" ); - + assertThat( aserviceCirros.getServiceCharacteristicByName("SSHKEY").getValue().getValue() ).isEqualTo( "MCKEYTESTINORDERExampleConcatSSHKEY_EnhancedByRule" ); + assertThat( aserviceCirros.getServiceCharacteristicByName("AProgrammaticChar").getValue().getValue() ).isEqualTo( "AProgrammaticNSDIDValue" ); + assertThat( aserviceCirros.getServiceCharacteristicByName("Another ProgrammaticChar").getValue().getValue() ).isEqualTo( "AnotherValue" ); + //we will further check LCM rules! diff --git a/src/test/java/org/etsi/osl/osom/SCMocked.java b/src/test/java/org/etsi/osl/osom/SCMocked.java index d048d88..f4b391d 100644 --- a/src/test/java/org/etsi/osl/osom/SCMocked.java +++ b/src/test/java/org/etsi/osl/osom/SCMocked.java @@ -222,7 +222,12 @@ public class SCMocked { InputStream in = new FileInputStream( sspec ); sspectext = IOUtils.toString(in, "UTF-8"); return sspectext; - } + } else if ( id.equals("89e027b5-24a9-4db7-b422-a963c9feeb7a") ) { + File sspec = new File( "src/test/resources/LcmCirrosRule1Test_CREATION.json" ); + InputStream in = new FileInputStream( sspec ); + sspectext = IOUtils.toString(in, "UTF-8"); + return sspectext; + } @@ -241,13 +246,24 @@ public class SCMocked { String sspectext = null; - if ( specid.equals("f2b74f90-4140-4895-80d1-ef243398117b") ) { - File sspec = new File( "src/test/resources/LcmRuleListSpecTest.json" ); - InputStream in = new FileInputStream( sspec ); - sspectext = IOUtils.toString(in, "UTF-8"); - return sspectext; - - } + if ( phaseName.equals("PRE_PROVISION") ) { + if ( specid.equals("f2b74f90-4140-4895-80d1-ef243398117b") ) { + File sspec = new File( "src/test/resources/LcmRuleListSpecTest.json" ); + InputStream in = new FileInputStream( sspec ); + sspectext = IOUtils.toString(in, "UTF-8"); + return sspectext; + + } + } else if ( phaseName.equals("CREATION") ) { + if ( specid.equals("f2b74f90-4140-4895-80d1-ef243398117b") ) { + File sspec = new File( "src/test/resources/LcmRuleListSpecTest_CREATION.json" ); + InputStream in = new FileInputStream( sspec ); + sspectext = IOUtils.toString(in, "UTF-8"); + return sspectext; + + + } + } return "[]"; diff --git a/src/test/resources/LcmCirrosRule1Test_CREATION.json b/src/test/resources/LcmCirrosRule1Test_CREATION.json new file mode 100644 index 0000000..591a7fd --- /dev/null +++ b/src/test/resources/LcmCirrosRule1Test_CREATION.json @@ -0,0 +1,31 @@ +{ + "uuid": "40f027b5-24a9-4db7-b422-a963c9feeb7a", + "lastUpdate": null, + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "BaseEntity", + "href": null, + "name": "OSM config depending on class", + "description": "LCM Rule for specification Cirros Test OSM config depending on class", + "lifecycleStatus": "In study", + "version": null, + "validFor": null, + "id": "40f027b5-24a9-4db7-b422-a963c9feeb7a", + "lcmrulephase": "CREATION", + "content": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"controls_if\" id=\"ezIW/Lp7?d[u/A8`K!VJ\" x=\"43\" y=\"110\"><mutation elseif=\"1\" else=\"1\"></mutation><value name=\"IF0\"><block type=\"logic_compare\" id=\"*ekZcAZ_,XZz{;WB,g5W\"><field name=\"OP\">EQ</field><value name=\"A\"><block type=\"getcharval_number\" id=\"WExcKv2H!)rCDI[uT?rm\"><field name=\"AVALUE\">Quality Class</field></block></value><value name=\"B\"><block type=\"literal_integer\" id=\"l1f(k)+1cls`GzX_ZE6A\"><field name=\"NUM\">2</field></block></value></block></value><statement name=\"DO0\"><block type=\"setcharval_string\" id=\"?gCX.V1+thXHr$r!X|^G\"><field name=\"NAMELBL\">cirros_2vnf_ns::OSM_CONFIG</field><value name=\"AVALUE\"><block type=\"osm_nsd_config\" id=\"*$NIN2?#,%E{nqD.C,[s\"><value name=\"NSDID\"><block type=\"literal_text\" id=\"%1c/IuALgz7!-]C;U.2+\"><field name=\"TEXT\">0b6853fc-8219-4580-9697-bf4a8f0a08f9</field></block></value><value name=\"VIMID\"><block type=\"literal_text\" id=\"wZ*p#fJKDLhjG|d3a1}m\"><field name=\"TEXT\">c224eb48-419e-4097-8a1d-11ec1bba087f</field></block></value></block></value></block></statement><value name=\"IF1\"><block type=\"logic_compare\" id=\"RCkz91fa[t(de{:W8z*u\"><field name=\"OP\">EQ</field><value name=\"A\"><block type=\"getcharval_number\" id=\"YyY0L]PctE#C%jytEtsY\"><field name=\"AVALUE\">Quality Class</field></block></value><value name=\"B\"><block type=\"literal_integer\" id=\"$3qYjNBhPmr%U,I=*;0o\"><field name=\"NUM\">1</field></block></value></block></value><statement name=\"DO1\"><block type=\"setcharval_string\" id=\"$q~oAJSlb(%rrZBx,Uf!\"><field name=\"NAMELBL\">cirros_2vnf_ns::OSM_CONFIG</field><value name=\"AVALUE\"><block type=\"osm_nsd_config\" id=\"CTljtvin=U?WpZD@@qQ~\"><value name=\"NSDID\"><block type=\"literal_text\" id=\"1V.Jyzj3d0x:gTCq^w+?\"><field name=\"TEXT\">eeeeeeee-8219-4580-9697-bf4a8f0a08f9</field></block></value><value name=\"VIMID\"><block type=\"literal_text\" id=\"qZOf!wzN~MaebefmIvx7\"><field name=\"TEXT\">eeeeeeee-419e-4097-8a1d-11ec1bba087f</field></block></value></block></value></block></statement><statement name=\"ELSE\"><block type=\"setcharval_string\" id=\"JQY#%xIXLvPK*DzyCR{_\"><field name=\"NAMELBL\">cirros_2vnf_ns::OSM_CONFIG</field><value name=\"AVALUE\"><block type=\"osm_nsd_config\" id=\"a-tUtYg:mDk^Qbe@CMGt\"><value name=\"NSDID\"><block type=\"literal_text\" id=\"ZY)+_ENMfz?mjiX.7O4:\"><field name=\"TEXT\">cccccccc-8219-4580-9697-bf4a8f0a08f9</field></block></value><value name=\"VIMID\"><block type=\"literal_text\" id=\"alJ:3%fxZr73K~qQQ`G%\"><field name=\"TEXT\">cccccccc-419e-4097-8a1d-11ec1bba087f</field></block></value></block></value></block></statement></block></xml>", + "code": "{\r\n java.util.HashMap<String,String> charvals = new java.util.HashMap<>();\r\n charvals.put(\"AProgrammaticChar\",\"AProgrammaticNSDIDValue\");\r\n charvals.put(\"Another ProgrammaticChar\",\"AnotherValue\");\r\n createServiceRefIf(\"cirros_2vnf_ns\", !(getCharValFromStringType(\"cirros_2vnf_ns::PackagingFormat\").equals(\"\")==true), charvals);\r\n }", + + "serviceSpecs": [ + { + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "name": "Cirros Test", + "version": null, + "targetServiceSchema": null, + "@referredType": null, + "id": "f2b74f90-4140-4895-80d1-ef243398117b" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/LcmRuleListSpecTest_CREATION.json b/src/test/resources/LcmRuleListSpecTest_CREATION.json new file mode 100644 index 0000000..70d831f --- /dev/null +++ b/src/test/resources/LcmRuleListSpecTest_CREATION.json @@ -0,0 +1,9 @@ +[ + { + "uuid": "89e027b5-24a9-4db7-b422-a963c9feeb7a", + "id": "89e027b5-24a9-4db7-b422-a963c9feeb7a", + "name": "OSM config depending on class", + "description": "LCM Rule for specification Cirros Test OSM config depending on class", + "lcmrulephase": "CREATION" + } +] \ No newline at end of file diff --git a/src/test/resources/cirros_2vnf_ns_RFS.json b/src/test/resources/cirros_2vnf_ns_RFS.json index 9e6b49f..1a4aea6 100644 --- a/src/test/resources/cirros_2vnf_ns_RFS.json +++ b/src/test/resources/cirros_2vnf_ns_RFS.json @@ -499,6 +499,100 @@ }, "@valueSchemaLocation": null, "id": "5c50dbe4-42f9-4d12-bed9-987c75b592d6" + }, + { + "uuid": "3a50dbe4-42f9-4d12-bed9-987c75b592d6", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristic", + "href": null, + "name": "AProgrammaticChar", + "configurable": false, + "description": "AProgrammaticChar dscription", + "extensible": null, + "isUnique": null, + "maxCardinality": 1, + "minCardinality": 1, + "regex": null, + "valueType": "TEXT", + "serviceSpecCharRelationship": [], + "serviceSpecCharacteristicValue": [ + { + "uuid": "54e00574-6d22-4f48-8bd4-17884f895c13", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "isDefault": true, + "rangeInterval": null, + "regex": null, + "unitOfMeasure": "N/A", + "valueFrom": null, + "valueTo": null, + "valueType": null, + "validFor": { + "endDateTime": "2040-09-06T23:48:24+03:00", + "startDateTime": "2020-09-06T23:48:24+03:00" + }, + "value": { + "value": "xzzx", + "alias": "AliASAProgrammaticChar" + } + } + ], + "validFor": { + "endDateTime": "2040-09-06T23:48:24+03:00", + "startDateTime": "2020-09-06T23:48:24+03:00" + }, + "@valueSchemaLocation": null, + "id": "5c50dbe4-42f9-4d12-bed9-987c75b592d6" + }, + { + "uuid": "3a22dbe4-42f9-4d12-bed9-987c75b592d6", + "@baseType": "BaseRootEntity", + "@schemaLocation": null, + "@type": "org.etsi.osl.tmf.scm633.model.ServiceSpecCharacteristic", + "href": null, + "name": "Another ProgrammaticChar", + "configurable": false, + "description": "Another AProgrammaticChar dscription", + "extensible": null, + "isUnique": null, + "maxCardinality": 1, + "minCardinality": 1, + "regex": null, + "valueType": "TEXT", + "serviceSpecCharRelationship": [], + "serviceSpecCharacteristicValue": [ + { + "uuid": "54e00522-6d22-4f48-8bd4-17884f895c13", + "@baseType": "BaseEntity", + "@schemaLocation": null, + "@type": null, + "href": null, + "isDefault": true, + "rangeInterval": null, + "regex": null, + "unitOfMeasure": "N/A", + "valueFrom": null, + "valueTo": null, + "valueType": null, + "validFor": { + "endDateTime": "2040-09-06T23:48:24+03:00", + "startDateTime": "2020-09-06T23:48:24+03:00" + }, + "value": { + "value": "aawwaa", + "alias": "AliASAProgrammaticChar" + } + } + ], + "validFor": { + "endDateTime": "2040-09-06T23:48:24+03:00", + "startDateTime": "2020-09-06T23:48:24+03:00" + }, + "@valueSchemaLocation": null, + "id": "5c50dbe4-42f9-4d12-bed9-987c75b592d6" } ], "serviceSpecRelationship": [], -- GitLab