Skip to content

Commit 859f357

Browse files
author
Rujun Chen
authored
Fix tests not executed in pipeline (Azure#20700)
1 parent ae5c926 commit 859f357

File tree

12 files changed

+140
-105
lines changed

12 files changed

+140
-105
lines changed

sdk/spring/azure-spring-boot-test-aad-b2c/src/test/java/com/azure/test/aad/b2c/selenium/AADB2CIT.java

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

44
package com.azure.test.aad.b2c.selenium;
55

6-
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_PROFILE_EDIT;
7-
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_SIGN_UP_OR_SIGN_IN;
8-
import static com.azure.test.aad.b2c.selenium.AADB2CSeleniumITHelper.createDefaultProperteis;
9-
106
import com.azure.spring.autoconfigure.b2c.AADB2COidcLoginConfigurer;
11-
import org.junit.After;
12-
import org.junit.Assert;
13-
import org.junit.Before;
14-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.Disabled;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.TestInstance;
1512
import org.springframework.boot.autoconfigure.SpringBootApplication;
1613
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1714
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
@@ -23,25 +20,33 @@
2320
import org.springframework.ui.Model;
2421
import org.springframework.web.bind.annotation.GetMapping;
2522

23+
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_PROFILE_EDIT;
24+
import static com.azure.spring.test.EnvironmentVariable.AAD_B2C_SIGN_UP_OR_SIGN_IN;
25+
import static com.azure.test.aad.b2c.selenium.AADB2CSeleniumITHelper.createDefaultProperteis;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
29+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2630
public class AADB2CIT {
2731

2832
private final String JOB_TITLE_A_WORKER = "a worker";
2933
private final String JOB_TITLE_WORKER = "worker";
3034
private AADB2CSeleniumITHelper aadB2CSeleniumITHelper;
3135

32-
@Before
36+
@BeforeAll
3337
public void initAndSignIn() {
3438
aadB2CSeleniumITHelper = new AADB2CSeleniumITHelper(DumbApp.class, createDefaultProperteis());
3539
aadB2CSeleniumITHelper.logIn();
3640
}
3741

42+
@Disabled // TODO (rujche) Fix it.
3843
@Test
3944
public void testSignIn() {
4045
String name = aadB2CSeleniumITHelper.getName();
4146
String userFlowName = aadB2CSeleniumITHelper.getUserFlowName();
42-
Assert.assertNotNull(name);
43-
Assert.assertNotNull(userFlowName);
44-
Assert.assertEquals(AAD_B2C_SIGN_UP_OR_SIGN_IN, userFlowName);
47+
assertNotNull(name);
48+
assertNotNull(userFlowName);
49+
assertEquals(AAD_B2C_SIGN_UP_OR_SIGN_IN, userFlowName);
4550
}
4651

4752
@Test
@@ -53,20 +58,20 @@ public void testProfileEdit() {
5358
String name = aadB2CSeleniumITHelper.getName();
5459
String jobTitle = aadB2CSeleniumITHelper.getJobTitle();
5560
String userFlowName = aadB2CSeleniumITHelper.getUserFlowName();
56-
Assert.assertNotNull(name);
57-
Assert.assertNotNull(jobTitle);
58-
Assert.assertEquals(newJobTitle, jobTitle);
59-
Assert.assertEquals(AAD_B2C_PROFILE_EDIT, userFlowName);
61+
assertNotNull(name);
62+
assertNotNull(jobTitle);
63+
assertEquals(newJobTitle, jobTitle);
64+
assertEquals(AAD_B2C_PROFILE_EDIT, userFlowName);
6065
}
6166

6267
@Test
6368
public void testLogOut() {
6469
aadB2CSeleniumITHelper.logout();
6570
String signInButtonText = aadB2CSeleniumITHelper.getSignInButtonText();
66-
Assert.assertEquals("Sign in", signInButtonText);
71+
assertEquals("Sign in", signInButtonText);
6772
}
6873

69-
@After
74+
@AfterAll
7075
public void destroy() {
7176
aadB2CSeleniumITHelper.destroy();
7277
}

sdk/spring/azure-spring-boot-test-aad-b2c/src/test/java/com/azure/test/aad/b2c/selenium/AADB2CSeleniumITHelper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class AADB2CSeleniumITHelper extends SeleniumITHelper {
2626

2727
private static final Logger LOGGER = LoggerFactory.getLogger(AADB2CSeleniumITHelper.class);
2828

29-
private String userEmail;
30-
private String userPassword;
31-
private boolean isAzureCloudGlobal;
29+
private final String userEmail;
30+
private final String userPassword;
31+
private final boolean isAzureCloudGlobal;
3232

3333
public static Map<String, String> createDefaultProperteis() {
3434
Map<String, String> defaultProperteis = new HashMap<>();
@@ -110,6 +110,10 @@ public String getJobTitle() {
110110
}
111111

112112
public String getName() {
113+
String currentUrl = driver.getCurrentUrl();
114+
LOGGER.info("AADB2CSeleniumITHelper, currenturl = {}", currentUrl);
115+
String pageSource = driver.getPageSource();
116+
LOGGER.info("AADB2CSeleniumITHelper, pageSource = {}", pageSource);
113117
return driver.findElement(By.cssSelector("tbody"))
114118
.findElement(By.xpath("tr[2]"))
115119
.findElement(By.xpath("th[2]"))

sdk/spring/azure-spring-boot-test-aad/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,12 @@
3737
<artifactId>spring-boot-starter-test</artifactId>
3838
<scope>test</scope>
3939
</dependency>
40-
4140
<dependency>
4241
<groupId>com.azure.spring</groupId>
4342
<artifactId>azure-spring-boot-test-selenium-common</artifactId>
4443
<version>1.0.0</version> <!-- {x-version-update;com.azure.spring:azure-spring-boot-test-selenium-common;current} -->
4544
<scope>test</scope>
4645
</dependency>
47-
48-
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
51-
<version>4.13.2</version> <!-- {x-version-update;junit:junit;external_dependency} -->
52-
<scope>test</scope>
53-
</dependency>
5446
</dependencies>
5547

5648
</project>

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/AADSeleniumITHelper.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@
1111
import java.util.HashMap;
1212
import java.util.Map;
1313

14-
import static com.azure.spring.test.EnvironmentVariable.*;
14+
import static com.azure.spring.test.EnvironmentVariable.AAD_SINGLE_TENANT_CLIENT_ID;
15+
import static com.azure.spring.test.EnvironmentVariable.AAD_SINGLE_TENANT_CLIENT_SECRET;
16+
import static com.azure.spring.test.EnvironmentVariable.AAD_TENANT_ID_1;
17+
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_NAME_1;
18+
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_PASSWORD_1;
19+
import static com.azure.spring.test.EnvironmentVariable.AZURE_CLOUD_TYPE;
1520
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
1621

1722
public class AADSeleniumITHelper extends SeleniumITHelper {
1823

1924
private static final Logger LOGGER = LoggerFactory.getLogger(AADSeleniumITHelper.class);
2025

21-
private String username;
22-
private String password;
26+
private final String username;
27+
private final String password;
2328

2429
public static Map<String, String> createDefaultProperties() {
2530
Map<String, String> defaultProperties = new HashMap<>();
@@ -50,7 +55,8 @@ public void logIn() {
5055
try {
5156
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("passwd"))).sendKeys(password + Keys.ENTER);
5257
} catch (Exception exception) {
53-
// Sometimes AAD cannot locate the user account and will ask to select it's a work account or personal account.
58+
// Sometimes AAD cannot locate the user account and will ask to select it's a work account or
59+
// personal account.
5460
// Here select work accout.
5561
// https://docs.microsoft.com/azure/devops/organizations/accounts/faq-azure-access?view=azure-devops#q-why-do-i-have-to-choose-between-a-work-or-school-account-and-my-personal-account
5662
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("aadTileTitle"))).click();
@@ -84,7 +90,7 @@ public String logoutAndGetLogoutUsername() {
8490
String cssSelector = "div[data-test-id='" + username + "']";
8591
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(cssSelector))).click();
8692
String id = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[tabindex='0']")))
87-
.getAttribute("data-test-id");
93+
.getAttribute("data-test-id");
8894
return id;
8995
}
9096

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/conditional/access/AADConditionalAccessIT.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
package com.azure.test.aad.selenium.conditional.access;
55

66
import com.azure.test.aad.selenium.AADSeleniumITHelper;
7-
import org.junit.After;
8-
import org.junit.Assert;
9-
import org.junit.Ignore;
10-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.Disabled;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.TestInstance;
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,35 +27,37 @@
2727

2828
import static com.azure.spring.test.EnvironmentVariable.CONDITIONAL_ACCESS_POLICY_TEST_WEB_API_A_CLIENT_ID;
2929
import static com.azure.test.aad.selenium.AADSeleniumITHelper.createDefaultProperties;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
3031
import static org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction.oauth2AuthorizedClient;
3132

33+
34+
/**
35+
* Before running this test case, follow the <a href="https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-test-aad/README.md#what-is-aad-conditional-access-in-aad">guide</a> to start <a href="https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/aad/webapi/conditional/access/webapi/a/ConditionalAccessPolicyTestWebApiA.java">WebapiA</a> and <a href="https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-test-aad-resource-server/src/test/java/com/azure/test/aad/conditional/access/webapi/b/ConditionalAccessPolicyTestWebApiB.java">webapiB</a>.
36+
*/
37+
@Disabled
38+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
3239
public class AADConditionalAccessIT {
3340

3441
private AADSeleniumITHelper aadSeleniumITHelper;
3542

3643
private static final String WEB_API_A_ENDPOINT = "http://localhost:8882/webapiA";
3744
private static final Logger LOGGER = LoggerFactory.getLogger(AADConditionalAccessIT.class);
3845

39-
/**
40-
* Before running this test case, follow the <a href="https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-test-aad/README.md#what-is-aad-conditional-access-in-aad">guide</a> to start <a href="https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-test-aad-obo/src/test/java/com/azure/test/aad/webapi/conditional/access/webapi/a/ConditionalAccessPolicyTestWebApiA.java">WebapiA</a> and <a href="https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-test-aad-resource-server/src/test/java/com/azure/test/aad/conditional/access/webapi/b/ConditionalAccessPolicyTestWebApiB.java">webapiB</a>.
41-
*/
42-
@Ignore
4346
@Test
4447
public void conditionalAccessTest() {
4548
Map<String, String> properties = createDefaultProperties();
4649
properties.put("azure.activedirectory.authorization-clients.webapiA.scopes",
4750
"api://" + CONDITIONAL_ACCESS_POLICY_TEST_WEB_API_A_CLIENT_ID + "/File.Read");
4851
aadSeleniumITHelper = new AADSeleniumITHelper(DumbApp.class, properties);
4952
String body = aadSeleniumITHelper.loginAndGetBodyText();
50-
Assert.assertEquals("Response from webapiB.", body);
53+
assertEquals("Response from webapiB.", body);
5154
}
5255

53-
@After
56+
@AfterAll
5457
public void destroy() {
5558
aadSeleniumITHelper.destroy();
5659
}
5760

58-
5961
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
6062
@SpringBootApplication
6163
@RestController

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/logout/AADLogoutIT.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33

44
package com.azure.test.aad.selenium.logout;
55

6-
import static com.azure.test.aad.selenium.AADSeleniumITHelper.createDefaultProperties;
7-
86
import com.azure.test.aad.selenium.AADSeleniumITHelper;
9-
import java.security.Principal;
10-
import org.junit.After;
11-
import org.junit.Assert;
12-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.TestInstance;
1310
import org.slf4j.Logger;
1411
import org.slf4j.LoggerFactory;
1512
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -19,6 +16,12 @@
1916
import org.springframework.web.bind.annotation.GetMapping;
2017
import org.springframework.web.bind.annotation.RestController;
2118

19+
import java.security.Principal;
20+
21+
import static com.azure.test.aad.selenium.AADSeleniumITHelper.createDefaultProperties;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
24+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2225
public class AADLogoutIT {
2326

2427
private static final Logger LOGGER = LoggerFactory.getLogger(AADLogoutIT.class);
@@ -30,10 +33,10 @@ public void logoutTest() {
3033
aadSeleniumITHelper.logIn();
3134
String logoutUsername = aadSeleniumITHelper.logoutAndGetLogoutUsername();
3235
String loginUsername = aadSeleniumITHelper.getUsername();
33-
Assert.assertEquals(loginUsername, logoutUsername);
36+
assertEquals(loginUsername, logoutUsername);
3437
}
3538

36-
@After
39+
@AfterAll
3740
public void destroy() {
3841
aadSeleniumITHelper.destroy();
3942
}

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/multitenant/AADMultipleTenantIT.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
package com.azure.test.aad.selenium.multitenant;
55

66
import com.azure.test.aad.selenium.AADSeleniumITHelper;
7-
import org.junit.After;
8-
import org.junit.Assert;
9-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.TestInstance;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
1213
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -19,28 +20,35 @@
1920
import java.security.Principal;
2021
import java.util.Map;
2122

22-
import static com.azure.spring.test.EnvironmentVariable.*;
23+
import static com.azure.spring.test.EnvironmentVariable.AAD_MULTI_TENANT_CLIENT_ID;
24+
import static com.azure.spring.test.EnvironmentVariable.AAD_MULTI_TENANT_CLIENT_SECRET;
25+
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_NAME_2;
26+
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_PASSWORD_2;
2327
import static com.azure.test.aad.selenium.AADSeleniumITHelper.createDefaultProperties;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
2429

30+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2531
public class AADMultipleTenantIT {
2632
private static final Logger LOGGER = LoggerFactory.getLogger(AADMultipleTenantIT.class);
2733
private AADSeleniumITHelper aadSeleniumITHelper;
2834

29-
@Test
30-
public void multipleTenantTest() {
35+
@BeforeAll
36+
public void beforeAll() {
3137
Map<String, String> properties = createDefaultProperties();
3238
properties.put("azure.activedirectory.client-id", AAD_MULTI_TENANT_CLIENT_ID);
3339
properties.put("azure.activedirectory.client-secret", AAD_MULTI_TENANT_CLIENT_SECRET);
34-
35-
aadSeleniumITHelper = new AADSeleniumITHelper(DumbApp.class, properties,
36-
AAD_USER_NAME_2, AAD_USER_PASSWORD_2);
40+
aadSeleniumITHelper = new AADSeleniumITHelper(
41+
DumbApp.class, properties, AAD_USER_NAME_2, AAD_USER_PASSWORD_2);
3742
aadSeleniumITHelper.logIn();
43+
}
3844

45+
@Test
46+
public void multipleTenantTest() {
3947
String httpResponse = aadSeleniumITHelper.httpGet("api/home");
40-
Assert.assertTrue(httpResponse.contains("home"));
48+
assertTrue(httpResponse.contains("home"));
4149
}
4250

43-
@After
51+
@AfterAll
4452
public void destroy() {
4553
aadSeleniumITHelper.destroy();
4654
}

sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/oauth2client/issuedat/AADOauth2AuthorizedClientCachedIT.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import com.azure.spring.utils.AzureCloudUrls;
77
import com.azure.test.aad.selenium.AADSeleniumITHelper;
8-
import org.junit.After;
9-
import org.junit.Assert;
10-
import org.junit.Test;
8+
import org.junit.jupiter.api.AfterAll;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.TestInstance;
1111
import org.springframework.boot.autoconfigure.SpringBootApplication;
1212
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
1313
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
@@ -22,7 +22,9 @@
2222

2323
import static com.azure.spring.test.EnvironmentVariable.AZURE_CLOUD_TYPE;
2424
import static com.azure.test.aad.selenium.AADSeleniumITHelper.createDefaultProperties;
25+
import static org.junit.jupiter.api.Assertions.assertEquals;
2526

27+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2628
public class AADOauth2AuthorizedClientCachedIT {
2729

2830
private AADSeleniumITHelper aadSeleniumITHelper;
@@ -42,20 +44,20 @@ public void testOauth2AuthorizedClientCached() {
4244
aadSeleniumITHelper.logIn();
4345

4446
// If Oauth2AuthorizedClient is cached, the issuedAt value should be equal.
45-
Assert.assertEquals(
47+
assertEquals(
4648
aadSeleniumITHelper.httpGet("accessTokenIssuedAt/azure"),
4749
aadSeleniumITHelper.httpGet("accessTokenIssuedAt/azure"));
4850

49-
Assert.assertEquals(
51+
assertEquals(
5052
aadSeleniumITHelper.httpGet("accessTokenIssuedAt/graph"),
5153
aadSeleniumITHelper.httpGet("accessTokenIssuedAt/graph"));
5254

53-
Assert.assertEquals(
55+
assertEquals(
5456
aadSeleniumITHelper.httpGet("accessTokenIssuedAt/arm"),
5557
aadSeleniumITHelper.httpGet("accessTokenIssuedAt/arm"));
5658
}
5759

58-
@After
60+
@AfterAll
5961
public void destroy() {
6062
aadSeleniumITHelper.destroy();
6163
}

0 commit comments

Comments
 (0)