I have a class in groovy:
public enum EnumStatus{
GREY,
YELLOW,
RED,
GREEN
}
public class Status {
private EnumStatus myStatus = EnumStatus.GREY
private List<String> failures = []
public Status(EnumStatus status, List<String> failureList) {
myStatus = status
failures = failureList
}
public EnumStatus getStatus() {
return myStatus
}
public void setStatus(EnumStatus status) {
myStatus = status
}
public void addFailure(String failure) {
failures.add(failure)
}
}
I am trying to generate the json of Map defined as this:
Status status11 = new Status()
Status status12 = new Status(RED,["myFailure"])
Map myMap = ["myId11": status11, "myId12": status12]
JsonOutput.toJson(myMap)
The print looks like this
["myId11":{"status":"GREY"},"myId12":{"status":"RED"}]
I don't understand why the JsonOutput.toJson doesn't show the list of failures.
Is there a method or an interface to implement to have a proper json ?
P.S: I am running the groovy script in a jenkins pipeline
Related
I have problem with select 2. It dont show all Items, but only subset. I dont see on Select2Choice any method, which show all items. Can someone give me a poit how to show whole items.
Here is code:
originStationDropDown = new Select2Choice<>("originDgfStation", new PropertyModel<Station>(this, "originStation") , new StationsProvider(originCountryDD, productDD));
ComponentHelper.addLabelAndComponent(originStationDropDown, this, "originStation.label", ComponentOptions.REQUIRED);
private class StationsProvider extends ChoiceProvider<Station> {
private Select2Choice<Country> countryDD;
private DropDownChoice<Product> productDD;
public StationsProvider(Select2Choice<Country> countryDD, DropDownChoice<Product> productDD) {
this.countryDD = countryDD;
this.productDD = productDD;
}
#Override
public void query(String codeNameFragment, int i, Response<Station> response) {
if(codeNameFragment == null || "".equals(codeNameFragment)) {
List<Station> stations = stationDao.findByCountryAndProduct(countryDD.getModel().getObject(), productDD.getModel().getObject(), "code");
for(Station station : stations) {
response.add(station);
}
} else {
response.addAll(stationDao.findByCountryAndProductAndFragment(countryDD.getModel().getObject(), productDD.getModel().getObject(), codeNameFragment));
}
System.out.println(response.size());
}
#Override
public void toJson(Station station, JSONWriter jsonWriter) throws JSONException {
jsonWriter.key("id").value(station.getId()).key("text").value(station.getNameWithCode());
}
#Override
public Collection<Station> toChoices(Collection<String> collection) {
List<Station> stations = new ArrayList<>();
List<Station> stationList = stationDao.findAll();
for(String id : collection) {
for(Station station : stationList) {
if(station.getId().equals(Long.valueOf(id))) {
stations.add(station);
}
}
}
return stations;
}
}
You don't explain which items are shown and which are not.
I will guess that only the first N items are always shown. The second parameter of #query() method is int page (named i in your code). This parameter should be used to paginate the results. I.e. you should not always return 10000 items and let the JavaScript to deal with them but you have to return 0-20, 21-40, 41-60, etc.
I am generating an extent report in specflow, I have written the code and my test execute successfully and report generating but it displays only the feature name no steps name displayed in the report.
Please suggest me what mistake I am doing in the code.
I am attaching a screenshot of my generated report, When I go to report dashboard it displays the number of steps there.
using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports.Reporter.Configuration;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;
namespace Extent_Report
{
[Binding]
[TestFixture]
class Hooks
{
public static ExtentReports extent;
public static ExtentHtmlReporter htmlReporter;
public static ExtentTest test;
// public static object Theme { get; private set; }
static Hooks()
{
if (extent == null)
{
BasicSetUp();
}
}
[BeforeScenario]
public static void Setup()
{
BasePage.Intitialize();
BasePage.Navigate();
test = extent.CreateTest(ScenarioContext.Current.ScenarioInfo.Title);
}
[AfterScenario]
public void TearDown()
{
if (ScenarioContext.Current.TestError != null)
{
var error = ScenarioContext.Current.TestError;
var errormessage = "<pre>" + error.Message + "</pre>";
extent.AddTestRunnerLogs(errormessage);
test.Log(Status.Error, errormessage);
test.Fail(errormessage);
}
BasePage.Quit();
}
[OneTimeSetUp]
public static void BasicSetUp()
{
string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
// string pth = System.IO.Directory.GetCurrentDirectory();
string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
string projectPath = new Uri(actualPath).LocalPath;
Console.WriteLine(" -----------Project Path--------------------------------------");
Console.WriteLine(projectPath);
string reportPath = projectPath + "Reports\\TestExecutionRunReport.html";
// Console.WriteLine("Report Path is " + reportPath);
htmlReporter = new ExtentHtmlReporter(reportPath);
htmlReporter.Configuration().Theme = Theme.Dark;
htmlReporter.Configuration().DocumentTitle = "SpecFlow Test Resport Document";
htmlReporter.Configuration().ReportName = "Feature Run Results";
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
//extent.LoadConfig(projectPath + "Extent-Config.xml");
}
[AfterFeature()]
public static void EndReport()
{
extent.Flush();
}
}
}
Reference:
You need to use hook [After step] or [Before step] and add below content to it
test = test.info(ScenarioStepContext.Current.StepInfo.Text);
you can also manipulate and provide more information in it if required.
Response takes a long time to come. How it is possible to wait for response time in rest-assured ?
In the past I've used awaitility, it allows you to wait for a response from the service before kicking off another call.
https://github.com/awaitility/awaitility.
You can return an extracted response and wait for the status code/body to return a value.
#Test
public void waitTest() throws Exception {
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> this.getStatus() == 200)
}
public int getStatus() {
return given()
.accept(ContentType.JSON)
.get(url)
.then()
.extract()
.statusCode();
}
On this class you declared the max time
public interface Constants {
Long MAX_TIMEOUT = 3000l;
}
Here on this class you implement the interface
public class BaseTest implements Constants {
#BeforeClass
public static void setup() {
ResponseSpecBuilder resBuilder = new ResponseSpecBuilder();
resBuilder.expectResponseTime(Matchers.lessThan(MAX_TIMEOUT));
RestAssured.responseSpecification = resBuilder.build();
}
Finally you can use the waiter strategy
public class SimulationTest extends BaseTest {
#Test
public void checkStatus200() {
given()
.when()
.get()
.then()
.statusCode(200)
;
}
}
I am getting the error in the Step "Warning:Multiple Step transformation matches to the input"..Is there anyway I can turn it off?
My code is
public class Transforms
{
[StepArgumentTransformation(#"\<([A-Za-z0-9\-]+)\>$?")]
public Object ApplyStringTransformations(string TestDataIdentifier)
{
GetData Test = new GetData();
var TestData = Test.ConvertData(TestDataIdentifier);
return TestData;
}
}
And in the Steps File
[Then(#"I Login as a Member with ""(.*)"" and ""(.*)""")]
public void ThenILoginAsAMemberWithAnd(object p0,object p1)
{
Console.WriteLine(p0);
}
I am implementing an interface for taking commands for creating , connecting and coloring vertices in JUNG when I want to connect two already existing vertices JUNG connects to vertices and creates an extra vertex , why?
Here is my code for connect method:
public class Connect extends Command {
private CommandMaster cm;
private BehGraphUndirected behGraph;
private static int edgenumber=0;
#Override
public Object run(BehGraphUndirected behGraph, VisualizationImageServer panel, InterpretMaster interpretMaster, String... args) {
System.out.print("connect Runs\n");
this.cm = new CommandMaster();
this.behGraph = behGraph;
if(cm.exists(args[0]))
{
//got to another command
}else
{
switch (args[0]) {
case "edge":
this.createEdge(args[1] , args[2]);
break;
}
}
interpretMaster.refreshAndRepaint();
return null;
}
public void createEdge(String nodeName1 , String nodeName2)
{
this.behGraph.addEdge(edgenumber++,nodeName1, nodeName2);
System.out.println(this.behGraph.getVertexCount());
System.out.println("edge between: "+nodeName1+" and "+ nodeName2+" added");
}
And it's the create method just in case you want to know the way I implemented the code:
package interpreter.command;
import GraphHandling.BehGraphUndirected;
import edu.uci.ics.jung.visualization.VisualizationImageServer;
import interpreter.Command;
import interpreter.CommandMaster;
import interpreter.InterpretMaster;
/**
*
* #author Administrator
*/
public class Create extends Command{
private CommandMaster cm;
private BehGraphUndirected behGraph;
#Override
public Object run(BehGraphUndirected behGraph, VisualizationImageServer panel, InterpretMaster interpretMaster, String... args) {
System.out.print("create Runs \n");
this.cm = new CommandMaster();
this.behGraph = behGraph;
if(cm.exists(args[0]))
{
//got to another command
}else
{
switch (args[0]) {
case "node":
this.createNode(args[1]);
break;
case "label":
this.createLabel(args[1]);
break;
}
}
interpretMaster.refreshAndRepaint();
return null;
}
public void createNode(String nodeName)
{
this.behGraph.addVertex(nodeName);
System.out.print("vertex: "+nodeName+" added");
}
private void createLabel(String string) {
}
class str
{
int i;
long j;
}
}
Graph images before and after connecting two nodes:
and Here is my BehGraphUndirected class:
package GraphHandling;
import edu.uci.ics.jung.graph.UndirectedSparseGraph;
import java.util.LinkedList;
/**
*
* #author Administrator
*/
public class BehGraphUndirected extends UndirectedSparseGraph{
private final LinkedList<Node> nodeList;
public BehGraphUndirected()
{
this.nodeList = new LinkedList<>();
}
public void addNode(Node newNode)
{
this.nodeList.add(newNode);
}
}
You should look at what BehGraphUndirected is doing; it's not a JUNG class or interface.
What is the name of the vertex that's being created, and how does that relate to what's being passed to the create method?
I have compiled and tested your code , The Jung library seems working right and It extinguishes the different nodes by the different object that was given to it It seems you have some other problem , Like a problem in processing the input strings that are used as objects that create nodes.