Skip to content

Commit ac00e21

Browse files
committed
account/activate: unbreak activation with empty name.
Broken since 00abf94 commit where I allow transformation from empty string to null for field with name. NOTE: I removed @CacheLookup annotation for body element to prevent StaleElementReferenceException when we moved from current page and trying to get text at another page.
1 parent eb28ade commit ac00e21

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

src/env/test/WEB-INF/classes/spring/test-credentials.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ invalid_user_password = test
1717

1818
# this user should be just registered but not activated
1919
not_activated_user_act_key = 7777744444
20+
not_activated_user2_act_key = 4444477777
2021

2122
# this country should always exist
2223
valid_country_name = Italy

src/env/test/WEB-INF/classes/test-data.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ VALUES(
1919
NOW()
2020
);
2121

22+
INSERT INTO users_activation(act_key, email, created_at)
23+
VALUES(
24+
'@not_activated_user2_act_key@',
25+
'test2@example.org',
26+
NOW()
27+
);
28+
2229
INSERT INTO countries(name, created_at)
2330
VALUES(
2431
'@valid_country_name@',

src/main/java/ru/mystamps/web/service/UserService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.transaction.annotation.Transactional;
3434

3535
import static com.google.common.base.Preconditions.checkArgument;
36+
import static com.google.common.base.Strings.isNullOrEmpty;
3637

3738
import ru.mystamps.web.entity.User;
3839
import ru.mystamps.web.entity.UsersActivation;
@@ -77,12 +78,11 @@ public void registerUser(final String login, final String password,
7778

7879
checkArgument(login != null, "Login should be non null");
7980
checkArgument(password != null, "Password should be non null");
80-
checkArgument(name != null, "Name should be non null");
8181
checkArgument(activationKey != null, "Activation key should be non null");
8282

8383
// use login as name if name is not provided
8484
final String finalName;
85-
if ("".equals(name)) {
85+
if (isNullOrEmpty(name)) {
8686
finalName = login;
8787
} else {
8888
finalName = name;

src/test/java/ru/mystamps/web/service/UserServiceTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ public void registerUserShouldDoNothingWhenRegistrationRequestNotFound() {
200200
verify(usersActivationDao, never()).delete(any(UsersActivation.class));
201201
}
202202

203-
@Test(expectedExceptions = IllegalArgumentException.class)
204-
public void registerUserShouldThrowExceptionWhenNameIsNull() {
205-
service.registerUser(TEST_LOGIN, TEST_PASSWORD, null, TEST_ACTIVATION_KEY);
206-
}
207-
208203
@Test
209204
public void registerUserShouldPassNameToDao() {
210205
when(usersActivationDao.findByActivationKey(anyString())).thenReturn(getUsersActivation());
@@ -216,6 +211,17 @@ public void registerUserShouldPassNameToDao() {
216211
assertThat(userCaptor.getValue().getName()).isEqualTo(TEST_NAME);
217212
}
218213

214+
@Test
215+
public void registerUserShouldPassLoginInsteadOfNameWhenNameIsNull() {
216+
when(usersActivationDao.findByActivationKey(anyString())).thenReturn(getUsersActivation());
217+
218+
service.registerUser(TEST_LOGIN, TEST_PASSWORD, null, TEST_ACTIVATION_KEY);
219+
220+
verify(userDao).save(userCaptor.capture());
221+
222+
assertThat(userCaptor.getValue().getName()).isEqualTo(TEST_LOGIN);
223+
}
224+
219225
@Test
220226
public void registerUserShouldPassLoginInsteadOfNameWhenNameIsEmpty() {
221227
when(usersActivationDao.findByActivationKey(anyString())).thenReturn(getUsersActivation());

src/test/java/ru/mystamps/web/tests/cases/WhenUserActivateAccount.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class WhenUserActivateAccount extends WhenUserAtAnyPageWithForm<ActivateA
5151
@Value("#{test.not_activated_user_act_key}")
5252
private String notActivatedUserActKey;
5353

54+
@Value("#{test.not_activated_user2_act_key}")
55+
private String secondNotActivatedUserActKey;
56+
5457
public WhenUserActivateAccount() {
5558
super(ActivateAccountPage.class);
5659
hasTitle(tr("t_activation_title"));
@@ -293,6 +296,23 @@ public void afterActivationShouldExistsMessageWithLinkForAuthentication() {
293296
.isTrue();
294297
}
295298

299+
@Test(groups = "logic", dependsOnGroups = {
300+
"std", "invalid", "valid", "misc"
301+
})
302+
public void activationShouldPassWhenUserProvidedEmptyName() {
303+
page.activateAccount(
304+
"2nd-test-login",
305+
"",
306+
"test-password",
307+
"test-password",
308+
secondNotActivatedUserActKey
309+
);
310+
311+
assertThat(page.getCurrentUrl()).isEqualTo(SUCCESSFUL_ACTIVATION_PAGE_URL);
312+
313+
assertThat(page.textPresent(stripHtmlTags(tr("t_activation_successful")))).isTrue();
314+
}
315+
296316
@DataProvider(name = "validNames")
297317
public Object[][] getValidNames() {
298318
return new Object[][] {

src/test/java/ru/mystamps/web/tests/page/AbstractPage.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.openqa.selenium.NoSuchElementException;
2828
import org.openqa.selenium.WebDriver;
2929
import org.openqa.selenium.WebElement;
30-
import org.openqa.selenium.support.CacheLookup;
3130
import org.openqa.selenium.support.FindBy;
3231

3332
import static com.google.common.base.Preconditions.checkArgument;
@@ -49,7 +48,6 @@ public abstract class AbstractPage {
4948
private final String pageUrl;
5049

5150
@FindBy(tagName = "body")
52-
@CacheLookup
5351
private WebElement body;
5452

5553
public void open() {

0 commit comments

Comments
 (0)