IllegalArgumentException Cucumber Custom Params Java - java

I'm getting a runtime CucumberException:
cucumber.runtime.CucumberException: Failed to invoke com.inin.testing.cucumber.stepdefs.ui.chat.ChatRosterStepDefs.a_splat_is_displayed_on_the_groups_tab_of_the_chat_roster(String,String) in file: *******/cucumber-tests/target/classes/, caused by java.lang.IllegalArgumentException: argument type mismatch
My feature step is: Then a splat is not displayed on the "user" tab of our roster
My custom param for cucumber expressions is:
registry.defineParameterType(new ParameterType<>(
"isOrIsNot", // name
"is|is not", // regexp
boolean.class, // type
(String arg) -> "is".equals(arg) // transformer function
));
And lastly my Gherkin:
#Then("a splat {isOrIsNot} displayed on the {string} tab of our roster")
I'm not too sure what I'm doing wrong, is my custom param defined incorrectly?

Well for anyone wondering, I simply needed to change the custom param definition to String.class, and have the function return the arg!

Related

XSL: Cannot convert argument/return type in call to method

I got XSL file which i'm trying to generate over my app.
The code goes like this:
TransformerFactory factory = TransformerFactory.newInstance();
Source styleSheetLoc = new ResourceSource(styleSheetLocation);
Templates t = factory.newTemplates(styleSheetLoc); // <<< throwing the Exception
return t.newTransformer();
The exception is:
ERROR: 'Cannot find external method 'com.am.caretalks.util.XsltUtils.getResourceString' (must be public).'
FATAL ERROR: 'Cannot convert argument/return type in call to method 'com.am.caretalks.util.XsltUtils.getResourceString(node-set, node-set, int)''
javax.xml.transform.TransformerConfigurationException: Cannot convert argument/return type in call to method 'com.am.caretalks.util.XsltUtils.getResourceString(node-set, node-set, int)'
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:990)
at com.am.caretalks.sendreport.CreatePDF.buildTransformer(CreatePDF.java:1147)
at com.am.caretalks.sendreport.CreatePDF.createProviderEngagementPDF(CreatePDF.java:608)
at com.am.caretalks.sendreport.CreatePDF.createProviderEngagementPDF(CreatePDF.java:586)
at com.am.caretalks.admin.EngagementReportExportServiceImpl.exportAndUpload(EngagementReportExportServiceImpl.java:131)
at com.am.caretalks.admin.EngagementReportExportServiceImpl$$FastClassBySpringCGLIB$$38327504.invoke(<generated>)
EDIT:
This is the called function from the XSL file
public static String getResourceString(final String messageKey, final String locale, final String customerIndex) {
.
.
}
I searched the web and I found a solution that tells me to use only objects (not primitives) while calling to a function from my XSL file to my java code and due to that i'm getting these error, but nothing did helped me here.
The big issue here that I don't understand what is the error and how to solve it, what do I need to do according the thrown Exception?
Any other suggestions to fix this issue are welcome
The error message suggests that you are passing inappropriate arguments to the function. It appears the method expects (string, string, string) and you are passing (node-set, node-set, int). I don't know Xalan well, but try doing an explicit conversion of the supplied arguments to the required type by calling number() or string().

Error in ColdFusion Javacast array to class from loadPaths

