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
@@ -0,0 +1,36 @@
package com.microsoft.bot.azure;

import java.io.File;
import java.io.IOException;

public class AzureEmulatorUtils {

private static boolean isStorageEmulatorAvailable = false;
private static boolean hasStorageEmulatorBeenTested = false;
private static final String NO_EMULATOR_MESSAGE = "This test requires Azure STORAGE Emulator! Go to https://docs.microsoft.com/azure/storage/common/storage-use-emulator to download and install.";

public static boolean isStorageEmulatorAvailable() {
if (!hasStorageEmulatorBeenTested) {
try {
File emulator = new File(System.getenv("ProgramFiles") + " (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe");
if (emulator.exists()) {
Process p = Runtime.getRuntime().exec("cmd /C \"" + System.getenv("ProgramFiles")
+ " (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe\" start");
int result = p.waitFor();
// status = 0: the service was started.
// status = -5: the service is already started. Only one instance of the
// application
// can be run at the same time.
isStorageEmulatorAvailable = result == 0 || result == -5;
} else {
isStorageEmulatorAvailable = false;
}
} catch (IOException | InterruptedException ex) {
isStorageEmulatorAvailable = false;
System.out.println(NO_EMULATOR_MESSAGE);
}
hasStorageEmulatorBeenTested = true;
}
return isStorageEmulatorAvailable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.microsoft.bot.schema.ConversationReference;
import org.apache.commons.codec.binary.Base64;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

Expand All @@ -42,20 +43,7 @@

public class AzureQueueTests {
private static final Integer DEFAULT_DELAY = 2000;
private static boolean emulatorIsRunning = false;
private final String connectionString = "UseDevelopmentStorage=true";
private static final String NO_EMULATOR_MESSAGE = "This test requires Azure STORAGE Emulator! Go to https://docs.microsoft.com/azure/storage/common/storage-use-emulator to download and install.";

@BeforeClass
public static void allTestsInit() throws IOException, InterruptedException {
Process p = Runtime.getRuntime().exec
("cmd /C \"" + System.getenv("ProgramFiles") + " (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe\" start");
int result = p.waitFor();
// status = 0: the service was started.
// status = -5: the service is already started. Only one instance of the application
// can be run at the same time.
emulatorIsRunning = result == 0 || result == -5;
}

// These tests require Azure Storage Emulator v5.7
public QueueClient containerInit(String name) {
Expand All @@ -68,9 +56,13 @@ public QueueClient containerInit(String name) {
return queue;
}

@Before
public void beforeTest() {
org.junit.Assume.assumeTrue(AzureEmulatorUtils.isStorageEmulatorAvailable());
}

@Test
public void continueConversationLaterTests() {
if (runIfEmulator()) {
String queueName = "continueconversationlatertests";
QueueClient queue = containerInit(queueName);

Expand Down Expand Up @@ -128,16 +120,6 @@ public void continueConversationLaterTests() {
e.printStackTrace();
Assert.fail();
}
}
}

private boolean runIfEmulator() {
if (!emulatorIsRunning) {
System.out.println(NO_EMULATOR_MESSAGE);
return false;
}

return true;
}

private class ContinueConversationLater extends Dialog {
Expand Down
Loading