@@ -210,6 +210,157 @@ class AssetInterfaceDescriptionUtilTest {
210210 expect ( tdObj . properties . device_name . forms [ 0 ] ) . not . to . have . property ( "security" ) ;
211211 }
212212
213+ @test async "should correctly roundtrip inverterModbus from/to AID" ( ) {
214+ const aasInput = ( await fs . readFile ( "test/util/inverterModbus.json" ) ) . toString ( ) ;
215+ const td = this . assetInterfaceDescriptionUtil . transformAAS2TD ( aasInput ) ;
216+
217+ const aidOutput = this . assetInterfaceDescriptionUtil . transformTD2SM ( td ) ;
218+
219+ const smObj = JSON . parse ( aidOutput ) ;
220+ expect ( smObj ) . to . have . property ( "idShort" ) . that . equals ( "AssetInterfacesDescription" ) ;
221+ expect ( smObj ) . to . have . property ( "submodelElements" ) . to . be . an ( "array" ) . to . have . lengthOf . greaterThan ( 0 ) ;
222+ const smInterface = smObj . submodelElements [ 0 ] ;
223+ expect ( smInterface ) . to . have . property ( "value" ) . to . be . an ( "array" ) . to . have . lengthOf . greaterThan ( 0 ) ;
224+ let hasThingTitle = false ;
225+ let hasEndpointMetadata = false ;
226+ for ( const smValue of smInterface . value ) {
227+ if ( smValue . idShort === "title" ) {
228+ hasThingTitle = true ;
229+ expect ( smValue ) . to . have . property ( "value" ) . to . equal ( "Inverter GEN44" ) ;
230+ } else if ( smValue . idShort === "EndpointMetadata" ) {
231+ hasEndpointMetadata = true ;
232+ const endpointMetadata = smValue ;
233+ expect ( endpointMetadata ) . to . have . property ( "value" ) . to . be . an ( "array" ) . to . have . lengthOf . greaterThan ( 0 ) ;
234+ let hasSecurity = false ;
235+ let hasSecurityDefinitions = false ;
236+ for ( const endpointMetadataValue of endpointMetadata . value ) {
237+ if ( endpointMetadataValue . idShort === "security" ) {
238+ hasSecurity = true ;
239+ expect ( endpointMetadataValue )
240+ . to . have . property ( "value" )
241+ . to . be . an ( "array" )
242+ . to . have . lengthOf . greaterThan ( 0 ) ;
243+ expect ( endpointMetadataValue . value [ 0 ] . value ) . to . equal ( "nosec_sc" ) ;
244+ } else if ( endpointMetadataValue . idShort === "securityDefinitions" ) {
245+ hasSecurityDefinitions = true ;
246+ expect ( endpointMetadataValue )
247+ . to . have . property ( "value" )
248+ . to . be . an ( "array" )
249+ . to . have . lengthOf . greaterThan ( 0 ) ;
250+ let hasBasicSC = false ;
251+ for ( const securityDefinitionValue of endpointMetadataValue . value ) {
252+ if ( securityDefinitionValue . idShort === "nosec_sc" ) {
253+ hasBasicSC = true ;
254+ expect ( securityDefinitionValue )
255+ . to . have . property ( "value" )
256+ . to . be . an ( "array" )
257+ . to . have . lengthOf . greaterThan ( 0 ) ;
258+ let hasBasic = false ;
259+ for ( const sec of securityDefinitionValue . value ) {
260+ if ( sec . idShort === "scheme" ) {
261+ hasBasic = true ;
262+ expect ( sec . value ) . to . equal ( "nosec" ) ;
263+ }
264+ }
265+ expect ( hasBasic ) . to . equal ( true ) ;
266+ }
267+ }
268+ expect ( hasBasicSC ) . to . equal ( true ) ;
269+ }
270+ }
271+ expect ( hasSecurity ) . to . equal ( true ) ;
272+ expect ( hasSecurityDefinitions ) . to . equal ( true ) ;
273+ }
274+ }
275+ expect ( hasThingTitle , "No thing title" ) . to . equal ( true ) ;
276+ expect ( hasEndpointMetadata , "No EndpointMetadata" ) . to . equal ( true ) ;
277+
278+ // InterfaceMetadata with properties etc
279+ let hasInterfaceMetadata = false ;
280+ for ( const smValue of smInterface . value ) {
281+ if ( smValue . idShort === "InterfaceMetadata" ) {
282+ hasInterfaceMetadata = true ;
283+ expect ( smValue ) . to . have . property ( "value" ) . to . be . an ( "array" ) . to . have . lengthOf . greaterThan ( 0 ) ;
284+ let hasProperties = false ;
285+ for ( const interactionValues of smValue . value ) {
286+ if ( interactionValues . idShort === "properties" ) {
287+ hasProperties = true ;
288+ expect ( interactionValues )
289+ . to . have . property ( "value" )
290+ . to . be . an ( "array" )
291+ . to . have . lengthOf . greaterThan ( 0 ) ;
292+ let hasPropertyDeviceName = false ;
293+ for ( const propertyValue of interactionValues . value ) {
294+ if ( propertyValue . idShort === "device_name" ) {
295+ hasPropertyDeviceName = true ;
296+ expect ( propertyValue )
297+ . to . have . property ( "value" )
298+ . to . be . an ( "array" )
299+ . to . have . lengthOf . greaterThan ( 0 ) ;
300+ let hasType = false ;
301+ let hasTitle = false ;
302+ let hasForms = false ;
303+ for ( const propProperty of propertyValue . value ) {
304+ if ( propProperty . idShort === "type" ) {
305+ hasType = true ;
306+ expect ( propProperty . value ) . to . equal ( "string" ) ;
307+ } else if ( propProperty . idShort === "title" ) {
308+ hasTitle = true ;
309+ expect ( propProperty . value ) . to . equal ( "Device name" ) ;
310+ } else if ( propProperty . idShort === "forms" ) {
311+ hasForms = true ;
312+ expect ( propProperty )
313+ . to . have . property ( "value" )
314+ . to . be . an ( "array" )
315+ . to . have . lengthOf . greaterThan ( 0 ) ;
316+ let hasHref = false ;
317+ let hasOp = false ;
318+ let hasContentType = false ;
319+ let hasModbusFunction = false ;
320+ let hasModbusType = false ;
321+ for ( const formEntry of propProperty . value ) {
322+ if ( formEntry . idShort === "href" ) {
323+ hasHref = true ;
324+ expect ( formEntry . value ) . to . equal (
325+ "modbus+tcp://192.168.178.146:502/1/40020?quantity=16"
326+ ) ;
327+ } else if ( formEntry . idShort === "op" ) {
328+ hasOp = true ;
329+ expect ( formEntry . value ) . to . equal ( "readproperty" ) ;
330+ } else if ( formEntry . idShort === "contentType" ) {
331+ hasContentType = true ;
332+ expect ( formEntry . value ) . to . equal ( "application/octet-stream" ) ;
333+ } else if ( formEntry . idShort === "modbus_function" ) {
334+ // vs. "modbus:function"
335+ hasModbusFunction = true ;
336+ expect ( formEntry . value ) . to . equal ( "readHoldingRegisters" ) ;
337+ } else if ( formEntry . idShort === "modbus_type" ) {
338+ // vs. "modbus:type"
339+ hasModbusType = true ;
340+ expect ( formEntry . value ) . to . equal ( "string" ) ;
341+ }
342+ }
343+ expect ( hasHref ) . to . equal ( true ) ;
344+ expect ( hasOp ) . to . equal ( true ) ;
345+ expect ( hasContentType ) . to . equal ( true ) ;
346+ expect ( hasModbusFunction ) . to . equal ( true ) ;
347+ expect ( hasModbusType ) . to . equal ( true ) ;
348+ }
349+ }
350+ expect ( hasType ) . to . equal ( true ) ;
351+ expect ( hasTitle ) . to . equal ( true ) ;
352+ expect ( hasForms ) . to . equal ( true ) ;
353+ }
354+ }
355+ expect ( hasPropertyDeviceName ) . to . equal ( true ) ;
356+ }
357+ }
358+ expect ( hasProperties ) . to . equal ( true ) ;
359+ }
360+ }
361+ expect ( hasInterfaceMetadata , "No InterfaceMetadata" ) . to . equal ( true ) ;
362+ }
363+
213364 td1Base = "https://www.example.com/" ;
214365 td1 : ThingDescription = {
215366 "@context" : "https://www.w3.org/2022/wot/td/v1.1" ,
@@ -242,7 +393,7 @@ class AssetInterfaceDescriptionUtilTest {
242393 } ,
243394 } ;
244395
245- @test async "should correctly transform sample TD into JSON submodel" ( ) {
396+ @test async "should correctly transform sample TD into AID submodel" ( ) {
246397 const sm = this . assetInterfaceDescriptionUtil . transformTD2SM ( JSON . stringify ( this . td1 ) , [ "https" ] ) ;
247398
248399 const smObj = JSON . parse ( sm ) ;
@@ -358,7 +509,6 @@ class AssetInterfaceDescriptionUtilTest {
358509 let hasHref = false ;
359510 let hasContentType = false ;
360511 let hasHtvMethodName = false ;
361- // let hasOp = false;
362512 for ( const formEntry of propProperty . value ) {
363513 if ( formEntry . idShort === "href" ) {
364514 hasHref = true ;
@@ -369,18 +519,14 @@ class AssetInterfaceDescriptionUtilTest {
369519 } else if ( formEntry . idShort === "contentType" ) {
370520 hasContentType = true ;
371521 expect ( formEntry . value ) . to . equal ( "application/json" ) ;
372- } else if ( formEntry . idShort === "htv:methodName " ) {
522+ } else if ( formEntry . idShort === "htv_methodName " ) {
373523 hasHtvMethodName = true ;
374524 expect ( formEntry . value ) . to . equal ( "GET" ) ;
375- // } else if (formEntry.idShort === "op") {
376- // hasOp = true;
377- // expect(formEntry.value).to.have.members(["readproperty"]);
378525 }
379526 }
380527 expect ( hasHref ) . to . equal ( true ) ;
381528 expect ( hasContentType ) . to . equal ( true ) ;
382529 expect ( hasHtvMethodName ) . to . equal ( true ) ;
383- // expect(hasOp).to.equal(true);
384530 }
385531 }
386532 expect ( hasType ) . to . equal ( true ) ;
0 commit comments