-
Notifications
You must be signed in to change notification settings - Fork 18
/
TriplestoreMessagesSpec.scala
55 lines (39 loc) · 1.63 KB
/
TriplestoreMessagesSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/
package org.knora.webapi.messages.store.triplestoremessages
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import spray.json.*
import dsp.errors.BadRequestException
import org.knora.webapi.messages.admin.responder.listsmessages.*
/**
* This spec is used to test 'ListAdminMessages'.
*/
class TriplestoreMessagesSpec extends AnyWordSpecLike with Matchers with ListADMJsonProtocol {
"Conversion from case class to JSON and back" should {
"work for a 'StringLiteralV2' without language iso" in {
val string = StringLiteralV2.from("stringwithoutlang", None)
val json = string.toJson.compactPrint
json should be("{\"value\":\"stringwithoutlang\"}")
val converted: StringLiteralV2 = json.parseJson.convertTo[StringLiteralV2]
converted should be(string)
}
"work for a 'StringLiteralV2' with language iso" in {
val string = StringLiteralV2.from("stringwithlang", Some("de"))
val json = string.toJson.compactPrint
json should be("{\"value\":\"stringwithlang\",\"language\":\"de\"}")
val converted = json.parseJson.convertTo[StringLiteralV2]
converted should be(string)
}
}
"Creating a `StringLiteralV2`" should {
"fail when language iso is given but value is missing" in {
val caught = intercept[BadRequestException](
StringLiteralV2.from("", Some("de")),
)
assert(caught.getMessage === "String value is missing.")
}
}
}