Karate karate-config.js not a js function - java

I'm trying use karate for e2e tests and have started with a minimal setup. I want to create some config items in karate-config.js for use in the tests but karate is reporting that file is not a js function and hence the test fails trying to get the config:
Warning: Nashorn engine is planned to be removed from a future JDK release
12:16:35.264 [Test worker] WARN com.intuit.karate - not a js function or feature file: read('classpath:karate-config.js') - [type: NULL, value: null]
---------------------------------------------------------
feature: classpath:karate/insurer.feature
scenarios: 1 | passed: 0 | failed: 1 | time: 0.0163
---------------------------------------------------------
HTML report: (paste into browser to view) | Karate version: 0.9.1
file:/Users/srowatt/dev/repos/api/price-service/build/surefire-reports/karate.insurer.html
---------------------------------------------------------
-unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
org.opentest4j.AssertionFailedError: -unknown-:4 - javascript evaluation failed: priceBaseUrl, ReferenceError: "priceBaseUrl" is not defined in <eval> at line number 1
This is my karate-config.js:
function fn() {
return {
priceBaseUrl: "http://localhost:8080"
};
}
This is my insurer.feature test:
Feature: which creates insurers
Background:
* url priceBaseUrl
* configure logPrettyRequest = true
* configure logPrettyResponse = true
Scenario: basic roundtrip
# create a new insurer
Given path 'insurers'
And request { name: 'Sammy Insurance', companyCode: '99' }
When method post
Then status 201
And match response == { resourceId: '#number', version: 0, createdBy: 'anonymousUser' }
* def insurerId = response.resourceId
# get insurer by resource id
Given path 'insurers', insurerId
When method get
Then status 200
And match response == { id: '#(id)', name: 'Sammy Insurance', companyCode: '99' }
This is the InsurerTest.java test runner:
package karate;
import com.intuit.karate.junit5.Karate;
class InsurerTest {
#Karate.Test
public Karate testInsurer() {
return new Karate().feature("classpath:karate/insurer.feature");
}
}

Please use below code in the karate-config.js
function() {
return priceBaseUrl='http://localhost:8080';
}

When I see this:
Warning: Nashorn engine is planned to be removed from a future JDK release
I suspect you are on Java 9 or 11 ? To be honest, we haven't fully tested Karate on those versions of Java yet. Would it be possible for you to confirm that Java 8 (maybe 9 / 10 also) is OK.
That said, we are interested in resolving this as soon as possible, so if you can submit a sample project where we can replicate this, please do so: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
EDIT: Karate 1.0 will use GraalVM instead of Nashorn and will run on even JDK 16: https://software-that-matters.com/2021/01/27/7-new-features-in-karate-test-automation-version-1_0/

Related

AWS-JAVA-SDK: Unzipped size must be smaller than 262144000 bytes

I'm trying to deploy a single lambda function on AWS in scala with SAM-CLI.
It works fine, but when I add the dependency to my build.sbt
"com.amazonaws" % "aws-java-sdk" % "1.11.46"
The deploy fails and return
"Unzipped size must be smaller than 262144000 bytes (Service: Lambda, Status Code: 400, Request ID: 53eeb ab6-9377-4a37-b20b-9e55ccbebd72, Extended Request ID: null)"
My function is
def handle(request: APIGatewayProxyRequestEvent, context: Context): Response = {
println("handling %s %s, remaining time is %d ms".format(
request.getHttpMethod, request.getPath, context.getRemainingTimeInMillis) )
println(s"""environment = ${sys.env.getOrElse("env", "n/a")}""")
val name = request.getPathParameters.get("name")
Response(s"Hello, $name\n", Map("Content-Type" -> "text/plain"))
}
case class Response(body: String, headers: Map[String,String], statusCode: Int = 200) {
def javaHeaders: java.util.Map[String, String] = headers.asJava `enter code here`}
And my template.yaml looks like
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >-
A SAM CLI template for a single-endpoint Hello World Lambda function in Scala
Resources:
HelloScalaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: HelloScala
Description: A simple AWS Lambda function in Scala
Runtime: java8
Handler: lambda.ApiGatewayProxyHandler
CodeUri: target/scala-2.12/hello-scala.jar
MemorySize: 512
Timeout: 15
Environment:
Variables:
env: staging
Events:
Hello:
Type: Api
Properties:
Path: /hello/{name}
Method: GET
Outputs:
ApiURL:
Description: "API endpoint URL for Prod environment"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/{name}"
Anyone has ever experienced something similar?
How would you solve this?
AWS Lambda functions have a code size limit. You tried to deploy something which was too big. It looks like you wanted to use something from the AWS SDK but instead of picking the specific module you picked the dependency with everything.
When working with Lambda try to reduce the size of your dependencies.

