Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the first test case for watson package. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ install: true
before_install:
- ./tools/travis/setup.sh

- openssl aes-256-cbc -K $encrypted_fddf8425fc8b_key -iv $encrypted_fddf8425fc8b_iv -in credentials.json.enc -out tests/credentials.json -d
script:
- ./tools/travis/build.sh
Binary file added credentials.json.enc
Binary file not shown.
43 changes: 43 additions & 0 deletions tests/src/packages/watson/WatsonTests.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package packages.watson

import org.junit.runner.RunWith
import org.scalatest.BeforeAndAfterAll
import org.scalatest.junit.JUnitRunner
import scala.concurrent.duration.DurationInt
import scala.language.postfixOps

import common.JsHelpers
import common.TestHelpers
import common.Wsk
import common.WskProps
import common.WskTestHelpers
import common.TestUtils
import spray.json.DefaultJsonProtocol.BooleanJsonFormat
import spray.json.DefaultJsonProtocol.StringJsonFormat
import spray.json.pimpAny

@RunWith(classOf[JUnitRunner])
class WatsonTests extends TestHelpers with WskTestHelpers with BeforeAndAfterAll with JsHelpers {
implicit val wskprops = WskProps()
val wsk = new Wsk(usePythonCLI = true)

val credentials = TestUtils.getVCAPcredentials("language_translation");

val languageIdAction = "/whisk.system/watson/languageId"
val username = credentials.get("username")
val password = credentials.get("password")

it should "The language Identify api should works" in withAssetCleaner(wskprops) {
(wp, assetHelper) =>
val payload = s"Comment allez-vous?".toJson
val run = wsk.action.invoke(languageIdAction, Map("username" -> username.toJson, "password" -> password.toJson, "payload" -> payload))
withActivation(wsk.activation, run, 1 second, 1 second, 180 seconds) {
activation =>
activation.getFieldPath("response", "success") should be(Some(true.toJson))
activation.getFieldPath("response", "result", "payload") should be(Some(payload))
activation.getFieldPath("response", "result", "confidence") == Some(0.785444)
activation.getFieldPath("response", "result", "language") should be(Some("fr".toJson))
}
}

}
6 changes: 3 additions & 3 deletions tests/template_credentials.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"credentials": {
"apiKey": "XXXXXXXX",
"apiToken": "YYYYYYY",
"base_uri": "https://openwhisk.ng.bluemix.net/api/v1",
"base_uri": "https://openwhisk.ng.bluemix.net/api/v1"
}
}],
"another_service": [{
Expand All @@ -14,7 +14,7 @@
"credentials": {
"apiKey": "ZZZZZZZZZZ",
"apiToken": "MMMMMMMMMM",
"base_uri": "https://openwhisk.ng.bluemix.net/api/v1",
"base_uri": "https://openwhisk.ng.bluemix.net/api/v1"
}
}]
}
}