Creating Test in Jira using Rest Assured - gson

I am new to Rest Assured and currently trying to create a JSON message for posting an issue of type TEST in Jira using Rest Assured. However, I am not able to properly create the test steps in the message. Below are the code and the message structure that I am getting.
TestStepMap teststep = new TestStepMap();
List<TestStepMap> s = new ArrayList<TestStepMap>();
for (int i=0; i<4; i++)
{
int index = i;
String step = "Step " + (i+1);
String data = "Data " + (i+1);
String result = "Result " + (i+1);
teststep.setIndex(index);
teststep.setStep(step);
teststep.setData(data);
teststep.setResult(result);
s.add(i, teststep);
}
CustomField10011Map customfield_10011 = new CustomField10011Map();
customfield_10011.setSteps(s);
This is the output that I am getting.
{
"fields": {
"project": {
"key": "RT"
},
"summary": "Sum of two numbers",
"description": "example of manual test",
"issuetype": {
"name": "Test"
},
"customfield_10007": {
"value": "Manual"
},
"customfield_10011": {
"steps": [
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
},
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
},
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
},
{
"index": 3,
"step": "Step 4",
"data": "Data 4",
"result": "Result 4"
}
]
}
}
}
The test steps 1, 2 and 3 are being overwritten by the last step. How can I solve the issue? Any suggestions are highly welcome.
Thanks in advance.

You're adding the same teststep instance to list s every time.
What you want is to create and add a new TestStepMap object per iteration, otherwise you'll always be overwriting updates on that object from an earlier iteration of the loop.
List<TestStepMap> s = new ArrayList<TestStepMap>();
for (int i=0; i<4; i++)
{
int index = i;
String step = "Step " + (i+1);
String data = "Data " + (i+1);
String result = "Result " + (i+1);
TestStepMap teststep = new TestStepMap();
teststep.setIndex(index);
teststep.setStep(step);
teststep.setData(data);
teststep.setResult(result);
s.add(i, teststep);
}

Related

vue-jstree does not open children when loading data via api

