Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,44 @@ protected CompletableFuture<Void> onEvent(TurnContext turnContext) {
* @return A task that represents the work queued to execute.
*/
protected CompletableFuture<Void> onInstallationUpdate(TurnContext turnContext) {
String action = turnContext.getActivity().getAction();
if (StringUtils.isEmpty(action)) {
return CompletableFuture.completedFuture(null);
}

switch (action) {
case "add":
case "add-upgrade":
return onInstallationUpdateAdd(turnContext);

case "remove":
case "remove-upgrade":
return onInstallationUpdateRemove(turnContext);

default:
return CompletableFuture.completedFuture(null);
}
}

/**
* Override this in a derived class to provide logic specific to ActivityTypes.InstallationUpdate
* activities with 'action' set to 'add'.
*
* @param turnContext The context object for this turn.
* @return A task that represents the work queued to execute.
*/
protected CompletableFuture<Void> onInstallationUpdateAdd(TurnContext turnContext) {
return CompletableFuture.completedFuture(null);
}

/**
* Override this in a derived class to provide logic specific to ActivityTypes.InstallationUpdate
* activities with 'action' set to 'remove'.
*
* @param turnContext The context object for this turn.
* @return A task that represents the work queued to execute.
*/
protected CompletableFuture<Void> onInstallationUpdateRemove(TurnContext turnContext) {
return CompletableFuture.completedFuture(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;
import org.mockito.internal.matchers.Not;

public class ActivityHandlerTests {
@Test
Expand All @@ -38,6 +39,82 @@ public void TestOnInstallationUpdate() {
Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0));
}

@Test
public void TestInstallationUpdateAdd() {
Activity activity = new Activity() {
{
setType(ActivityTypes.INSTALLATION_UPDATE);
setAction("add");
}
};

TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity);

TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

Assert.assertEquals(2, bot.getRecord().size());
Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0));
Assert.assertEquals("onInstallationUpdateAdd", bot.getRecord().get(1));
}

@Test
public void TestInstallationUpdateAddUpgrade() {
Activity activity = new Activity() {
{
setType(ActivityTypes.INSTALLATION_UPDATE);
setAction("add-upgrade");
}
};

TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity);

TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

Assert.assertEquals(2, bot.getRecord().size());
Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0));
Assert.assertEquals("onInstallationUpdateAdd", bot.getRecord().get(1));
}

@Test
public void TestInstallationUpdateRemove() {
Activity activity = new Activity() {
{
setType(ActivityTypes.INSTALLATION_UPDATE);
setAction("remove");
}
};

TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity);

TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

Assert.assertEquals(2, bot.getRecord().size());
Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0));
Assert.assertEquals("onInstallationUpdateRemove", bot.getRecord().get(1));
}

@Test
public void TestInstallationUpdateRemoveUpgrade() {
Activity activity = new Activity() {
{
setType(ActivityTypes.INSTALLATION_UPDATE);
setAction("remove-upgrade");
}
};

TurnContext turnContext = new TurnContextImpl(new NotImplementedAdapter(), activity);

TestActivityHandler bot = new TestActivityHandler();
bot.onTurn(turnContext).join();

Assert.assertEquals(2, bot.getRecord().size());
Assert.assertEquals("onInstallationUpdate", bot.getRecord().get(0));
Assert.assertEquals("onInstallationUpdateRemove", bot.getRecord().get(1));
}

@Test
public void TestOnTypingActivity() {
Activity activity = new Activity(ActivityTypes.TYPING);
Expand Down Expand Up @@ -570,6 +647,18 @@ protected CompletableFuture onInstallationUpdate(TurnContext turnContext) {
return super.onInstallationUpdate(turnContext);
}

@Override
protected CompletableFuture<Void> onInstallationUpdateAdd(TurnContext turnContext) {
record.add("onInstallationUpdateAdd");
return CompletableFuture.completedFuture(null);
}

@Override
protected CompletableFuture<Void> onInstallationUpdateRemove(TurnContext turnContext) {
record.add("onInstallationUpdateRemove");
return CompletableFuture.completedFuture(null);
}

@Override
protected CompletableFuture onTypingActivity(TurnContext turnContext) {
record.add("onTypingActivity");
Expand Down