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

org.conqat.engine.sourcecode.coverage.TestWithClusterId Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) CQSE GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 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.
 */

package org.conqat.engine.sourcecode.coverage;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.conqat.lib.commons.uniformpath.UniformPath;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Test with additional information about which cluster of tests the test case belongs to during
 * prioritization.
 */
public class TestWithClusterId implements Comparable {

	/** The name of the JSON property name for {@link #testName}. */
	private static final String TEST_NAME_PROPERTY = "testName";

	/** The name of the JSON property name for {@link #type}. */
	private static final String TYPE_PROPERTY = "type";

	/** The name of the JSON property name for {@link #clusterId}. */
	private static final String CLUSTER_ID_PROPERTY = "clusterId";

	/** The name of the JSON property name for {@link #hash}. */
	protected static final String HASH_PROPERTY = "hash";

	/** The name of the JSON property name for {@link #partition}. */
	protected static final String PARTITION_PROPERTY = "partition";

	/**
	 * The uniform path the test (unescaped and without -test-execution- prefix).
	 */
	@JsonProperty(TEST_NAME_PROPERTY)
	public final String testName;

	/**
	 * The type of test (test execution or an execution unit). If omitted test execution is assumed.
	 */
	@JsonProperty(TYPE_PROPERTY)
	public final UniformPath.@Nullable EType type;

	@JsonProperty(HASH_PROPERTY)
	@Nullable
	private final String hash;

	@JsonProperty(PARTITION_PROPERTY)
	private final String partition;

	/**
	 * A unique identifier for the cluster this test should be prioritized within. May not be null.
	 */
	@JsonProperty(CLUSTER_ID_PROPERTY)
	public final String clusterId;

	@JsonCreator
	public TestWithClusterId(@JsonProperty(TEST_NAME_PROPERTY) String testName,
			@JsonProperty(TYPE_PROPERTY) UniformPath.@Nullable EType type,
			@JsonProperty(HASH_PROPERTY) @Nullable String hash, @JsonProperty(PARTITION_PROPERTY) String partition,
			@JsonProperty(CLUSTER_ID_PROPERTY) String clusterId) {
		this.testName = testName;
		this.type = type;
		this.hash = hash;
		this.partition = partition;
		this.clusterId = clusterId;
	}

	/** {@inheritDoc} */
	@Override
	public int compareTo(TestWithClusterId other) {
		return testName.compareTo(other.testName);
	}

	/** Compute the test execution path. */
	public String getUniformPath() {
		return toUniformPath().toString();
	}

	/** Compute the test execution path. */
	public UniformPath toUniformPath() {
		if (type == UniformPath.EType.EXECUTION_UNIT) {
			return TestUniformPathUtils.convertToExecutionUnitUniformPath(testName);
		}
		return TestUniformPathUtils.escapeAndConvertToTestExecutionUniformPath(testName);
	}

	@Override
	public String toString() {
		return testName;
	}

	public @Nullable String getHash() {
		return hash;
	}

	public String getPartition() {
		return partition;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy