Skip to content

Commit

Permalink
chore: Add -Xfatal-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
siers committed Feb 13, 2024
1 parent 686c8fb commit ff3a3a1
Show file tree
Hide file tree
Showing 36 changed files with 60 additions and 87 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ val customScalacOptions = Seq(
"-Wvalue-discard",
"-Xlint:doc-detached",
// silence twirl templates unused imports warnings
"-Wconf:src=target/.*:s"
"-Wconf:src=target/.*:s",
"-Xfatal-warnings"
)

lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
Expand Down
3 changes: 2 additions & 1 deletion integration/src/test/scala/org/knora/sipi/SipiIT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ object MockDspApiServer {
)
)
.logError
.fold(err => false, succ => true)
.fold(_ => false, _ => true)
}

private def stubGetJsonResponse(
Expand All @@ -355,6 +355,7 @@ object MockDspApiServer {
val jsonResponse = aResponse().withStatus(status).withBody(json).withHeader("Content-Type", "application/json")
val stubBuilder = get(urlEqualTo(url)).willReturn(jsonResponse)
server.stubFor(stubBuilder)
()
}

private def acquireWireMockServer: Task[WireMockServer] = ZIO.attempt {
Expand Down
15 changes: 0 additions & 15 deletions integration/src/test/scala/org/knora/webapi/E2ESpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration

import dsp.errors.FileWriteException
import org.knora.webapi.config.AppConfig
import org.knora.webapi.core.AppRouter
import org.knora.webapi.core.AppServer
Expand Down Expand Up @@ -207,18 +206,4 @@ abstract class E2ESpec
)
responseAsString
}

private def createTmpFileDir(): Unit = {
// check if tmp datadir exists and create it if not
val tmpFileDir = Path.of(appConfig.tmpDatadir)

if (!Files.exists(tmpFileDir)) {
try {
Files.createDirectories(tmpFileDir)
} catch {
case e: Throwable =>
throw FileWriteException(s"Tmp data directory ${appConfig.tmpDatadir} could not be created: ${e.getMessage}")
}
}
}
}
4 changes: 2 additions & 2 deletions integration/src/test/scala/org/knora/webapi/R2RSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package org.knora.webapi

import com.typesafe.scalalogging.Logger
import org.apache.pekko.actor.ActorRef
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.model.HttpResponse
import org.apache.pekko.http.scaladsl.testkit.RouteTestTimeout
import org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTest
Expand Down Expand Up @@ -67,7 +66,7 @@ abstract class R2RSpec
implicit val runtime: Runtime.Scoped[Environment] = Unsafe.unsafe(implicit u => Runtime.unsafe.fromLayer(bootstrap))

// the default timeout for route tests
implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
implicit def default: RouteTestTimeout = RouteTestTimeout(
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

Expand Down Expand Up @@ -99,6 +98,7 @@ abstract class R2RSpec
runtime.unsafe.shutdown()
}
system.terminate()
()
}

protected def responseToJsonLDDocument(httpResponse: HttpResponse): JsonLDDocument = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi.core
import org.apache.pekko
import zio.*

