Skip to content

Commit

Permalink
Rename notification utils to client (#6074)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmoriceau committed Apr 21, 2023
1 parent 4310e5b commit dde4bc7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
*/
@Singleton
@Slf4j
public class NotificationUtils {
public class NotificationClient {

private final FeatureFlagClient featureFlagClient;
private final WorkflowClient client;

public NotificationUtils(final FeatureFlagClient featureFlagClient, WorkflowClient client) {
public NotificationClient(final FeatureFlagClient featureFlagClient, WorkflowClient client) {
this.featureFlagClient = featureFlagClient;
this.client = client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ public class TemporalClient {
private final WorkflowServiceStubs service;
private final StreamResetPersistence streamResetPersistence;
private final ConnectionManagerUtils connectionManagerUtils;
private final NotificationUtils notificationUtils;
private final NotificationClient notificationClient;
private final StreamResetRecordsHelper streamResetRecordsHelper;

public TemporalClient(@Named("workspaceRootTemporal") final Path workspaceRoot,
final WorkflowClient client,
final WorkflowServiceStubs service,
final StreamResetPersistence streamResetPersistence,
final ConnectionManagerUtils connectionManagerUtils,
final NotificationUtils notificationUtils,
final NotificationClient notificationClient,
final StreamResetRecordsHelper streamResetRecordsHelper) {
this.workspaceRoot = workspaceRoot;
this.client = client;
this.service = service;
this.streamResetPersistence = streamResetPersistence;
this.connectionManagerUtils = connectionManagerUtils;
this.notificationUtils = notificationUtils;
this.notificationClient = notificationClient;
this.streamResetRecordsHelper = streamResetRecordsHelper;
}

Expand Down Expand Up @@ -533,7 +533,7 @@ public void forceDeleteWorkflow(final UUID connectionId) {
}

public void sendSchemaChangeNotification(final UUID connectionId, final String url, final boolean containsBreakingChange) {
notificationUtils.sendSchemaChangeNotification(connectionId, url, containsBreakingChange);
notificationClient.sendSchemaChangeNotification(connectionId, url, containsBreakingChange);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Test the notificationUtils.
*/
class NotificationUtilsTest {
class NotificationClientTest {

private static final String WEBHOOK_URL = "url";

Expand All @@ -37,7 +37,7 @@ class NotificationUtilsTest {
private final FeatureFlagClient featureFlagClient = mock(TestClient.class);
private final WorkflowClient workflowClient = mock(WorkflowClient.class);

private final NotificationUtils notificationUtils = spy(new NotificationUtils(featureFlagClient, workflowClient));
private final NotificationClient notificationClient = spy(new NotificationClient(featureFlagClient, workflowClient));

@Test
void testCallNewNotifyWorkflow() {
Expand All @@ -47,7 +47,7 @@ void testCallNewNotifyWorkflow() {
when(workflowClient.newWorkflowStub(NotificationWorkflow.class, TemporalWorkflowUtils.buildWorkflowOptions(TemporalJobType.NOTIFY)))
.thenReturn(notificationWorkflow);

notificationUtils.sendSchemaChangeNotification(connectionId, "", false);
notificationClient.sendSchemaChangeNotification(connectionId, "", false);

verify(notificationWorkflow).sendNotification(eq(connectionId), any(), any(), any());
}
Expand All @@ -60,12 +60,12 @@ void testCallRightTemplate() throws IOException {
when(workflowClient.newWorkflowStub(NotificationWorkflow.class, TemporalWorkflowUtils.buildWorkflowOptions(TemporalJobType.NOTIFY)))
.thenReturn(notificationWorkflow);

notificationUtils.sendSchemaChangeNotification(connectionId, WEBHOOK_URL, false);
verify(notificationUtils).renderTemplate("slack/non_breaking_schema_change_slack_notification_template.txt", connectionId.toString(),
notificationClient.sendSchemaChangeNotification(connectionId, WEBHOOK_URL, false);
verify(notificationClient).renderTemplate("slack/non_breaking_schema_change_slack_notification_template.txt", connectionId.toString(),
WEBHOOK_URL);

notificationUtils.sendSchemaChangeNotification(connectionId, WEBHOOK_URL, true);
verify(notificationUtils).renderTemplate("slack/breaking_schema_change_slack_notification_template.txt", connectionId.toString(), WEBHOOK_URL);
notificationClient.sendSchemaChangeNotification(connectionId, WEBHOOK_URL, true);
verify(notificationClient).renderTemplate("slack/breaking_schema_change_slack_notification_template.txt", connectionId.toString(), WEBHOOK_URL);
}

@Test
Expand All @@ -76,7 +76,7 @@ void testCallOldNotifyWorkflow() throws JsonValidationException, ConfigNotFoundE
when(workflowClient.newWorkflowStub(ConnectionNotificationWorkflow.class, TemporalWorkflowUtils.buildWorkflowOptions(TemporalJobType.NOTIFY)))
.thenReturn(connectionNotificationWorkflow);

notificationUtils.sendSchemaChangeNotification(connectionId, WEBHOOK_URL, false);
notificationClient.sendSchemaChangeNotification(connectionId, WEBHOOK_URL, false);

verify(connectionNotificationWorkflow).sendSchemaChangeNotification(connectionId, WEBHOOK_URL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class TemporalClientTest {
private WorkflowServiceBlockingStub workflowServiceBlockingStub;
private StreamResetPersistence streamResetPersistence;
private ConnectionManagerUtils connectionManagerUtils;
private NotificationUtils notificationUtils;
private NotificationClient notificationClient;
private StreamResetRecordsHelper streamResetRecordsHelper;
private Path workspaceRoot;

Expand All @@ -127,26 +127,28 @@ void setup() throws IOException {
streamResetPersistence = mock(StreamResetPersistence.class);
mockWorkflowStatus(WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_RUNNING);
connectionManagerUtils = spy(new ConnectionManagerUtils());
notificationUtils = spy(new NotificationUtils(featureFlagClient, workflowClient));
notificationClient = spy(new NotificationClient(featureFlagClient, workflowClient));
streamResetRecordsHelper = mock(StreamResetRecordsHelper.class);
temporalClient =
spy(new TemporalClient(workspaceRoot, workflowClient, workflowServiceStubs, streamResetPersistence, connectionManagerUtils, notificationUtils,
spy(new TemporalClient(workspaceRoot, workflowClient, workflowServiceStubs, streamResetPersistence, connectionManagerUtils,
notificationClient,
streamResetRecordsHelper));
}

@Nested
class RestartPerStatus {

private ConnectionManagerUtils mConnectionManagerUtils;
private NotificationUtils mNotificationUtils;
private NotificationClient mNotificationClient;

@BeforeEach
void init() {
mConnectionManagerUtils = mock(ConnectionManagerUtils.class);
mNotificationUtils = mock(NotificationUtils.class);
mNotificationClient = mock(NotificationClient.class);

temporalClient = spy(
new TemporalClient(workspaceRoot, workflowClient, workflowServiceStubs, streamResetPersistence, mConnectionManagerUtils, mNotificationUtils,
new TemporalClient(workspaceRoot, workflowClient, workflowServiceStubs, streamResetPersistence, mConnectionManagerUtils,
mNotificationClient,
streamResetRecordsHelper));
}

Expand Down

0 comments on commit dde4bc7

Please sign in to comment.