com.liferay.jenkins.results.parser.test.clazz.group.PlaywrightSegmentTestClassGroup Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.jenkins.results.parser
Show all versions of com.liferay.jenkins.results.parser
Liferay Jenkins Results Parser
/**
* SPDX-FileCopyrightText: (c) 2023 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.jenkins.results.parser.test.clazz.group;
import com.liferay.jenkins.results.parser.job.property.JobProperty;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
/**
* @author Kenji Heigel
*/
public class PlaywrightSegmentTestClassGroup extends SegmentTestClassGroup {
@Override
public Integer getMinimumSlaveRAM() {
for (AxisTestClassGroup axisTestClassGroup : getAxisTestClassGroups()) {
return axisTestClassGroup.getMinimumSlaveRAM();
}
return super.getMinimumSlaveRAM();
}
public String getProjectName() {
return _projectName;
}
@Override
public String getSlaveLabel() {
for (AxisTestClassGroup axisTestClassGroup : getAxisTestClassGroups()) {
return axisTestClassGroup.getSlaveLabel();
}
return super.getSlaveLabel();
}
@Override
public String getTestCasePropertiesContent() {
StringBuilder sb = new StringBuilder();
sb.append(super.getTestCasePropertiesContent());
PlaywrightBatchTestClassGroup playwrightBatchTestClassGroup =
(PlaywrightBatchTestClassGroup)getBatchTestClassGroup();
String playwrightTestProjectPropertyName =
PlaywrightBatchTestClassGroup.PLAYWRIGHT_TEST_PROJECT_PROPERTY_NAME;
if (playwrightBatchTestClassGroup.testRelevantChanges) {
List jobProperties =
playwrightBatchTestClassGroup.
getRelevantPlaywrightJobProperties();
List playwrightTestProjectJobProperties =
_getJobProperties(
playwrightTestProjectPropertyName, jobProperties);
String playwrightTestProjectProperty = _concatPropertyValues(
playwrightTestProjectJobProperties, " ");
if (playwrightTestProjectProperty != null) {
sb.append(playwrightTestProjectProperty);
sb.append("\n");
}
}
else {
JobProperty jobProperty =
playwrightBatchTestClassGroup.getJobProperty(
playwrightTestProjectPropertyName,
playwrightBatchTestClassGroup.testSuiteName,
playwrightBatchTestClassGroup.batchName);
if (jobProperty.getValue() != null) {
sb.append(jobProperty.getBasePropertyName());
sb.append("=");
sb.append(jobProperty.getValue());
sb.append("\n");
}
}
int axisCount = getAxisCount();
if (axisCount >= 1) {
for (int axisIndex = 0; axisIndex < getAxisCount(); axisIndex++) {
sb.append("PLAYWRIGHT_ARGS_");
sb.append(axisIndex);
sb.append("=--shard=");
sb.append(axisIndex + 1);
sb.append("/");
sb.append(axisCount);
sb.append("\n");
}
}
sb.append("PLAYWRIGHT_PROJECT_NAME=");
sb.append(getProjectName());
return sb.toString();
}
public void setProjectName(String projectName) {
_projectName = projectName;
}
protected PlaywrightSegmentTestClassGroup(
BatchTestClassGroup parentBatchTestClassGroup) {
super(parentBatchTestClassGroup);
}
protected PlaywrightSegmentTestClassGroup(
BatchTestClassGroup parentBatchTestClassGroup, JSONObject jsonObject) {
super(parentBatchTestClassGroup, jsonObject);
}
private String _concatPropertyValues(
List jobProperties, String delimiter) {
if (jobProperties.isEmpty()) {
return null;
}
StringBuilder sb = new StringBuilder();
for (JobProperty jobProperty : jobProperties) {
if (jobProperty.getValue() != null) {
sb.append(jobProperty.getValue());
sb.append(delimiter);
}
}
if (sb.length() > 0) {
JobProperty jobProperty = jobProperties.get(0);
sb.insert(0, "=");
sb.insert(0, jobProperty.getBasePropertyName());
sb.setLength(sb.length() - delimiter.length());
}
return sb.toString();
}
private List _getJobProperties(
String propertyName, List jobProperties) {
List filteredJobProperties = new ArrayList<>();
for (JobProperty jobProperty : jobProperties) {
if (propertyName.equals(jobProperty.getBasePropertyName())) {
filteredJobProperties.add(jobProperty);
}
}
return filteredJobProperties;
}
private String _projectName;
}