AggregationSpec.scala 4.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * rico2edm
 * Copyright (C) 2021  UB Basel
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */


package ch.memobase.rico2edm.edm

Günter Hipler's avatar
Günter Hipler committed
23
import ch.memobase.Utils
24
25
26
27
import ch.memobase.Utils.loadFile
import ch.memobase.rico2edm.edm.subjects.Aggregation
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
Günter Hipler's avatar
Günter Hipler committed
28
29
import ujson.Value.Value

30
31
32
33
34

class AggregationSpec extends AnyFunSuite with Matchers {

  private lazy val rawRicoIndent = loadFile("src/test/resources/rawIndent.json")
  private lazy val rawCertainty = loadFile("src/test/resources/rico.certainty.json")
Günter Hipler's avatar
Günter Hipler committed
35
  private lazy val rawNoFoto = loadFile("src/test/resources/rico.duration.json")
36
37
  private lazy val rawEdmRights = loadFile("src/test/resources/rico.certainty.json")

38
39
  private lazy val rawTestedmObject = loadFile("src/test/resources/apf-001-1280.json")

40

41

Günter Hipler's avatar
Günter Hipler committed
42
43
44
45
46
47
  private def testAggregation = {
    val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    Aggregation(shortRecordId.get)
  }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

  test ("id creation for Aggregation") {
    val graph = Extractors.jsonGraph(rawRicoIndent).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    assert(shortRecordId.isDefined &&  s"https://memobase.ch/object/${shortRecordId.get}" == "https://memobase.ch/object/ati-001-L_44_13")
  }

  test ("edm:aggregatedCHO") {

    //entspricht id - identifier (keine http URI)
    val graph = Extractors.jsonGraph(rawCertainty).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    assert(shortRecordId.isDefined &&  shortRecordId.get == "lmz-001--597216")

  }

  test ("edm:isShownAt") {

Günter Hipler's avatar
Günter Hipler committed
68
   //entspricht id - identifier (keine http URI)
69
70
71
72
73
74
    val graph = Extractors.jsonGraph(rawCertainty).get.arr
    val record = Extractors.record(graph).get
    val shortRecordId = Extractors.recordIdShort(graph)(record)
    assert(shortRecordId.isDefined &&  shortRecordId.get == "lmz-001--597216")


Günter Hipler's avatar
Günter Hipler committed
75

76
77
78
79
80
81
    /*
    val agg = Aggregation(shortRecordId.get)
    agg.addIsShownAt(shortRecordId)

    val rdfWriter = new EDMRdfXmlWriter(System.out)
    Rio.write(agg.getModel, rdfWriter)
Günter Hipler's avatar
Günter Hipler committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    */


  }


  test ("edm:isShownBy") {

    val graph = Extractors.jsonGraph(rawCertainty).get.arr
    val doObj = Extractors.digitalObject(graph).get
    val shortDobjectId = Extractors.digitalObjectIdShort(graph)(doObj)
    assert(shortDobjectId.isDefined && shortDobjectId.get == "lmz-001--597216-1")

  }

  private def createAgg(rawGraph: String): Aggregation = {
    val graph = Extractors.jsonGraph(rawGraph).get.arr
    val record = Extractors.record(graph).get
    val doObj = Extractors.digitalObject(graph).get
    val digiObjIdShort = Extractors.digitalObjectIdShort(graph)(doObj)
    val tempTestAgg = testAggregation
    Extractors.ricoType(record) match {
      case Some(value) =>
        if (value == "Foto") {
          tempTestAgg.addEDMObjectFoto(digiObjIdShort)
        }else {
          tempTestAgg.addEDMObjectNoFoto(digiObjIdShort)
        }
      case None =>

    }
    tempTestAgg

  }


  test ("aggregation edm:object") {
119

120
121
    //todo: test it with: apf-001-1280

Günter Hipler's avatar
Günter Hipler committed
122
123
124
    val aggFoto = createAgg(rawCertainty)
    assert(Utils.serializeRDFModel(aggFoto.getModel).contains(
      s"<edm:object>https://media.memobase.ch/memo/lmz-001--597216-1/master</edm:object>"))
125

Günter Hipler's avatar
Günter Hipler committed
126
127
128
    val aggNoFoto = createAgg(rawNoFoto)
    assert(Utils.serializeRDFModel(aggNoFoto.getModel).contains(
      s"<edm:object>https://media.memobase.ch/memo/raf-001-2893-1-poster</edm:object>"))
129

130
131
132
133

    //warum bekomme ich einen anderen Werz in der API
    val errorCase = createAgg(rawTestedmObject)
    println(Utils.serializeRDFModel(errorCase.getModel))
134
135
  }

136
137
138
139
140
141
142
143
144
145
  test ("edm:rights property for aggregation ") {

    val graphGet: Value = Extractors.jsonGraph(rawEdmRights).get
    val dObj = Extractors.digitalObject(graphGet.arr)
    val usage = Extractors.usageRegulationDigitalObject(graphGet.arr)(dObj.get)
    assert(usage.head == "http://rightsstatements.org/vocab/CNE/1.0/")

  }


146
147

}