There is a HashMap variable "AA" in my java class "PMS". Now I want to access "AA" in a cpp file. I use JNI to resolve this. Here is my code:
jclass clazz=env->FindClass("com/pms/PMS");
jfieldID field=env->GetStaticFieldID(clazz, "AA", "Ljava/util/HashMap");
jobject objPackages=env->GetStaticObjectField(clazz,field);
But I get "java/lang/NoSuchFieldError", that is "AA" cannot be found. Then I try this:
jclass clsPackages=env->FindClass("com/pms/PMS$AA");
This time I get "java/lang/NoClassDefFoundError". How should I do?
I think the second line in your code should be:
jfieldID field=env->GetStaticFieldID(clazz, "AA", "Ljava/util/HashMap;");
Semicolon at the end. It's part of the syntax. I forgot why.
a
Related
Custom Keyword written in python 2.7:
#keyword("Update ${filename} with ${properties}")
def set_multiple_test_properties(self, filename, properties):
for each in values.split(","):
each = each.replace(" ", "")
key, value = each.split("=")
self.set_test_properties(filename, key, value)
When we send paremeters in a single line as shown below, its working as expected:
"Update sample.txt with "test.update=11,timeout=20,delay.seconds=10,maxUntouchedTime=10"
But when we modify the above line with a new lines (for better readability) it's not working.
Update sample.txt with "test.update = 11,
timeout=20,
delay.seconds=10,
maxUntouchedTime=10"
Any clue on this please?
I am not very sure whether it will work or not, but please try like this
Update sample.txt with "test.update = 11,
... timeout=20,
... delay.seconds=10,
... maxUntouchedTime=10"
Your approach is not working, cause the 2nd line is considered a call to a keyword (called "timeout=20,"), the 3rd another one, and so on. The 3 dots don't work cause they are "cell separators" - delimiter b/n arguments.
If you are going for readability, you can use the Catenate kw (it's in the Strings library):
${props}= Catenate SEPARATOR=${SPACE}
... test.update = 11,
... timeout=20,
... delay.seconds=10,
... maxUntouchedTime=10
, and then call your keyword with that variable:
Update sample.txt with "${props}"
btw, a) I think your keyword declaration in the decorator is without the double quotes - i.e. called like that ^ they'll be treated as part of the argument's value, b) there seems to be an error in the py method - the argument's name is "properties" while the itterator uses "values", and c) you might want to consider using named varargs (**kwargs in python, ${kwargs} in RF syntax) for this purpose (sorry, offtopic, but couldn't resist :)
I try
#Test
public void testGetSingleUser() {
given().expect().
statusCode(200).contentType(ContentType.JSON).
body("_testingString", equalTo("got it")).when().
get("http://localhost:8080/getIt");
}
But always got this error message
java.lang.AssertionError : JSON path _testingString dosen't match.
Expected : "got it" got : [got it]
how to ignore "" and [] problem
Thanks
Note: This is untested code snippet but while looking at your error trace it may help you.
try
equalTo(Arrays.asList("got it"))
instead of
equalTo("got it")
When you receive a error saying, same like that:
JSON path total doesn't match.
Expected: 2000
Actual: <[2000]>
It means that your result(Actual:) is coming inside an array.
Hence, you should use a rest-assured-command(for example, hasItem) that verifies values 'inside an array'.
My code below illustrate a solution for this situation:
RestAssuredWebTestClient
.given()
.webTestClient(mockedWebClient)
.queryParam("cost", 1000)
.when()
.get(TEMPL_AGGREG_DATE)
.then()
.log()
.everything()
.statusCode(OK.value())
.body("_id", hasItem(project2.getStartDate()))
.body("total", hasItem((int)project2.getEstimatedCost()))
.body(matchesJsonSchemaInClasspath("contracts/aggregations/CostsGroupByStartDate.json"))
;
I am working on JNI program and I am not able to call a java method from my C++ program.
The code snippet of java method is here
public static void getTables(Connection conn) throws Exception {
String TABLE_NAME = "TABLE_NAME";
String TABLE_SCHEMA = "TABLE_SCHEM";
String[] TABLE_TYPES = {"TABLE"};
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet tables = dbmd.getTables(null, null, null, TABLE_TYPES);
while (tables.next()) {
System.out.println(tables.getString(TABLE_NAME));
System.out.println(tables.getString(TABLE_SCHEMA));
}
}
And I want to call this java method from C++ program.
I am able to call the main method
for that the code is
midMain = env->GetStaticMethodID(clsH, "main", "([Ljava/lang/String;)V");
I want to call getTables method like this. Please help me to solve it.
Please see
https://stackoverflow.com/a/14872927/755804
and probably these:
https://stackoverflow.com/a/14021142/755804
https://stackoverflow.com/a/15941319/755804
https://stackoverflow.com/a/21109940/755804
There is some difference between calling static and non-static methods, but not much.
I suggest you start with something that works and gradually change it to what you want.
I've begun experimenting with ANTLR3 today. There seems to be a discrepency in the expressions that I use.
I want my class name to start with a capital letter, followed by mixed case letters and numbers. For instance, Car is valid, 8Car is invalid.
CLASS_NAME : ('A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*;
This works fine when I test it individually. However when I use it in the following rule,
model
: '~model' CLASS_NAME model_block
;
However, the CLASS_NAME begins to pick up class names beginning with numbers as well. In this case, ANTLR picks up Car, 8Car or even #Car as valid tokens. I'm missing something silly. Any pointers would be appreciated. Thanks.
CLASS_NAME will not match 8Car or #Car. You're probably using ANTLRWorks' interpreter (or the Eclipse plugin, which uses the same interpreter), which is printing errors on a UI tab you're not aware of, and displaying the incorrect chars in the tokens. Use ANTLRWorks' debugger instead, or write a small test class yourself:
T.g
grammar T;
parse : CLASS_NAME EOF;
CLASS_NAME : ('A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')*;
Main.java
import org.antlr.runtime.*;
public class Main {
public static void main(String[] args) throws Exception {
TLexer lexer = new TLexer(new ANTLRStringStream("8Car"));
TParser parser = new TParser(new CommonTokenStream(lexer));
parser.parse();
}
}
I'm running into trouble trying to call a Python function from my C++ code.
I'm trying to call the Django function call_command, with the following parameters:
call_command('test', stdout=content)
See here why. This runs the command without the stdout=content argument:
PyObject_CallFunctionObjArgs(executeFunc, PyString_FromString("test"), NULL)
I can't, for the life of me, figure out how to create this keyword.
PyDict_New();
PyDict_SetItemString(...);
Nets me a 'stdout'='content' string, instead of stdout=content.
Py_BuildValue("{s=s}", ... , ...)
Does the same thing.
I can get the content PyObject no problem if necessary, I just can't seem to correctly create the stdout keyword argument without Python putting quotes (handling it as a string) at some point.
How can I call call_command('test', stdout=content) from the C API?
PyObject *args = Py_BuildValue("(s)", "test");
PyObject *kwargs = PyBuildValue("{s:O}", "stdout", content);
PyObject_Call(executeFunc, args, kwargs);
Note that even in Python, you can call the function the same way:
args = ("test",)
kwargs = {"stdout" : content}
call_command(*args,**kwargs)
"stdout" is a string with quotes here too, but it works. You are trying to get the same syntax as you use in Python, with noquotename=noquotevalue, but the syntax is just a representation. Both {"quotedname" : noquotevalue} and noquotename=noquotevalue are two different ways to represent the same thing. They both actually represent a dictionary whose key is a string and value is an object. That is what you pass as the third argument to PyObject_Call.
Py_BuildValue("{s:O}", "stdout", content_obj)