com.teamscale.wia.TeamscaleIssueSerializationTestBase Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of teamscale-wia-test-fixtures Show documentation
Show all versions of teamscale-wia-test-fixtures Show documentation
The Teamscale Work Item Analysis provides the basis to analyze Work Items/Tickets/Requirements/Issues.
package com.teamscale.wia;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import org.junit.jupiter.api.Test;
/**
* Base class for testing the (de)serialization for {@link TeamscaleIssue} and subclasses.
*/
public abstract class TeamscaleIssueSerializationTestBase {
private static TeamscaleIssue createTeamscaleIssue() {
return new TeamscaleIssue(new TeamscaleIssueId("connectorId", "externalId"), "subject", "assignee", "author",
"description", 1L, 2L, "status", false, "http://foo.bar",
Collections.singletonList("additionalFieldName"), Collections.singletonList("additionalFieldValue"),
"parentId");
}
private static SpecItem createSpecItem() {
return new SpecItem(createTeamscaleIssue(), Collections.singletonList("secondAssignee"),
Collections.singletonList("additionalParent"), Collections.singletonList("relatesTo"),
Collections.singletonList(Collections.singletonList("relatesToId")), "type", "T");
}
private static ManualTestCase createManualTestCase() {
return new ManualTestCase(createSpecItem(),
Collections.singletonList(new ManualTestCase.TestStep("action", "check")));
}
@Test
void testTeamscaleIssueSerialization() throws Exception {
TeamscaleIssue originalIssue = createTeamscaleIssue();
String json = serialize(originalIssue);
assertIsTeamscaleIssue(originalIssue, json);
}
@Test
void testSpecItemSerialization() throws Exception {
SpecItem originalSpecItem = createSpecItem();
String json = serialize(originalSpecItem);
assertIsSpecItem(originalSpecItem, json);
}
@Test
void testManualTestCaseSerialization() throws Exception {
ManualTestCase originalTestItem = createManualTestCase();
String json = serialize(originalTestItem);
assertIsManualTestCase(originalTestItem, json);
}
/**
* Serialize the provided {@link TeamscaleIssue} into the string representation.
*/
protected abstract String serialize(TeamscaleIssue originalIssue) throws Exception;
/**
* Deserialize the provided String representation back into {@code T}.
*/
protected abstract T deserialize(Class deserializeAs, String serializedRepresentation)
throws Exception;
private void assertIsManualTestCase(ManualTestCase originalTestItem, String json) throws Exception {
assertIsSpecItem(originalTestItem, json);
assertDeserializedIs(originalTestItem, ManualTestCase.class, json);
}
private void assertIsSpecItem(SpecItem originalSpecItem, String json) throws Exception {
assertIsTeamscaleIssue(originalSpecItem, json);
assertDeserializedIs(originalSpecItem, SpecItem.class, json);
}
private void assertIsTeamscaleIssue(TeamscaleIssue originalIssue, String json) throws Exception {
assertDeserializedIs(originalIssue, TeamscaleIssue.class, json);
}
private void assertDeserializedIs(T originalIssue, Class deserializeAs, String json)
throws Exception {
Object deserialized = deserialize(deserializeAs, json);
assertThat(deserialized).isInstanceOf(originalIssue.getClass()).usingRecursiveComparison()
.isEqualTo(originalIssue);
}
}