Skip to content

Commit 6e9b41c

Browse files
committed
Add test
1 parent 1caa89a commit 6e9b41c

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

LabApiUtilities/src/test/com/microsoft/identity/labapi/utilities/client/LabClientTest.java

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.junit.After;
3434
import org.junit.Assert;
3535
import org.junit.Before;
36-
import org.junit.Ignore;
3736
import org.junit.Rule;
3837
import org.junit.Test;
3938

@@ -73,12 +72,7 @@ public void canFetchCloudAccount() {
7372

7473
try {
7574
final ILabAccount labAccount = mLabClient.getLabAccount(query);
76-
Assert.assertNotNull(labAccount);
77-
Assert.assertNotNull(labAccount.getUsername());
78-
Assert.assertNotNull(labAccount.getPassword());
79-
Assert.assertNotNull(labAccount.getUserType());
80-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
81-
Assert.assertEquals(UserType.CLOUD, labAccount.getUserType());
75+
assertLabAccount(labAccount, UserType.CLOUD, "msidlab4");
8276
} catch (final LabApiException e) {
8377
throw new AssertionError(e);
8478
}
@@ -92,12 +86,7 @@ public void canFetchMSAAccount() {
9286

9387
try {
9488
final ILabAccount labAccount = mLabClient.getLabAccount(query);
95-
Assert.assertNotNull(labAccount);
96-
Assert.assertNotNull(labAccount.getUsername());
97-
Assert.assertNotNull(labAccount.getPassword());
98-
Assert.assertNotNull(labAccount.getUserType());
99-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("outlook"));
100-
Assert.assertEquals(UserType.MSA, labAccount.getUserType());
89+
assertLabAccount(labAccount, UserType.MSA, "outlook");
10190
} catch (final LabApiException e) {
10291
throw new AssertionError(e);
10392
}
@@ -111,12 +100,7 @@ public void canFetchGuestAccount() {
111100

112101
try {
113102
final ILabAccount labAccount = mLabClient.getLabAccount(query);
114-
Assert.assertNotNull(labAccount);
115-
Assert.assertNotNull(labAccount.getUsername());
116-
Assert.assertNotNull(labAccount.getPassword());
117-
Assert.assertNotNull(labAccount.getUserType());
118-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
119-
Assert.assertEquals(UserType.GUEST, labAccount.getUserType());
103+
assertLabAccount(labAccount, UserType.GUEST, "msidlab4");
120104
} catch (final LabApiException e) {
121105
throw new AssertionError(e);
122106
}
@@ -130,12 +114,7 @@ public void canFetchFederatedAccount() {
130114

131115
try {
132116
final ILabAccount labAccount = mLabClient.getLabAccount(query);
133-
Assert.assertNotNull(labAccount);
134-
Assert.assertNotNull(labAccount.getUsername());
135-
Assert.assertNotNull(labAccount.getPassword());
136-
Assert.assertNotNull(labAccount.getUserType());
137-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
138-
Assert.assertEquals(UserType.FEDERATED, labAccount.getUserType());
117+
assertLabAccount(labAccount, UserType.FEDERATED, "msidlab4");
139118
} catch (final LabApiException e) {
140119
throw new AssertionError(e);
141120
}
@@ -145,12 +124,7 @@ public void canFetchFederatedAccount() {
145124
public void canCreateBasicTempUser() {
146125
try {
147126
final ILabAccount labAccount = mLabClient.createTempAccount(TempUserType.BASIC);
148-
Assert.assertNotNull(labAccount);
149-
Assert.assertNotNull(labAccount.getUsername());
150-
Assert.assertNotNull(labAccount.getPassword());
151-
Assert.assertNotNull(labAccount.getUserType());
152-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
153-
Assert.assertEquals(UserType.CLOUD, labAccount.getUserType());
127+
assertLabAccount(labAccount, UserType.CLOUD, "msidlab4");
154128
} catch (final LabApiException e) {
155129
throw new AssertionError(e);
156130
}
@@ -160,11 +134,7 @@ public void canCreateBasicTempUser() {
160134
public void canCreateMAMCATempUser() {
161135
try {
162136
final ILabAccount labAccount = mLabClient.createTempAccount(TempUserType.MAM_CA);
163-
Assert.assertNotNull(labAccount);
164-
Assert.assertNotNull(labAccount.getUsername());
165-
Assert.assertNotNull(labAccount.getPassword());
166-
Assert.assertNotNull(labAccount.getUserType());
167-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
137+
assertLabAccount(labAccount, UserType.CLOUD, "msidlab4");
168138
} catch (final LabApiException e) {
169139
throw new AssertionError(e);
170140
}
@@ -203,4 +173,22 @@ public void canDisablePolicy() {
203173
}
204174
}
205175

176+
177+
// Helper to assert common properties of a lab account
178+
private void assertLabAccount(final ILabAccount labAccount,
179+
final UserType expectedUserType,
180+
final String expectedUsernameContains) {
181+
Assert.assertNotNull(labAccount);
182+
Assert.assertNotNull(labAccount.getUsername());
183+
Assert.assertNotNull(labAccount.getPassword());
184+
Assert.assertNotNull(labAccount.getUserType());
185+
if (expectedUsernameContains != null) {
186+
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains(expectedUsernameContains));
187+
}
188+
if (expectedUserType != null) {
189+
Assert.assertEquals(expectedUserType, labAccount.getUserType());
190+
}
191+
Assert.assertNotNull(labAccount.getHomeObjectId());
192+
Assert.assertNotNull(labAccount.getHomeTenantId());
193+
}
206194
}

0 commit comments

Comments
 (0)