/* * Media Converter * Extracts media files from Fedora repository * Copyright (C) 2020 Memoriav * * 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 . */ package ch.memobase import ch.memobase.models.{BinaryResourceMetadata, NoLocalBinary, UnknownEventType, UnmanageableMediaFileType} import org.scalatest.funsuite.AnyFunSuite import scala.io.Source class BinaryResourceMetadataTest extends AnyFunSuite { val externalBaseUrl = "https://memobase.ch" private def loadMessageWithBinaryResource(eventType: String, mimeType: String, locator: String): String = { val file = Source.fromFile("src/test/resources/incoming_message_with_binary.json") val result = file.mkString .replaceAll(raw"\{\{eventType\}\}", eventType) .replaceAll(raw"\{\{mimeType\}\}", mimeType) .replaceAll(raw"\{\{locator\}\}", locator) file.close() result } test("the value of the id field of a KafkaMessage should match the id of the parsed object") { val km = BinaryResourceMetadata.build(loadMessageWithBinaryResource("Create", "image/jpeg", "https://memobase.ch/digital/BAZ-MEI_77466-1/binary"), externalBaseUrl) assert(km.isSuccess) } test("a reference to a non-local binary should throw a NoLocalBinary exception") { assertThrows[NoLocalBinary] { BinaryResourceMetadata.build(loadMessageWithBinaryResource("Create", "image/jpeg", "https://example.com"), externalBaseUrl).get } } test("a unmanageable mime type should throw a UnmanageableMediaFileType exception") { assertThrows[UnmanageableMediaFileType] { BinaryResourceMetadata.build(loadMessageWithBinaryResource("Create", "application/pdf", "https://memobase.ch/digital/BAZ-MEI_77466-1/binary"), externalBaseUrl).get } } test("a unknown event type should throw a UnknownEventType exception") { assertThrows[UnknownEventType] { BinaryResourceMetadata.build(loadMessageWithBinaryResource("Upload", "image/jpeg", "https://memobase.ch/digital/BAZ-MEI_77466-1/binary"), externalBaseUrl).get } } }