Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add unit test for logging attachments
  • Loading branch information
LeeParrishMSFT committed Mar 30, 2021
commit bab9f3abf3616c42ff266cba1ce6909a6ac27013
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.microsoft.bot.connector.Channels;
import com.microsoft.bot.schema.Activity;
import com.microsoft.bot.schema.ActivityTypes;
import com.microsoft.bot.schema.Attachment;
import com.microsoft.bot.schema.ChannelAccount;
import com.microsoft.bot.schema.ResourceResponse;
import com.microsoft.bot.schema.Serialization;
Expand Down Expand Up @@ -528,6 +529,45 @@ public void Telemetry_AdditionalProps() {
);
}

@Test
public void Telemetry_LogAttachments() throws JsonProcessingException {
BotTelemetryClient mockTelemetryClient = mock(BotTelemetryClient.class);
TestAdapter adapter = new TestAdapter(Channels.MSTEAMS).use(
new TelemetryLoggerMiddleware(mockTelemetryClient, true)
);

TeamInfo teamInfo = new TeamInfo();
teamInfo.setId("teamId");
teamInfo.setName("teamName");

Activity activity = MessageFactory.text("test");
ChannelAccount from = new ChannelAccount();
from.setId("userId");
from.setName("userName");
from.setAadObjectId("aadId");
activity.setFrom(from);
Attachment attachment = new Attachment();
attachment.setContent("Hello World");
attachment.setContentType("test/attachment");
attachment.setName("testname");
activity.setAttachment(attachment);

new TestFlow(adapter).send(activity).startTest().join();

verify(mockTelemetryClient).trackEvent(
eventNameCaptor.capture(),
propertiesCaptor.capture()
);
List<String> eventNames = eventNameCaptor.getAllValues();
List<Map<String, String>> properties = propertiesCaptor.getAllValues();

Assert.assertEquals(TelemetryLoggerConstants.BOTMSGRECEIVEEVENT, eventNames.get(0));
String loggedAttachment = properties.get(0).get("attachments");
String originalAttachment = Serialization.toString(activity.getAttachments());
Assert.assertTrue(StringUtils.equals(loggedAttachment, originalAttachment));
}


@Test
public void Telemetry_LogTeamsProperties() throws JsonProcessingException {
BotTelemetryClient mockTelemetryClient = mock(BotTelemetryClient.class);
Expand Down