Skip to content

Commit

Permalink
Adjusting the class names based on feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Ciocanu <[email protected]>
  • Loading branch information
Artur Ciocanu committed Dec 9, 2024
1 parent a0f6511 commit 23febff
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Wrapper for Durable Task Framework {@link TaskActivityContext}.
*/
class DaprWorkflowActivityContext implements WorkflowActivityContext {
class DefaultWorkflowActivityContext implements WorkflowActivityContext {
private final TaskActivityContext innerContext;

/**
Expand All @@ -28,7 +28,7 @@ class DaprWorkflowActivityContext implements WorkflowActivityContext {
* @param context TaskActivityContext
* @throws IllegalArgumentException if context is null
*/
public DaprWorkflowActivityContext(TaskActivityContext context) throws IllegalArgumentException {
public DefaultWorkflowActivityContext(TaskActivityContext context) throws IllegalArgumentException {
if (context == null) {
throw new IllegalArgumentException("Context cannot be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.microsoft.durabletask.TaskOptions;
import com.microsoft.durabletask.TaskOrchestrationContext;
import io.dapr.workflows.WorkflowContext;
import io.dapr.workflows.runtime.saga.DaprSagaContext;
import io.dapr.workflows.runtime.saga.DefaultSagaContext;
import io.dapr.workflows.saga.Saga;
import io.dapr.workflows.saga.SagaContext;
import org.slf4j.Logger;
Expand All @@ -33,7 +33,7 @@
import java.util.List;
import java.util.UUID;

public class DaprWorkflowContext implements WorkflowContext {
public class DefaultWorkflowContext implements WorkflowContext {
private final TaskOrchestrationContext innerContext;
private final Logger logger;
private final Saga saga;
Expand All @@ -44,7 +44,7 @@ public class DaprWorkflowContext implements WorkflowContext {
* @param context TaskOrchestrationContext
* @throws IllegalArgumentException if context is null
*/
public DaprWorkflowContext(TaskOrchestrationContext context) throws IllegalArgumentException {
public DefaultWorkflowContext(TaskOrchestrationContext context) throws IllegalArgumentException {
this(context, LoggerFactory.getLogger(WorkflowContext.class));
}

Expand All @@ -55,11 +55,11 @@ public DaprWorkflowContext(TaskOrchestrationContext context) throws IllegalArgum
* @param logger Logger
* @throws IllegalArgumentException if context or logger is null
*/
public DaprWorkflowContext(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
this(context, logger, null);
}

public DaprWorkflowContext(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
public DefaultWorkflowContext(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
this(context, LoggerFactory.getLogger(WorkflowContext.class), saga);
}

Expand All @@ -71,7 +71,7 @@ public DaprWorkflowContext(TaskOrchestrationContext context, Saga saga) throws I
* @param saga saga object, if null, saga is disabled
* @throws IllegalArgumentException if context or logger is null
*/
public DaprWorkflowContext(TaskOrchestrationContext context, Logger logger, Saga saga)
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger, Saga saga)
throws IllegalArgumentException {
if (context == null) {
throw new IllegalArgumentException("Context cannot be null");
Expand Down Expand Up @@ -249,6 +249,6 @@ public SagaContext getSagaContext() {
throw new UnsupportedOperationException("Saga is not enabled");
}

return new DaprSagaContext(this.saga, this);
return new DefaultSagaContext(this.saga, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public TaskActivity create() {
);
}

result = activity.run(new DaprWorkflowActivityContext(ctx));
result = activity.run(new DefaultWorkflowActivityContext(ctx));
return result;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public TaskOrchestration create() {

if (workflow.getSagaOption() != null) {
Saga saga = new Saga(workflow.getSagaOption());
workflow.run(new DaprWorkflowContext(ctx, saga));
workflow.run(new DefaultWorkflowContext(ctx, saga));
} else {
workflow.run(new DaprWorkflowContext(ctx));
workflow.run(new DefaultWorkflowContext(ctx));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Dapr Saga Context implementation.
*/
public class DaprSagaContext implements SagaContext {
public class DefaultSagaContext implements SagaContext {

private final Saga saga;
private final WorkflowContext workflowContext;
Expand All @@ -32,7 +32,7 @@ public class DaprSagaContext implements SagaContext {
* @param workflowContext Workflow context.
* @throws IllegalArgumentException if saga or workflowContext is null.
*/
public DaprSagaContext(Saga saga, WorkflowContext workflowContext) {
public DefaultSagaContext(Saga saga, WorkflowContext workflowContext) {
if (saga == null) {
throw new IllegalArgumentException("Saga should not be null");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.microsoft.durabletask.TaskOptions;
import com.microsoft.durabletask.TaskOrchestrationContext;

import io.dapr.workflows.runtime.DaprWorkflowContext;
import io.dapr.workflows.runtime.DefaultWorkflowContext;
import io.dapr.workflows.saga.Saga;
import io.dapr.workflows.saga.SagaContext;

Expand All @@ -44,15 +44,15 @@
import static org.mockito.Mockito.when;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class DaprWorkflowContextTest {
private DaprWorkflowContext context;
public class DefaultWorkflowContextTest {
private DefaultWorkflowContext context;
private TaskOrchestrationContext mockInnerContext;
private WorkflowContext testWorkflowContext;

@BeforeEach
public void setUp() {
mockInnerContext = mock(TaskOrchestrationContext.class);
context = new DaprWorkflowContext(mockInnerContext);
context = new DefaultWorkflowContext(mockInnerContext);
testWorkflowContext = new WorkflowContext() {
@Override
public Logger getLogger() {
Expand Down Expand Up @@ -191,13 +191,13 @@ public void callActivityTest() {
@Test
public void DaprWorkflowContextWithEmptyInnerContext() {
assertThrows(IllegalArgumentException.class, () -> {
context = new DaprWorkflowContext(mockInnerContext, (Logger)null);
context = new DefaultWorkflowContext(mockInnerContext, (Logger)null);
}); }

@Test
public void DaprWorkflowContextWithEmptyLogger() {
assertThrows(IllegalArgumentException.class, () -> {
context = new DaprWorkflowContext(null, (Logger)null);
context = new DefaultWorkflowContext(null, (Logger)null);
});
}

Expand All @@ -217,7 +217,7 @@ public void getIsReplayingTest() {
public void getLoggerReplayingTest() {
Logger mockLogger = mock(Logger.class);
when(context.isReplaying()).thenReturn(true);
DaprWorkflowContext testContext = new DaprWorkflowContext(mockInnerContext, mockLogger);
DefaultWorkflowContext testContext = new DefaultWorkflowContext(mockInnerContext, mockLogger);

String expectedArg = "test print";
testContext.getLogger().info(expectedArg);
Expand All @@ -229,7 +229,7 @@ public void getLoggerReplayingTest() {
public void getLoggerFirstTimeTest() {
Logger mockLogger = mock(Logger.class);
when(context.isReplaying()).thenReturn(false);
DaprWorkflowContext testContext = new DaprWorkflowContext(mockInnerContext, mockLogger);
DefaultWorkflowContext testContext = new DefaultWorkflowContext(mockInnerContext, mockLogger);

String expectedArg = "test print";
testContext.getLogger().info(expectedArg);
Expand Down Expand Up @@ -323,15 +323,15 @@ public void newUuidTestNoImplementationExceptionTest() {
@Test
public void getSagaContextTest_sagaEnabled() {
Saga saga = mock(Saga.class);
WorkflowContext context = new DaprWorkflowContext(mockInnerContext, saga);
WorkflowContext context = new DefaultWorkflowContext(mockInnerContext, saga);

SagaContext sagaContext = context.getSagaContext();
assertNotNull("SagaContext should not be null", sagaContext);
}

@Test
public void getSagaContextTest_sagaDisabled() {
WorkflowContext context = new DaprWorkflowContext(mockInnerContext);
WorkflowContext context = new DefaultWorkflowContext(mockInnerContext);
assertThrows(UnsupportedOperationException.class, () -> {
context.getSagaContext();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import io.dapr.workflows.runtime.saga.DaprSagaContext;
import io.dapr.workflows.runtime.saga.DefaultSagaContext;
import org.junit.Test;

import io.dapr.workflows.WorkflowContext;

public class DaprSagaContextTest {
public class DefaultSagaContextTest {

@Test
public void testDaprSagaContextImpl_IllegalArgumentException() {
Saga saga = mock(Saga.class);
WorkflowContext workflowContext = mock(WorkflowContext.class);

assertThrows(IllegalArgumentException.class, () -> {
new DaprSagaContext(saga, null);
new DefaultSagaContext(saga, null);
});

assertThrows(IllegalArgumentException.class, () -> {
new DaprSagaContext(null, workflowContext);
new DefaultSagaContext(null, workflowContext);
});
}

@Test
public void test_registerCompensation() {
Saga saga = mock(Saga.class);
WorkflowContext workflowContext = mock(WorkflowContext.class);
DaprSagaContext ctx = new DaprSagaContext(saga, workflowContext);
DefaultSagaContext ctx = new DefaultSagaContext(saga, workflowContext);

String activityClassName = "name1";
Object activityInput = new Object();
Expand All @@ -45,7 +45,7 @@ public void test_registerCompensation() {
public void test_compensate() {
Saga saga = mock(Saga.class);
WorkflowContext workflowContext = mock(WorkflowContext.class);
DaprSagaContext ctx = new DaprSagaContext(saga, workflowContext);
DefaultSagaContext ctx = new DefaultSagaContext(saga, workflowContext);

doNothing().when(saga).compensate(workflowContext);

Expand Down

0 comments on commit 23febff

Please sign in to comment.