Windows, Gradle and Cucumber combination throws an IOException upon generating reports

I'm working on a project which uses a combination of Windows, Java, Groovy, Gradle and Cucumber. This combination gives me some problems on my Windows machine that my *NIX colleagues are not experiencing. Upon running the gradle build, gradle wants to output some reports. The location and filename of these reports is apparently determined by the definition or output of the Cucumber tests. The name used is unfortunately not something that can be used as a filename, so I'm getting an IOException for each test report.
For the Cucumber test, we use the following structure:
Scenario Outline: Receive and parse ReturnItem from Service
Given The message from service return item outlined in <messagePath>
When We process the message
Then XXX posted a message to YYY on topic <topic> with event <eventType>
And payload matches <resultPath>
| messagePath | topic | eventType | resultPath |
| /test/testxml.xml | test_topic | EVENT_TYPE | /result/result.json |
After running this, I receive the following exception:
Caused by: org.gradle.api.UncheckedIOException: Could not write to file 'C:\xxx\project\build\reports\tests\test\packages\| \test\testxml.xml | test_topic | EVENT_TYPE | \result\result.html'.
at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:151)
at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:127)
at org.gradle.internal.IoActions.writeTextFile(IoActions.java:45)
at org.gradle.reporting.HtmlReportRenderer$DefaultHtmlReportContext.renderHtmlPage(HtmlReportRenderer.java:118)
at org.gradle.api.internal.tasks.testing.report.DefaultTestReport$HtmlReportFileGenerator.run(DefaultTestReport.java:147)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:300)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:292)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:174)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.access$900(DefaultBuildOperationExecutor.java:48)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$ParentPreservingQueueWorker.execute(DefaultBuildOperationExecutor.java:342)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.java:230)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.access$600(DefaultBuildOperationQueue.java:172)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.java:209)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable$1.call(DefaultBuildOperationQueue.java:203)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:154)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.java:203)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.java:177)
... 3 more
Caused by: java.io.IOException: Unable to create directory 'C:\xxx\project\project-test\build\reports\tests\test\packages\| \test\testxml.xml | test_topic | EVENT_TYPE | \result'
at org.gradle.internal.IoActions$TextFileWriterIoAction.execute(IoActions.java:141)
... 19 more
Does anybody know how to fix this? The only 'solution' I could come up with is disabling the reports, which works, but is more a workaround than a solution. For disabling I used the following configuration in the gradle.build for this:
apply plugin: 'java'
apply plugin: 'groovy'
test {
reports {
junitXml.enabled = false
html.enabled = false
}
}
(Inspired by: How to make Gradle build produce HTML test report instead of XML default?)
I finally found the culprit. Apparently these filenames correspond to the default behaviour of JUnit for report generation of Cucumber tests. On *NIX, this doesn't provide any problem. On Windows however, this will result in an exception due to the pipes in the Examples. The IOException is somewhat special apparently, since the most exceptions that I found on the internet were FileNotFoundExceptions. That explains why it took me so long to find an answer, I focused on the exception.
The solution here is to use the following JUnitOption as an #CucumberOptions annotation when running the Cucumber tests: --filename-compatible-names.
A code example for Java & Spring looks like this:
#RunWith(Cucumber.class)
#CucumberOptions(junit = {"--filename-compatible-names"})
public class CucumberRunner {
}
It would be nice if these kind of non-breaking OS dependent options would be default instead of optional.
Based upon the information provided, it looks like it's trying to create a directory called:
'C:\xxx\project\project-test\build\reports\tests\test\packages\| \test\testxml.xml | test_topic | EVENT_TYPE | \result'
Can you show the code around passing in messagePath? I suspect you are passing in the entire row of data rather than just the messagePath (I'm going to take a wild guess that you are performing a .toString() on an array instead of passing in the first element of the array)

JACOB Catastrophic Failure Invoking an .OCX Method

Hi I am currently task to convert a legacy Visual Basic 6 Application that communicates with the a Passbook Printer via third Party Application XFS.ocx (No source).
Based on my research I could JACOB to do this task but I am encountering an error. Can anyone help me? Based on the logs my program can instantiate the activeXcomponent and see the id of the methods I want to use however when I try to use them I encounter an error.
In the sample VB6 code I am using as a guide the method VersionRequired requires two integers as a parameter while ApplicationID requires just a string.
Hopefully I just made a mistake on the syntax or JACOB method to use as I only want to use java JNI as a last resort. Please note this application will always be installed in a Windows(7/10) workstation so other OS compatibility is not an issue.
Here is my Code
ActiveXComponent activeXComponent = new ActiveXComponent("XFS.XFSCtrl.1");
System.out.println( activeXComponent.getIDOfName(activeXComponent, "ApplicationID"));
System.out.println( activeXComponent.getIDOfName(activeXComponent, "VersionRequired"));
System.out.println( activeXComponent.getIDOfName(activeXComponent, "Description"));
System.out.println( activeXComponent.getIDOfName(activeXComponent, "Open"));
//Variant variant = activeXComponent.call(activeXComponent, "VersionRequired",1,1);
//Variant variant = activeXComponent.call(activeXComponent, "Description"); // added 072318 for David answer
//Variant variant = activeXComponent.getProperty("Description");
//activeXComponent.setProperty("Description", "Description");
//Variant variant = activeXComponent.get(activeXComponent,"Description");
activeXComponent.call(activeXComponent, "Description", "value");
Here is the logs and error I am encountering
WARNING: JNI local refs: zu, exceeds capacity: zu
at java.lang.System.initProperties(Native Method)
at java.lang.System.initializeSystemClass(System.java:1166)
main: Loading library jacob-1.19-x86 using System.loadLibrary
main: Loading library jacob-1.19-x86 using System.loadLibrary
main: Loading library jacob-1.19-x86 using System.loadLibrary
main: ComThread: before Init: 0
main: ComThread: after Init: 0
main: ROT: Automatic GC flag == false
main: ComThread: after ROT.addThread: 0
main: ROT: adding com.jacob.activeX.ActiveXComponent#11d50c0->com.jacob.activeX.ActiveXComponent table size prior to addition:0
13
31
1
21
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:1
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:2
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:3
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:4
main: ROT: adding ->com.jacob.com.Variant table size prior to addition:5
Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered:
At Invoke of: Description
Description: 8000ffff / Catastrophic failure
at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:625)
at com.jacob.com.Dispatch.callN(Dispatch.java:453)
// at com.jacob.com.Dispatch.get(Dispatch.java:788) // added 072318 when using activeXComponent.get(activeXComponent,"Description")
at com.jacob.com.Dispatch.call(Dispatch.java:541)
// at com.jacob.com.Dispatch.call(Dispatch.java:529) // added 072318 for David answer
at ph.com.bdo.icos.passbook.Launcher.main(Launcher.java:32)
VB Code I am Using as a reference
With XFS1
'Set up the versions required of XFS and SP
.VersionRequired(WFS_VERSREQ_OLE, WFS_VERSREQ_LOW) = 1# ' 2.00
.VersionRequired(WFS_VERSREQ_OLE, WFS_VERSREQ_HIGH) = 2# ' 2.00
.VersionRequired(WFS_VERSREQ_API, WFS_VERSREQ_LOW) = 1.01
.VersionRequired(WFS_VERSREQ_API, WFS_VERSREQ_HIGH) = 2#
.VersionRequired(WFS_VERSREQ_SRV, WFS_VERSREQ_LOW) = 1.01
.VersionRequired(WFS_VERSREQ_SRV, WFS_VERSREQ_HIGH) = 2.1
'Get back one of the values for testing
fResult = .VersionRequired(WFS_VERSREQ_API, WFS_VERSREQ_LOW)
'Set and Get the Application property for testing
.ApplicationID = "Passbook Printer"
sAppID = .ApplicationID
sDescription = .Description
My guess is than Description is a read-only property, not a function
so you can't use a call on it and this code will bug, producing a catastrophic failure (COM error have always been obscure):
activeXComponent.call(activeXComponent, "Description", "value");
as explained by the message log :
Exception in thread "main" com.jacob.com.ComFailException: A COM exception has been encountered: At Invoke of: Description
and you can't set a property either because it's read-only:
activeXComponent.setProperty("Description", "Description");
Actually if you read your VB6 code correctly, the Description property is just read
sDescription = XFS1.Description
Try this instead:
Variant v = activeXComponent.call(activeXComponent, "Description");
String description = v.toString();

Chef download and install Oracle Java on Windows

I want to install Java with Chef 13 on Windows 7.
Installing from file is easy, but I want also to download it from Oracle archives. The thing is, Oracle requires special cookie - oraclelicense=accept-securebackup-cookie.
I've tried java cookbook, as it seems people did it without problems. Hovewer, after running Chef I get error:
Recipe: java::notify
* log[jdk-version-changed] action nothing (skipped due to action :nothing)
Recipe: java::windows
* ruby_block[Enable Accessing cookies] action run
- execute the ruby block Enable Accessing cookies
* remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] action create[2017-05-25T08:30:21+02:00] WARN: remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] cannot be downloaded from http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe: 401 "Authorization Required"
[2017-05-25T08:30:21+02:00] WARN: remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe] cannot be downloaded from http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe: 401 "Authorization Required"
================================================================================
Error executing action `create` on resource 'remote_file[C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe]'
================================================================================
Net::HTTPServerException
------------------------
401 "Authorization Required"
Resource Declaration:
---------------------
# In C:/Users/User/.chef/local-mode-cache/cache/cookbooks/java/recipes/windows.rb
62: remote_file cache_file_path do
63: checksum pkg_checksum if pkg_checksum
64: source node['java']['windows']['url']
65: backup false
66: action :create
67: end
68: end
Compiled Resource:
------------------
# Declared in C:/Users/User/.chef/local-mode-cache/cache/cookbooks/java/recipes/windows.rb:62:in `from_file'
remote_file("C:/Users/User\.chef\local-mode-cache\cache/jdk-7u79-windows-i586.exe") do
provider Chef::Provider::RemoteFile
action [:create]
default_guard_interpreter :default
source ["http://download.oracle.com/otn/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe"]
use_etag true
use_last_modified true
declared_type :remote_file
cookbook_name "java"
recipe_name "windows"
path "C:/Users/User\\.chef\\local-mode-cache\\cache/jdk-7u79-windows-i586.exe"
checksum nil
rights nil
deny_rights nil
verifications []
end
System Info:
------------
chef_version=13.0.118
platform=windows
platform_version=6.1.7600
ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [i386-mingw32]
program_name=C:/opscode/chef/bin/chef-client
executable=C:/opscode/chef/bin/chef-client
As you can see in logs above, I've set ['java']['oracle']['accept_oracle_download_terms'] to true (execute the ruby block Enable Accessing cookies).
Since this cookbook didn't work for me, I've tried to do my own java cookbook:
windows_package package_name do
source source
action :install
installer_type :custom
remote_file_attributes ({
:headers => {"Cookie" => "oraclelicense=accept-securebackup-cookie"}
})
options opts
end
... and it still gets the same error.
Did anything change on Oracle site that downloading JDK doesn't work anymore? Or do I have to set firewall or something?
Oracle introduces changes like this from time to time, that's unfortunately common. Since nothing can be done about it from a regular user's perspective, the best solution is to host the packages yourself, and modify your node attributes to point to that source. That's what I do, with the attributes looking something like this (for linux and a samba share):
"java": {
"install_flavor": "oracle",
"jdk_version": "8",
"jdk" : {
"8" : {
"x86_64" : {
"url" : "file:///path/to/jdk-8u131-linux-x64.tar.gz",
"checksum": "the file's checksum"
}
}
}
}
This way, changes like the one made by Oracle are no longer problematic.