<v-jstree :data="data"
textFieldName="name"
#item-click="itemClick"
/>
If I use statics - then this works:
data() {
return {
data: [
{
"name": "title 1",
"children": [
{
"name": "Child 1",
},
{
"name": "Child 2",
},
]
}
]
}
},
If I use ajax, then all data is loaded, but openChildren doesn't work(
Response comes in the correct format:
[{ "id": 1, "name": "Title", "children": [{ "id": 1, "name": "Child 1" }, { "id": 2, "name": "Child 2" }.......
children are also loaded, why does the functionality break down?
By trial, I found a way to solve it) in the server response in parent, the "opened" parameter must be specified , either true or false

How to use lodash filter to find objects in a list that dont have a certain property

I have an array that looks like this
{
"id": "1",
"name": "Test 1",
"age": 23
},
{
"id": "2",
"name": "Test 2",
"age": 62
},
{
"id": "3",
"name": "Test 3"
}
Using lodash filter, how do I filter objects where age is not defined? as in the last item with name "Test 3"
You can use _.filter() to remove items, with _.has() to detect if they have the age property:
const arr = [{"id":"1","name":"Test 1","age":23},{"id":"2","name":"Test 2","age":62},{"id":"3","name":"Test 3"}]
const result = _.filter(arr, o => _.has(o, 'age'))
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.js"></script>
Or use lodash/fp to generate a function:
const fn = _.filter(_.has('age'))
const arr = [{"id":"1","name":"Test 1","age":23},{"id":"2","name":"Test 2","age":62},{"id":"3","name":"Test 3"}]
const result = fn(arr)
console.log(result)
<script src='https://cdn.jsdelivr.net/g/lodash#4(lodash.min.js+lodash.fp.min.js)'></script>

Java 8 Copy Map with Filter of Another Map

I am trying to filter an original map by comparing with a condition map which has only the key sets with id. Based on the condition map, I want to filter from the original map.
The original map which I have is,
Map<Integer, AppFeatureDTO> appFeatureMap = new TreeMap<>();
which will result like,
{
"101": {
"id": 101,
"subFeature": {
"1": {
"id": 1,
"title": "Title Value",
"desc": "Description Value"
}
}
},
"102": {
"id": 102,
"subFeature": {
"1": {
"id": 1,
"title": "Title Value",
"desc": "Description Value"
}
}
},
"103": {
"id": 103,
"subFeature": {
"1": {
"id": 1,
"title": "Title Value",
"desc": "Description Value"
},
"2": {
"id": 2,
"title": "Title Value",
"desc": "Description Value"
},
"3": {
"id": 3,
"title": "Title Value",
"desc": "Description Value"
},
"4": {
"id": 4,
"title": "Title Value",
"desc": "Description Value"
}
}
}
}
and the corresponding classes are:
class AppFeatureDTO {
private int id;
private Map<Integer, AppSubFeatureDTO> subFeature;
}
class AppSubFeatureDTO{
private int id;
private String title;
private String description;
}
then I have a filter map,
Map<Integer, FeatureDTO> conditionFilterMap = new TreeMap<>();
which is resulting like,
{
"101": {
"id": 101,
"subFeature": {
"1": {
"id": 1,
}
}
},
"103": {
"id": 103,
"subFeature": {
"2": {
"id": 2
},
"4": {
"id": 4
}
}
}
}
the corresponding classes for the filter map are,
class FeatureDTO {
private int id;
private Map<Integer, SubFeatureDTO> subFeature;
}
class SubFeatureDTO{
private int id;
}
I want to filter the result map using conditionFilterMap like,
{
"101": {
"id": 101,
"subFeature": {
"1": {
"id": 1,
"title": "Title Value",
"desc": "Description Value"
}
}
},
"103": {
"id": 103,
"subFeature": {
"2": {
"id": 2,
"title": "Title Value",
"desc": "Description Value"
},
"4": {
"id": 4,
"title": "Title Value",
"desc": "Description Value"
}
}
}
}
I'm using spring modelMapper to copy AppFeatureDTO to FeatureDTO. But, filtering the map, I didn't get clue.
Could you please suggest how to get the resultMap using Java 8?
Even I couldn't imagine a simple solution using Java 7 or 6 also.
Assuming that the map key is the same as the id field:
Map<Integer, AppFeatureDTO> resultMap = conditionFilterMap.values().stream()
.map(FeatureDTO::getId)
.map(appFeatureMap::get)
.collect(Collectors.toMap(AppFeatureDTO::getId, a -> new AppFeatureDTO(a.getId(),
conditionFilterMap.get(a.getId()).getSubFeature().values().stream()
.map(SubFeatureDTO::getId)
.map(a.getSubFeature()::get)
.collect(Collectors.toMap(AppSubFeatureDTO::getId, x -> x)))));
If you need TreeMap, add the arguments (a, b) -> a, TreeMap::new to the Collectors.toMap calls.
The non-stream version doesn't really look any worse:
Map<Integer, AppFeatureDTO> resultMap = new TreeMap<>();
for (FeatureDTO f : conditionFilterMap.values()) {
AppFeatureDTO a = appFeatureMap.get(f.getId());
Map<Integer, AppSubFeatureDTO> resultSub = new TreeMap<>();
for (SubFeatureDTO s : f.getSubFeature().values()) {
resultSub.put(s.getId(), a.getSubFeature().get(s.getId()));
}
resultMap.put(a.getId(), new AppFeatureDTO(a.getId(), resultSub));
}

Patch Values Reactive Forms Array of Array Angular 2

{
"id": "1",
"name": ""
"parts": [
{
"name": "partname1",
"description": "description 1"
"messages": [
{
"text": "text 1"
"sender": "sender 1"
}
]
},
{
"name": "partname2",
"description": "description 1"
"messages": [
{
"text": "text 2"
"sender": "sender 2"
}
]
}
]
}
Based on this: https://angular.io/guide/reactive-forms
Using this code:
setParts(parts) {
const partsFormGroup= parts.map(part => this.fb.group(part));
const partsFormArray = this.fb.array(partsFormGroup);
this.myForm.setControl('parts', partsFormArray);
}
patchValue works fine for parts properties: name & description.
How to patchValue to messages?
I am getting this error:
ERROR TypeError: this.validator is not a function

I need to Parse this json in angular js and java script

i need to parse this json in list structure like setup->Finantial Setup->Banks
->charge Item
[
{
"label_name": "Setup",
"data": {
"name": "Setup",
"url": "/setup",
"sub_menues": [
{
" ": {
"name": "Finantial Setup",
"url": "Setup/Finantial Setup",
"sub_menues": [
{
"sub_list": {
"name": "Banks",
"url": "/setup/Finantial Setup/Banks"
}
},
{
"sub_list": {
"name": "Charge Items",
"url": "/setup/Finantial Setup/Charge Items"
}
}
]
}
}
]
}
}
]
Here is some code that finds all the sub_list items with the name 'Charge Items'. We really don't know what you want in your question but I hope this helps.
var json = [{"label_name": "Setup", "data": {"name": "Setup", "url": "/setup", "sub_menues":
[{" ": {"name": "Finantial Setup", "url": "Setup/Finantial Setup",
"sub_menues": [{"sub_list": {"name": "Banks", "url": "/setup/Finantial Setup/Banks"}},
{"sub_list": {"name": "Charge Items", "url": "/setup/Finantial Setup/Charge Items"}}]}}]}}];
var sm = json[0].data.sub_menues;
var urls = [];
for (var i = 0; i < sm.length; i++) {
var aSm = sm[i] //get a sub menu
var aSmObject = aSm[" "]; //this is a little sketchy
var sm2 = aSmObject.sub_menues;
for (var j = 0; j < sm2.length; j++) {
var subList = sm2[j].sub_list;
if(subList.name.toLowerCase() === "charge items"){
urls.push(subList.url);
}
}
}
console.log(urls);
alert(urls);

Resources