Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test cases related to Broker Host changes. #1803

Merged
merged 4 commits into from
Apr 25, 2023
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 @@ -44,38 +44,41 @@ public class TestCase1561087 extends AbstractMsalBrokerTest {
@Test
public void test_1561087() {
// Set flights and get to check if the flight information is returned
final String flightsJson = "{\"SetFlightsTest\":\"true\"}";
final String flightKey = "SetFlightsTest";
final String flightValue = "true";
final String flightsJson = "{\""+flightKey+"\":\""+flightValue+"\"}";
mBroker.overwriteFlights(flightsJson);
checkIfBrokerContainsFlight(flightsJson);
checkIfBrokerContainsFlight(flightKey, flightValue);

// Add flights and get to check if the flight information is returned
final String anotherFlightJson = "{\"AnotherFlight\":\"hello\"}";
mBroker.setFlights(anotherFlightJson);
checkIfBrokerContainsFlight(anotherFlightJson);
checkIfBrokerContainsFlight(flightsJson);
final String anotherFlightKey = "AnotherFlight";
final String anotherFlightValue = "hello";
mBroker.setFlights(anotherFlightKey, anotherFlightValue);
checkIfBrokerContainsFlight(anotherFlightKey, anotherFlightValue);
checkIfBrokerContainsFlight(flightKey, flightValue);

// Override flights and get to check if the flight information is returned
final String flightToOverwrite = "{\"SetFlightsTest\":\"false\"}";
mBroker.setFlights(flightToOverwrite);
checkIfBrokerContainsFlight(anotherFlightJson);
checkIfBrokerContainsFlight(flightToOverwrite);
final String flightToOverwriteKey = "SetFlightsTest";
final String flightToOverwriteValue = "false";
mBroker.setFlights(flightToOverwriteKey, flightToOverwriteValue);
checkIfBrokerContainsFlight(anotherFlightKey, anotherFlightValue);
checkIfBrokerContainsFlight(flightToOverwriteKey, flightToOverwriteValue);

// Add flight with null value. SetFlightsTest should be removed.
final String flightMapWithNullValue = "{\"SetFlightsTest\": null}";
mBroker.setFlights(flightMapWithNullValue);
checkIfBrokerContainsFlight(anotherFlightJson);
final String flightMapWithEmptyValueKey = "SetFlightsTest";
final String flightMapWithEmptyValueValue = "";
mBroker.setFlights(flightMapWithEmptyValueKey, flightMapWithEmptyValueValue);
checkIfBrokerContainsFlight(anotherFlightKey, anotherFlightValue);
Assert.assertFalse(mBroker.getFlights().contains("SetFlightsTest"));

// Add an empty flight map. the flight map should not change.
final String emptyFlightMap = "{}";
final String oldFlights = mBroker.getFlights();
mBroker.setFlights(emptyFlightMap);
mBroker.setFlights("", "");
Assert.assertEquals(oldFlights, mBroker.getFlights());

// clear flights and get to check if the flights are cleared.
// Looks like some defaults flights are added even after flights are cleared, so we can check that the flights we added have been deleted.
final String clearFlightsJson = "{}";
mBroker.overwriteFlights(clearFlightsJson);
mBroker.overwriteFlights("{}");
Assert.assertFalse(mBroker.getFlights().contains("AnotherFlight"));
}

Expand Down Expand Up @@ -107,12 +110,14 @@ public int getConfigFileResourceId() {
}

/**
* Check if the Broker contain the parameter flight by removing brackets from the parameter and using String.contains()
* Check if the Broker contain the fligth key and value
*
* @param flightToCheck flight to be checked against flight set from BrokerHost
* @param flightKey flight key to be checked against flight set from BrokerHost
* @param flightValue flight value to be checked against flight set from BrokerHost
*/
private void checkIfBrokerContainsFlight(@NonNull final String flightToCheck) {
final String withoutBrackets = flightToCheck.replace("{", "").replace("}", "");
Assert.assertTrue(mBroker.getFlights().contains(withoutBrackets));
private void checkIfBrokerContainsFlight(@NonNull final String flightKey, @NonNull final String flightValue) {
final String flights = mBroker.getFlights();
Assert.assertTrue(flights.contains(flightKey));
Assert.assertTrue(flights.contains(flightValue));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void test_1561136() throws Throwable {

BrokerHost brokerHost = (BrokerHost) mBroker;
// Get accounts without signing in, does not return any accounts
Assert.assertEquals(0, brokerHost.getAllAccounts(false).size());
Assert.assertEquals(0, brokerHost.getAllAccounts().size());

// Make an interactive call with MSAL
final MsalSdk msalSdk = new MsalSdk();
Expand Down Expand Up @@ -90,7 +90,7 @@ public void handleUserInteraction() {
authResult.assertSuccess();

// Check get accounts returns the account signed in with MSAL
List<String> accounts = brokerHost.getAllAccounts(false);
List<String> accounts = brokerHost.getAllAccounts();
Assert.assertEquals(1, accounts.size());

// create another temp user
Expand All @@ -103,7 +103,7 @@ public void handleUserInteraction() {
brokerHost.performDeviceRegistration(username2, password2);

// get accounts this time must show two accounts - to verify this we have check for 2 dialog boxes
accounts = brokerHost.getAllAccounts(true);
accounts = brokerHost.getAllAccounts();
Assert.assertEquals(2, accounts.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void test_1561137() throws Throwable {

BrokerHost brokerHost = (BrokerHost) mBroker;
// Check getAccounts returns 0 accounts initially
Assert.assertEquals(0, brokerHost.getAllAccounts(false).size());
Assert.assertEquals(0, brokerHost.getAllAccounts().size());

final MsalSdk msalSdk = new MsalSdk();

Expand Down Expand Up @@ -86,12 +86,12 @@ public void handleUserInteraction() {
authResult.assertSuccess();

// Check getAccounts returns the account added
Assert.assertEquals(1, brokerHost.getAllAccounts(false).size());
Assert.assertEquals(1, brokerHost.getAllAccounts().size());

// Remove the added account
brokerHost.removeAccount(username);
// Check getAccounts returns 0 accounts after removal
Assert.assertEquals(0, brokerHost.getAllAccounts(false).size());
Assert.assertEquals(0, brokerHost.getAllAccounts().size());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void test_1592468() throws Throwable {
.build();

// Set EnableCrossCloudTokenRequests flight to true
mBroker.setFlights("{'EnableCrossCloudTokenRequests' : 'true'}");

Logger.setLogger("TEST_LOGGER", (tag, logLevel, message, containsPII) -> {
// Not expecting the BrokerJoinedAccountController to be used for the cross cloud request
Expand Down