Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Marcin Procyk <marcin.procyk@dasch.swiss>
- Loading branch information
Showing
3 changed files
with
225 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
.../knora/webapi/messages/util/search/gravsearch/transformers/ConstructTransformerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright © 2021 - 2023 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.util.search.gravsearch.transformers | ||
|
||
import zio.ZIO | ||
import zio.test.ZIOSpecDefault | ||
import zio.test.assertTrue | ||
|
||
import org.knora.webapi.messages.IriConversions._ | ||
import org.knora.webapi.messages.SmartIri | ||
import org.knora.webapi.messages.StringFormatter | ||
import org.knora.webapi.messages.util.search._ | ||
import org.knora.webapi.slice.ontology.repo.service.OntologyCacheFake | ||
import org.knora.webapi.slice.resourceinfo.domain.IriConverter | ||
|
||
object ConstructTransformerSpec extends ZIOSpecDefault { | ||
|
||
private implicit val sf: StringFormatter = StringFormatter.getInitializedTestInstance | ||
|
||
private def constructTransformerTransform(q: ConstructQuery, limit: Option[Set[SmartIri]] = None) = | ||
ZIO.serviceWithZIO[ConstructTransformer](_.transform(q, limit)) | ||
|
||
val spec = suite("ConstructTransformerLive")( | ||
test( | ||
"Given an optional pattern in the Where clause it should transform the inner but not split the pattern" | ||
) { | ||
val query = ConstructQuery( | ||
constructClause = ConstructClause( | ||
statements = Vector( | ||
StatementPattern( | ||
subj = QueryVariable("letter"), | ||
pred = IriRef("http://api.knora.org/ontology/knora-api/simple/v2#isMainResource".toSmartIri), | ||
obj = XsdLiteral("true", "http://www.w3.org/2001/XMLSchema#boolean".toSmartIri) | ||
) | ||
) | ||
), | ||
whereClause = WhereClause( | ||
patterns = Vector( | ||
OptionalPattern( | ||
patterns = Vector( | ||
StatementPattern( | ||
subj = QueryVariable("person1"), | ||
pred = IriRef("http://0.0.0.0:3333/ontology/0801/beol/simple/v2#hasFamilyName".toSmartIri), | ||
obj = QueryVariable("name") | ||
), | ||
StatementPattern( | ||
subj = IriRef("http://0.0.0.0:3333/ontology/0801/beol/simple/v2#hasFamilyName".toSmartIri), | ||
pred = IriRef("http://api.knora.org/ontology/knora-api/simple/v2#objectType".toSmartIri), | ||
obj = IriRef("http://www.w3.org/2001/XMLSchema#string".toSmartIri) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
for { | ||
transformed <- constructTransformerTransform(query) | ||
} yield assertTrue(transformed.whereClause.patterns.count(_.isInstanceOf[OptionalPattern]) == 1) | ||
} | ||
).provide( | ||
ConstructTransformer.layer, | ||
IriConverter.layer, | ||
StringFormatter.test, | ||
OntologyInferencer.layer, | ||
OntologyCacheFake.emptyCache | ||
) | ||
} |
Oops, something went wrong.