TestCheckLocator.kt 1.44 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
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
package org.memobase

import com.beust.klaxon.json
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.memobase.helpers.Filter
import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCheckLocator {
    @Test
    fun `test check locator no digital object`() {
        val result = Filter.checkLocator(null, emptyList())
        assertThat(result).isFalse()
    }

    @Test
    fun `test check locator digital object no locator`() {
        val result = Filter.checkLocator(json {
            obj(
            )
        }, emptyList())
        assertThat(result).isFalse()
    }

    @Test
    fun `test check locator digital object has locator no access`() {
        val result = Filter.checkLocator(json {
            obj(
                Pair("locator", "https://example.org")
            )
        }, emptyList())
        assertThat(result).isFalse()
    }


    @Test
    fun `test check locator digital object has locator and public access`() {
        val result = Filter.checkLocator(
            json {
                obj(
                    Pair("locator", "https://example.org")
                )
            }, listOf(
                FacetContainer(LanguageContainer.EMPTY, filter = null, facet = listOf("public"))
            )
        )
        assertThat(result).isTrue()
    }

}