XText: 7 languages tutorial can't resolve reference to JvmIdentifiableElement in example 1 scripting

I'm following 7 languages tutoiral from XText homepage (http://www.eclipse.org/Xtext/7languages.html)
In the first example "scripting" I've managed to get almost everything running, but there seems to be a problem with identifiers scoping.
I have editor running and code generation for empty script, but trying to write anything useful doesn't work.
I typed code for grammar and model inferer verbatim from tutorial and also tried to use versions from github repo with examples https://github.com/xtext-dev/seven-languages-xtext
demo.script
val i = 1
demo.java generated
public class demo {
public static void main(final String[] args) {
final int i = 1;
}
}
This works fine
Now here is input that causes problems
error.script
println("test")
This reports two errors:
Error 1
Description: Couldn't resolve reference to JvmIdentifiableElement 'println'.
Resource: error.script
Path: /org.xtext.scripting.demo/scripting
Location: line: 3 /org.xtext.scripting.demo/scripting/demo.script
Type: Scripting Problem
Error 2
Description: This expression is not allowed in this context, since it doesn't cause any side effects.
Resource: error.script
Path: /org.xtext.scripting.demo/scripting
Location: line: 1 /org.xtext.scripting.demo/scripting/error.script
Type: Scripting Problem
I'm using XText plugins in version 2.4.0
Any suggestions what to change to make this example working as described in tutorial?
You have to add a dependency to the xbase.lib to the project that contains the script file.

Categories