Skip to content

Commit

Permalink
added QaseId and QaseTitle annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
savkk committed Dec 30, 2022
1 parent 3bbe5c2 commit 241cc20
Show file tree
Hide file tree
Showing 44 changed files with 144 additions and 75 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.qase</groupId>
<artifactId>qase-java</artifactId>
<packaging>pom</packaging>
<version>3.0.1</version>
<version>3.0.2</version>
<modules>
<module>qase-api</module>
<module>qase-testng</module>
Expand Down
2 changes: 1 addition & 1 deletion qase-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-api</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</dependency>

```
Expand Down
2 changes: 1 addition & 1 deletion qase-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 4 additions & 0 deletions qase-api/src/main/java/io/qase/api/annotation/CaseId.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.lang.annotation.*;

/**
* @deprecated use {@link QaseId} instead.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Deprecated
public @interface CaseId {
long value();
}
3 changes: 3 additions & 0 deletions qase-api/src/main/java/io/qase/api/annotation/CaseTitle.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.lang.annotation.*;


/**
* @deprecated use {@link QaseTitle} instead.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
Expand Down
10 changes: 10 additions & 0 deletions qase-api/src/main/java/io/qase/api/annotation/QaseId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.qase.api.annotation;

import java.lang.annotation.*;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface QaseId {
long value();
}
11 changes: 11 additions & 0 deletions qase-api/src/main/java/io/qase/api/annotation/QaseTitle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.qase.api.annotation;

import java.lang.annotation.*;


@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface QaseTitle {
String value();
}
12 changes: 4 additions & 8 deletions qase-api/src/main/java/io/qase/api/services/Attachments.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.qase.api.CasesStorage;
import io.qase.api.StepStorage;
import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.QaseId;
import io.qase.api.annotation.Step;
import io.qase.api.config.QaseConfig;
import io.qase.api.exceptions.QaseException;
Expand All @@ -13,11 +13,7 @@
import io.qase.guice.Injectors;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand All @@ -28,7 +24,7 @@ public class Attachments {

/**
* Adds attachments to the current context.
* The context could be either {@link io.qase.api.annotation.CaseId} or {@link io.qase.api.annotation.Step}
* The context could be either {@link io.qase.api.annotation.QaseId} or {@link io.qase.api.annotation.Step}
*
* @throws QaseException if the invocation context can not be found
* */
Expand Down Expand Up @@ -92,7 +88,7 @@ private static AttachmentContext lookupCurrentContext() {
return AttachmentContext.TEST_CASE;
}
throw new UncheckedQaseException(new QaseException(String.format(
"It is expected either %s or %s-annotated method be called.", Step.class.getName(), CaseId.class.getName()
"It is expected either %s or %s-annotated method be called.", Step.class.getName(), QaseId.class.getName()
)));
}

Expand Down
25 changes: 25 additions & 0 deletions qase-api/src/main/java/io/qase/api/utils/IntegrationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.CaseTitle;
import io.qase.api.annotation.QaseId;
import io.qase.api.annotation.QaseTitle;

import java.io.PrintWriter;
import java.io.StringWriter;
Expand All @@ -24,6 +26,10 @@ public static String getStacktrace(Throwable throwable) {
}

public static Long getCaseId(Method method) {
Long qaseId = getQaseId(method);
if (qaseId != null) {
return qaseId;
}
if (method.isAnnotationPresent(CaseId.class)) {
return method
.getDeclaredAnnotation(CaseId.class).value();
Expand All @@ -32,9 +38,28 @@ public static Long getCaseId(Method method) {
}

public static String getCaseTitle(Method method) {
String qaseTitle = getQaseTitle(method);
if (qaseTitle != null) {
return qaseTitle;
}
if (method.isAnnotationPresent(CaseTitle.class)) {
return method.getDeclaredAnnotation(CaseTitle.class).value();
}
return null;
}

private static Long getQaseId(Method method) {
if (method.isAnnotationPresent(QaseId.class)) {
return method
.getDeclaredAnnotation(QaseId.class).value();
}
return null;
}

private static String getQaseTitle(Method method) {
if (method.isAnnotationPresent(QaseTitle.class)) {
return method.getDeclaredAnnotation(QaseTitle.class).value();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.google.gson.Gson;
import io.qase.api.CasesStorage;
import io.qase.api.StepStorage;
import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.QaseId;
import io.qase.api.annotation.Step;
import io.qase.api.exceptions.QaseException;
import io.qase.api.services.Attachments;
Expand Down Expand Up @@ -73,14 +73,14 @@ public void afterEach() {
stopCaseIfInProgress();
}

@CaseId(CASE_WITHOUT_STEPS_ID)
@QaseId(CASE_WITHOUT_STEPS_ID)
public void caseWithAttachmentsWithoutSteps() throws QaseException {
startCase();
Attachments.addAttachmentsToCurrentContext(getTestAttachments());
// No finishCase for being able to verify CaseStorage.getCurrentCase()
}

@CaseId(CASE_WITH_STEPS_ID)
@QaseId(CASE_WITH_STEPS_ID)
public void caseWithAttachmentsWithSteps() throws QaseException {
startCase();
stepWithAttachments();
Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber3-jvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber3-jvm</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber3-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber4-jvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber4-jvm</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber4-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber5-jvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-cucumber5-jvm</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
</dependency>
</dependencies>
<build>
Expand Down
2 changes: 1 addition & 1 deletion qase-cucumber5-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion qase-junit4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Add the following dependency and repository to your pom.xml:
<dependency>
<groupId>io.qase</groupId>
<artifactId>qase-junit4</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion qase-junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>qase-java</artifactId>
<groupId>io.qase</groupId>
<version>3.0.1</version>
<version>3.0.2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
20 changes: 20 additions & 0 deletions qase-junit4/src/main/java/io/qase/junit4/QaseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.qase.api.StepStorage;
import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.CaseTitle;
import io.qase.api.annotation.QaseId;
import io.qase.api.annotation.QaseTitle;
import io.qase.api.config.QaseConfig;
import io.qase.api.services.QaseTestCaseListener;
import io.qase.client.model.ResultCreate;
Expand Down Expand Up @@ -101,15 +103,33 @@ private ResultCreate setupResultItem(ResultCreate resultCreate, Description desc
}

private Long getCaseId(Description description) {
Long qaseId = getQaseId(description);
if (qaseId != null) {
return qaseId;
}
CaseId caseIdAnnotation = description.getAnnotation(CaseId.class);
return caseIdAnnotation != null ? caseIdAnnotation.value() : null;
}

private String getCaseTitle(Description description) {
String qaseTitle = getQaseTitle(description);
if (qaseTitle != null) {
return qaseTitle;
}
CaseTitle caseTitleAnnotation = description.getAnnotation(CaseTitle.class);
return caseTitleAnnotation != null ? caseTitleAnnotation.value() : null;
}

private Long getQaseId(Description description) {
QaseId caseIdAnnotation = description.getAnnotation(QaseId.class);
return caseIdAnnotation != null ? caseIdAnnotation.value() : null;
}

private String getQaseTitle(Description description) {
QaseTitle caseTitleAnnotation = description.getAnnotation(QaseTitle.class);
return caseTitleAnnotation != null ? caseTitleAnnotation.value() : null;
}

private static QaseTestCaseListener createQaseListener() {
return Junit4Module.getInjector().getInstance(QaseTestCaseListener.class);
}
Expand Down
4 changes: 2 additions & 2 deletions qase-junit4/src/test/java/io/qase/junit/samples/Failed.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.qase.junit.samples;


import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.QaseId;
import org.junit.Test;

public class Failed {
@Test
@CaseId(321)
@QaseId(321)
public void failedTest() {
throw new AssertionError("Error message");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.qase.junit.samples;

import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.QaseId;
import org.junit.Test;

import java.util.concurrent.TimeUnit;

public class FailedWithTime {
@Test
@CaseId(321)
@QaseId(321)
public void failedTest() throws InterruptedException {
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
throw new AssertionError("Error message");
Expand Down
8 changes: 4 additions & 4 deletions qase-junit4/src/test/java/io/qase/junit/samples/Multiple.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.qase.junit.samples;

import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.QaseId;
import io.qase.junit.samples.steps.Steps;
import org.junit.Test;

Expand All @@ -9,22 +9,22 @@

public class Multiple {
@Test
@CaseId(123)
@QaseId(123)
public void failedWithStepsTest() {
Steps steps = new Steps();
steps.successStep();
steps.failureStep();
}

@Test
@CaseId(456)
@QaseId(456)
public void passedWithStepsTest() {
Steps steps = new Steps();
steps.successStep();
}

@Test
@CaseId(321)
@QaseId(321)
public void failedTest() throws InterruptedException {
Thread.sleep(TimeUnit.SECONDS.toMillis(2));
throw new AssertionError("Error message");
Expand Down
4 changes: 2 additions & 2 deletions qase-junit4/src/test/java/io/qase/junit/samples/NewCase.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.qase.junit.samples;

import io.qase.api.annotation.CaseTitle;
import io.qase.api.annotation.QaseTitle;
import io.qase.junit.samples.steps.Steps;
import org.junit.Test;


public class NewCase {
@Test
@CaseTitle("Case Title")
@QaseTitle("Case Title")
public void passedTest() {
Steps steps = new Steps();
steps.successStep();
Expand Down
4 changes: 2 additions & 2 deletions qase-junit4/src/test/java/io/qase/junit/samples/Passed.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.qase.junit.samples;


import io.qase.api.annotation.CaseId;
import io.qase.api.annotation.QaseId;
import org.junit.Test;

public class Passed {
@Test
@CaseId(123)
@QaseId(123)
public void passedTest() {

}
Expand Down
Loading

0 comments on commit 241cc20

Please sign in to comment.