All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.verisoft.fw.xray.XrayJsonFormatObject Maven / Gradle / Ivy

Go to download

VeriSoft framework for testing web and mobile applications. junit 5 Module

There is a newer version: 2.0.4
Show newest version
package co.verisoft.fw.xray;
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import co.verisoft.fw.utils.Builder;
import co.verisoft.fw.utils.JsonObject;
import lombok.ToString;
import org.jetbrains.annotations.Nullable;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Representation of Xray Json format. This class follows the builder design pattern
* *
From Xray documentation:
* Xray provides a proprietary JSON format for importing execution results into Jira/Xray.
* Although Xray supports multiple report formats used by different testing frameworks/runners (e.g. JUnit, NUnit, * xUnit, TestNG, Cucumber, Robot Framework), there are scenarios where using these formats is not an option like:
* Using a testing framework report that is not supported by Xray
* Having your own testing framework
* Limited support of existing formats to import detailed execution results back into Jira
* * @author Nir Gallner * @see * Using Xray JSON format to import execution results - info * @since 0.0.2 (Jan 2022) */ @ToString public class XrayJsonFormatObject extends XrayJsonFormat implements JsonObject { private final Map fields; public @Nullable String getTestExecutionKey() { return (String) fields.get("testExecutionKey"); } public @Nullable XrayJsonInfoObject getInfo() { return (XrayJsonInfoObject) fields.get("info"); } public @Nullable List getTests() { return (List) fields.get("tests"); } private XrayJsonFormatObject(XrayJsonFormatObjectBuilder builder) { this.fields = builder.fields; } @SuppressWarnings("unchecked") @Override public JSONObject asJsonObject() { JSONObject obj = new JSONObject(); if (this.getTestExecutionKey() != null) obj.put("testExecutionKey", this.getTestExecutionKey()); if (this.getInfo() != null) obj.put("info", this.getInfo().asJsonObject()); if (this.getTests() != null) { JSONArray arr = new JSONArray(); for (XrayJsonTestObject test : this.getTests()) { arr.add(test.asJsonObject()); } if (!arr.isEmpty()) obj.put("tests", arr); } return obj; } @Override public String asString() { return this.asJsonObject().toJSONString(); } /** * Builder class for XrayInfoObject * * @author Nir Gallner * @since 0.0.2 (Jan 2022) */ @ToString public static class XrayJsonFormatObjectBuilder implements Builder { private final Map fields; public XrayJsonFormatObjectBuilder(XrayJsonFormatObject obj) { this.fields = obj.fields; } public XrayJsonFormatObjectBuilder() { fields = new HashMap<>(); } public XrayJsonFormatObjectBuilder testExecutionKey(String testExecutionKey) { fields.put("testExecutionKey", testExecutionKey); return this; } public XrayJsonFormatObjectBuilder info(XrayJsonInfoObject info) { fields.put("info", info); return this; } public XrayJsonFormatObjectBuilder tests(List tests) { fields.put("tests", tests); return this; } public XrayJsonFormatObjectBuilder test(XrayJsonTestObject test) { if (fields.get("tests") != null) { List testList = ((List) fields.get("tests")); testList.add(test); fields.put("tests", testList); } else { List testList = new ArrayList<>(); testList.add(test); fields.put("tests", testList); } return this; } public XrayJsonFormatObject build() { XrayJsonFormatObject info = new XrayJsonFormatObject(this); validateXrayFormatObject(info); return info; } private void validateXrayFormatObject(XrayJsonFormatObject obj) { // TOOD: some validation code here } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy