Is there any Alternative of --guess in java runcukes - java

i am getting an error `cucumber.runtime.AmbiguousStepDefinitionsException: ✽.Then I should validate my username with expected value (features/sanity.feature:32) matches more than one step definition:
^I should validate ([^"]*) with expected value in UserSteps.iShouldValidateWithExpectedValue(String)
^I should validate my username with expected value$ in HomeSteps.iShouldValidateMyUsernameWithExpectedValue()
`
When i run with calabash i use to add "--guess" in the run command.
But Don't know how to resolve the same in CucumberJvm in Java.
Is there any possiblities to add this in #cucumberoptions ?
Am using the maven dependency
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>

--guess is not an option that you can set in the command line runner. Recall that cucumber can always guess wrong. I recommend that you simply change a few words near the beginning of the failing statement to make sure that that statement is unique. Better safe than sorry.
Searching through the cucumber-jvm source, there is at least one reference to --guess being set by default.

Related

ERROR: illegal value 'false1' specified for bool flag 'cprof_enable_heap_sampling'

I am trying to configure Profiler for GCP by injecting a boolean value from in pom.xml for cprof_enable_heap_sampling (which worked all fine until value for heap option was boolean).
Just to test it out I provided a non-boolean value for this property and even after using the correct booleans(true/false) seems the previous values are getting picked up.
Error:
Picked up JAVA_TOOL_OPTIONS: -Xms6G -Xmx10G
ERROR: illegal value 'false1' specified for bool flag 'cprof_enable_heap_sampling'
Code:
pom.xml:
<properties>
<heap.option>true</heap.option>
</properties>
....
<jvmFlag>
-agentpath:<path>=-logtostderr,-cprof_enable_heap_sampling=${heap.option},-cprof_service=<service>,-cprof_project_id=<project>
</jvmFlag>
Note: It worked all fine when I had hardcoded it earlier.
As soon as I tried with a non-boolean value to test it out it started throwing the error.
Is there a way we can unset/overwrite JAVA_TOOL_OPTIONS?

how to fix java.lang.NoClassDefFoundError: org/apache/commons/net/ntp/NTPUDPClient

I downloaded commons-net-3.1.jar on this website:
https://jar-download.com/maven-repository-class-search.php?search_box=org.apache.commons.net.ntp.NTPUDPClient
it worked fine, but now I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/net/ntp/NTPUDPClient
Caused by: java.lang.ClassNotFoundException: org.apache.commons.net.ntp.NTPUDPClient
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
Can someone help me to fix this problem? I already searched for a solution, but I just find android threads without a solution for my problem.
Edit: I am using javaSE-14 (java-JDK) and eclipse. I am using the standard javaSE-14 library and a new created library with commons-net-3.7.jar (from Uroš answer), but I still have the same error. (I am not using a maven projekt, I am using a normal java projekt)
I tried to install the jar into my pom.xml with this text:
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.7</version>
<scope>system</scope>
<systemPath>
C:\Users\denni\Downloads\Apache jar\commons-net-3.7.jar
</systemPath>
</dependency>
I also tried the text that was written below, but I still have the same problem
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.7</version>
</dependency>
import java.net.InetAddress;
import java.util.Date;
import org.apache.commons.net.ntp.NTPUDPClient;
import org.apache.commons.net.ntp.TimeInfo;
public class time {
public static void main(String[] args) throws Exception {
NTPUDPClient client = new NTPUDPClient();
client.open();
// use host name or IP address of target NTP server
InetAddress hostAddr = InetAddress.getByName("pool.ntp.org");
TimeInfo info = client.getTime(hostAddr);
info.computeDetails(); // compute offset/delay if not already done
Long offsetValue = info.getOffset();
Long delayValue = info.getDelay();
String delay = (delayValue == null) ? "N/A" : delayValue.toString();
String offset = (offsetValue == null) ? "N/A" : offsetValue.toString();
System.out.println(" Roundtrip delay(ms)=" + delay
+ ", clock offset(ms)=" + offset); // offset in ms
client.close();
}
}
Hi Hans and welcome to SO.
java.lang.NoClassDefFoundError is not the same as java.lang.ClassNotFoundException.
What is most likely happening to you is that you have included commons-net-3.1.jar, but that doesn't mean commons-net-3.1.jar doesn't depend on some other .jar.
You haven't posted what your classpath looks like or in which IDE you are working in, whatever the case may be I strongly suggest you avoid manually adding .jar files from random sources because:
You will get errors like this one, missing dependencies.
More importantly, it is insecure! You may include some malicious stuff without knowing, and let us be honest here - you sure ain't gonna decompile that .jar and check if it is fishy or not.
Ergo I recommend looking up Maven and how to use it with your IDE, there are plenty of tutorials online about it.
You can use https://mvnrepository.com/ to find the dependecy you need, for example the one you are looking for can be found here, and is currently at version 3.7.
To include it in you maven project all you would need to do is to add it to pom.xml
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.7</version>
</dependency>

Call java method from Drools rules

