Karate - How to deal with unicode characters? - unicode

I want to send a Unicode string as a request parameter like this:
{"mobile": "۹۸.۹۱۲۳۴۳۰۴۱۲"}
but Karate send it like this instead:
{"mobile": "??.??????????"}
I've tried to read Unicode text from a file contains my text:
۹۸.۹۱۲۳۴۳۰۴۱۲
then read and send it this way:
* def persianMobile1 = read('classpath:account/unicode/persian.mobile.txt')
Given url karate.get('urlBase') + "account/activateMobileByVerificationCode"
And request
"""
{
"mobile":#(persianMobile1),
"code":#(defaultVerificationCode)
}
"""
Same problem occurred. What should I do?

Set the maven-surefire-plugin in your pom.xml to use the UTF-8 file encoding. Add this <plugin> if it is not there already.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
EDIT: looks like OP is using Gradle. You need to get Karate (which I assume is run via JUnit) to have the JVM file.encoding set to UTF-8 - to fix this.
Here is a link that should help you do this in Gradle: https://discuss.gradle.org/t/no-possibility-to-set-file-encoding-for-junit-tests-in-gradle-2-13-and-odler/17223
I suggest you work with a Java dev if you need to.

Related

Eclipse, Maven and incorrect MANIFEST.MF file being used

This time I have a problem with running my Web App project in Eclipse.
Whenever I'll commit my app to SVN, then build it and deploy using Jenkins to Tomcat container - the app runs fine, and the correct MANIFEST.MF is used.
But, when I want to debug it inside Eclipse (with Tomcat 8.5 container) - there is an deafult manifest file used instead of the one containing my custom properties from pom.xml.
I've defined few variables in pom.xml regarding the application name, version and so on. The manifest file is being generated in /target/generated-resources/m2e-wtp/webResources/META-INF/MANIFEST.MF. This file contain all of my custom properties.
But when I call
resources = getClass().getClassLoader()
.getResources("META-INF/MANIFEST.MF");
The path returned is: /META-INF/MANIFEST.MF. The file indeed exists, but is almost empty:
Manifest-Version: 1.0
Class-Path:
Here's my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Exclude an unnecessary file generated by the GWT compiler. -->
<!-- <packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>-->
<manifest>
<addClasspath>true</addClasspath>
<addDefaultImplementationEntries>false</addDefaultImplementationEntries>
</manifest>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Specification-Title>${project.name}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<App-Version>${build.version}</App-Version>
<Build-Number>${build.number}</Build-Number>
<SVN-Revision>${rev.number}</SVN-Revision>
<Sys-Name>${sys.name}</Sys-Name>
<Sys-Full-Name>${sys.full.name}</Sys-Full-Name>
</manifestEntries>
</archive>
<!-- <packagingExcludes>WEB-INF/classes/META-INF/MANIFEST.MF</packagingExcludes> -->
</configuration>
</plugin>
I've tried almost every suggestion I've googled so far and nothing works :(
Please help!
Thank you in advance
Tom
Okay,
Finally I've found a solution. It turned out that I just need to simply copy a generated MANIFEST.MF file from the genrated wtp output folder to my project META-INF.
During building on Jenkins - the file is getting ovewritten by the generated one anyway so it seems that this makes no harm to project.

Karate BDD URL encoding issue

I am trying to automate the endpoint BestBuy which has special characters and the resource URI is /products?$select[]=name&$select[]=price
I have also added the configuration for the UTF-8 encoding in the maven-surefire-plugin as below under the /build/plugins
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
But when am running (either through IDE or mvn test on the terminal) am getting error as 404 not found, and in the error getting
info: (404) Route: /products%3F$select%5B%5D=name&$select%5B%5D=pbrice
- Page not found
Appreciate any help with this.
I was able to fix by altering the test as below.
Given path 'products'
And param $select[] = 'name'
And param $select[] = 'price'
When method get
Then status 200
Then print response
Posting, so that can be helpful for someone who might be facing similar issue.
Reference URL: Karate Test

How can I run a Maven webapp in Eclipse when I need resource filtering for properties files?

I need to get some updates on this issue, I found this thread back in 2009 here, but the answer was to use maven 2, I'm not sure if Q4E works with maven 3 or not. I need to have some properties files filtered during the mvn package phase for the resulting war to be functional, the resource filtering is working fine with CLI mvn install. But when I do "Run on server/debug on server", the filtering is not working any more.
The aforementioned thread author ended up using q4e, claiming q4e gets the resource filtering right. I have q4e installed as well along with m2e, but still doesn't work, so I don't know if q4e is not working with maven 3, or I'm doing something wrong.
Thanks,
David
updated to the latest m2e-wtp plugin 0.15 (resource filtering bug fix since 0.12), it works fine now.
I'm not sure if this matches your problem, but I wanted to populate my web.xml file with properties from the pom during build and I put a groovy script in the pom to do it. It worked a treat and might work for you too. It definately works in both eclipse and on the command line. Here is my pom fragment:
<plugin>
<!-- Groovy script to set the description and version in the web.xml display name -->
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>groovy-magic</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def file = new File("src/main/webapp/WEB-INF/web.xml");
def fileText = file.text;
def match = "<display-name>[^<]*</display-name>";
def replace = "<display-name>"+project.description+" "+project.version+"</display-name>";
fileText = fileText.replaceAll(match, replace);
file.write(fileText);
println "Updated web.xml"
</source>
</configuration>
</execution>
</executions>
</plugin>

glassfish 3.1 system properties deployment

I had a log4j error (see here) and the suggested fix worked. I set the org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES system property to false in the console with asadmin.
As I am working with maven in a project using glassfish 3.1 I have to insert this fix in my code somewhere to make it run for everybody. I figured out this can be done with the maven-embedded-glassfish-plugin as a command. So i wrote this code and put it in my pom.xml:
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.1</version>
<configuration>
<commands>
<command>create-system-properties org.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false</command>
</commands>
</configuration>
</plugin>
But the server will not create the system property. What am I missing here?
Is there another way to realize this? Any help is appreciated.

Ignoring Maven/Scala unit test files

I am writing my unit test cases for a Java project using Scala (JUnit 4). I am running the tests using Maven.
I have written a src/test/scala/com.xxx.BaseTest class for the tests to provide some common functionality (#BeforeClass, etc.), but no actual #Test cases.
Whenever I run the tests using mvn on the command line, it insists on trying to look for tests in the BaseTest class, and gets an error because there are none present.
Other than using an #Ignore, is there any way to have Maven/Scala/Surefire not try to run the BaseTest class? Adding the #Ignore is not a big deal, but my test run shows one more test than I actually have with the label "Skipped: 1".
UPDATE: I found a solution. I renamed BaseTest to Base; Maven now ignores it. Is there any other way?
You can either rename the base test class not to have *Test ending, for example BaseTestCase.java. This is what I would recommend.
Most likely maven executes tests with surefire plugin, so alternatively you just can configure surefire plugin to skip BaseTest.java. I think, by default surefire assumes that all classes ending with *Test are test classes. Something like this in the pom.xml.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>**/BaseTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>