Skip to content

Commit cdabcee

Browse files
authored
Add api status update (#190)
* throw error if engagement type participant roles don't match the allowed values in the config * Add api to update engagement states
1 parent 0d2139e commit cdabcee

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2020
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
2121
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
22-
<quarkus.platform.version>2.2.2.Final</quarkus.platform.version>
22+
<quarkus.platform.version>2.10.0.Final</quarkus.platform.version>
2323
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
2424
<sonar.projectKey>rht-labs_open-management-portal-backend</sonar.projectKey>
2525
<sonar.organization>rht-labs</sonar.organization>

src/main/java/com/redhat/labs/lodestar/resource/RefreshResource.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ public Response refresh(
9595

9696
}
9797

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

src/main/java/com/redhat/labs/lodestar/rest/client/EngagementApiClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ List<Engagement> getEngagementsWithCategory(@QueryParam("page") int page, @Query
6969
@Path("refresh")
7070
Response refresh(@QueryParam("uuids") Set<String> uuids);
7171

72+
@PUT
73+
@Path("refresh/state")
74+
Response refreshStates();
75+
7276
@GET
7377
@Path("suggest")
7478
Response suggest(@QueryParam("partial") String partial);

src/main/java/com/redhat/labs/lodestar/service/EngagementService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,8 @@ public void refresh(Set<String> uuids) {
437437
engagementApiClient.refresh(uuids);
438438
}
439439

440+
public Response refreshState() {
441+
return engagementApiClient.refreshStates();
442+
}
443+
440444
}

src/test/java/com/redhat/labs/lodestar/resource/RefreshResourceTest.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.HashMap;
1717

1818
import static io.restassured.RestAssured.given;
19+
import static org.hamcrest.Matchers.equalTo;
1920

2021
@QuarkusTest
2122
@Tag("nested")
@@ -33,6 +34,10 @@ class RefreshResourceTest {
3334
@RestClient
3435
public ParticipantApiClient participantClient;
3536

37+
@InjectMock
38+
@RestClient
39+
public HostingEnvironmentApiClient hostingEnvironmentApiClient;
40+
3641
@InjectMock
3742
@RestClient
3843
public EngagementStatusApiClient engagementStatusApiClient;
@@ -67,6 +72,15 @@ void testActivityReload() {
6772

6873
Mockito.verify(activityClient, Mockito.timeout(1000)).refresh();
6974
}
75+
76+
@Test
77+
void testHostingReload() {
78+
79+
given().queryParam("hosting", true).when().auth().oauth2(validToken)
80+
.put("/engagements/refresh").then().statusCode(202).body("size()", equalTo(1)).body("[0]", equalTo("hosting"));
81+
82+
Mockito.verify(hostingEnvironmentApiClient, Mockito.timeout(1000)).refresh();
83+
}
7084

7185
@Test
7286
void testParticipantReload() {
@@ -125,14 +139,11 @@ void testDbRefreshWithPurge() throws Exception {
125139
}
126140

127141
@Test
128-
void testDbRefreshWithoutPurge() throws Exception {
129-
130-
HashMap<String, Long> timeClaims = new HashMap<>();
131-
String token = TokenUtils.generateTokenString("/JwtClaimsWriter.json", timeClaims);
142+
void testDbRefreshWithoutPurge() {
132143

133144
given()
134145
.auth()
135-
.oauth2(token)
146+
.oauth2(validToken)
136147
.queryParam("purgeFirst", false)
137148
.queryParam("engagements", true)
138149
.when()
@@ -141,4 +152,16 @@ void testDbRefreshWithoutPurge() throws Exception {
141152
.statusCode(202);
142153

143154
}
155+
156+
@Test
157+
void testRefreshState() {
158+
Mockito.when(engagementApiClient.refreshStates()).thenReturn(Response.ok().build());
159+
given()
160+
.auth()
161+
.oauth2(validToken)
162+
.when()
163+
.put("/engagements/refresh/states")
164+
.then()
165+
.statusCode(200);
166+
}
144167
}

0 commit comments

Comments
 (0)