Skip to content

Commit

Permalink
Add test for loading rawx
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Sep 29, 2023
1 parent 379c3e7 commit c9411c2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/main/Solver.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
package com.github.statnett.loadflowservice

import com.powsybl.cgmes.conversion.CgmesImport
import com.powsybl.ieeecdf.converter.IeeeCdfImporter
import com.powsybl.iidm.network.ImportersLoader
import com.powsybl.iidm.network.ImportersLoaderList
import com.powsybl.iidm.network.Network
import com.powsybl.iidm.xml.XMLImporter
import com.powsybl.loadflow.LoadFlow
import com.powsybl.loadflow.LoadFlowParameters
import com.powsybl.loadflow.json.JsonLoadFlowParameters
import com.powsybl.matpower.converter.MatpowerImporter
import com.powsybl.powerfactory.converter.PowerFactoryImporter
import com.powsybl.psse.converter.PsseImporter
import com.powsybl.ucte.converter.UcteImporter
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream

fun networkFromStream(
fname: String,
filename: String,
content: InputStream,
): Network {
return Network.read(fname, content)
val importerLoader = ImportersLoaderList(
PsseImporter(), XMLImporter(), CgmesImport(),
IeeeCdfImporter(), UcteImporter(),
MatpowerImporter(), PowerFactoryImporter()
)
return Network.read(filename, content)
}

fun networkFromFileContent(content: FileContent): Network {
Expand Down
43 changes: 41 additions & 2 deletions src/test/AppTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ApplicationTest {
}

@TestFactory
fun `test internal server error when file parsing fails`() = listOf(
fun `test internal server error when file parsing fails`() = listOf(
"/buses",
"/run-load-flow",
"/substation-names",
Expand Down Expand Up @@ -208,6 +208,19 @@ class ApplicationTest {
assertTrue(isPlausibleSvg(body))
assertEquals(response.headers["Content-Type"].toString(), "image/svg+xml")
}

@Test
fun `test read rawx`() =
testApplication {
val response = client.submitFormWithBinaryData(
url = "/buses",
formData = formDataMinimalNetworkRawx()
)
assertEquals(HttpStatusCode.OK, response.status)
val body = response.bodyAsText()
val num = body.split("},{").size
assertEquals(2, num)
}
}

fun formDataFromFile(file: File): List<PartData> {
Expand Down Expand Up @@ -247,4 +260,30 @@ fun ieeeCdfNetwork14File(): File {
// is a valid svg image
fun isPlausibleSvg(body: String): Boolean {
return body.contains("<svg") && body.contains("<?xml version")
}
}

fun formDataMinimalNetworkRawx(): List<PartData> {
return formData {
append(
"network",
minimalRawx(),
Headers.build {
append(HttpHeaders.ContentDisposition, "filename=network.rawx")
}
)
}
}

fun minimalRawx(): ByteArray {
return ("{\"network\":{\"caseid\":{" +
"\"fields\":[\"ic\",\"sbase\",\"rev\",\"xfrrat\",\"nxfrat\",\"basfrq\",\"title1\"]," +
"\"data\":[0,100.00,35,0,0,60.00,\"PSS(R)EMinimumRAWXCase\"]}," +
"\"bus\":{\"fields\":[\"ibus\",\"name\",\"baskv\",\"ide\"]," +
"\"data\":[[1,\"Slack-Bus\",138.0,3],[2,\"Load-Bus\",138.01]]}," +
"\"load\":{\"fields\":[\"ibus\",\"loadid\",\"stat\",\"pl\",\"ql\"]," +
"\"data\":[[2,\"1\",1,40.0,15.0]]}," +
"\"generator\":{\"fields\":[\"ibus\",\"machid\",\"pg\",\"qg\"]," +
"\"data\":[[1,\"1\",\"40.35\",\"10.87\"]]}," +
"\"acline\":{\"fields\":[\"ibus\",\"jbus\",\"ckt\",\"rpu\",\"xpu\",\"bpu\"]," +
"\"data\":[[1,2,\"1\",0.01938,0.05917,0.05280]]}}}").toByteArray()
}

0 comments on commit c9411c2

Please sign in to comment.