This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #817 from zalando/ARUHA-1428
ARUHA-1428: Added submitting of subscription log events;
- Loading branch information
Showing
7 changed files
with
128 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/org/zalando/nakadi/service/SubscriptionServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.zalando.nakadi.service; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
import org.zalando.nakadi.domain.Subscription; | ||
import org.zalando.nakadi.domain.SubscriptionBase; | ||
import org.zalando.nakadi.repository.EventTypeRepository; | ||
import org.zalando.nakadi.repository.db.SubscriptionDbRepository; | ||
import org.zalando.nakadi.service.subscription.SubscriptionService; | ||
import org.zalando.nakadi.service.subscription.SubscriptionValidationService; | ||
import org.zalando.nakadi.service.subscription.zk.SubscriptionClientFactory; | ||
import org.zalando.nakadi.service.subscription.zk.ZkSubscriptionClient; | ||
import org.zalando.nakadi.service.timeline.TimelineService; | ||
import org.zalando.nakadi.utils.RandomSubscriptionBuilder; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.zalando.nakadi.utils.TestUtils.checkKPIEventSubmitted; | ||
|
||
public class SubscriptionServiceTest { | ||
|
||
private static final String SUBSCRIPTION_LOG_ET = "subscription_log_et"; | ||
|
||
private final SubscriptionDbRepository subscriptionRepository; | ||
private final NakadiKpiPublisher nakadiKpiPublisher; | ||
private final SubscriptionService subscriptionService; | ||
|
||
public SubscriptionServiceTest() throws Exception { | ||
final SubscriptionClientFactory zkSubscriptionClientFactory = mock(SubscriptionClientFactory.class); | ||
final ZkSubscriptionClient zkSubscriptionClient = mock(ZkSubscriptionClient.class); | ||
when(zkSubscriptionClientFactory.createClient(any(), any())).thenReturn(zkSubscriptionClient); | ||
final TimelineService timelineService = mock(TimelineService.class); | ||
final CursorOperationsService cursorOperationsService = mock(CursorOperationsService.class); | ||
final CursorConverter cursorConverter = mock(CursorConverter.class); | ||
final SubscriptionValidationService subscriptionValidationService = mock(SubscriptionValidationService.class); | ||
final EventTypeRepository eventTypeRepository = mock(EventTypeRepository.class); | ||
nakadiKpiPublisher = mock(NakadiKpiPublisher.class); | ||
subscriptionRepository = mock(SubscriptionDbRepository.class); | ||
|
||
subscriptionService = new SubscriptionService(subscriptionRepository, zkSubscriptionClientFactory, | ||
timelineService, eventTypeRepository, subscriptionValidationService, cursorConverter, | ||
cursorOperationsService, nakadiKpiPublisher, SUBSCRIPTION_LOG_ET); | ||
} | ||
|
||
@Test | ||
public void whenSubscriptionCreatedThenKPIEventSubmitted() throws Exception { | ||
final SubscriptionBase subscriptionBase = RandomSubscriptionBuilder.builder() | ||
.buildSubscriptionBase(); | ||
final Subscription subscription = RandomSubscriptionBuilder.builder() | ||
.withId("my_subscription_id1") | ||
.build(); | ||
when(subscriptionRepository.createSubscription(subscriptionBase)).thenReturn(subscription); | ||
|
||
subscriptionService.createSubscription(subscriptionBase); | ||
|
||
checkKPIEventSubmitted(nakadiKpiPublisher, SUBSCRIPTION_LOG_ET, | ||
new JSONObject() | ||
.put("subscription_id", "my_subscription_id1") | ||
.put("status", "created")); | ||
} | ||
|
||
@Test | ||
public void whenSubscriptionDeletedThenKPIEventSubmitted() throws Exception { | ||
subscriptionService.deleteSubscription("my_subscription_id1"); | ||
|
||
checkKPIEventSubmitted(nakadiKpiPublisher, SUBSCRIPTION_LOG_ET, | ||
new JSONObject() | ||
.put("subscription_id", "my_subscription_id1") | ||
.put("status", "deleted")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters