Skip to content

Commit

Permalink
SLUB: Put prefix "id" before id identifier
Browse files Browse the repository at this point in the history
to prepare for different kinds of identifiers
  • Loading branch information
StefRe committed Oct 23, 2020
1 parent a1bc27b commit 31d6006
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ open class SLUB : OkHttpBaseApi() {
}
type = mediaTypes[it.getJSONArray("format").optString(0)]
?: SearchResult.MediaType.NONE
id = it.getString("id")
id = "id/${it.getString("id")}"
}
}
//TODO: get status (one request per item!)
Expand All @@ -161,7 +161,7 @@ open class SLUB : OkHttpBaseApi() {
val json: JSONObject
try {
json = JSONObject(httpGet(
"$baseurl/id/$id/?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app",
"$baseurl/$id/?type=1369315142&tx_find_find[format]=data&tx_find_find[data-format]=app",
ENCODING))
} catch (e: JSONException) {
throw OpacApi.OpacErrorException(stringProvider.getFormattedString(
Expand Down Expand Up @@ -212,7 +212,9 @@ open class SLUB : OkHttpBaseApi() {
is String -> arrayItem
is JSONObject -> arrayItem.optString("title").also {
// if item is part of multiple collections, collectionsId holds the last one
collectionId = arrayItem.optString("id", null)
arrayItem.optString("id", null)?.let {
collectionId = "id/$it"
}
}
else -> null
}
Expand Down Expand Up @@ -517,7 +519,7 @@ open class SLUB : OkHttpBaseApi() {
}

override fun getShareUrl(id: String?, title: String?): String {
return "$baseurl/id/$id"
return "$baseurl/$id"
}

override fun getSupportFlags(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ import org.mockito.Matchers
import org.mockito.Matchers.argThat
import org.mockito.Matchers.eq
import org.mockito.Mockito
import org.mockito.Mockito.verify
import kotlin.collections.HashSet
import org.mockito.Mockito.*


/**
* Tests for SLUB API
Expand All @@ -58,6 +58,7 @@ import kotlin.collections.HashSet
@Suite.SuiteClasses(
SLUBAccountTest::class,
SLUBSearchTest::class,
SLUBMiscellaneousTests::class,
SLUBAccountMockTest::class,
SLUBReservationMockTest::class,
SLUBAccountValidateMockTest::class,
Expand Down Expand Up @@ -189,12 +190,12 @@ class SLUBSearchTest : BaseHtmlTest() {
val result1 = SearchResult().apply {
innerhtml = "<b>Mastering software testing with JUnit 5 comprehensive guide to develop high quality Java applications Boni García</b><br>Garcia, Boni<br>(2017)"
type = SearchResult.MediaType.BOOK
id = "0-1014939550"
id = "id/0-1014939550"
}
val result2 = SearchResult().apply {
innerhtml = """<b>Title with " and &</b><br><br>(2222)"""
type = SearchResult.MediaType.NONE
id = "123"
id = "id/123"
}

val searchresults = slub.parseSearchResults(json)
Expand All @@ -210,7 +211,7 @@ class SLUBSearchTest : BaseHtmlTest() {
val result1 = SearchResult().apply {
innerhtml = "<b>Tu en hagiois patros hēmōn Maximu tu homologetu Hapanta = S.P.N. Maximi Confessoris Opera omnia eruta, Latine transl., notisque ill. opera et studio Francisci Combefis. Adauxit Franciscus Oehler. Accurante et denuo recognoscente J.-P. Migne</b><br>Maximus Confessor"
type = SearchResult.MediaType.BOOK
id = "0-1093989777"
id = "id/0-1093989777"
}

val searchresults = slub.parseSearchResults(json)
Expand All @@ -233,18 +234,18 @@ class SLUBSearchTest : BaseHtmlTest() {
addDetail(Detail("Sprache", "Deutsch"))
addDetail(Detail("Schlagwörter", "Quellcode; Softwaretest; JUnit"))
addDetail(Detail("Inhaltsverzeichnis", "http://d-nb.info/970689268/04"))
id = "0-1182402208"
id = "id/0-1182402208"
copies = arrayListOf(Copy().apply {
barcode = "31541466"
department = "Freihand"
branch = "Bereichsbibliothek DrePunct"
status = "Ausleihbar"
shelfmark = "ST 233 H939"
})
collectionId = "0-1183957874"
collectionId = "id/0-1183957874"
}

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

//details are in unspecified order, see https://stackoverflow.com/a/4920304/3944322
assertThat(item, sameBeanAs(expected).ignoring("details"))
Expand All @@ -271,7 +272,7 @@ class SLUBSearchTest : BaseHtmlTest() {
resInfo = "stackRequest\t33364639"
}

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertEquals(19, item.copies.size)
// the copies arrays may occur in any order
Expand All @@ -288,7 +289,7 @@ class SLUBSearchTest : BaseHtmlTest() {
)

// is part of "Undergraduate topics in computer science" but no id (--> collectionid) given
val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertThat(volumes, sameBeanAs(item.volumes))
assertNull(item.collectionId)
Expand All @@ -299,7 +300,7 @@ class SLUBSearchTest : BaseHtmlTest() {
val json = JSONObject(readResource("/slub/search/item-with_umlaute_in_title_and_volumes.json"))
val volume = Volume("0-1149529121", "(inse,5): in 6 Bänden")

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertEquals("Urania-Tierreich: in 6 Bänden", item.title)
assertThat(item.volumes, hasItem(sameBeanAs(volume)))
Expand All @@ -314,12 +315,12 @@ class SLUBSearchTest : BaseHtmlTest() {
title = "Maya"
addDetail(Detail("Sprache", "Kein linguistischer Inhalt"))
addDetail(Detail("Schlagwörter", "Skulptur; Statue; Ortskatalog zur Kunst und Architektur"))
id = "dswarm-67-b2FpOmRldXRzY2hlZm90b3RoZWsuZGU6YTg0NTA6Om9ianwzMzA1NTgxMHxkZl9oYXVwdGthdGFsb2dfMDEwMDMzNg"
id = "id/dswarm-67-b2FpOmRldXRzY2hlZm90b3RoZWsuZGU6YTg0NTA6Om9ianwzMzA1NTgxMHxkZl9oYXVwdGthdGFsb2dfMDEwMDMzNg"
cover = "http://fotothek.slub-dresden.de/thumbs/df_hauptkatalog_0100336.jpg"
addDetail(Detail("In der Deutschen Fotothek ansehen", "http://www.deutschefotothek.de/obj33055810.html"))
}

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertThat(item, sameBeanAs(expected).ignoring("details"))
assertThat(HashSet(expected.details), sameBeanAs(HashSet(item.details)))
Expand All @@ -338,14 +339,14 @@ class SLUBSearchTest : BaseHtmlTest() {
addDetail(Detail("Sprache", "Deutsch"))
addDetail(Detail("Schlagwörter", "Java; JUnit"))
addDetail(Detail("Beschreibung", "Literaturverz. S. 351"))
id = "0-727434322"
id = "id/0-727434322"
addDetail(Detail("Inhaltsverzeichnis", "http://www.gbv.de/dms/tib-ub-hannover/727434322.pdf"))
addDetail(Detail("Inhaltstext", "http://deposit.d-nb.de/cgi-bin/dokserv?id=4155321&prov=M&dok_var=1&dok_ext=htm"))
addDetail(Detail("Zugang zur Ressource (via ProQuest Ebook Central)", "http://wwwdb.dbod.de/login?url=http://slub.eblib.com/patron/FullRecord.aspx?p=1575685"))
addDetail(Detail("Online-Ausgabe", "Tamm, Michael: JUnit-Profiwissen (SLUB)"))
}

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertThat(item, sameBeanAs(expected).ignoring("details"))
assertThat(HashSet(expected.details), sameBeanAs(HashSet(item.details)))
Expand All @@ -360,11 +361,11 @@ class SLUBSearchTest : BaseHtmlTest() {
title = "A Study of Classic Maya Rulership"
addDetail(Detail("Sprache", "Englisch"))
addDetail(Detail("Schlagwörter", "Archaeology; Latin American history; Ancient history; Native American studies"))
id = "ai-34-b2FpOnBxZHRvYWkucHJvcXVlc3QuY29tOjM0Nzc2Mzg"
id = "id/ai-34-b2FpOnBxZHRvYWkucHJvcXVlc3QuY29tOjM0Nzc2Mzg"
addDetail(Detail("Link", "http://pqdtopen.proquest.com/#viewpdf?dispub=3477638"))
}

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertThat(item, sameBeanAs(expected).ignoring("details"))
assertThat(HashSet(expected.details), sameBeanAs(HashSet(item.details)))
Expand All @@ -383,7 +384,7 @@ class SLUBSearchTest : BaseHtmlTest() {
addDetail(Detail("Sprache", "Deutsch"))
addDetail(Detail("Schlagwörter", "Walther, Wilhelm; Albertiner; Albertiner; Fries; Walther, Wilhelm"))
addDetail(Detail("Beschreibung", "Literaturverz. S. 222 - 224"))
id = "0-276023927"
id = "id/0-276023927"
copies = arrayListOf(
Copy().apply {
barcode = "10059731"
Expand Down Expand Up @@ -414,13 +415,32 @@ class SLUBSearchTest : BaseHtmlTest() {
isReservable = true
}

val item = slub.parseResultById(json.getString("id"), json)
val item = slub.parseResultById("id/${json.getString("id")}", json)

assertThat(item, sameBeanAs(expected).ignoring("details"))
assertThat(HashSet(expected.details), sameBeanAs(HashSet(item.details)))
}
}

class SLUBMiscellaneousTests() : BaseHtmlTest() {
private var slub = SLUB()

init {
slub.init(Library().apply {
data = JSONObject().apply {
put("baseurl", "https://test.de")
put("illrenewurl", "https://test-renew.de")
}
}, HttpClientFactory("test"))
}

@Test
fun testGetShareUrl() {
val expected = slub.getShareUrl("id/123", "not used")
assertEquals(expected, "https://test.de/id/123")
}
}

@RunWith(Parameterized::class)
class SLUBAccountMockTest(@Suppress("unused") private val name: String,
private val response: String,
Expand Down

0 comments on commit 31d6006

Please sign in to comment.