|
31 | 31 | import com.microsoft.bot.builder.UserState;
|
32 | 32 | import com.microsoft.bot.builder.adapters.TestAdapter;
|
33 | 33 | import com.microsoft.bot.builder.adapters.TestFlow;
|
| 34 | +import com.microsoft.bot.dialogs.memory.DialogStateManager; |
| 35 | +import com.microsoft.bot.dialogs.memory.DialogStateManagerConfiguration; |
| 36 | +import com.microsoft.bot.dialogs.memory.PathResolver; |
| 37 | +import com.microsoft.bot.dialogs.memory.scopes.MemoryScope; |
34 | 38 | import com.microsoft.bot.dialogs.prompts.PromptOptions;
|
35 | 39 | import com.microsoft.bot.dialogs.prompts.TextPrompt;
|
36 | 40 | import com.microsoft.bot.schema.Activity;
|
37 | 41 | import com.microsoft.bot.schema.ActivityTypes;
|
| 42 | +import com.microsoft.bot.schema.ChannelAccount; |
38 | 43 | import com.microsoft.bot.schema.ConversationAccount;
|
39 | 44 | import com.microsoft.bot.schema.ResourceResponse;
|
40 | 45 | import com.microsoft.bot.schema.ResultPair;
|
41 | 46 |
|
| 47 | +import org.apache.commons.lang3.NotImplementedException; |
42 | 48 | import org.apache.commons.lang3.StringUtils;
|
43 | 49 | import org.junit.Assert;
|
44 | 50 | import org.junit.Test;
|
@@ -462,6 +468,44 @@ public void SkillShouldReturnEmptyOnRepromptWithNoDialog() {
|
462 | 468 | Assert.assertEquals(DialogTurnStatus.EMPTY, _dmTurnResult.getTurnResult().getStatus());
|
463 | 469 | }
|
464 | 470 |
|
| 471 | + @Test |
| 472 | + public void DialogManager_StateConfigurationTest() { |
| 473 | + // Arrange |
| 474 | + WaterfallDialog dialog = new WaterfallDialog("test-dialog", null); |
| 475 | + |
| 476 | + CustomMemoryScope memoryScope = new CustomMemoryScope(); |
| 477 | + CustomPathResolver pathResolver = new CustomPathResolver(); |
| 478 | + |
| 479 | + DialogManager dialogManager = new DialogManager(dialog, null); |
| 480 | + dialogManager.setStateManagerConfiguration(new DialogStateManagerConfiguration()); |
| 481 | + dialogManager.getStateManagerConfiguration().getMemoryScopes().add(memoryScope); |
| 482 | + dialogManager.getStateManagerConfiguration().getPathResolvers().add(pathResolver); |
| 483 | + |
| 484 | + // The test dialog being used here happens to not send anything so we only need to mock the type. |
| 485 | + TestAdapter adapter = new TestAdapter(); |
| 486 | + |
| 487 | + // ChannelId and Conversation.Id are required for ConversationState and |
| 488 | + // ChannelId and From.Id are required for UserState. |
| 489 | + Activity activity = new Activity(ActivityTypes.MESSAGE); |
| 490 | + activity.setChannelId("test-channel"); |
| 491 | + ConversationAccount conversation = new ConversationAccount(); |
| 492 | + conversation.setId("test-conversation-id"); |
| 493 | + ChannelAccount channelAccount = new ChannelAccount(); |
| 494 | + channelAccount.setId("test-id"); |
| 495 | + activity.setConversation(conversation); |
| 496 | + activity.setFrom(channelAccount); |
| 497 | + |
| 498 | + // Act |
| 499 | + TurnContext turnContext = new TurnContextImpl(adapter, activity); |
| 500 | + turnContext.getTurnState().add(new ConversationState(new MemoryStorage())); |
| 501 | + dialogManager.onTurn(turnContext).join(); |
| 502 | + DialogStateManager actual = turnContext.getTurnState().get(DialogStateManager.class); |
| 503 | + |
| 504 | + // Assert |
| 505 | + Assert.assertTrue(actual.getConfiguration().getMemoryScopes().contains(memoryScope)); |
| 506 | + Assert.assertTrue(actual.getConfiguration().getPathResolvers().contains(pathResolver)); |
| 507 | + } |
| 508 | + |
465 | 509 | private Dialog CreateTestDialog(String property) {
|
466 | 510 | return new AskForNameDialog(property.replace(".", ""), property);
|
467 | 511 | }
|
@@ -539,6 +583,33 @@ public CompletableFuture<ResourceResponse[]> invoke(TurnContext context, List<Ac
|
539 | 583 | }
|
540 | 584 | }
|
541 | 585 |
|
| 586 | + private class CustomMemoryScope extends MemoryScope { |
| 587 | + CustomMemoryScope() { |
| 588 | + super("custom", false); |
| 589 | + } |
| 590 | + |
| 591 | + @Override |
| 592 | + public Object getMemory(DialogContext dialogContext) { |
| 593 | + throw new NotImplementedException("Not implemented"); |
| 594 | + } |
| 595 | + |
| 596 | + @Override |
| 597 | + public void setMemory(DialogContext dialogContext, Object memory) { |
| 598 | + throw new NotImplementedException("Not implemented"); |
| 599 | + } |
| 600 | + } |
| 601 | + |
| 602 | + private class CustomPathResolver implements PathResolver { |
| 603 | + CustomPathResolver() { |
| 604 | + } |
| 605 | + |
| 606 | + @Override |
| 607 | + public String transformPath(String path) { |
| 608 | + throw new NotImplementedException("Not implemented"); |
| 609 | + } |
| 610 | + |
| 611 | + } |
| 612 | + |
542 | 613 | private class AskForNameDialog extends ComponentDialog implements DialogDependencies {
|
543 | 614 | private final String property;
|
544 | 615 |
|
|
0 commit comments