I am trying to use Elasticsearch's Java API.
I am trying to create a RestClientBuilder.
Host=createObject("java", "org.apache.http.HttpHost").init(variables.HostName, variables.Port);
Node=createObject("java", "org.elasticsearch.client.Node").init(Host);
RestClient=createObject("java", "org.elasticsearch.client.RestClient").builder(Javacast("org.elasticsearch.client.Node[]", [Node])).build();
I get the error
Cannot convert the value to Java array because type org.elasticsearch.client.Node is unknown.
Also if I just try to use:
RestClient=createObject("java", "org.elasticsearch.client.RestClient").builder(Javacast("org.apache.http.HttpHost[]", [Host]));
I get the following error
Either there are no methods with the specified method name and
argument types or the builder method is overloaded with argument types
that ColdFusion cannot decipher reliably. ColdFusion found 0 methods
that match the provided arguments. If this is a Java object and you
verified that the method exists, use the javacast function to reduce
ambiguity.
This I assume is because ColdFusion doesn't play nicely with varargs
I found a workaround using this method
https://www.bennadel.com/blog/1980-tojava---a-coldfusion-user-defined-function-for-complex-java-casting.htm
I believe there is a bug with Javacast and javaSettings loadPaths not being used.
coldfusion.runtime.Cast$UnknownTypeException: Cannot convert the value
to Java array because type org.elasticsearch.client.Node is unknown.
at coldfusion.runtime.Cast.toJavaArray(Cast.java:1602)
Additionally if I try to perform the actiuons that the UDF takes
local.javaClass = createObject("java", "org.apache.http.HttpHost");
local.HostArrayReflect = createObject("java", "java.lang.reflect.Array");
local.HostArray = local.HostArrayReflect.newInstance(
local.javaClass.GetClass()
, JavaCast( "int", ArrayLen(local.Hosts))
);
for (i=0; i LT ArrayLen(local.Hosts); i=i+1) {
local.HostArrayReflect.Set(local.HostArray, JavaCast("int", i), local.Hosts[i]);
}
I get the error
An exception occurred while instantiating a Java object. The class
must not be an interface or an abstract class. If the class has a
constructor that accepts an argument, you must call the constructor
explicitly using the init(args) method. Error :
org.apache.http.HttpHost
java.lang.NoSuchMethodException: org.apache.http.HttpHost.() at
java.lang.Class.getConstructor0(Class.java:3082) at
java.lang.Class.newInstance(Class.java:412) at
coldfusion.runtime.java.JavaProxy.createObjectWithDefaultConstructor(JavaProxy.java:209)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:92)
This happens when I try to run getClass(), but in the UDF there is no issue. A coworker tried to run this on Lucee and it seems to have worked, so I believe there is a bug in CF related to this.

Error in .jcall("weka/filters/Filter", "Weka/core/Instances;", "useFilter", : java.lang.IllegalArgumentException:

I am trying to execute the following code to filter features using mlr as shown in here
fv = generateFilterValuesData(classifTask, method = c("information.gain", "chi.squared"))
But I get the following error although the specified attribute is numeric in the dataset Task(classifTask)
Error in .jcall("weka/filters/Filter", "Weka/core/Instances;",
"useFilter", : java.lang.IllegalArgumentException: A nominal attribute
(weighted_rev) cannot have duplicate labels
How can I fix this?

Create input control using jasper restapiv2

I'm using Jasper API rest v2 https://github.com/Jaspersoft/jrs-rest-java-client. I'm trying to create input control's dynamically.
ClientInputControl cliInp = new ClientInputControl();
cliInp.setLabel("FUNCIONARIO_ID_1");
cliInp.setDataType(new ClientDataType().setType(TypeOfDataType.date));
cliInp.setUri("/datatypes/FUNCIONARIO_ID_1");
session.resourcesService().resource("/datatypes").createNew(cliInp);
I need to create this input control so I can add to my report.
When executing this code I have
Exception in thread "main" com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.BadRequestException: Bad Request
EDIT
Log files give following error:
mt error:[{
"message":"The type 0 is invalid",
"errorCode":"illegal.parameter.value.error",
"parameters":
["type",
"0"]
}]
Can someone tell me what I'm doing wrong?
You should define more values
ClientDataType type = new ClientDataType()
.setLabel("Data")
.setType(TypeOfDataType.date)
.setUri("/types");
byte singleValue = 2;
ClientInputControl inputControl = new ClientInputControl()
.setLabel("Data")
.setType(singleValue) //this parameter missing is your error
.setDataType(type)
.setUri("/inputs");

JUnit which is recommended assertTrue() or assertEquals() for String?

My code is like below
#Test
public void testMyMethod(){
MyClass mc = new MyClass();
String exeVal="sometext some text";
String x=mc.exampleMethod();
// Assertion type 1
Assert.assertEquals(exeVal,x);
//Assertion Type 2
Assert.assertTrue(exeVal.equals(x));
}
I want to know which is the best approach.
Type 1 is preferred because of the assertion message you will receive when they do not match.
org.junit.ComparisonFailure: expected: <[foo]> but was: <[bar]>
vs
java.lang.AssertionError
Type 1 is preferred because of the following reasons.
It gives you a better error message.
ex:- "expected [3] but found [4]" . The second approach will evaluate the condition and will give you a message like "expected [true] but found [false]" and the user will not get the values evaluated.
AssertEquals is null safe and assertTrue isn't

Categories

Resources