Skip to content

Commit

Permalink
Upgraded Scala version to 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-podzigun committed Jul 22, 2021
1 parent 5584520 commit 4773a92
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ before_install:
tar xv -C travis -f travis/secrets.tar;
fi
script:
- sbt clean coverage test coverageReport &&
sbt coverageAggregate &&
sbt coveralls &&
- sbt clean coverage test &&
sbt coverageAggregate coveralls &&
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" -o "$TRAVIS_BRANCH" == "$TRAVIS_TAG" ]; then
if [ -z "$TRAVIS_TAG" ]; then
echo "Publish a snapshot";
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[![Build Status](https://travis-ci.com/scommons/scommons-api.svg?branch=master)](https://travis-ci.com/scommons/scommons-api)
[![Coverage Status](https://coveralls.io/repos/github/scommons/scommons-api/badge.svg?branch=master)](https://coveralls.io/github/scommons/scommons-api?branch=master)
[![scala-index](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core/latest.svg)](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core)
[![scala-index](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core/latest-by-scala-version.svg?targetType=Js)](https://index.scala-lang.org/scommons/scommons-api/scommons-api-core)
[![Scala.js](https://www.scala-js.org/assets/badges/scalajs-0.6.29.svg)](https://www.scala-js.org)

## scommons-api
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/scala/scommons/api/http/ApiHttpResponse.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package scommons.api.http

import scala.collection.immutable.ArraySeq

class ApiHttpResponse(val url: String,
val status: Int,
val headers: Map[String, Seq[String]],
val headers: Map[String, scala.collection.Seq[String]],
getBody: => String,
getBodyAsBytes: => Seq[Byte]) {

Expand All @@ -15,7 +17,11 @@ class ApiHttpResponse(val url: String,

object ApiHttpResponse {

def apply(url: String, status: Int, headers: Map[String, Seq[String]], body: String): ApiHttpResponse = {
new ApiHttpResponse(url, status, headers, body, body.getBytes)
def apply(url: String,
status: Int,
headers: Map[String, scala.collection.Seq[String]],
body: String): ApiHttpResponse = {

new ApiHttpResponse(url, status, headers, body, ArraySeq.unsafeWrapArray(body.getBytes))
}
}
4 changes: 2 additions & 2 deletions core/src/test/scala/scommons/api/http/ApiHttpClientSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class ApiHttpClientSpec extends AsyncFlatSpec

//then
inside(ex) { case ApiHttpStatusException(error, resp) =>
error shouldBe {
"Fail to parse http response, error: List((/name,List(JsonValidationError(List(error.path.missing),WrappedArray()))))"
error should startWith {
"Fail to parse http response, error: List((/name,List(JsonValidationError(List(error.path.missing)"
}
resp shouldBe response
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scommons.api.http.ws

import java.net.URLEncoder
import java.util.concurrent.TimeoutException

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.util.ByteString
Expand All @@ -14,7 +13,7 @@ import org.scalatest.concurrent.ScalaFutures
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Inside}
import org.scalatestplus.mockito.MockitoSugar
import play.api.libs.ws.ahc.StandaloneAhcWSClient
import play.api.libs.ws.{EmptyBody, InMemoryBody, StandaloneWSRequest, StandaloneWSResponse}
Expand All @@ -26,6 +25,7 @@ import scala.concurrent.{ExecutionContext, Future}

class WsApiHttpClientSpec extends AnyFlatSpec
with Matchers
with Inside
with BeforeAndAfterAll
with BeforeAndAfterEach
with MockitoSugar
Expand Down Expand Up @@ -58,7 +58,7 @@ class WsApiHttpClientSpec extends AnyFlatSpec
private val timeout = 5.seconds

override protected def beforeEach(): Unit = {
reset(client, response)
reset[AnyRef](client, response)
}

override protected def afterEach(): Unit = {
Expand All @@ -82,7 +82,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))

//when
val Some(result) = client.execute("GET", targetUrl, params, headers, body, timeout).futureValue
val result = inside(client.execute("GET", targetUrl, params, headers, body, timeout).futureValue) {
case Some(res) => res
}

//then
assertApiHttpResponse(result, expectedResult)
Expand All @@ -108,7 +110,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))

//when
val Some(result) = client.execute("POST", targetUrl, params, headers, body, timeout).futureValue
val result = inside(client.execute("POST", targetUrl, params, headers, body, timeout).futureValue) {
case Some(res) => res
}

//then
assertApiHttpResponse(result, expectedResult)
Expand All @@ -134,7 +138,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))

//when
val Some(result) = client.execute("POST", targetUrl, params, headers, body, timeout).futureValue
val result = inside(client.execute("POST", targetUrl, params, headers, body, timeout).futureValue) {
case Some(res) => res
}

//then
assertApiHttpResponse(result, expectedResult)
Expand Down Expand Up @@ -163,7 +169,9 @@ class WsApiHttpClientSpec extends AnyFlatSpec
when(response.bodyAsBytes).thenReturn(ByteString.apply(expectedResult.body))

//when
val Some(result) = client.execute("POST", targetUrl, params, headers, body, timeout).futureValue
val result = inside(client.execute("POST", targetUrl, params, headers, body, timeout).futureValue) {
case Some(res) => res
}

//then
assertApiHttpResponse(result, expectedResult)
Expand Down
6 changes: 6 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositor

addSbtPlugin(("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0-SNAPSHOT").changing())
//addSbtPlugin("org.scommons.sbt" % "sbt-scommons-plugin" % "0.5.0")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.5")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scommons.api.http.ApiHttpData._
import scommons.api.http.xhr.XhrApiHttpClient._
import scommons.api.http.{ApiHttpClient, ApiHttpData, ApiHttpResponse}

import scala.collection.immutable.ArraySeq
import scala.concurrent.duration._
import scala.concurrent.{Future, Promise}
import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue
Expand Down Expand Up @@ -85,7 +86,8 @@ object XhrApiHttpClient {
if (response == null || js.isUndefined(response)) Nil
else {
//TODO: handle Blob response as well
new Int8Array(response.asInstanceOf[ArrayBuffer]).toArray
val resArr = new Int8Array(response.asInstanceOf[ArrayBuffer]).toArray
ArraySeq.unsafeWrapArray(resArr)
}
}

Expand Down

0 comments on commit 4773a92

Please sign in to comment.