Skip to content

Commit

Permalink
Updated tests, fixed a bug with a SPEC subject not marked as an subje…
Browse files Browse the repository at this point in the history
…ct_area.
  • Loading branch information
Stefan Jonasson authored and Stefan Jonasson committed Nov 29, 2019
1 parent 1cc70c3 commit 32cb72b
Show file tree
Hide file tree
Showing 141 changed files with 231 additions and 43,228 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.gradle
.idea/**
build/**
out/**
out/**
archived/**
1 change: 1 addition & 0 deletions .java-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.8
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,27 @@ class IndividualFiledSubjectDataExtractor(private val skolverketFileArchive: Sko
private fun getSubject(openDataDocumentStream: InputStream, typeOfSyllabus: SyllabusType? = null): SubjectHtml {
val openDataDocument = Jsoup.parse(openDataDocumentStream, null, "", Parser.xmlParser())
fun extractString(elementName: String): String = openDataDocument.select("subject > $elementName" ).text()
val code = extractString("code")

// GRSPKOU01 should be a subject area!
val syllabusType: SyllabusType? = if (code == "GRSPKOU01") {
SyllabusType.SUBJECT_AREA_SYLLABUS
} else {
valueOfOrNull<SyllabusType>(extractString("typeOfSyllabus")) ?: typeOfSyllabus
}

return SubjectHtml(
extractString("name"),
extractString("description"),
extractString("version").toIntOrNull(),
extractString("code"),
code,
extractString("designation"),
extractString("skolfsId"),
convertDashListToList(extractString("purpose")),
extractCourses(openDataDocument, typeOfSyllabus),
extractString("createdDate"),
extractString("modifiedDate"),
valueOfOrNull<SyllabusType>(extractString("typeOfSyllabus")) ?: typeOfSyllabus,
syllabusType,
valueOfOrNull<TypeOfSchooling>(extractString("typeOfSchooling")),
valueOfOrNull<TypeOfSchooling>(extractString("originatorTypeOfSchooling")),
extractString("gradeScale"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.junit.jupiter.api.TestFactory
import java.io.File

class SkolverketFileArchiveTest {
private val dataDir = File("./src/test/resources/opendata/2018-09-26")
private val dataDir = File("./src/test/resources/opendata/2019-11-29")

@TestFactory
fun testSkolverketArchives() = SchoolType.values().map { schoolType ->
Expand Down Expand Up @@ -36,11 +36,11 @@ class SkolverketFileArchiveTest {

private fun expectedNumberOfXMLFiles(schoolType: SchoolType): Int {
return when (schoolType) {
SchoolType.GR -> 25
SchoolType.GR -> 26
SchoolType.GRS -> 23
SchoolType.GRSAM -> 25
SchoolType.GRSPEC -> 34
SchoolType.GY -> 294
SchoolType.GY -> 296
SchoolType.VUXGR -> 15
SchoolType.VUXGRS -> 13
SchoolType.GYS -> 74
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package org.edtech.curriculum.internal

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import org.edtech.curriculum.Curriculum
import org.edtech.curriculum.GradeStep
import org.edtech.curriculum.SchoolType
import org.edtech.curriculum.YearGroup
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.module.kotlin.*
import org.edtech.curriculum.*
import org.jsoup.Jsoup
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
Expand Down Expand Up @@ -36,16 +35,26 @@ class KnowledgeRequirementParserTest {
}

private fun getObjectMapper(): ObjectMapper {
val mapper = jacksonObjectMapper()
mapper.configure( DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true )
mapper.registerModule(JavaTimeModule())
return mapper
}

private fun getObjectWriter(): ObjectMapper {
val mapper = ObjectMapper()
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.registerModule(JavaTimeModule())
return mapper
}


@TestFactory
fun testAgainstJsonFiles(): List<DynamicTest> {
val mapper = getObjectMapper()
// Pretty print the result so that we manually can understand the result.
val objectWriter = getObjectWriter().writerWithDefaultPrettyPrinter()
return SchoolType.values().flatMap { schoolType ->

File("$validDataDir/").listFiles().flatMap { versionDir ->
Expand All @@ -56,13 +65,12 @@ class KnowledgeRequirementParserTest {
.filter { it.name.endsWith(".json") }
.map { file ->
DynamicTest.dynamicTest("${schoolType.name}/${versionDir.name} - ${file.nameWithoutExtension}") {
val parsedSubject = subjectMap[file.nameWithoutExtension]
val parsedSubject = subjectMap[file.nameWithoutExtension]?.copy(modifiedDate = null, applianceDate = null, skolfsId = "", validTo = null,version = 0)
if (parsedSubject == null) {
fail("No subject ${file.nameWithoutExtension} for file ${file.absolutePath}")
} else {
val expected = file.readText()
val actual = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(parsedSubject)
assertEquals(expected, actual, "Difference for subject ${versionDir.name} - ${schoolType.name}/${file.nameWithoutExtension}")
val expected = mapper.readValue<Subject>( file.readText() )?.copy(modifiedDate = null, applianceDate = null, skolfsId = "", validTo = null,version = 0)
assertEquals(objectWriter.writeValueAsString(expected), objectWriter.writeValueAsString(parsedSubject), "Difference for subject ${versionDir.name} - ${schoolType.name}/${file.nameWithoutExtension}")
}
}
}
Expand Down
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-09-26/gys.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-09-26/sfi.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-09-26/syllabus.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-09-26/vuxgr.tgz
Binary file not shown.
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-11-26/gys.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-11-26/sfi.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-11-26/syllabus.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2018-11-26/vuxgr.tgz
Binary file not shown.
Binary file not shown.
Binary file removed src/test/resources/opendata/2019-08-23/gys.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2019-08-23/sfi.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/2019-08-23/vuxgr.tgz
Binary file not shown.
Binary file not shown.
Binary file added src/test/resources/opendata/2019-11-29/gys.tgz
Binary file not shown.
Binary file not shown.
Binary file added src/test/resources/opendata/2019-11-29/sfi.tgz
Binary file not shown.
Binary file not shown.
Binary file added src/test/resources/opendata/2019-11-29/vuxgr.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/latest/compulsory.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/latest/gys.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/latest/sfi.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/latest/syllabus.tgz
Binary file not shown.
Binary file removed src/test/resources/opendata/latest/vuxgr.tgz
Binary file not shown.
Loading

0 comments on commit 32cb72b

Please sign in to comment.