Skip to content

Commit

Permalink
Merge pull request #422 from statisticsnorway/Barnevern_bugfix_xsd
Browse files Browse the repository at this point in the history
Barnevern: Add TiltaksgrunnlagType
  • Loading branch information
jonolehagemo authored Jan 12, 2024
2 parents 6501801 + e4138c6 commit 5f8f718
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ data class KostraTiltakType(
@field:XmlElement(name = "Kategori", required = true)
val kategori: KostraKategoriType,

@field:JacksonXmlProperty(localName = "Tiltaksgrunnlag")
@field:JacksonXmlElementWrapper(useWrapping = false)
val tiltaksgrunnlag: MutableList<KostraTiltaksgrunnlagType> = mutableListOf(),

@field:XmlElement(name = "Lovhjemmel", required = true)
val lovhjemmel: KostraLovhjemmelType,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package no.ssb.kostra.barnevern.xsd

import jakarta.xml.bind.annotation.*

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TiltaksgrunnlagType", propOrder = ["presisering"])
data class KostraTiltaksgrunnlagType(

@field:XmlAttribute(name = "Kode", required = true)
val kode: String,

@field:XmlElement(name = "Presisering")
val presisering: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import no.ssb.kostra.barnevern.KostraValidationUtils.getSchemaValidator
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.EMPTY_DATE_ERROR
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.EMPTY_ID_ERROR
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.INVALID_DATE_ERROR
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.JMFR_LOVHJEMMEL_XML
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.LOVHJEMMEL_XML
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.TOO_LONG_ID_ERROR
import no.ssb.kostra.barnevern.xsd.XsdTestUtils.buildIndividXml
Expand All @@ -21,7 +22,7 @@ class TiltakTypeTest : BehaviorSpec({
Given("misc TiltakType XML") {

/** make sure it's possible to make a valid test XML */
When("valid XML, expect no exceptions") {
When("minimal valid XML, expect no exceptions") {
shouldNotThrowAny {
getSchemaValidator(INDIVID_XSD_RESOURCE).validate(
buildIndividXml(
Expand All @@ -34,6 +35,23 @@ class TiltakTypeTest : BehaviorSpec({
}
}

/** make sure it's possible to make a valid test XML */
When("maximal valid XML, expect no exceptions") {
shouldNotThrowAny {
getSchemaValidator(INDIVID_XSD_RESOURCE).validate(
buildIndividXml(
"<Tiltak Id=\"42\" StartDato=\"2022-11-14\" SluttDato=\"2022-11-15\">" +
LOVHJEMMEL_XML +
JMFR_LOVHJEMMEL_XML +
"<Kategori Kode=\"1.1\"/>" +
"<Tiltaksgrunnlag Kode=\"1\"/>" +
"<Opphevelse Kode=\"4\"><Presisering>~presisering~</Presisering></Opphevelse>" +
"</Tiltak>"
).toStreamSource()
)
}
}

forAll(
/** Id */
row(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fun String.toStreamSource() = StreamSource(StringReader(this))
object XsdTestUtils {

const val LOVHJEMMEL_XML = "<Lovhjemmel Lov=\"BVL\" Kapittel=\"4\" Paragraf=\"8\" Ledd=\"3\"/>"
const val JMFR_LOVHJEMMEL_XML = "<JmfrLovhjemmel Lov=\"BVL\" Kapittel=\"4\" Paragraf=\"8\" Ledd=\"2\"/>"

const val EMPTY_DATE_ERROR = "cvc-datatype-valid.1.2.1: '' is not a valid value for 'date'."
const val INVALID_DATE_ERROR = "cvc-datatype-valid.1.2.1: '2022' is not a valid value for 'date'."
Expand Down

0 comments on commit 5f8f718

Please sign in to comment.