001package org.conqat.engine.sourcecode.coverage;
002
003import java.io.Serializable;
004import java.util.Objects;
005
006import javax.annotation.Nonnull;
007import javax.annotation.Nullable;
008
009import org.conqat.lib.commons.js_export.ExportToJavaScript;
010import org.conqat.lib.commons.uniformpath.UniformPath;
011
012import com.fasterxml.jackson.annotation.JsonCreator;
013import com.fasterxml.jackson.annotation.JsonProperty;
014
015/**
016 * Represents a test case data class, holding an uniformPath (Teamscale
017 * internal).
018 */
019@ExportToJavaScript
020public class TestDetails implements Comparable<TestDetails>, Serializable {
021
022        private static final long serialVersionUID = 1L;
023
024        /** The name of the JSON property name for {@link #uniformPath}. */
025        protected static final String UNIFORM_PATH_PROPERTY = "uniformPath";
026
027        /** The name of the JSON property name for {@link #sourcePath}. */
028        protected static final String SOURCE_PATH_PROPERTY = "sourcePath";
029
030        /** The name of the JSON property name for {@link #content}. */
031        protected static final String CONTENT_PROPERTY = "content";
032
033        /** The name of the JSON property name for {@link #lastChangedTimestamp}. */
034        protected static final String LAST_CHANGED_TIMESTAMP_PROPERTY = "lastChangedTimestamp";
035
036        /** The uniform path the test (unescaped and without -test- prefix). */
037        @JsonProperty(UNIFORM_PATH_PROPERTY)
038        public String uniformPath;
039
040        /**
041         * Path to the source of the method. Will be equal to {@link #uniformPath} in
042         * most cases, but e.g. <code>@Test</code> methods in a base class will have the
043         * sourcePath pointing to the base class which contains the actual
044         * implementation, whereas {@link #uniformPath} will contain the class name of
045         * the most specific subclass from where it was actually executed.
046         */
047        @JsonProperty(SOURCE_PATH_PROPERTY)
048        @Nullable
049        private String sourcePath;
050
051        /**
052         * Some kind of content to tell whether the test specification has changed. Can
053         * be revision number or hash over the specification or similar.
054         */
055        @JsonProperty(CONTENT_PROPERTY)
056        @Nullable
057        private String content;
058
059        /** The last timestamp at which the content of the test did change. */
060        @JsonProperty(LAST_CHANGED_TIMESTAMP_PROPERTY)
061        private long lastChangedTimestamp;
062
063        public TestDetails(String uniformPath, String content) {
064                this(uniformPath, null, content, 0L);
065        }
066
067        public TestDetails(String uniformPath, String sourcePath, String content) {
068                this(uniformPath, sourcePath, content, 0L);
069        }
070
071        @JsonCreator
072        public TestDetails(@JsonProperty(UNIFORM_PATH_PROPERTY) String uniformPath,
073                        @JsonProperty(SOURCE_PATH_PROPERTY) String sourcePath, @JsonProperty(CONTENT_PROPERTY) String content,
074                        @JsonProperty(LAST_CHANGED_TIMESTAMP_PROPERTY) long lastChangedTimestamp) {
075                this.uniformPath = uniformPath;
076                this.content = content;
077                this.sourcePath = sourcePath;
078                this.lastChangedTimestamp = lastChangedTimestamp;
079        }
080
081        /** {@inheritDoc} */
082        @Override
083        public int compareTo(@Nonnull TestDetails other) {
084                return uniformPath.compareTo(other.uniformPath);
085        }
086
087        /** We explicitly don't check {@link #lastChangedTimestamp} here. */
088        @Override
089        public boolean equals(Object o) {
090                if (this == o) {
091                        return true;
092                }
093                if (o == null || getClass() != o.getClass()) {
094                        return false;
095                }
096                TestDetails that = (TestDetails) o;
097                return Objects.equals(uniformPath, that.uniformPath) && Objects.equals(sourcePath, that.sourcePath)
098                                && Objects.equals(content, that.content);
099        }
100
101        /** We explicitly don't check {@link #lastChangedTimestamp} here. */
102        @Override
103        public int hashCode() {
104                return Objects.hash(uniformPath, sourcePath, content);
105        }
106
107        /** Compute the test execution path. */
108        public UniformPath toUniformPath() {
109                return TestUniformPathUtils.convertToUniformPath(uniformPath);
110        }
111
112        /** @see #sourcePath */
113        public String getSourcePath() {
114                return sourcePath;
115        }
116
117        /** @see #sourcePath */
118        public void setSourcePath(String sourcePath) {
119                this.sourcePath = sourcePath;
120        }
121
122        /** @see #content */
123        public String getContent() {
124                return content;
125        }
126
127        /** @see #content */
128        public void setContent(String content) {
129                this.content = content;
130        }
131
132        /** @see #lastChangedTimestamp */
133        public long getLastChangedTimestamp() {
134                return lastChangedTimestamp;
135        }
136
137        /** @see #lastChangedTimestamp */
138        public void setLastChangedTimestamp(long lastChangedTimestamp) {
139                this.lastChangedTimestamp = lastChangedTimestamp;
140        }
141
142        @Override
143        public String toString() {
144                return uniformPath;
145        }
146}