|
| 1 | +import { expect } from "chai"; |
| 2 | + |
| 3 | +import { Server } from "./Server.js"; |
| 4 | + |
| 5 | +const scl = new DOMParser().parseFromString( |
| 6 | + `<SCL xmlns="http://www.iec.ch/61850/2003/SCL" > |
| 7 | + <IED name="IED1"> |
| 8 | + <AccessPoint name="AP1"> |
| 9 | + <Server timeout="30"> |
| 10 | + <Authentication /> |
| 11 | + <LDevice inst="lDevice1"> |
| 12 | + <LN0 lnClass="LLN0" inst="" lnType="LLN0" /> |
| 13 | + <LN lnClass="MMXU" inst="1" lnType="MMXU" /> |
| 14 | + <LN lnClass="MMXU" inst="2" lnType="MMXU" /> |
| 15 | + </LDevice> |
| 16 | + <LDevice inst="lDevice2"> |
| 17 | + <LN0 lnClass="LLN0" inst="" lnType="LLN0" /> |
| 18 | + <LN lnClass="MMXU" inst="1" lnType="MMXU" /> |
| 19 | + </LDevice> |
| 20 | + <Association iedName="IED3" ldInst="lDevice2" lnClass="LLN0" lnInst="" kind="pre-established" associationId="someId" /> |
| 21 | + <Association iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="1" kind="predefined" associationId="someId" /> |
| 22 | + <Association desc="" iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="2" kind="predefined" associationId="someId" /> |
| 23 | + <Association desc="" iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="2" kind="predefined" associationId="someId" /> |
| 24 | + </Server> |
| 25 | + </AccessPoint> |
| 26 | + </IED> |
| 27 | + <IED name="IED2"> |
| 28 | + <AccessPoint name="AP1"> |
| 29 | + <Server> |
| 30 | + <Authentication none="true" password="false" weak="false" strong="false" certificate="false" /> |
| 31 | + <LDevice inst="lDevice2"> |
| 32 | + <LN0 lnClass="LLN0" inst="" lnType="LLN0" /> |
| 33 | + <LN lnClass="MMXU" inst="1" lnType="MMXU" /> |
| 34 | + </LDevice> |
| 35 | + <LDevice inst="lDevice1"> |
| 36 | + <LN0 lnClass="LLN0" inst="" lnType="LLN0" /> |
| 37 | + <LN lnClass="MMXU" inst="2" lnType="MMXU" /> |
| 38 | + <LN lnClass="MMXU" inst="1" lnType="MMXU" /> |
| 39 | + </LDevice> |
| 40 | + <Association iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="1" /> |
| 41 | + <Association desc="" iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="1" kind="predefined" associationId="someId" /> |
| 42 | + <Association iedName="IED3" ldInst="lDevice2" lnClass="LLN0" lnInst="" kind="pre-established" associationId="someId" /> |
| 43 | + <Association desc="" iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="2" kind="predefined" associationId="someId" /> |
| 44 | + <Association desc="" iedName="IED3" ldInst="lDevice2" lnClass="MMXU" lnInst="2" kind="predefined" associationId="someId" /> |
| 45 | + </Server> |
| 46 | + </AccessPoint> |
| 47 | + </IED> |
| 48 | + <IED name="IED3"> |
| 49 | + <AccessPoint name="AP1"> |
| 50 | + <Server timeout="13"> |
| 51 | + <Authentication none="false" password="true" weak="true" strong="true" certificate="true" /> |
| 52 | + <LDevice inst="lDevice1"> |
| 53 | + <LN0 lnClass="LLN0" inst="" lnType="LLN02" /> |
| 54 | + <LN lnClass="MMXU" inst="2" lnType="MMXU" /> |
| 55 | + </LDevice> |
| 56 | + </Server> |
| 57 | + </AccessPoint> |
| 58 | + </IED> |
| 59 | + <IED name="IED4"> |
| 60 | + <AccessPoint name="AP1"> |
| 61 | + <Server timeout="13"> |
| 62 | + <LDevice inst="lDevice1"> |
| 63 | + <LN0 lnClass="LLN0" inst="" lnType="LLN02" /> |
| 64 | + <LN lnClass="MMXU" inst="2" lnType="MMXU" /> |
| 65 | + </LDevice> |
| 66 | + </Server> |
| 67 | + </AccessPoint> |
| 68 | + </IED> |
| 69 | + <DataTypeTemplates> |
| 70 | + <LNodeType id="LLN0" desc="desc" lnClass="LLN0"> |
| 71 | + <DO name="Beh" type="BehENS"/> |
| 72 | + </LNodeType> |
| 73 | + <LNodeType id="MMXU" desc="desc" lnClass="MMXU"> |
| 74 | + <DO name="A" type="WYE"/> |
| 75 | + </LNodeType> |
| 76 | + <DOType cdc="ENS" id="BehENS" > |
| 77 | + <DA name="stVal" bType="Enum" type="BehModKind" fc="ST" > |
| 78 | + <Val>off</Val> |
| 79 | + </DA> |
| 80 | + </DOType> |
| 81 | + <DOType id="WYE" cdc="WYE"> |
| 82 | + <SDO name="phsA" type="CMV" /> |
| 83 | + </DOType> |
| 84 | + <DOType id="CMV" cdc="CMV" > |
| 85 | + <DA name="cVal" bType="Struct" fc="MX" type="Vector"/> |
| 86 | + </DOType> |
| 87 | + <DAType id="Vector" > |
| 88 | + <BDA name="mag" bType="Struct" type="AnalogueValue" /> |
| 89 | + </DAType> |
| 90 | + <DAType id="AnalogueValue" > |
| 91 | + <BDA name="f" bType="FLOAT32" > |
| 92 | + <Val sGroup="3">60.60</Val> |
| 93 | + <Val sGroup="1">10.10</Val> |
| 94 | + <Val sGroup="2">40.10</Val> |
| 95 | + </BDA> |
| 96 | + </DAType> |
| 97 | + <EnumType id="BehModKind" > |
| 98 | + <EnumVal ord="1">on</EnumVal> |
| 99 | + <EnumVal ord="3">test</EnumVal> |
| 100 | + <EnumVal ord="5">off</EnumVal> |
| 101 | + </EnumType> |
| 102 | + </DataTypeTemplates> |
| 103 | + </SCL>`, |
| 104 | + "application/xml", |
| 105 | +); |
| 106 | + |
| 107 | +const baseServer = scl.querySelector('IED[name="IED1"] Server')!; |
| 108 | +const equalServer = scl.querySelector('IED[name="IED2"] Server')!; |
| 109 | +const diffServer = scl.querySelector('IED[name="IED3"] Server')!; |
| 110 | +const invalidServer = scl.querySelector('IED[name="IED4"] Server')!; |
| 111 | + |
| 112 | +describe("Description for SCL schema type LDevice", () => { |
| 113 | + it("returns undefined with missing lnType attribute", () => |
| 114 | + expect(Server(invalidServer)).to.be.undefined); |
| 115 | + |
| 116 | + it("default timeout attribute if present", () => |
| 117 | + expect(Server(equalServer)?.timeout).to.equal(30)); |
| 118 | + |
| 119 | + it("default timeout attribute if present", () => |
| 120 | + expect(Server(diffServer)?.timeout).to.equal(13)); |
| 121 | + |
| 122 | + it("returns same description with semantically equal LDevice's", () => |
| 123 | + expect(JSON.stringify(Server(baseServer))).to.equal( |
| 124 | + JSON.stringify(Server(equalServer)), |
| 125 | + )); |
| 126 | + |
| 127 | + it("returns different description with unequal LDevice elements", () => |
| 128 | + expect(JSON.stringify(Server(baseServer))).to.not.equal( |
| 129 | + JSON.stringify(Server(diffServer)), |
| 130 | + )); |
| 131 | +}); |
0 commit comments