|
| 1 | +/* |
| 2 | + * Copyright 2017 IBM Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package integration |
| 17 | + |
| 18 | +import common._ |
| 19 | +import org.junit.runner.RunWith |
| 20 | +import org.scalatest.junit.JUnitRunner |
| 21 | +import java.io.File |
| 22 | +import common.rest.WskRest |
| 23 | +import spray.json._ |
| 24 | + |
| 25 | +@RunWith(classOf[JUnitRunner]) |
| 26 | +class CredentialsIBMPythonDb2CloudTests extends TestHelpers with WskTestHelpers { |
| 27 | + |
| 28 | + implicit val wskprops: WskProps = WskProps() |
| 29 | + val defaultKind = Some("python-jessie:3") |
| 30 | + val wsk = new WskRest |
| 31 | + val datdir = System.getProperty("user.dir") + "/dat/db2" |
| 32 | + val actionName = "testDB2Service" |
| 33 | + val actionFileName = "testDB2Service.py" |
| 34 | + |
| 35 | + val creds = TestUtils.getVCAPcredentials("dashDB") |
| 36 | + val ssldsn = creds.get("ssldsn") |
| 37 | + val __bx_creds = JsObject("dashDB" -> JsObject("ssldsn" -> JsString(ssldsn))) |
| 38 | + |
| 39 | + it should "Test connection to DB2 on IBM Cloud" in withAssetCleaner(wskprops) { (wp, assetHelper) => |
| 40 | + val file = Some(new File(datdir, actionFileName).toString()) |
| 41 | + |
| 42 | + assetHelper.withCleaner(wsk.action, actionName) { (action, _) => |
| 43 | + action.create( |
| 44 | + actionName, |
| 45 | + file, |
| 46 | + main = Some("main"), |
| 47 | + kind = defaultKind, |
| 48 | + parameters = Map("__bx_creds" -> __bx_creds)) |
| 49 | + } |
| 50 | + |
| 51 | + withActivation(wsk.activation, wsk.action.invoke(actionName)) { activation => |
| 52 | + val response = activation.response |
| 53 | + response.result.get.fields.get("error") shouldBe empty |
| 54 | + response.result.get.fields.get("HISP_DESC") should be(Some(JsString("Puerto Rican"))) |
| 55 | + } |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments