Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 82e0747

Browse files
authored
Added missing unit test - ShouldNotLogContinueConversation (#1077)
* Added unit test for BotFrameworkAdapter - ShouldNotLogContinueConversation * Corrected wrong constant
1 parent 9d60e67 commit 82e0747

File tree

5 files changed

+56
-17
lines changed

5 files changed

+56
-17
lines changed

libraries/bot-builder/src/main/java/com/microsoft/bot/builder/BotFrameworkAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.microsoft.bot.connector.rest.RestOAuthClient;
3232
import com.microsoft.bot.schema.AadResourceUrls;
3333
import com.microsoft.bot.schema.Activity;
34+
import com.microsoft.bot.schema.ActivityEventNames;
3435
import com.microsoft.bot.schema.ActivityTypes;
3536
import com.microsoft.bot.schema.CallerIdConstants;
3637
import com.microsoft.bot.schema.ChannelAccount;
@@ -1040,7 +1041,7 @@ public CompletableFuture<Void> createConversation(
10401041
.thenCompose(conversationResourceResponse -> {
10411042
// Create a event activity to represent the result.
10421043
Activity eventActivity = Activity.createEventActivity();
1043-
eventActivity.setName("CreateConversation");
1044+
eventActivity.setName(ActivityEventNames.CREATE_CONVERSATION);
10441045
eventActivity.setChannelId(channelId);
10451046
eventActivity.setServiceUrl(serviceUrl);
10461047
eventActivity.setId(

libraries/bot-builder/src/test/java/com/microsoft/bot/builder/BotFrameworkAdapterTests.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
99
import com.fasterxml.jackson.databind.node.ObjectNode;
10+
import com.microsoft.bot.builder.adapters.TestAdapter;
11+
import com.microsoft.bot.builder.adapters.TestFlow;
1012
import com.microsoft.bot.connector.Channels;
1113
import com.microsoft.bot.connector.ConnectorClient;
1214
import com.microsoft.bot.connector.Conversations;
@@ -19,6 +21,7 @@
1921
import com.microsoft.bot.connector.authentication.SimpleChannelProvider;
2022
import com.microsoft.bot.connector.authentication.SimpleCredentialProvider;
2123
import com.microsoft.bot.schema.Activity;
24+
import com.microsoft.bot.schema.ActivityEventNames;
2225
import com.microsoft.bot.schema.ActivityTypes;
2326
import com.microsoft.bot.schema.CallerIdConstants;
2427
import com.microsoft.bot.schema.ConversationAccount;
@@ -32,6 +35,8 @@
3235
import java.util.HashMap;
3336
import java.util.List;
3437
import java.util.Map;
38+
import java.util.UUID;
39+
import org.apache.commons.lang3.StringUtils;
3540
import org.junit.Assert;
3641
import org.junit.Test;
3742
import org.junit.runner.RunWith;
@@ -66,7 +71,7 @@ public void CreateConversationOverloadProperlySetsTenantId() {
6671
final String ActivityIdValue = "SendActivityId";
6772
final String ConversationIdValue = "NewConversationId";
6873
final String TenantIdValue = "theTenantId";
69-
final String EventActivityName = "CreateConversation";
74+
final String EventActivityName = ActivityEventNames.CREATE_CONVERSATION;
7075

7176
// so we can provide a mock ConnectorClient.
7277
class TestBotFrameworkAdapter extends BotFrameworkAdapter {
@@ -319,6 +324,39 @@ private void processActivityCreatesCorrectCredsAndClient(
319324
}, callback).join();
320325
}
321326

327+
@Test
328+
public void ShouldNotLogContinueConversation() {
329+
TranscriptStore transcriptStore = new MemoryTranscriptStore();
330+
TranscriptLoggerMiddleware sut = new TranscriptLoggerMiddleware(transcriptStore);
331+
332+
String conversationId = UUID.randomUUID().toString();
333+
TestAdapter adapter = new TestAdapter(TestAdapter.createConversationReference(conversationId, "User1", "Bot"))
334+
.use(sut);
335+
336+
Activity continueConversation = new Activity(ActivityTypes.EVENT);
337+
continueConversation.setName(ActivityEventNames.CONTINUE_CONVERSATION);
338+
339+
new TestFlow(adapter, turnContext -> {
340+
return turnContext.sendActivity("bar").thenApply(resourceResponse -> null);
341+
})
342+
.send("foo")
343+
.assertReply(activity -> {
344+
Assert.assertEquals("bar", activity.getText());
345+
PagedResult<Activity> activities = transcriptStore.getTranscriptActivities(activity.getChannelId(), conversationId).join();
346+
Assert.assertEquals(2, activities.getItems().size());
347+
})
348+
.send(continueConversation)
349+
.assertReply(activity -> {
350+
// Ensure the event hasn't been added to the transcript.
351+
PagedResult<Activity> activities = transcriptStore.getTranscriptActivities(activity.getChannelId(), conversationId).join();
352+
353+
Assert.assertFalse(activities.getItems().stream().anyMatch(a -> a.isType(ActivityTypes.EVENT) && StringUtils
354+
.equals(a.getName(), ActivityEventNames.CONTINUE_CONVERSATION)));
355+
Assert.assertEquals(3, activities.getItems().size());
356+
})
357+
.startTest().join();
358+
}
359+
322360
private static void getAppCredentialsAndAssertValues(
323361
TurnContext turnContext,
324362
String expectedAppId,

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/rest/RestAttachments.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public CompletableFuture<AttachmentInfo> getAttachmentInfo(String attachmentId)
100100
} catch (ErrorResponseException e) {
101101
throw e;
102102
} catch (Throwable t) {
103-
throw new ErrorResponseException("getAttachmentInfoAsync", responseBodyResponse);
103+
throw new ErrorResponseException("getAttachmentInfo", responseBodyResponse);
104104
}
105105
});
106106
}
@@ -146,7 +146,7 @@ public CompletableFuture<InputStream> getAttachment(String attachmentId, String
146146
} catch (ErrorResponseException e) {
147147
throw e;
148148
} catch (Throwable t) {
149-
throw new ErrorResponseException("getAttachmentAsync", responseBodyResponse);
149+
throw new ErrorResponseException("getAttachment", responseBodyResponse);
150150
}
151151
});
152152
}

