Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adjust cucumber tests #788

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void iCheckIfQualityInvestigationHasProperValues(DataTable dataTable) {
.ignoreExceptions()
.until(() -> {
try {
QualityNotificationResponse result = restProvider.getNotification(getNotificationIdBasedOnEnv(), INVESTIGATION);
QualityNotificationResponse result = restProvider.getNotification(getNotificationIdBasedOnEnv());
NotificationValidator.assertHasFields(result, normalize(dataTable.asMap()));
return true;
} catch (AssertionError assertionError) {
Expand All @@ -134,27 +134,27 @@ public void iCheckIfQualityInvestigationHasProperValues(DataTable dataTable) {

@When("I approve quality investigation")
public void iApproveQualityInvestigation() {
restProvider.approveNotification(getNotificationIdBasedOnEnv(), INVESTIGATION);
restProvider.approveNotification(getNotificationIdBasedOnEnv());
}

@When("I cancel quality investigation")
public void iCancelQualityInvestigation() {
restProvider.cancelNotification(getNotificationIdBasedOnEnv(), INVESTIGATION);
restProvider.cancelNotification(getNotificationIdBasedOnEnv());
}

@When("I cancel quality alert")
public void iCancelQualityAlert() {
restProvider.cancelNotification(getNotificationIdBasedOnEnv(), ALERT);
restProvider.cancelNotification(getNotificationIdBasedOnEnv());
}

@When("I close quality investigation")
public void iCloseQualityInvestigation() {
restProvider.closeNotification(getNotificationIdBasedOnEnv(), INVESTIGATION);
restProvider.closeNotification(getNotificationIdBasedOnEnv());
}

@When("I close quality alert")
public void iCloseQualityAlert() {
restProvider.closeNotification(getNotificationIdBasedOnEnv(), ALERT);
restProvider.closeNotification(getNotificationIdBasedOnEnv());
}

@When("I check, if quality investigation has been received")
Expand All @@ -164,7 +164,7 @@ public void iCanSeeNotificationWasReceived() {
.atMost(Duration.FIVE_MINUTES)
.pollInterval(1, TimeUnit.SECONDS)
.until(() -> {
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications(INVESTIGATION);
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications();
result.stream().map(QualityNotificationResponse::getDescription).forEach(System.out::println);
return result.stream().filter(qn -> Objects.equals(qn.getDescription(), notificationDescription)).findFirst().orElse(null);
}, Matchers.notNullValue()
Expand All @@ -177,7 +177,7 @@ public void iCanSeeNotificationWasReceived() {

@When("I check, if quality investigation has not been received")
public void iCanSeeInvestigationWasNotReceived() {
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications(INVESTIGATION);
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications();
Optional<QualityNotificationResponse> first = result.stream()
.filter(qualityNotificationResponse -> Objects.equals(qualityNotificationResponse.getId(), getNotificationIdBasedOnEnv()))
.findFirst();
Expand All @@ -186,7 +186,7 @@ public void iCanSeeInvestigationWasNotReceived() {

@When("I check, if quality alert has not been received")
public void iCanSeeAlertWasNotReceived() {
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications(ALERT);
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications();
Optional<QualityNotificationResponse> first = result.stream()
.filter(qualityNotificationResponse -> Objects.equals(qualityNotificationResponse.getId(), getNotificationIdBasedOnEnv()))
.findFirst();
Expand All @@ -195,28 +195,28 @@ public void iCanSeeAlertWasNotReceived() {

@When("I acknowledge quality investigation")
public void iAcknowledgeQualityInvestigation() {
restProvider.updateNotification(INVESTIGATION, getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACKNOWLEDGED, "");
restProvider.updateNotification(getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACKNOWLEDGED, "");
}

@When("I accept quality investigation")
public void iAcceptQualityInvestigation(DataTable dataTable) {
String reason = normalize(dataTable.asMap()).get("reason");
System.out.println("reason: " + reason);
restProvider.updateNotification(INVESTIGATION, getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACCEPTED, reason);
restProvider.updateNotification(getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACCEPTED, reason);
}

@When("I decline quality investigation")
public void iDeclineQualityInvestigation(DataTable dataTable) {
String reason = normalize(dataTable.asMap()).get("reason");
System.out.println("reason: " + reason);
restProvider.updateNotification(INVESTIGATION, getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.DECLINED, reason);
restProvider.updateNotification(getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.DECLINED, reason);
}

@When("I decline quality alert")
public void iDeclineQualityAlert(DataTable dataTable) {
String reason = normalize(dataTable.asMap()).get("reason");
System.out.println("reason: " + reason);
restProvider.updateNotification(ALERT, getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.DECLINED, reason);
restProvider.updateNotification(getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.DECLINED, reason);
}

private Long getNotificationIdBasedOnEnv() {
Expand Down Expand Up @@ -275,7 +275,7 @@ public void iCheckIfQualityAlertHasProperValues(DataTable dataTable) {
.ignoreExceptions()
.until(() -> {
try {
QualityNotificationResponse result = restProvider.getNotification(getNotificationIdBasedOnEnv(), ALERT);
QualityNotificationResponse result = restProvider.getNotification(getNotificationIdBasedOnEnv());
NotificationValidator.assertHasFields(result, normalize(dataTable.asMap()));
return true;
} catch (AssertionError assertionError) {
Expand All @@ -289,7 +289,7 @@ public void iCheckIfQualityAlertHasProperValues(DataTable dataTable) {

@When("I approve quality alert")
public void iApproveQualityAlert() {
restProvider.approveNotification(getNotificationIdBasedOnEnv(), ALERT);
restProvider.approveNotification(getNotificationIdBasedOnEnv());
}


Expand All @@ -300,7 +300,7 @@ public void iCanSeeQualityAlertWasReceived() {
.atMost(Duration.FIVE_MINUTES)
.pollInterval(1, TimeUnit.SECONDS)
.until(() -> {
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications(ALERT);
final List<QualityNotificationResponse> result = restProvider.getReceivedNotifications();
result.stream().map(QualityNotificationResponse::getDescription).forEach(System.out::println);
return result.stream().filter(qn -> Objects.equals(qn.getDescription(), notificationDescription)).findFirst().orElse(null);
}, Matchers.notNullValue()
Expand All @@ -313,14 +313,14 @@ public void iCanSeeQualityAlertWasReceived() {

@When("I acknowledge quality alert")
public void iAcknowledgeQualityAlert() {
restProvider.updateNotification(ALERT, getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACKNOWLEDGED, "");
restProvider.updateNotification(getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACKNOWLEDGED, "");
}


@When("I accept quality alert")
public void iAcceptQualityAlert(DataTable dataTable) {
String reason = normalize(dataTable.asMap()).get("reason");
System.out.println("reason: " + reason);
restProvider.updateNotification(ALERT, getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACCEPTED, reason);
restProvider.updateNotification(getNotificationIdBasedOnEnv(), UpdateQualityNotificationStatusRequest.ACCEPTED, reason);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
********************************************************************************/
package org.eclipse.tractusx.traceability.test.tooling;

public enum NotificationTypeEnum {
ALERT("alerts"),
import qualitynotification.base.request.QualityNotificationTypeRequest;

INVESTIGATION("investigations");
public enum NotificationTypeEnum {
ALERT,

public final String label;
INVESTIGATION;

NotificationTypeEnum(String label) {
this.label = label;
public QualityNotificationTypeRequest toRequest() {
return QualityNotificationTypeRequest.fromValue(this.name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,23 @@ public QualityNotificationIdResponse createNotification(
.description(description)
.targetDate(targetDate)
.severity(QualityNotificationSeverityRequest.fromValue(severity))
.type(notificationType.toRequest())
.receiverBpn(receiverBpn)
.build();
return given().log().body()
.spec(getRequestSpecification())
.contentType(ContentType.JSON)
.body(requestBody)
.when()
.post("/api/" + notificationType.label)
.post("/api/notifications")
.then()
.statusCode(HttpStatus.SC_CREATED)
.extract()
.as(QualityNotificationIdResponse.class);

}

public void approveNotification(final Long notificationId, NotificationTypeEnum notificationType) {
public void approveNotification(final Long notificationId) {
await()
.atMost(Duration.FIVE_MINUTES)
.pollInterval(10, TimeUnit.SECONDS)
Expand All @@ -128,7 +129,7 @@ public void approveNotification(final Long notificationId, NotificationTypeEnum
ValidatableResponse validatableResponse = given().spec(getRequestSpecification())
.contentType(ContentType.JSON)
.when()
.post("api/" + notificationType.label + "/{notificationId}/approve".replace(
.post("api/notifications/{notificationId}/approve".replace(
"{notificationId}",
notificationId.toString()
))
Expand All @@ -144,20 +145,20 @@ public void approveNotification(final Long notificationId, NotificationTypeEnum

}

public void cancelNotification(final Long notificationId, NotificationTypeEnum notificationType) {
public void cancelNotification(final Long notificationId) {

given().spec(getRequestSpecification())
.contentType(ContentType.JSON)
.when()
.post("api/" + notificationType.label + "/{notificationId}/cancel".replace(
.post("api/notifications/{notificationId}/cancel".replace(
"{notificationId}",
notificationId.toString()
))
.then()
.statusCode(HttpStatus.SC_NO_CONTENT);
}

public void closeNotification(final Long notificationId, NotificationTypeEnum notificationType) {
public void closeNotification(final Long notificationId) {
await()
.atMost(Duration.FIVE_MINUTES)
.pollInterval(10, TimeUnit.SECONDS)
Expand All @@ -167,7 +168,7 @@ public void closeNotification(final Long notificationId, NotificationTypeEnum no
.contentType(ContentType.JSON)
.when()
.body("{\"reason\": \"stringstringstr\"}")
.post("api/" + notificationType.label + "/{notificationId}/close".replace(
.post("api/notifications/{notificationId}/close".replace(
"{notificationId}",
notificationId.toString()
))
Expand All @@ -182,7 +183,7 @@ public void closeNotification(final Long notificationId, NotificationTypeEnum no

}

public void updateNotification(NotificationTypeEnum notificationType, final Long notificationId,
public void updateNotification(final Long notificationId,
UpdateQualityNotificationStatusRequest status, String reason) {
UpdateQualityNotificationRequest requestBody = UpdateQualityNotificationRequest.builder()
.status(status)
Expand All @@ -198,7 +199,7 @@ public void updateNotification(NotificationTypeEnum notificationType, final Long
.contentType(ContentType.JSON)
.body(requestBody)
.when()
.post("api/" + notificationType.label + "/{notificationId}/update".replace(
.post("api/notifications/{notificationId}/update".replace(
"{notificationId}",
notificationId.toString()
))
Expand All @@ -215,7 +216,7 @@ public void updateNotification(NotificationTypeEnum notificationType, final Long

}

public List<QualityNotificationResponse> getReceivedNotifications(NotificationTypeEnum notificationType) {
public List<QualityNotificationResponse> getReceivedNotifications() {

return given().spec(getRequestSpecification())
.contentType(ContentType.JSON)
Expand All @@ -230,19 +231,19 @@ public List<QualityNotificationResponse> getReceivedNotifications(NotificationTy
" ]\n" +
" }\n" +
"}")
.post("/api/" + notificationType.label + "/filter")
.post("/api/notifications/filter")
.then()
.statusCode(HttpStatus.SC_OK)
.extract()
.body()
.jsonPath().getList("content", QualityNotificationResponse.class);
}

public QualityNotificationResponse getNotification(Long investigationId, NotificationTypeEnum notificationType) {
public QualityNotificationResponse getNotification(Long investigationId) {
return given().spec(getRequestSpecification())
.contentType(ContentType.JSON)
.when()
.get("/api/" + notificationType.label + "/" + investigationId)
.get("/api/notifications/" + investigationId)
.then()
.statusCode(HttpStatus.SC_OK)
.log()
Expand Down
Loading