I am new in scala programming, please consider the scenario...
.exec(http("request_7")
.post("/test/listing")
.headers(headers_12)
.formParam("abcId", "${abcID}")
.formParam("action_id", "100")
.formParam("controller", "/test/listing")
.check(jsonPath("$.data[*].xyzId").findAll.saveAs("xyzID"))
.check(jsonPath("$.data[*].abcNo").findAll.saveAs("ABCNo"))
.check(jsonPath("$.data[*].revId").findAll.saveAs("revID"))
.check(jsonPath("$.data[*].dTypeId").findAll.saveAs("dTypeID")))
In this request, I have to implement multiple check(s) to get the value. It is manual procedure.
Is there any method in scala to perform this scenario in single check? In other words,
I want to get these values in single json check. Is it possible???
So can anyone tell me what is the method to implement this scenario???
Your help would be much appreciated.
Thanks,
Praveen Mourya
Related
I'm trying to get specific data from a bigger/nested API JSON Response. But because it's highly dynamic, it fails quite often because there are some branches missing down the JSON Tree.
Is there a good way or some best practices how to get the data?
Example:
#myrecords.cvss31 = jsonresponse["result"]["CVE_Items"][0]["impact"]["baseMetricV3"]["cvssV3"]["vectorString"]
In this case, sometimes it's throwing an error, because "cvssV3" is nil. Maybe in the future also "baseMetricV3" could be nil.
So, my approach would be to create 7 if-Statements - for every attribute. "if jsonresponse["result"].present?...", next: "if jsonresponse["result"]["CVE_Items"].present?" and so on. But that doesn't seem right.
I also tried something like "..["vectorString"].presence ||= "no NVD CVSS 3.1 Score"", but because the attribute before "vectorString" is missing, this doesn't seem to work either.
I also have a lot of other attributes to extract from that API. So basically I would have to write hundrets of conditional statements.
Is there a better way if I don't want to get ALL Data from that JSON Response extracted?
Putting it here for anyone stumbling on this issue. By using dig:
jsonresponse.dig("result", "CVE_Items", 0, "impact", "baseMetricV3", "cvssV3", "vectorString").presence || "no NVD CVSS 3.1 Score"
I am trying to find complete documentation for cursor.fetchone and all I can find is:
http://mysql-python.sourceforge.net/MySQLdb-1.2.2/public/MySQLdb.cursors.CursorStoreResultMixIn-class.html#fetchone
my questions are:
what is exactly returned? a normal python array?
what does it return if there no more rows?
what does it do if the connection is dropped? throw an error? have a unique return value?
I am not sure why I can't find real documentation on this. Thank you in advance
I'll try to answer in order your questions.
What is exactly returned?
A tuple or a dictionary, depending how you did the connection.
What does it return if there no more rows?
None
What does it do if the connection is dropped?
An Exception is raised. If it's due to a timeout, for instance, it will be a MySQLdb.OperationalError.
I am not sure why I can't find real documentation on this
Try here: https://mysqlclient.readthedocs.io/
I am new to Java and I am having trouble understanding a question. I am asked to select which of the following choices throws an exception. The options are:
1.) Integer.parseInt(" ")
2.) Integer.parseInt("54 ")
3.) Integer.parseInt("")
4.) Integer.parseInt("-54")
5.) Integer.parseInt("54n")
To answer this question, I need some explanations. What does the Integer.parseInt method do? Doesn't it turn an integer into a String? What sort of arguments are illegal to put inside this method. For example, are you allowed to include negative numbers? Strings? Or does it only accept integers?
I was also wondering if you could clarify what "throws an exception" means. I have a rough idea, I think it just means that if there is an error in your program, it gets terminated. Howevere, you can use the "try-catch-finally" method to try and predicate any errors your program would have and write a possible code to fix it?
Sorry for all the questions, I just want to understand this completely.
There's an API I have no influence on that has a JSON result object with a member that has 23 fields. The paradigm of case classes doesn't work, because there's a limit of 22. I've seen Slick and other libraries use HLists to resolve this. Is there a way to do this in Argonaut? If so, please give me sample piece of code to leverage. Thank you!
object BusinessResults{
implicit def BusinessResultsCodecJson: CodecJson[BusinessResults] =
casecodec23(BusinessResults.apply, BusinessResults.unapply)( /**... 23 fields ...**/)
}
I did not create an elegant solution for this. I just hand jammed a 23 piece for-comprehension to create the decoder.
I'm writing some unit tests for my MVC application but I have some trouble about common sense.
So, I have a function in my model to test called add_Member. I'm using CodeIgniter that turns empty inputs ($_POST) to 0. In mysql, 0 values are not considered as NULL values so the constraint NOT NULL on my column (ME_Email in this example) can't be applied.
In my controller, I'm checking if my field $_POST['email'] is not empty and if it's a valid email. I do that before calling my add_Member function from my model.
My question is, do I need to test an empty post value in my add_Member ?
Thanks for answers
It's a good practice to test all the methods in your app. If you are gonna make any refactoring later, this will help you or if you deside just to extend this functionality in other classes. Also, this test can help you in the debbing process. My kind advice is to try to test all methods and functionalities.