import org.knora.webapi.config.AppConfig.AppConfigurationsTest
import org.knora.webapi.config.AppConfig.AppConfigurations
import org.knora.webapi.config.AppConfigForTestContainers
import org.knora.webapi.messages.StringFormatter
Expand Down Expand Up @@ -81,7 +82,7 @@ object LayersTest {
with DspIngestTestContainer
with SharedVolumes.Images

type CommonR0 = ActorSystem with AppConfigurations with JwtService with SipiService with StringFormatter
type CommonR0 = ActorSystem with AppConfigurationsTest with JwtService with SipiService with StringFormatter
type CommonR =
ApiRoutes
with ApiV2Endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import scala.concurrent.duration.NANOSECONDS
import org.knora.webapi.E2ESpec
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.HttpMethods.*
import pekko.http.scaladsl.model.HttpResponse
import pekko.http.scaladsl.model.StatusCodes
Expand All @@ -25,7 +24,7 @@ import pekko.http.scaladsl.testkit.RouteTestTimeout
*/
class CORSSupportE2ESpec extends E2ESpec {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
implicit def default: RouteTestTimeout = RouteTestTimeout(
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ClientTestDataCollector(appConfig: AppConfig) extends LazyLogging {
Files.createDirectories(fullPath.getParent())
Files.createFile(fullPath)
Files.write(fullPath, s.getBytes(StandardCharsets.UTF_8))
()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ import org.knora.webapi.E2ESpec
import org.knora.webapi.core.State
import org.knora.webapi.core.domain.AppState

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.*
import pekko.http.scaladsl.testkit.RouteTestTimeout

/**
* End-to-End (E2E) test specification for testing route rejections.
*/
class HealthRouteE2ESpec extends E2ESpec {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
implicit def default: RouteTestTimeout = RouteTestTimeout(
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.knora.webapi.messages.IriConversions.*
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.util.FileUtil

import pekko.actor.ActorSystem
import pekko.http.scaladsl.testkit.RouteTestTimeout

/**
Expand All @@ -26,7 +25,7 @@ import pekko.http.scaladsl.testkit.RouteTestTimeout
class InstanceCheckerSpec extends E2ESpec {
private implicit val stringFormatter: StringFormatter = StringFormatter.getGeneralInstance

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
implicit def default: RouteTestTimeout = RouteTestTimeout(
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.util.AkkaHttpUtils
import org.knora.webapi.util.MutableTestIri

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.*
import pekko.http.scaladsl.model.headers.*
import pekko.http.scaladsl.testkit.RouteTestTimeout
Expand All @@ -32,7 +31,7 @@ import pekko.http.scaladsl.unmarshalling.Unmarshal
*/
class GroupsADME2ESpec extends E2ESpec with GroupsADMJsonProtocol {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(30.seconds)
implicit def default: RouteTestTimeout = RouteTestTimeout(30.seconds)
// Directory path for generated client test data
private val clientTestDataPath: Seq[String] = Seq("admin", "groups")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.util.AkkaHttpUtils
import org.knora.webapi.util.MutableTestIri

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.*
import pekko.http.scaladsl.testkit.RouteTestTimeout
import pekko.http.scaladsl.unmarshalling.Unmarshal
Expand All @@ -33,7 +32,7 @@ import pekko.http.scaladsl.unmarshalling.Unmarshal
*/
class CreateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtocol with ListADMJsonProtocol {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(5.seconds)
implicit def default: RouteTestTimeout = RouteTestTimeout(5.seconds)

// Directory path for generated client test data
private val clientTestDataPath: Seq[String] = Seq("admin", "lists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.knora.webapi.sharedtestdata.SharedListsTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.util.AkkaHttpUtils

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.HttpResponse
import pekko.http.scaladsl.model.StatusCodes
import pekko.http.scaladsl.model.headers.BasicHttpCredentials
Expand All @@ -31,7 +30,7 @@ import pekko.http.scaladsl.testkit.RouteTestTimeout
*/
class DeleteListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtocol with ListADMJsonProtocol {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(5.seconds)
implicit def default: RouteTestTimeout = RouteTestTimeout(5.seconds)

// Directory path for generated client test data
private val clientTestDataPath: Seq[String] = Seq("admin", "lists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import org.knora.webapi.sharedtestdata.SharedListsTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.util.AkkaHttpUtils

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.*
import pekko.http.scaladsl.model.headers.*
import pekko.http.scaladsl.testkit.RouteTestTimeout
Expand All @@ -30,7 +29,7 @@ import pekko.http.scaladsl.testkit.RouteTestTimeout
*/
class GetListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtocol with ListADMJsonProtocol {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(5.seconds)
implicit def default: RouteTestTimeout = RouteTestTimeout(5.seconds)

// Directory path for generated client test data
private val clientTestDataPath: Seq[String] = Seq("admin", "lists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.knora.webapi.sharedtestdata.SharedListsTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.util.AkkaHttpUtils

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.ContentTypes
import pekko.http.scaladsl.model.HttpEntity
import pekko.http.scaladsl.model.HttpResponse
Expand All @@ -33,7 +32,7 @@ import pekko.http.scaladsl.testkit.RouteTestTimeout
*/
class UpdateListItemsRouteADME2ESpec extends E2ESpec with TriplestoreJsonProtocol with ListADMJsonProtocol {

implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(5.seconds)
implicit def default: RouteTestTimeout = RouteTestTimeout(5.seconds)

// Directory path for generated client test data
private val clientTestDataPath: Seq[String] = Seq("admin", "lists")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import scala.concurrent.duration.NANOSECONDS
import org.knora.webapi.E2ESpec
import org.knora.webapi.http.version.ServerVersion

import pekko.actor.ActorSystem
import pekko.http.scaladsl.model.*
import pekko.http.scaladsl.testkit.RouteTestTimeout

/**
* End-to-End (E2E) test specification for testing the server response.
*/
class ServerVersionE2ESpec extends E2ESpec {
implicit def default(implicit system: ActorSystem): RouteTestTimeout = RouteTestTimeout(
implicit def default: RouteTestTimeout = RouteTestTimeout(
FiniteDuration(appConfig.defaultTimeout.toNanos, NANOSECONDS)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ class AuthenticationV2E2ESpec extends E2ESpec with AuthenticationV2JsonProtocol
}

"The Authentication Route ('v2/authentication')" should {

var token = new MutableTestString
val token = new MutableTestString

"login with IRI" in {

Expand Down Expand Up @@ -279,8 +278,7 @@ class AuthenticationV2E2ESpec extends E2ESpec with AuthenticationV2JsonProtocol
}

"The Users V1 Route using the Authenticator trait " ignore {

var token = new MutableTestString
val token = new MutableTestString

"login in v2" in {
/* Correct username and correct password */
Expand Down Expand Up @@ -348,8 +346,7 @@ class AuthenticationV2E2ESpec extends E2ESpec with AuthenticationV2JsonProtocol
}

"The Users ADM Route using the Authenticator trait" should {

var token = new MutableTestString
val token = new MutableTestString

"login in v2" in {
/* Correct username and correct password */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class OntologyV2R2RSpec extends R2RSpec {

Files.createDirectories(newOutputFile.getParent)
FileUtil.writeTextFile(newOutputFile, responseStr)
()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi.e2e.v2
import org.apache.pekko.http.scaladsl.model.*
import org.apache.pekko.http.scaladsl.model.headers.BasicHttpCredentials
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import org.scalatest.compatible.Assertion
import org.xmlunit.builder.DiffBuilder
import org.xmlunit.builder.Input
import org.xmlunit.diff.Diff
Expand Down Expand Up @@ -215,12 +216,12 @@ class ValuesRouteV2E2ESpec extends E2ESpec {
resourceIri: IRI,
maybePreviousLastModDate: Option[Instant],
maybeUpdatedLastModDate: Option[Instant]
): Unit =
): Assertion =
maybeUpdatedLastModDate match {
case Some(updatedLastModDate) =>
maybePreviousLastModDate match {
case Some(previousLastModDate) => assert(updatedLastModDate.isAfter(previousLastModDate))
case None => ()
case None => assert(true)
}

case None => throw AssertionException(s"Resource $resourceIri has no knora-api:lastModificationDate")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder

import dsp.errors.BadRequestException
import org.knora.webapi.*
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionProfileType
import org.knora.webapi.messages.admin.responder.permissionsmessages.PermissionsDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
Expand All @@ -33,8 +32,6 @@ class UsersMessagesADMSpec extends CoreSpec {
private val projects = SharedTestDataADM.rootUser.projects
private val permissions = SharedTestDataADM.rootUser.permissions

private implicit val stringFormatter: StringFormatter = StringFormatter.getInstanceForConstantOntologies

"The UserADM case class" should {
"return a RESTRICTED UserADM when requested " in {
val rootUser = User(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.knora.webapi.util

import org.scalatest.compatible.Assertion

import dsp.errors.BadRequestException
import org.knora.webapi.CoreSpec
import org.knora.webapi.messages.util.*
Expand All @@ -18,7 +20,7 @@ class CalendarDateUtilV2Spec extends CoreSpec {
expectedStartJDN: Int,
expectedEndJDN: Int,
dateStr: String
): Unit = {
): Assertion = {
val calendarDateRange = CalendarDateRangeV2(
startCalendarDate = calendarDate,
endCalendarDate = calendarDate
Expand All @@ -37,7 +39,7 @@ class CalendarDateUtilV2Spec extends CoreSpec {
expectedStartJDN: Int,
expectedEndJDN: Int,
dateStr: String
): Unit = {
): Assertion = {
// Convert the date range to Julian Day Numbers and check that they're correct.
val (startJDN: Int, endJDN: Int) = calendarDateRange.toJulianDayRange
assert(startJDN == expectedStartJDN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.knora.webapi.util.rdf

import org.apache.jena
import org.scalatest.compatible.Assertion

import java.io.BufferedInputStream
import java.io.ByteArrayInputStream
Expand All @@ -30,7 +31,7 @@ import org.knora.webapi.util.FileUtil
*/
class RdfFormatUtilSpec() extends CoreSpec {

private def checkModelForRdfTypeBook(rdfModel: RdfModel, context: Option[IRI] = None): Unit = {
private def checkModelForRdfTypeBook(rdfModel: RdfModel, context: Option[IRI] = None): Assertion = {
val statements: Set[Statement] = rdfModel
.find(
subj = Some(JenaNodeFactory.makeIriNode("http://rdfh.ch/0803/2a6221216701")),
Expand All @@ -44,7 +45,7 @@ class RdfFormatUtilSpec() extends CoreSpec {
assert(statements.head.obj == JenaNodeFactory.makeIriNode("http://0.0.0.0:3333/ontology/0803/incunabula/v2#book"))
}

private def checkJsonLDDocumentForRdfTypeBook(jsonLDDocument: JsonLDDocument): Unit =
private def checkJsonLDDocumentForRdfTypeBook(jsonLDDocument: JsonLDDocument): Assertion =
assert(
jsonLDDocument.body
.getRequiredString(JsonLDKeywords.TYPE)
Expand Down
Loading

0 comments on commit ff3a3a1

Please sign in to comment.