Skip to content

Commit b9692e1

Browse files
authored
Participant test (#189)
* throw error if engagement type participant roles don't match the allowed values in the config * add test to verify participant role is allowed
1 parent 71d12b1 commit b9692e1

File tree

1 file changed

+72
-52
lines changed

1 file changed

+72
-52
lines changed

src/test/java/com/redhat/labs/lodestar/service/EngagementServiceTest.java

Lines changed: 72 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,85 @@
11
package com.redhat.labs.lodestar.service;
22

3+
import com.redhat.labs.lodestar.model.Engagement;
4+
import com.redhat.labs.lodestar.model.EngagementUser;
5+
import com.redhat.labs.lodestar.rest.client.CategoryApiClient;
6+
import com.redhat.labs.lodestar.rest.client.EngagementApiClient;
7+
import io.quarkus.test.junit.QuarkusTest;
8+
import io.quarkus.test.junit.mockito.InjectMock;
9+
import org.junit.jupiter.api.BeforeEach;
10+
import org.junit.jupiter.api.Test;
11+
import org.mockito.Mockito;
12+
13+
import javax.inject.Inject;
14+
import javax.ws.rs.WebApplicationException;
15+
import java.util.Collections;
16+
import java.util.Map;
17+
import java.util.Set;
18+
319
import static org.junit.jupiter.api.Assertions.assertEquals;
4-
import static org.junit.jupiter.api.Assertions.assertFalse;
5-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6-
import static org.junit.jupiter.api.Assertions.assertNotNull;
7-
import static org.junit.jupiter.api.Assertions.assertNull;
820
import static org.junit.jupiter.api.Assertions.assertThrows;
9-
import static org.junit.jupiter.api.Assertions.assertTrue;
1021

11-
import java.util.ArrayList;
12-
import java.util.Arrays;
13-
import java.util.Collection;
14-
import java.util.List;
15-
import java.util.Optional;
16-
import java.util.Set;
17-
import java.util.UUID;
18-
import java.util.stream.Stream;
22+
@QuarkusTest
23+
class EngagementServiceTest {
1924

20-
import javax.json.bind.Jsonb;
21-
import javax.json.bind.JsonbBuilder;
22-
import javax.json.bind.JsonbConfig;
23-
import javax.json.bind.config.PropertyNamingStrategy;
24-
import javax.ws.rs.WebApplicationException;
25+
private final String lastUpdate = "2007-12-03T10:15:30.00Z";
2526

26-
import org.apache.commons.lang3.StringUtils;
27-
import org.junit.jupiter.api.AfterEach;
28-
import org.junit.jupiter.api.BeforeEach;
29-
import org.junit.jupiter.api.Test;
30-
import org.junit.jupiter.params.ParameterizedTest;
31-
import org.junit.jupiter.params.provider.NullAndEmptySource;
32-
import org.junit.jupiter.params.provider.ValueSource;
33-
import org.mockito.Mockito;
27+
@Inject
28+
EngagementService engagementService;
3429

35-
import com.google.common.collect.Lists;
36-
import com.google.common.collect.Sets;
37-
import com.redhat.labs.lodestar.model.Artifact;
38-
import com.redhat.labs.lodestar.model.Category;
39-
import com.redhat.labs.lodestar.model.Engagement;
40-
import com.redhat.labs.lodestar.model.EngagementUser;
41-
import com.redhat.labs.lodestar.model.Hook;
42-
import com.redhat.labs.lodestar.model.HostingEnvironment;
43-
import com.redhat.labs.lodestar.model.Launch;
44-
import com.redhat.labs.lodestar.model.Score;
45-
import com.redhat.labs.lodestar.model.UseCase;
46-
import com.redhat.labs.lodestar.model.event.EventType;
47-
import com.redhat.labs.lodestar.model.filter.FilterOptions;
48-
import com.redhat.labs.lodestar.model.filter.ListFilterOptions;
30+
@InjectMock
31+
EngagementApiClient engagementApiClient;
4932

50-
import io.vertx.mutiny.core.eventbus.EventBus;
33+
@InjectMock
34+
CategoryApiClient categoryApiClient;
5135

52-
class EngagementServiceTest {
36+
@InjectMock
37+
HostingService hostingService;
38+
39+
@InjectMock
40+
ArtifactService artifactService;
41+
42+
@InjectMock
43+
ParticipantService participantService;
44+
45+
@InjectMock
46+
ConfigService configService;
47+
48+
@InjectMock
49+
ActivityService activityService;
50+
51+
@BeforeEach
52+
public void setUp() {
53+
String uuid = "uuid";
54+
Mockito.when(engagementApiClient.getEngagement(uuid)).thenReturn(Engagement.builder().uuid("uuid").lastUpdate(lastUpdate).build());
55+
Mockito.when(hostingService.getHostingEnvironments(uuid)).thenReturn(Collections.emptyList());
56+
Mockito.when(artifactService.getArtifacts(uuid)).thenReturn(Collections.emptyList());
57+
Mockito.when(participantService.getParticipantsForEngagement(uuid)).thenReturn(Collections.emptyList());
58+
Mockito.when(configService.getParticipantOptions("Res")).thenReturn(Map.of("monkey", "Monkey", "giraffe", "Giraffe"));
59+
Mockito.when(categoryApiClient.getCategories(uuid)).thenReturn(Collections.emptyList());
60+
Mockito.when(activityService.getActivityForUuid(uuid)).thenReturn(Collections.emptyList());
61+
}
62+
63+
@Test
64+
public void testParticipantValid() {
65+
EngagementUser participant = EngagementUser.builder().email("[email protected]").firstName("Kevin").lastName("RH").role("monkey").build();
66+
Engagement engagement = Engagement.builder().uuid("uuid").type("Res").lastUpdate(lastUpdate).engagementUsers(Set.of(participant)).build();
67+
engagementService.update(engagement);
68+
Mockito.verify(participantService, Mockito.times(2)).getParticipantsForEngagement("uuid");
69+
}
70+
71+
@Test
72+
@SuppressWarnings("unchecked")
73+
public void testParticipantInValid() {
74+
EngagementUser participant = EngagementUser.builder().email("[email protected]").firstName("Kevin").lastName("RH").role("Chef").build();
75+
Engagement engagement = Engagement.builder().uuid("uuid").type("Res").lastUpdate(lastUpdate).engagementUsers(Set.of(participant)).build();
76+
77+
WebApplicationException ex = assertThrows(WebApplicationException.class, () -> engagementService.update(engagement));
78+
Map<String, String> body = ex.getResponse().readEntity(Map.class);
79+
assertEquals("Participant [email protected] has invalid role Chef.", body.get("lodestarMessage"));
80+
assertEquals(400, ex.getResponse().getStatus());
81+
}
5382

54-
// JsonbConfig config = new JsonbConfig().withFormatting(true)
55-
// .withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_UNDERSCORES);
56-
// Jsonb jsonb = JsonbBuilder.create(config);
57-
//
58-
// EngagementRepository repository;
59-
// EventBus eventBus;
60-
// LodeStarGitApiClient gitApi;
61-
//
62-
// EngagementService service;
6383
//
6484
// @BeforeEach
6585
// void setup() {
@@ -813,7 +833,7 @@ class EngagementServiceTest {
813833
// // launch
814834
//
815835
// @Test
816-
// void testLaunchAlreadyLaunced() {
836+
// void testLaunchAlreadyLaunched() {
817837
//
818838
// Engagement e = MockUtils.mockMinimumEngagement("c1", "p1", "1234");
819839
// e.setLaunch(Launch.builder().build());

0 commit comments

Comments
 (0)