Skip to content

Commit

Permalink
Add api status update (#190)
Browse files Browse the repository at this point in the history
* throw error if engagement type participant roles don't match the allowed values in the config

* Add api to update engagement states
  • Loading branch information
mcanoy authored Jun 28, 2022
1 parent 0d2139e commit cdabcee
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>2.2.2.Final</quarkus.platform.version>
<quarkus.platform.version>2.10.0.Final</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<sonar.projectKey>rht-labs_open-management-portal-backend</sonar.projectKey>
<sonar.organization>rht-labs</sonar.organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,14 @@ public Response refresh(

}

@PUT
@Path("states")
@SecurityRequirement(name = "jwt")
@APIResponses(value = { @APIResponse(responseCode = "401", description = "Missing or Invalid JWT"),
@APIResponse(responseCode = "200", description = "The request was accepted and will be processed.") })
@Operation(summary = "Refreshes the state of the engagement in gitlab")
public Response refreshStates() {
return engagementService.refreshState();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ List<Engagement> getEngagementsWithCategory(@QueryParam("page") int page, @Query
@Path("refresh")
Response refresh(@QueryParam("uuids") Set<String> uuids);

@PUT
@Path("refresh/state")
Response refreshStates();

@GET
@Path("suggest")
Response suggest(@QueryParam("partial") String partial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,8 @@ public void refresh(Set<String> uuids) {
engagementApiClient.refresh(uuids);
}

public Response refreshState() {
return engagementApiClient.refreshStates();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

@QuarkusTest
@Tag("nested")
Expand All @@ -33,6 +34,10 @@ class RefreshResourceTest {
@RestClient
public ParticipantApiClient participantClient;

@InjectMock
@RestClient
public HostingEnvironmentApiClient hostingEnvironmentApiClient;

@InjectMock
@RestClient
public EngagementStatusApiClient engagementStatusApiClient;
Expand Down Expand Up @@ -67,6 +72,15 @@ void testActivityReload() {

Mockito.verify(activityClient, Mockito.timeout(1000)).refresh();
}

@Test
void testHostingReload() {

given().queryParam("hosting", true).when().auth().oauth2(validToken)
.put("/engagements/refresh").then().statusCode(202).body("size()", equalTo(1)).body("[0]", equalTo("hosting"));

Mockito.verify(hostingEnvironmentApiClient, Mockito.timeout(1000)).refresh();
}

@Test
void testParticipantReload() {
Expand Down Expand Up @@ -125,14 +139,11 @@ void testDbRefreshWithPurge() throws Exception {
}

@Test
void testDbRefreshWithoutPurge() throws Exception {

HashMap<String, Long> timeClaims = new HashMap<>();
String token = TokenUtils.generateTokenString("/JwtClaimsWriter.json", timeClaims);
void testDbRefreshWithoutPurge() {

given()
.auth()
.oauth2(token)
.oauth2(validToken)
.queryParam("purgeFirst", false)
.queryParam("engagements", true)
.when()
Expand All @@ -141,4 +152,16 @@ void testDbRefreshWithoutPurge() throws Exception {
.statusCode(202);

}

@Test
void testRefreshState() {
Mockito.when(engagementApiClient.refreshStates()).thenReturn(Response.ok().build());
given()
.auth()
.oauth2(validToken)
.when()
.put("/engagements/refresh/states")
.then()
.statusCode(200);
}
}

0 comments on commit cdabcee

Please sign in to comment.