libraries/bot-connector/src/main/java/com/microsoft/bot/connector/rest/RestConversations.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public CompletableFuture<ConversationsResult> getConversations(String continuati
236236
} catch (ErrorResponseException e) {
237237
throw e;
238238
} catch (Throwable t) {
239-
throw new ErrorResponseException("getConversationsAsync", responseBodyResponse);
239+
throw new ErrorResponseException("getConversations", responseBodyResponse);
240240
}
241241
});
242242
}
@@ -279,7 +279,7 @@ public CompletableFuture<ConversationResourceResponse> createConversation(
279279
throw e;
280280
} catch (Throwable t) {
281281
throw new ErrorResponseException(
282-
"createConversationAsync",
282+
"createConversation",
283283
responseBodyResponse
284284
);
285285
}
@@ -339,7 +339,7 @@ public CompletableFuture<ResourceResponse> sendToConversation(
339339
} catch (ErrorResponseException e) {
340340
throw e;
341341
} catch (Throwable t) {
342-
throw new ErrorResponseException("sendToConversationAsync", responseBodyResponse);
342+
throw new ErrorResponseException("sendToConversation", responseBodyResponse);
343343
}
344344
});
345345
}
@@ -402,7 +402,7 @@ public CompletableFuture<ResourceResponse> updateActivity(
402402
throw e;
403403
} catch (Throwable t) {
404404
throw new ErrorResponseException(
405-
"updateActivityAsync", responseBodyResponse);
405+
"updateActivity", responseBodyResponse);
406406
}
407407
});
408408
});
@@ -463,7 +463,7 @@ public CompletableFuture<ResourceResponse> replyToActivity(
463463
} catch (ErrorResponseException e) {
464464
throw e;
465465
} catch (Throwable t) {
466-
throw new ErrorResponseException("replyToActivityAsync", responseBodyResponse);
466+
throw new ErrorResponseException("replyToActivity", responseBodyResponse);
467467
}
468468
});
469469
}
@@ -511,7 +511,7 @@ public CompletableFuture<Void> deleteActivity(String conversationId, String acti
511511
} catch (ErrorResponseException e) {
512512
throw e;
513513
} catch (Throwable t) {
514-
throw new ErrorResponseException("deleteActivityAsync", responseBodyResponse);
514+
throw new ErrorResponseException("deleteActivity", responseBodyResponse);
515515
}
516516
});
517517
}
@@ -553,7 +553,7 @@ public CompletableFuture<List<ChannelAccount>> getConversationMembers(String con
553553
throw e;
554554
} catch (Throwable t) {
555555
throw new ErrorResponseException(
556-
"getConversationMembersAsync",
556+
"getConversationMembers",
557557
responseBodyResponse
558558
);
559559
}
@@ -603,7 +603,7 @@ public CompletableFuture<ChannelAccount> getConversationMember(
603603
throw e;
604604
} catch (Throwable t) {
605605
throw new ErrorResponseException(
606-
"getConversationMembersAsync",
606+
"getConversationMember",
607607
responseBodyResponse
608608
);
609609
}
@@ -656,7 +656,7 @@ public CompletableFuture<Void> deleteConversationMember(
656656
throw e;
657657
} catch (Throwable t) {
658658
throw new ErrorResponseException(
659-
"deleteConversationMemberAsync",
659+
"deleteConversationMember",
660660
responseBodyResponse
661661
);
662662
}
@@ -707,7 +707,7 @@ public CompletableFuture<List<ChannelAccount>> getActivityMembers(
707707
} catch (ErrorResponseException e) {
708708
throw e;
709709
} catch (Throwable t) {
710-
throw new ErrorResponseException("getActivityMembersAsync", responseBodyResponse);
710+
throw new ErrorResponseException("getActivityMembers", responseBodyResponse);
711711
}
712712
});
713713
}
@@ -757,7 +757,7 @@ public CompletableFuture<ResourceResponse> uploadAttachment(
757757
} catch (ErrorResponseException e) {
758758
throw e;
759759
} catch (Throwable t) {
760-
throw new ErrorResponseException("uploadAttachmentAsync", responseBodyResponse);
760+
throw new ErrorResponseException("uploadAttachment", responseBodyResponse);
761761
}
762762
});
763763
}
@@ -812,7 +812,7 @@ public CompletableFuture<ResourceResponse> sendConversationHistory(
812812
throw e;
813813
} catch (Throwable t) {
814814
throw new ErrorResponseException(
815-
"sendConversationHistoryAsync",
815+
"sendConversationHistory",
816816
responseBodyResponse
817817
);
818818
}

libraries/bot-schema/src/main/java/com/microsoft/bot/schema/ConversationReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static ConversationReference clone(ConversationReference conversationRefe
7373
@JsonIgnore
7474
public Activity getContinuationActivity() {
7575
Activity activity = Activity.createEventActivity();
76-
activity.setName("ContinueConversation");
76+
activity.setName(ActivityEventNames.CONTINUE_CONVERSATION);
7777
activity.setId(UUID.randomUUID().toString());
7878
activity.setChannelId(getChannelId());
7979
activity.setConversation(getConversation());

0 commit comments

Comments
 (0)