|
1 | 1 | package com.redhat.labs.lodestar.service;
|
2 | 2 |
|
| 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 | + |
3 | 19 | 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; |
8 | 20 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
9 |
| -import static org.junit.jupiter.api.Assertions.assertTrue; |
10 | 21 |
|
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 { |
19 | 24 |
|
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"; |
25 | 26 |
|
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; |
34 | 29 |
|
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; |
49 | 32 |
|
50 |
| -import io.vertx.mutiny.core.eventbus.EventBus; |
| 33 | + @InjectMock |
| 34 | + CategoryApiClient categoryApiClient; |
51 | 35 |
|
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 | + } |
53 | 82 |
|
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; |
63 | 83 | //
|
64 | 84 | // @BeforeEach
|
65 | 85 | // void setup() {
|
@@ -813,7 +833,7 @@ class EngagementServiceTest {
|
813 | 833 | // // launch
|
814 | 834 | //
|
815 | 835 | // @Test
|
816 |
| -// void testLaunchAlreadyLaunced() { |
| 836 | +// void testLaunchAlreadyLaunched() { |
817 | 837 | //
|
818 | 838 | // Engagement e = MockUtils.mockMinimumEngagement("c1", "p1", "1234");
|
819 | 839 | // e.setLaunch(Launch.builder().build());
|
|
0 commit comments