I want to create a Drools rule that says that if the CPU usage from the data I gather using a HTTP request is over a specific threshold (e.g. 20%) then call a function that lays on the class Netdata which are also passed to Drools Fusion. So what I have written until now is:
rule "CPU usage over 20% once"
when
$cpu : Netdata(cpuUsagePerc > 0)
from entry-point Netdata
then
System.out.println("CPU usage is now over 20%");
$cpu.setCpuOverCount();
end
But the thing is, that I get this error: java.lang.RuntimeException: wrong class format. If I delete this line $cpu.setCpuOverCount(); the rule executes, and prints CPU usage is now over 20% without any problems.
The method I am trying to call is this one:
public void setCpuOverCount() {
cpuOverCount++;
}
Is there a way to call a method in the first place, and if yes how do I do it? If not, how can I overcome such problems?
I am using Drools version 5.1.1.
It could be due to ECJ version not supporting your Java version as per this answer. You can try manually updating the ECJ version:
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>>4.5.1</version> <!-- latest is 4.6.1 -->
</dependency>

How to call Java methods in Maven archetype XML

I am trying to install a custom archetype in my local repo. When user generate a project based on this archetype, they are required to provide the artifactId. Most of the time it is in all lower case. However, the main Class name (also the java filename) is dependent on this artifactId with the first letter capitalized. Instead of asking user to input another variable, I would like to call some String method to convert the artifactId to the correct format for class name.
In Maven archetype: Modify artifactId, looks like you can embed Java method in archetype-metadata.xml as below:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
So I did something similar in my archetype-metadata.xml to capitalize first letter.
<requiredProperty key="artifactId" />
<requiredProperty key="serviceName">
<defaultValue>${artifactId.toLowerCase().substring(0,1).toUpperCase()+actifactId.toLowerCase().substring(1)}</defaultValue>
</requiredProperty>
However I got the following parse error:
SEVERE: Parser Exception: serviceName
org.apache.velocity.runtime.parser.ParseException: Encountered "+artifactId.toLowerCase().substring(1)}" at line 1, column 55.
Was expecting one of:
"[" ...
"}" ...
at org.apache.velocity.runtime.parser.Parser.generateParseException(Parser.java:3679)
What is correct way to insert Java String method in this archetype xml?
The plus character can't be used as string concatenation operator here, it's also not needed. Just concatenate two replacements (without any operator between):
<defaultValue>${artifactId.toLowerCase().substring(0,1).toUpperCase()}${actifactId.toLowerCase().substring(1)}</defaultValue>
<defaultValue>
${artifactId.substring(0,1).toUpperCase()}${artifactId.substring(1).toLowerCase()}
</defaultValue>
works for me, but artifactId is coming from the archetype project and not from my argument artifactId as expected...
This will capitalize the first letter.
<requiredProperty key="artifactId" />
<requiredProperty key="serviceName">
<defaultValue>${StringUtils.capitalize("artifactId")}</defaultValue>
</requiredProperty>
Make sure you have Apache commons dependency included.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>

Running *.ktr in Java throws KettleMissingPluginsException - Why?

I created a variety of data transformations (*.ktr files) which run perfectly when started from the Spoon GUI (PDI-CE 5.4.0.1-130; Windows 7).
I try to run them from Java with the following code (close to the example code from the documentation):
KettleClientEnvironment.init();
TransMeta metaData = new TransMeta("C:\\examplepath\\test.ktr");
Trans transformation = new Trans(metaData);
transformation.execute(null);
transformation.waitUntilFinished();
...
When executed, I get the following exception:
org.pentaho.di.core.exception.KettleMissingPluginsException:
Missing plugins found while loading a transformation
Step : CsvInput
Step : XMLOutput
at org.pentaho.di.trans.TransMeta.loadXML(TransMeta.java:2882)
at org.pentaho.di.trans.TransMeta.<init>(TransMeta.java:2718)
at org.pentaho.di.trans.TransMeta.<init>(TransMeta.java:2670)
at org.pentaho.di.trans.TransMeta.<init>(TransMeta.java:2647)
at org.pentaho.di.trans.TransMeta.<init>(TransMeta.java:2627)
at org.pentaho.di.trans.TransMeta.<init>(TransMeta.java:2592)
at org.pentaho.di.trans.TransMeta.<init>(TransMeta.java:2555)
at (caller method in my code)
As I am not using any plugins but only native steps (in this example CsvInput, XMLOutput), I do not understand the reason for the thrown Exception. Why is it thrown and how can I fix the code to run?
Am I maybe missing maven dependencies? I use the following repository http://repository.pentaho.org/content/groups/omni/ and dependencies:
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>5.4.0.1-130</version>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
<version>5.4.0.1-130</version>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-ui-swt</artifactId>
<version>5.4.0.1-130</version>
</dependency>
<dependency>
<groupId>pentaho-library</groupId>
<artifactId>libformula</artifactId>
<version>5.4.0.1-130</version>
</dependency>
Thanks a lot in advance for your answers.
I accidentally used KettleClientEnvironment.init() but I should have used KettleEnvironment.init(). Consequently, the environment was not properly initialized which triggered the Exception. Wow. That's a rookie mistake :)
The corrected code, as it can also be found in the Kettle docs and Rishu's example:
KettleEnvironment.init();
TransMeta metaData = new TransMeta("C:\\examplepath\\test.ktr");
Trans transformation = new Trans(metaData);
transformation.execute(null);
transformation.waitUntilFinished();
...
Thanks lufki and Rishu for the comments and pointers.

Categories

Resources