diff --git a/.vscode/launch.json b/.vscode/launch.json index 59f23bba..c2e6488c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -75,7 +75,7 @@ "runtimeExecutable": "npm", "runtimeArgs": [ "run-script", - "test:debug", + "test", "-w", "aas-server" ], @@ -88,7 +88,7 @@ "runtimeExecutable": "npm", "runtimeArgs": [ "run-script", - "test:debug", + "test", "-w", "aas-server", "--testPathPattern", @@ -96,7 +96,7 @@ ], }, { - "name": "Test common", + "name": "Test aas-core", "type": "node", "request": "launch", "cwd": "${workspaceFolder}", @@ -109,7 +109,7 @@ ] }, { - "name": "Debug common test", + "name": "Debug aas-core test", "type": "node", "request": "launch", "cwd": "${workspaceFolder}", diff --git a/.vscode/settings.json b/.vscode/settings.json index 8a639300..465eaa96 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -46,7 +46,7 @@ "name": "aas-core", "rootPath": "./projects/aas-core", "runMode": "on-demand", - "jestCommandLine": "node --experimental-vm-modules --no-warnings ../../node_modules/jest/bin/jest.js" + "jestCommandLine": "node --experimental-vm-modules --no-warnings ../../node_modules/jest/bin/jest.js", }, { "name": "aas-server", diff --git a/projects/aas-server/src/app/packages/json-reader-v2.ts b/projects/aas-server/src/app/packages/json-reader-v2.ts index 0e8f3b80..3424b492 100644 --- a/projects/aas-server/src/app/packages/json-reader-v2.ts +++ b/projects/aas-server/src/app/packages/json-reader-v2.ts @@ -154,7 +154,7 @@ export class JsonReaderV2 extends AASReader { return submodel; } - private readSubmodelElements(sources: aasv2.SubmodelElement[], ancestors?: aas.Referable[]): aas.SubmodelElement[] { + private readSubmodelElements(sources: aasv2.SubmodelElement[], ancestors: aas.Referable[]): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const source of sources) { const submodelElement = this.readSubmodelElement(source, ancestors); @@ -168,7 +168,7 @@ export class JsonReaderV2 extends AASReader { private readSubmodelElement( source: aasv2.SubmodelElement, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.SubmodelElement | undefined { switch (source.modelType.name) { case 'AnnotatedRelationshipElement': @@ -200,7 +200,7 @@ export class JsonReaderV2 extends AASReader { } } - private readSubmodelElementType(source: aasv2.SubmodelElement, ancestors?: aas.Referable[]): aas.SubmodelElement { + private readSubmodelElementType(source: aasv2.SubmodelElement, ancestors: aas.Referable[]): aas.SubmodelElement { return { ...this.readReferable(source, undefined, ancestors), ...this.readHasSemantic(source), @@ -212,17 +212,22 @@ export class JsonReaderV2 extends AASReader { private readAnnotatedRelationshipElement( source: aasv2.AnnotatedRelationshipElement, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.AnnotatedRelationshipElement { const relationship: aas.AnnotatedRelationshipElement = { ...this.readRelationshipElement(source, ancestors), - annotations: source.annotation?.map(item => this.readSubmodelElementType(item)) ?? [], }; + if (source.annotation) { + relationship.annotations = source.annotation.map(item => + this.readSubmodelElementType(item, [...ancestors, relationship]), + ); + } + return relationship; } - private readBasicEvent(source: aasv2.BasicEvent, ancestors?: aas.Referable[]): aas.BasicEventElement { + private readBasicEvent(source: aasv2.BasicEvent, ancestors: aas.Referable[]): aas.BasicEventElement { if (!source.observed) { throw new Error('BasicEvent.observed'); } @@ -237,7 +242,7 @@ export class JsonReaderV2 extends AASReader { return basicEvent; } - private readProperty(source: aasv2.Property, ancestors?: aas.Referable[]): aas.Property { + private readProperty(source: aasv2.Property, ancestors: aas.Referable[]): aas.Property { let valueType = this.readValueTypeDef(source.valueType); if (!valueType && source.value != null) { valueType = determineType(source.value); @@ -266,7 +271,7 @@ export class JsonReaderV2 extends AASReader { private readMultiLanguageProperty( source: aasv2.MultiLanguageProperty, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.MultiLanguageProperty { const value = this.readLangStringSet(source.value.langString); const property: aas.MultiLanguageProperty = { @@ -277,7 +282,7 @@ export class JsonReaderV2 extends AASReader { return property; } - private readFile(source: aasv2.File, ancestors?: aas.Referable[]): aas.File { + private readFile(source: aasv2.File, ancestors: aas.Referable[]): aas.File { let contentType = source.mimeType; if (!contentType) { contentType = ''; @@ -295,7 +300,7 @@ export class JsonReaderV2 extends AASReader { return file; } - private readBlob(source: aasv2.Blob, ancestors?: aas.Referable[]): aas.Blob { + private readBlob(source: aasv2.Blob, ancestors: aas.Referable[]): aas.Blob { let contentType = source.mimeType; if (!contentType) { contentType = ''; @@ -315,23 +320,20 @@ export class JsonReaderV2 extends AASReader { private readSubmodelElementCollection( source: aasv2.SubmodelElementCollection, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.SubmodelElementCollection { const collection: aas.SubmodelElementCollection = { ...this.readSubmodelElementType(source, ancestors), }; if (source.value) { - collection.value = this.readSubmodelElements( - source.value, - ancestors ? [...ancestors, collection] : undefined, - ); + collection.value = this.readSubmodelElements(source.value, [...ancestors, collection]); } return collection; } - private readReferenceElement(source: aasv2.ReferenceElement, ancestors?: aas.Referable[]): aas.ReferenceElement { + private readReferenceElement(source: aasv2.ReferenceElement, ancestors: aas.Referable[]): aas.ReferenceElement { if (!source.value) { throw new Error('ReferenceElement.value'); } @@ -346,7 +348,7 @@ export class JsonReaderV2 extends AASReader { private readRelationshipElement( source: aasv2.RelationshipElement, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.RelationshipElement { if (!source.first) { throw new Error('RelationshipElement.first'); @@ -365,34 +367,40 @@ export class JsonReaderV2 extends AASReader { return relationship; } - private readOperation(source: aasv2.Operation, ancestors?: aas.Referable[]): aas.Operation { + private readOperation(source: aasv2.Operation, ancestors: aas.Referable[]): aas.Operation { const operation: aas.Operation = { ...this.readSubmodelElementType(source, ancestors), }; if (source.inputVariable) { - operation.inputVariables = source.inputVariable.map(item => this.readOperationVariable(item)); + operation.inputVariables = source.inputVariable.map(item => + this.readOperationVariable(item, [...ancestors, operation]), + ); } if (source.inoutputVariable) { - operation.inoutputVariables = source.inoutputVariable.map(item => this.readOperationVariable(item)); + operation.inoutputVariables = source.inoutputVariable.map(item => + this.readOperationVariable(item, [...ancestors, operation]), + ); } if (source.outputVariable) { - operation.outputVariables = source.outputVariable.map(item => this.readOperationVariable(item)); + operation.outputVariables = source.outputVariable.map(item => + this.readOperationVariable(item, [...ancestors, operation]), + ); } return operation; } - private readOperationVariable(source: aasv2.OperationVariable): aas.OperationVariable { + private readOperationVariable(source: aasv2.OperationVariable, ancestors: aas.Referable[]): aas.OperationVariable { let value: aas.SubmodelElement | undefined; if (this.isSubmodelElement(source.value)) { - value = this.readSubmodelElementType(source.value); + value = this.readSubmodelElementType(source.value, ancestors); } else if ('submodelElement' in source.value) { const submodelElement = (source.value as { submodelElement: aasv2.SubmodelElement }).submodelElement; if (this.isSubmodelElement(submodelElement)) { - value = this.readSubmodelElementType(submodelElement); + value = this.readSubmodelElementType(submodelElement, ancestors); } } @@ -403,7 +411,7 @@ export class JsonReaderV2 extends AASReader { return { value }; } - private readEntity(source: aasv2.Entity, ancestors?: aas.Referable[]): aas.Entity { + private readEntity(source: aasv2.Entity, ancestors: aas.Referable[]): aas.Entity { if (source.entityType == null) { throw new Error('Entity.entityType'); } @@ -418,13 +426,13 @@ export class JsonReaderV2 extends AASReader { } if (source.statements) { - entity.statements = this.readSubmodelElements(source.statements); + entity.statements = this.readSubmodelElements(source.statements, [...ancestors, entity]); } return entity; } - private readRange(source: aasv2.Range, ancestors?: aas.Referable[]): aas.Range { + private readRange(source: aasv2.Range, ancestors: aas.Referable[]): aas.Range { if (source.valueType == null) { throw new Error('Range.valueType'); } diff --git a/projects/aas-server/src/app/packages/json-reader-v3.ts b/projects/aas-server/src/app/packages/json-reader-v3.ts index 24aa213d..41d3300f 100644 --- a/projects/aas-server/src/app/packages/json-reader-v3.ts +++ b/projects/aas-server/src/app/packages/json-reader-v3.ts @@ -197,7 +197,7 @@ export class JsonReaderV3 extends AASReader { return submodel; } - private readSubmodelElements(sources: aas.SubmodelElement[], ancestors?: aas.Referable[]): aas.SubmodelElement[] { + private readSubmodelElements(sources: aas.SubmodelElement[], ancestors: aas.Referable[]): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const source of sources) { const submodelElement = this.readSubmodelElement(source, ancestors); @@ -211,7 +211,7 @@ export class JsonReaderV3 extends AASReader { private readSubmodelElement( source: aas.SubmodelElement, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.SubmodelElement | undefined { switch (source.modelType) { case 'AnnotatedRelationshipElement': @@ -245,7 +245,7 @@ export class JsonReaderV3 extends AASReader { } } - private readSubmodelElementType(source: aas.SubmodelElement, ancestors?: aas.Referable[]): aas.SubmodelElement { + private readSubmodelElementType(source: aas.SubmodelElement, ancestors: aas.Referable[]): aas.SubmodelElement { return { ...this.readReferable(source, ancestors), ...this.readHasSemantics(source), @@ -256,27 +256,24 @@ export class JsonReaderV3 extends AASReader { private readAnnotatedRelationshipElement( source: aas.AnnotatedRelationshipElement, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.AnnotatedRelationshipElement { const relationship: aas.AnnotatedRelationshipElement = { ...this.readRelationshipElement(source, ancestors), }; if (source.annotations) { - relationship.annotations = this.readSubmodelElements( - source.annotations, - ancestors ? [...ancestors, relationship] : undefined, - ); + relationship.annotations = this.readSubmodelElements(source.annotations, [...ancestors, relationship]); } return relationship; } - private readEventElement(source: aas.EventElement, ancestor?: aas.Referable[]): aas.EventElement { + private readEventElement(source: aas.EventElement, ancestor: aas.Referable[]): aas.EventElement { return { ...this.readSubmodelElementType(source, ancestor) }; } - private readBasicEventElement(source: aas.BasicEventElement, ancestors?: aas.Referable[]): aas.BasicEventElement { + private readBasicEventElement(source: aas.BasicEventElement, ancestors: aas.Referable[]): aas.BasicEventElement { if (!source.observed) { throw new Error('BasicEventElement.observed'); } @@ -319,7 +316,7 @@ export class JsonReaderV3 extends AASReader { return eventElement; } - private readProperty(source: aas.Property, ancestors?: aas.Referable[]): aas.Property { + private readProperty(source: aas.Property, ancestors: aas.Referable[]): aas.Property { let valueType: aas.DataTypeDefXsd | undefined = source.valueType; if (!valueType && source.value) { valueType = determineType(source.value); @@ -348,7 +345,7 @@ export class JsonReaderV3 extends AASReader { private readMultiLanguageProperty( source: aas.MultiLanguageProperty, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.MultiLanguageProperty { let value: aas.LangString[] | undefined; if (Array.isArray(source.value)) { @@ -362,35 +359,41 @@ export class JsonReaderV3 extends AASReader { return { ...this.readSubmodelElementType(source, ancestors), value }; } - private readOperation(source: aas.Operation, ancestors: aas.Referable[] | undefined): aas.Operation { + private readOperation(source: aas.Operation, ancestors: aas.Referable[]): aas.Operation { const operation: aas.Operation = { ...this.readSubmodelElementType(source, ancestors), }; if (source.inputVariables) { - operation.inputVariables = source.inputVariables.map(item => this.readOperationVariable(item)); + operation.inputVariables = source.inputVariables.map(item => + this.readOperationVariable(item, [...ancestors, operation]), + ); } if (source.inoutputVariables) { - operation.inoutputVariables = source.inoutputVariables.map(item => this.readOperationVariable(item)); + operation.inoutputVariables = source.inoutputVariables.map(item => + this.readOperationVariable(item, [...ancestors, operation]), + ); } if (source.outputVariables) { - operation.outputVariables = source.outputVariables.map(item => this.readOperationVariable(item)); + operation.outputVariables = source.outputVariables.map(item => + this.readOperationVariable(item, [...ancestors, operation]), + ); } return operation; } - private readOperationVariable(source: aas.OperationVariable): aas.OperationVariable { + private readOperationVariable(source: aas.OperationVariable, ancestors: aas.Referable[]): aas.OperationVariable { if (!source.value) { throw new Error('OperationVariable.value'); } - return { value: this.readSubmodelElementType(source.value) }; + return { value: this.readSubmodelElementType(source.value, ancestors) }; } - private readFile(source: aas.File, ancestors?: aas.Referable[]): aas.File { + private readFile(source: aas.File, ancestors: aas.Referable[]): aas.File { const value = source.value?.trim(); let contentType: string | undefined = source.contentType?.trim(); if (!contentType && value) { @@ -416,7 +419,7 @@ export class JsonReaderV3 extends AASReader { return file; } - private readBlob(source: aas.Blob, ancestors?: aas.Referable[]): aas.Blob { + private readBlob(source: aas.Blob, ancestors: aas.Referable[]): aas.Blob { const blob: aas.Blob = { ...this.readSubmodelElementType(source, ancestors), contentType: source.contentType ?? '', @@ -429,7 +432,7 @@ export class JsonReaderV3 extends AASReader { return blob; } - private readEntity(source: aas.Entity, ancestors: aas.Referable[] | undefined): aas.Entity { + private readEntity(source: aas.Entity, ancestors: aas.Referable[]): aas.Entity { if (!source.entityType) { throw new Error('Entity.entityType'); } @@ -440,9 +443,7 @@ export class JsonReaderV3 extends AASReader { }; if (source.statements) { - entity.statements = source.statements.map( - item => this.readSubmodelElement(item, ancestors ? [...ancestors, entity] : undefined)!, - ); + entity.statements = source.statements.map(item => this.readSubmodelElement(item, [...ancestors, entity])!); } if (source.globalAssetId) { @@ -458,17 +459,14 @@ export class JsonReaderV3 extends AASReader { private readSubmodelElementCollection( source: aas.SubmodelElementCollection, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.SubmodelElementCollection { const collection: aas.SubmodelElementCollection = { ...this.readSubmodelElementType(source, ancestors), }; if (source.value) { - collection.value = this.readSubmodelElements( - source.value, - ancestors ? [...ancestors, collection] : undefined, - ); + collection.value = this.readSubmodelElements(source.value, [...ancestors, collection]); } return collection; @@ -476,7 +474,7 @@ export class JsonReaderV3 extends AASReader { private readSubmodelElementList( source: aas.SubmodelElementList, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.SubmodelElementCollection { if (!source.typeValueListElement) { throw new Error('SubmodelElement.typeValueListElement'); @@ -497,13 +495,13 @@ export class JsonReaderV3 extends AASReader { } if (source.value) { - list.value = this.readSubmodelElements(source.value, ancestors ? [...ancestors, list] : undefined); + list.value = this.readSubmodelElements(source.value, [...ancestors, list]); } return list; } - private readReferenceElement(source: aas.ReferenceElement, ancestors?: aas.Referable[]): aas.ReferenceElement { + private readReferenceElement(source: aas.ReferenceElement, ancestors: aas.Referable[]): aas.ReferenceElement { const reference: aas.ReferenceElement = { ...this.readSubmodelElementType(source, ancestors), }; @@ -517,7 +515,7 @@ export class JsonReaderV3 extends AASReader { private readRelationshipElement( source: aas.RelationshipElement, - ancestors?: aas.Referable[], + ancestors: aas.Referable[], ): aas.RelationshipElement { if (!source.first) { throw new Error('RelationshipElement.first'); @@ -536,7 +534,7 @@ export class JsonReaderV3 extends AASReader { return relationship; } - private readRange(source: aas.Range, ancestors?: aas.Referable[]): aas.Range { + private readRange(source: aas.Range, ancestors: aas.Referable[]): aas.Range { if (!source.valueType) { throw new Error('Range.valueType'); } diff --git a/projects/aas-server/src/app/packages/opcua/opcua-reader.ts b/projects/aas-server/src/app/packages/opcua/opcua-reader.ts index 2f31165e..cf2c52e6 100644 --- a/projects/aas-server/src/app/packages/opcua/opcua-reader.ts +++ b/projects/aas-server/src/app/packages/opcua/opcua-reader.ts @@ -131,7 +131,7 @@ export class OpcuaReader extends AASReader { return submodel; } - private readSubmodelElements(component: OPCUAComponent, parent?: aas.Reference): aas.SubmodelElement[] { + private readSubmodelElements(component: OPCUAComponent, parent: aas.Reference): aas.SubmodelElement[] { const results = this.where( component.hasComponent, 'AASBlobType', @@ -160,7 +160,7 @@ export class OpcuaReader extends AASReader { return submodelElements; } - private readSubmodelElement(component: OPCUAComponent, parent?: aas.Reference): aas.SubmodelElement | undefined { + private readSubmodelElement(component: OPCUAComponent, parent: aas.Reference): aas.SubmodelElement | undefined { switch (component.typeDefinition) { case 'AASBlobType': break; @@ -220,14 +220,14 @@ export class OpcuaReader extends AASReader { private readSubmodelElementCollection( component: OPCUAComponent, - parent?: aas.Reference, + parent: aas.Reference, ): aas.SubmodelElementCollection { const base = this.readSubmodelElementType(component, parent); const collection: aas.SubmodelElementCollection = { ...base, }; - const value = this.readSubmodelElements(component, parent ? this.createReference(parent, base) : undefined); + const value = this.readSubmodelElements(component, this.createReference(parent, base)); if (value.length > 0) { collection.value = value; } @@ -235,7 +235,7 @@ export class OpcuaReader extends AASReader { return collection; } - private readProperty(component: OPCUAComponent, parent?: aas.Reference): aas.Property { + private readProperty(component: OPCUAComponent, parent: aas.Reference): aas.Property { const value = this.readPropertyValue(component, 'Value'); let valueType = this.readDataTypeDefXsd(this.readPropertyValue(component, 'ValueType')); if (!valueType && value != null) { @@ -259,7 +259,7 @@ export class OpcuaReader extends AASReader { return property; } - private readFile(component: OPCUAComponent, parent?: aas.Reference): aas.File { + private readFile(component: OPCUAComponent, parent: aas.Reference): aas.File { const contentType = this.readStringProperty(component, 'MimeType'); if (!contentType) { throw new Error('File.mimeType'); @@ -283,7 +283,7 @@ export class OpcuaReader extends AASReader { return file; } - private readMultiLanguageProperty(component: OPCUAComponent, parent?: aas.Reference): aas.MultiLanguageProperty { + private readMultiLanguageProperty(component: OPCUAComponent, parent: aas.Reference): aas.MultiLanguageProperty { const langString = this.readLangStringSet(component, 'Value') ?? []; return { ...this.readSubmodelElementType(component, parent), value: langString }; } @@ -298,7 +298,7 @@ export class OpcuaReader extends AASReader { return langStrings; } - private readEntity(component: OPCUAComponent, parent?: aas.Reference): aas.Entity { + private readEntity(component: OPCUAComponent, parent: aas.Reference): aas.Entity { const entityType: aas.EntityType | undefined = this.toEntityType( this.readPropertyValue(component, 'EntityType'), ); @@ -321,7 +321,7 @@ export class OpcuaReader extends AASReader { return entity; } - private readReferenceElement(component: OPCUAComponent, parent?: aas.Reference): aas.ReferenceElement { + private readReferenceElement(component: OPCUAComponent, parent: aas.Reference): aas.ReferenceElement { const value = this.readReference(component, 'Value'); if (!value) { throw new Error('ReferenceElement.value'); @@ -333,7 +333,7 @@ export class OpcuaReader extends AASReader { }; } - private readOperation(component: OPCUAComponent, parent?: aas.Reference): aas.Operation { + private readOperation(component: OPCUAComponent, parent: aas.Reference): aas.Operation { const inputVariables: aas.OperationVariable[] = []; const outputVariables: aas.OperationVariable[] = []; const inoutputVariables: aas.OperationVariable[] = []; @@ -445,7 +445,7 @@ export class OpcuaReader extends AASReader { return { value }; } - private readSubmodelElementType(component: OPCUAComponent, parent?: aas.Reference): aas.SubmodelElement { + private readSubmodelElementType(component: OPCUAComponent, parent: aas.Reference): aas.SubmodelElement { return { ...this.readReferable(component, parent), ...this.readHasSemantic(component), diff --git a/projects/aas-server/src/app/packages/xml-reader-v1.ts b/projects/aas-server/src/app/packages/xml-reader-v1.ts index 21fa4054..1c8140d9 100644 --- a/projects/aas-server/src/app/packages/xml-reader-v1.ts +++ b/projects/aas-server/src/app/packages/xml-reader-v1.ts @@ -122,7 +122,7 @@ export class XmlReaderV1 extends AASReader { private readSubmodel(node: Node): aas.Submodel { const submodel: aas.Submodel = { ...this.readIdentifiable(node), - ...this.readHaSemantic(node), + ...this.readHasSemantics(node), ...this.readQualifiable(node), ...this.readHasKind(node), ...this.readHasDataSpecification(node), @@ -144,7 +144,7 @@ export class XmlReaderV1 extends AASReader { return submodel; } - private readSubmodelElements(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readSubmodelElements(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:submodelElements/aas:submodelElement/*[1]', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -156,7 +156,7 @@ export class XmlReaderV1 extends AASReader { return submodelElements; } - private readCollectionValue(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readCollectionValue(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:value/aas:submodelElement/*[1]', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -168,7 +168,7 @@ export class XmlReaderV1 extends AASReader { return submodelElements; } - private readSubmodelElement(node: Node, parent?: aas.Reference): aas.SubmodelElement | undefined { + private readSubmodelElement(node: Node, parent: aas.Reference): aas.SubmodelElement | undefined { let submodelElement: aas.SubmodelElement | undefined; const modelType = this.getModelTypeFromLocalName(node); switch (modelType) { @@ -210,7 +210,7 @@ export class XmlReaderV1 extends AASReader { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - private readAnnotatedRelationshipElement(node: Node, parent?: aas.Reference): aas.AnnotatedRelationshipElement { + private readAnnotatedRelationshipElement(node: Node, parent: aas.Reference): aas.AnnotatedRelationshipElement { throw new Error('Method not implemented.'); } @@ -219,7 +219,7 @@ export class XmlReaderV1 extends AASReader { throw new Error('Method not implemented.'); } - private readBlob(node: Node, parent?: aas.Reference): aas.Blob { + private readBlob(node: Node, parent: aas.Reference): aas.Blob { const contentType = this.selectNode('./aas:mimeType', node)?.textContent; if (!contentType) { throw new Error('File.mimetype'); @@ -238,17 +238,17 @@ export class XmlReaderV1 extends AASReader { return blob; } - private readSubmodelElementCollection(node: Node, parent?: aas.Reference): aas.SubmodelElementCollection { + private readSubmodelElementCollection(node: Node, parent: aas.Reference): aas.SubmodelElementCollection { const base = this.readSubmodelElementType(node, parent); const collection: aas.SubmodelElementCollection = { ...base, - value: this.readCollectionValue(node, parent ? this.createReference(parent, base) : undefined), + value: this.readCollectionValue(node, this.createReference(parent, base)), }; return collection; } - private readProperty(node: Node, parent?: aas.Reference): aas.Property { + private readProperty(node: Node, parent: aas.Reference): aas.Property { const valueNode = this.selectNode('./aas:value', node); let value = valueNode?.textContent; @@ -285,7 +285,7 @@ export class XmlReaderV1 extends AASReader { throw new Error('Method not implemented.'); } - private readFile(node: Node, parent?: aas.Reference): aas.File { + private readFile(node: Node, parent: aas.Reference): aas.File { let contentType = this.selectNode('./aas:mimeType', node)?.textContent; if (!contentType) { contentType = ''; @@ -304,20 +304,20 @@ export class XmlReaderV1 extends AASReader { return file; } - private readMultiLanguageProperty(node: Node, parent?: aas.Reference): aas.MultiLanguageProperty { + private readMultiLanguageProperty(node: Node, parent: aas.Reference): aas.MultiLanguageProperty { const langString = this.readLangString('./aas:value', node) ?? []; return { ...this.readSubmodelElementType(node, parent), value: langString }; } - private readReferenceElement(node: Node, parent?: aas.Reference): aas.ReferenceElement { + private readReferenceElement(node: Node, parent: aas.Reference): aas.ReferenceElement { const value = this.getReference(node); return { ...this.readSubmodelElementType(node, parent), value }; } - private readSubmodelElementType(node: Node, parent?: aas.Reference): aas.SubmodelElement { + private readSubmodelElementType(node: Node, parent: aas.Reference): aas.SubmodelElement { return { ...this.readReferable(node, undefined, parent), - ...this.readHaSemantic(node), + ...this.readHasSemantics(node), ...this.readHasKind(node), ...this.readHasDataSpecification(node), ...this.readQualifiable(node), @@ -326,7 +326,7 @@ export class XmlReaderV1 extends AASReader { private readIdentifiable(node: Node): aas.Identifiable { const id = this.readIdentifier(node); - const identifiable: aas.Identifiable = { ...this.readReferable(node, id), id }; + const identifiable: aas.Identifiable = { ...this.readReferable(node, id, undefined), id }; const administration = this.readAdministrativeInformation(node); if (administration) { identifiable.administration = administration; @@ -335,7 +335,7 @@ export class XmlReaderV1 extends AASReader { return identifiable; } - private readReferable(node: Node, id?: string, parent?: aas.Reference): aas.Referable { + private readReferable(node: Node, id: string | undefined, parent: aas.Reference | undefined): aas.Referable { let idShort = this.selectNode('./aas:idShort', node)?.textContent; if (!idShort) { idShort = id ? this.createIdShort(id) : ''; @@ -358,7 +358,7 @@ export class XmlReaderV1 extends AASReader { return referable; } - private readHaSemantic(node: Node): aas.HasSemantics { + private readHasSemantics(node: Node): aas.HasSemantics { const semanticId = this.readReference('./aas:semanticId', node); return semanticId ? { semanticId } : {}; } diff --git a/projects/aas-server/src/app/packages/xml-reader-v2.ts b/projects/aas-server/src/app/packages/xml-reader-v2.ts index ec4d8899..cbaccabd 100644 --- a/projects/aas-server/src/app/packages/xml-reader-v2.ts +++ b/projects/aas-server/src/app/packages/xml-reader-v2.ts @@ -144,7 +144,7 @@ export class XmlReaderV2 extends AASReader { return submodel; } - private readSubmodelElements(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readSubmodelElements(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:submodelElements/aas:submodelElement/*[1]', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -156,7 +156,7 @@ export class XmlReaderV2 extends AASReader { return submodelElements; } - private readCollectionValue(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readCollectionValue(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:value/aas:submodelElement/*[1]', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -168,7 +168,7 @@ export class XmlReaderV2 extends AASReader { return submodelElements; } - private readSubmodelElement(node: Node, parent?: aas.Reference): aas.SubmodelElement | undefined { + private readSubmodelElement(node: Node, parent: aas.Reference): aas.SubmodelElement | undefined { let submodelElement: aas.SubmodelElement | undefined; const modelType = this.getModelTypeFromLocalName(node); switch (modelType) { @@ -213,7 +213,7 @@ export class XmlReaderV2 extends AASReader { } // eslint-disable-next-line @typescript-eslint/no-unused-vars - private readAnnotatedRelationshipElement(node: Node, parent?: aas.Reference): aas.AnnotatedRelationshipElement { + private readAnnotatedRelationshipElement(node: Node, parent: aas.Reference): aas.AnnotatedRelationshipElement { throw new Error('Method not implemented.'); } @@ -222,7 +222,7 @@ export class XmlReaderV2 extends AASReader { throw new Error('Method not implemented.'); } - private readBlob(node: Node, parent?: aas.Reference): aas.Blob { + private readBlob(node: Node, parent: aas.Reference): aas.Blob { const contentType = this.selectNode('./aas:mimeType', node)?.textContent; if (!contentType) { throw new Error('File.mimetype'); @@ -241,7 +241,7 @@ export class XmlReaderV2 extends AASReader { return blob; } - private readEntity(node: Node, parent?: aas.Reference): aas.Entity { + private readEntity(node: Node, parent: aas.Reference): aas.Entity { const entityType = this.selectNode('./aas:entityType', node)?.textContent as aas.EntityType; if (!entityType) { throw new Error('File.contentType'); @@ -262,7 +262,7 @@ export class XmlReaderV2 extends AASReader { entity.specificAssetIds = specificAssetIds; } - const statements = this.readStatements(node, parent ? this.createReference(parent, entity) : undefined); + const statements = this.readStatements(node, this.createReference(parent, entity)); if (statements.length > 0) { entity.statements = statements; } @@ -270,7 +270,7 @@ export class XmlReaderV2 extends AASReader { return entity; } - private readStatements(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readStatements(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const statements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:statements/*', node)) { const se = this.selectNode('./*[1]', child); @@ -321,17 +321,17 @@ export class XmlReaderV2 extends AASReader { return value; } - private readSubmodelElementCollection(node: Node, parent?: aas.Reference): aas.SubmodelElementCollection { + private readSubmodelElementCollection(node: Node, parent: aas.Reference): aas.SubmodelElementCollection { const base = this.readSubmodelElementType(node, parent); const collection: aas.SubmodelElementCollection = { ...base, - value: this.readCollectionValue(node, parent ? this.createReference(parent, base) : undefined), + value: this.readCollectionValue(node, this.createReference(parent, base)), }; return collection; } - private readProperty(node: Node, parent?: aas.Reference): aas.Property { + private readProperty(node: Node, parent: aas.Reference): aas.Property { const valueNode = this.selectNode('./aas:value', node); let value = valueNode?.textContent; @@ -358,7 +358,7 @@ export class XmlReaderV2 extends AASReader { return property; } - private readRange(node: Node, parent?: aas.Reference): aas.Range { + private readRange(node: Node, parent: aas.Reference): aas.Range { const range: aas.Range = { ...this.readSubmodelElementType(node, parent), valueType: this.getTextContent('./aas:valueType', node) as aas.DataTypeDefXsd, @@ -377,7 +377,7 @@ export class XmlReaderV2 extends AASReader { return range; } - private readRelationshipElement(node: Node, parent?: aas.Reference): aas.RelationshipElement { + private readRelationshipElement(node: Node, parent: aas.Reference): aas.RelationshipElement { const first = this.readReference('./aas:first', node); if (!first) { throw new Error('RelationshipElement.first'); @@ -395,7 +395,7 @@ export class XmlReaderV2 extends AASReader { }; } - private readFile(node: Node, parent?: aas.Reference): aas.File { + private readFile(node: Node, parent: aas.Reference): aas.File { let contentType = this.selectNode('./aas:mimeType', node)?.textContent; if (!contentType) { contentType = ''; @@ -414,17 +414,17 @@ export class XmlReaderV2 extends AASReader { return file; } - private readMultiLanguageProperty(node: Node, parent?: aas.Reference): aas.MultiLanguageProperty { + private readMultiLanguageProperty(node: Node, parent: aas.Reference): aas.MultiLanguageProperty { const langString = this.readLangString('./aas:value', node) ?? []; return { ...this.readSubmodelElementType(node, parent), value: langString }; } - private readReferenceElement(node: Node, parent?: aas.Reference): aas.ReferenceElement { + private readReferenceElement(node: Node, parent: aas.Reference): aas.ReferenceElement { const value = this.getReference(node); return { ...this.readSubmodelElementType(node, parent), value }; } - private readSubmodelElementType(node: Node, parent?: aas.Reference): aas.SubmodelElement { + private readSubmodelElementType(node: Node, parent: aas.Reference): aas.SubmodelElement { return { ...this.readReferable(node, undefined, parent), ...this.readHasSemantics(node), @@ -436,7 +436,7 @@ export class XmlReaderV2 extends AASReader { private readIdentifiable(node: Node): aas.Identifiable { const id = this.readIdentifier(node); - const identifiable: aas.Identifiable = { ...this.readReferable(node, id), id }; + const identifiable: aas.Identifiable = { ...this.readReferable(node, id, undefined), id }; const administration = this.readAdministrativeInformation(node); if (administration) { identifiable.administration = administration; @@ -445,7 +445,7 @@ export class XmlReaderV2 extends AASReader { return identifiable; } - private readReferable(node: Node, id?: string, parent?: aas.Reference): aas.Referable { + private readReferable(node: Node, id: string | undefined, parent: aas.Reference | undefined): aas.Referable { let idShort = this.selectNode('./aas:idShort', node)?.textContent; if (!idShort) { idShort = id ? this.createIdShort(id) : ''; diff --git a/projects/aas-server/src/app/packages/xml-reader-v3.ts b/projects/aas-server/src/app/packages/xml-reader-v3.ts index 732269a3..f4fa73dc 100644 --- a/projects/aas-server/src/app/packages/xml-reader-v3.ts +++ b/projects/aas-server/src/app/packages/xml-reader-v3.ts @@ -208,7 +208,7 @@ export class XmlReaderV3 extends AASReader { return submodel; } - private readSubmodelElements(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readSubmodelElements(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:submodelElements/*', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -220,7 +220,7 @@ export class XmlReaderV3 extends AASReader { return submodelElements; } - private readSubmodelElement(node: Node, parent?: aas.Reference): aas.SubmodelElement | undefined { + private readSubmodelElement(node: Node, parent: aas.Reference): aas.SubmodelElement | undefined { let submodelElement: aas.SubmodelElement | undefined; const modelType = this.getModelTypeFromLocalName(node); switch (modelType) { @@ -242,6 +242,9 @@ export class XmlReaderV3 extends AASReader { case 'MultiLanguageProperty': submodelElement = this.readMultiLanguageProperty(node, parent); break; + case 'Operation': + submodelElement = this.readOperation(node, parent); + break; case 'Property': submodelElement = this.readProperty(node, parent); break; @@ -267,7 +270,7 @@ export class XmlReaderV3 extends AASReader { return submodelElement; } - private readAnnotatedRelationshipElement(node: Node, parent?: aas.Reference): aas.AnnotatedRelationshipElement { + private readAnnotatedRelationshipElement(node: Node, parent: aas.Reference): aas.AnnotatedRelationshipElement { const base = this.readSubmodelElementType(node, parent); const first = this.readReference(this.selectNode('./aas:first', node)); if (!first) { @@ -279,7 +282,7 @@ export class XmlReaderV3 extends AASReader { throw new Error('RelationshipElement.second'); } - const annotations = this.readAnnotations(node, parent ? this.createReference(parent, base) : undefined); + const annotations = this.readAnnotations(node, this.createReference(parent, base)); return { ...base, @@ -289,7 +292,7 @@ export class XmlReaderV3 extends AASReader { }; } - private readAnnotations(node: Node, parent?: aas.Reference): aas.DataElement[] { + private readAnnotations(node: Node, parent: aas.Reference): aas.DataElement[] { const dataElements: aas.DataElement[] = []; for (const child of this.selectNodes('./aas:annotations/*', node)) { const dataElement = this.readDataElement(child, parent); @@ -301,7 +304,7 @@ export class XmlReaderV3 extends AASReader { return dataElements; } - private readDataElement(node: Node, parent?: aas.Reference): aas.DataElement | undefined { + private readDataElement(node: Node, parent: aas.Reference): aas.DataElement | undefined { let dataElement: aas.DataElement | undefined; const modelType = this.getModelTypeFromLocalName(node); switch (modelType) { @@ -330,7 +333,7 @@ export class XmlReaderV3 extends AASReader { return dataElement; } - private readBasicEventElement(node: Node, parent?: aas.Reference): aas.BasicEventElement { + private readBasicEventElement(node: Node, parent: aas.Reference): aas.BasicEventElement { const observed = this.readReference(this.selectNode('./aas:observed', node)); if (!observed) { throw new Error('BasicEventElement.observed'); @@ -381,7 +384,7 @@ export class XmlReaderV3 extends AASReader { return basicEvent; } - private readEntity(node: Node, parent?: aas.Reference): aas.Entity { + private readEntity(node: Node, parent: aas.Reference): aas.Entity { const entityType = this.selectNode('./aas:entityType', node)?.textContent as aas.EntityType; if (!entityType) { throw new Error('File.contentType'); @@ -402,7 +405,7 @@ export class XmlReaderV3 extends AASReader { entity.specificAssetIds = specificAssetIds; } - const statements = this.readStatements(node, parent ? this.createReference(parent, entity) : undefined); + const statements = this.readStatements(node, this.createReference(parent, entity)); if (statements.length > 0) { entity.statements = statements; } @@ -410,7 +413,7 @@ export class XmlReaderV3 extends AASReader { return entity; } - private readStatements(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readStatements(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const statements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:statements/*', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -422,7 +425,7 @@ export class XmlReaderV3 extends AASReader { return statements; } - private readBlob(node: Node, parent?: aas.Reference): aas.Blob { + private readBlob(node: Node, parent: aas.Reference): aas.Blob { const contentType = this.selectNode('./aas:contentType', node)?.textContent; if (!contentType) { throw new Error('File.contentType'); @@ -441,28 +444,28 @@ export class XmlReaderV3 extends AASReader { return blob; } - private readSubmodelElementCollection(node: Node, parent?: aas.Reference): aas.SubmodelElementCollection { + private readSubmodelElementCollection(node: Node, parent: aas.Reference): aas.SubmodelElementCollection { const base = this.readSubmodelElementType(node, parent); const collection: aas.SubmodelElementCollection = { ...base, - value: this.readCollectionValue(node, parent ? this.createReference(parent, base) : undefined), + value: this.readCollectionValue(node, this.createReference(parent, base)), }; return collection; } - private readSubmodelElementList(node: Node, parent?: aas.Reference): aas.SubmodelElementList { + private readSubmodelElementList(node: Node, parent: aas.Reference): aas.SubmodelElementList { const base = this.readSubmodelElementType(node, parent); const list: aas.SubmodelElementList = { ...base, - value: this.readCollectionValue(node, parent ? this.createReference(parent, base) : undefined), + value: this.readCollectionValue(node, this.createReference(parent, base)), typeValueListElement: this.getTextContent('./aas:typeValueListElement', node) as aas.AASSubmodelElements, }; return list; } - private readCollectionValue(node: Node, parent?: aas.Reference): aas.SubmodelElement[] { + private readCollectionValue(node: Node, parent: aas.Reference): aas.SubmodelElement[] { const submodelElements: aas.SubmodelElement[] = []; for (const child of this.selectNodes('./aas:value/*', node)) { const submodelElement = this.readSubmodelElement(child, parent); @@ -474,7 +477,7 @@ export class XmlReaderV3 extends AASReader { return submodelElements; } - private readProperty(node: Node, parent?: aas.Reference): aas.Property { + private readProperty(node: Node, parent: aas.Reference): aas.Property { const valueNode = this.selectNode('./aas:value', node); let value = valueNode?.textContent; @@ -501,7 +504,7 @@ export class XmlReaderV3 extends AASReader { return property; } - private readRange(node: Node, parent?: aas.Reference): aas.Range { + private readRange(node: Node, parent: aas.Reference): aas.Range { const range: aas.Range = { ...this.readSubmodelElementType(node, parent), valueType: this.getTextContent('./aas:valueType', node) as aas.DataTypeDefXsd, @@ -520,7 +523,7 @@ export class XmlReaderV3 extends AASReader { return range; } - private readRelationshipElement(node: Node, parent?: aas.Reference): aas.RelationshipElement { + private readRelationshipElement(node: Node, parent: aas.Reference): aas.RelationshipElement { const first = this.readReference(this.selectNode('./aas:first', node)); if (!first) { throw new Error('RelationshipElement.first'); @@ -538,7 +541,7 @@ export class XmlReaderV3 extends AASReader { }; } - private readFile(node: Node, parent?: aas.Reference): aas.File { + private readFile(node: Node, parent: aas.Reference): aas.File { let contentType = this.selectNode('./aas:mimeType', node)?.textContent; const value = this.selectNode('./aas:value', node)?.textContent; if (!contentType && value) { @@ -564,12 +567,79 @@ export class XmlReaderV3 extends AASReader { return file; } - private readMultiLanguageProperty(node: Node, parent?: aas.Reference): aas.MultiLanguageProperty { + private readMultiLanguageProperty(node: Node, parent: aas.Reference): aas.MultiLanguageProperty { const value = this.readLangStrings('./aas:value', node) ?? []; return { ...this.readSubmodelElementType(node, parent), value }; } - private readReferenceElement(node: Node, parent?: aas.Reference): aas.ReferenceElement { + private readOperation(node: Node, parent: aas.Reference): aas.Operation { + const operation: aas.Operation = { + ...this.readSubmodelElementType(node, parent), + }; + + const inputVariablesElement = this.selectNode('./aas:inputVariables', node); + if (inputVariablesElement) { + const inputVariables = this.readOperationVariables( + inputVariablesElement, + this.createReference(parent, operation), + ); + + if (inputVariables) { + operation.inputVariables = inputVariables; + } + } + + const inoutputVariablesElement = this.selectNode('./aas:inoutputVariables', node); + if (inoutputVariablesElement) { + const inoutputVariables = this.readOperationVariables( + inoutputVariablesElement, + this.createReference(parent, operation), + ); + + if (inoutputVariables) { + operation.inoutputVariables = inoutputVariables; + } + } + + const outputVariablesElement = this.selectNode('./aas:outputVariables', node); + if (outputVariablesElement) { + const outputVariables = this.readOperationVariables( + outputVariablesElement, + this.createReference(parent, operation), + ); + + if (outputVariables) { + operation.outputVariables = outputVariables; + } + } + + return operation; + } + + private readOperationVariables(node: Node, parent: aas.Reference): aas.OperationVariable[] { + const variables: aas.OperationVariable[] = []; + for (const element of this.selectNodes('./aas:operationVariable', node)) { + const variable = this.readOperationVariable(element, parent); + if (variable) { + variables.push(variable); + } + } + + return variables; + } + + private readOperationVariable(node: Node, parent: aas.Reference): aas.OperationVariable | undefined { + for (const element of this.selectNodes('./aas:value/*', node)) { + const value = this.readSubmodelElement(element, parent); + if (value) { + return { value }; + } + } + + return undefined; + } + + private readReferenceElement(node: Node, parent: aas.Reference): aas.ReferenceElement { const reference: aas.ReferenceElement = { ...this.readSubmodelElementType(node, parent), }; @@ -582,7 +652,7 @@ export class XmlReaderV3 extends AASReader { return reference; } - private readSubmodelElementType(node: Node, parent?: aas.Reference): aas.SubmodelElement { + private readSubmodelElementType(node: Node, parent: aas.Reference): aas.SubmodelElement { return { ...this.readReferable(node, undefined, parent), ...this.readHasSemantics(node), @@ -594,7 +664,7 @@ export class XmlReaderV3 extends AASReader { private readIdentifiable(node: Node): aas.Identifiable { const id = this.getTextContent('./aas:id', node); - const identifiable: aas.Identifiable = { ...this.readReferable(node, id), id }; + const identifiable: aas.Identifiable = { ...this.readReferable(node, id, undefined), id }; const administration = this.readAdministrativeInformation(this.selectNode('./aas:administration', node)); if (administration) { @@ -604,7 +674,7 @@ export class XmlReaderV3 extends AASReader { return identifiable; } - private readReferable(node: Node, id?: string, parent?: aas.Reference): aas.Referable { + private readReferable(node: Node, id: string | undefined, parent: aas.Reference | undefined): aas.Referable { let idShort = this.selectTextContent('./aas:idShort', node); if (!idShort) { idShort = id ? this.createIdShort(id) : ''; diff --git a/projects/aas-server/src/test/assets/xml/v3/operation.xml b/projects/aas-server/src/test/assets/xml/v3/operation.xml new file mode 100644 index 00000000..ba25d2ba --- /dev/null +++ b/projects/aas-server/src/test/assets/xml/v3/operation.xml @@ -0,0 +1,131 @@ + + + + something_48c66017 + + + + + something_aa1af8b3 + + + something_d7cf2dff + PiXO1wyHierj + + + zh-CN-a-myext-x-private + something_535aeb51 + + + + + es-419 + something_be9deae0 + + + + ExternalReference + + + GlobalReference + urn:something00:f4547d0c + + + + + + ModelReference + + + Submodel + urn:another-example10:42487f5a + + + + + + + something_500f973e + xs:long + + + + + + + + + sl-rozaj-biske + something_7e795ee2 + + + en-GB + Something random in English c8512bdf + + + something_4e9c19b7 + + + + ModelReference + + + Submodel + urn:another-company15:2bd0986b + + + + + + + + + + something_c8b0a9a0 + SelfManagedEntity + urn:an-example03:cc3a7d47 + + + + + + + + + something_0921a907 + + ModelReference + + + Submodel + urn:another-example04:27451000 + + + + + ModelReference + + + Submodel + urn:example03:74d93fcf + + + + + + + + + + + + something_89e4ed5f + + + + + + + + + \ No newline at end of file diff --git a/projects/aas-server/src/test/packages/server-message.spec.ts b/projects/aas-server/src/test/packages/server-message.spec.ts index e0b31163..6b1decc4 100644 --- a/projects/aas-server/src/test/packages/server-message.spec.ts +++ b/projects/aas-server/src/test/packages/server-message.spec.ts @@ -133,7 +133,7 @@ describe('ServerMessage', function () { it('validates a connection', async function () { socket.on.mockImplementation((event, listener) => { - if (event === 'connect') { + if (event === 'end') { setTimeout(() => (listener as () => void)()); } diff --git a/projects/aas-server/src/test/packages/xml-reader-v3.spec.ts b/projects/aas-server/src/test/packages/xml-reader-v3.spec.ts index 5216a5c4..87d94ace 100644 --- a/projects/aas-server/src/test/packages/xml-reader-v3.spec.ts +++ b/projects/aas-server/src/test/packages/xml-reader-v3.spec.ts @@ -6,31 +6,46 @@ * *****************************************************************************/ -import { describe, beforeAll, beforeEach, it, expect } from '@jest/globals'; +import { describe, beforeEach, expect, it } from '@jest/globals'; import { readFile } from 'fs/promises'; import { resolve } from 'path/posix'; +import { aas } from 'aas-core'; import { XmlReaderV3 } from '../../app/packages/xml-reader-v3.js'; -describe('XmlReaderV3', function () { +describe('XmlReaderV3', () => { let reader: XmlReaderV3; let xml: string; let path: string; - beforeAll(async function () { - path = resolve('./src/test/assets/aas-example-v3.xml'); - xml = (await readFile(path)).toString(); - }); + // beforeEach(async () => { + // path = resolve('./src/test/assets/aas-example-v3.xml'); + // xml = (await readFile(path)).toString(); + // reader = new XmlReaderV3(xml); + // }); - beforeEach(function () { - reader = new XmlReaderV3(xml); - }); + // it('should be created', function () { + // expect(reader).toBeTruthy(); + // }); - it('should be created', function () { - expect(reader).toBeTruthy(); - }); + // it('reads the AAS environment from a xml source', function () { + // const environment = reader.readEnvironment(); + // expect(environment).toBeDefined(); + // }); + + describe('read Operation', () => { + beforeEach(async () => { + path = resolve('./src/test/assets/xml/v3/operation.xml'); + xml = (await readFile(path)).toString(); + reader = new XmlReaderV3(xml); + }); - it('reads the AAS environment from a xml source', function () { - const environment = reader.readEnvironment(); - expect(environment).toBeDefined(); + it('reads an Operation element', () => { + const env = reader.readEnvironment(); + const operation = env.submodels![0].submodelElements![0] as aas.Operation; + expect(operation.modelType === 'Operation').toBeTruthy(); + expect(operation.inputVariables?.length).toEqual(1); + expect(operation.inoutputVariables?.length).toEqual(1); + expect(operation.outputVariables?.length).toEqual(1); + }); }); });