Skip to content

Commit

Permalink
SONAR-15143 - Using ISO8601 for DateTimes
Browse files Browse the repository at this point in the history
  • Loading branch information
belen-pruvost-sonarsource authored and sonartech committed Sep 16, 2021
1 parent d9127ca commit 4a6a0f2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.ObjectUtils;
import org.sonar.api.utils.DateUtils;
import org.sonar.db.user.UserDto;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -162,7 +163,8 @@ public String toString() {
addField(sb, "\"local\": ", ObjectUtils.toString(this.local), false);
addField(sb, "\"onboarded\": ", ObjectUtils.toString(this.onboarded), false);
addField(sb, "\"root\": ", ObjectUtils.toString(this.root), false);
addField(sb, "\"lastConnectionDate\": ", ObjectUtils.toString(this.lastConnectionDate), false);
addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ?
"" : DateUtils.formatDateTime(this.lastConnectionDate), false);
endString(sb);
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.ObjectUtils;
import org.sonar.api.utils.DateUtils;
import org.sonar.db.user.UserDto;
import org.sonar.db.user.UserTokenDto;

Expand Down Expand Up @@ -89,7 +89,8 @@ public String toString() {
addField(sb, "\"userUuid\": ", this.userUuid, true);
addField(sb, "\"userLogin\": ", this.userLogin, true);
addField(sb, "\"tokenName\": ", this.tokenName, true);
addField(sb, "\"lastConnectionDate\": ", ObjectUtils.toString(this.lastConnectionDate), false);
addField(sb, "\"lastConnectionDate\": ", this.lastConnectionDate == null ?
"" : DateUtils.formatDateTime(this.lastConnectionDate), false);
endString(sb);
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.DateUtils;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.audit.AuditPersister;
Expand Down Expand Up @@ -114,7 +115,9 @@ public void updateUserIsPersisted() {
.containsExactly(updatedUser.getUuid(), updatedUser.getLogin(), updatedUser.getName(), updatedUser.getEmail(), updatedUser.isActive(),
updatedUser.getScmAccounts(), updatedUser.getExternalId(), updatedUser.getExternalLogin(), updatedUser.getExternalIdentityProvider(),
updatedUser.isLocal(), updatedUser.isOnboarded(), updatedUser.isRoot(), updatedUser.getLastConnectionDate());
assertThat(newValue.toString()).contains("name");
assertThat(newValue.toString())
.contains("name")
.contains(DateUtils.formatDateTime(updatedUser.getLastConnectionDate()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.ArgumentCaptor;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.UserTokenNewValue;

import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -53,7 +55,8 @@ public class UserTokenDaoWithPersisterTest {

@Test
public void insert_token_is_persisted() {
UserTokenDto userToken = newUserToken();
UserTokenDto userToken = newUserToken()
.setLastConnectionDate(nextLong());
underTest.insert(db.getSession(), userToken, "login");

verify(auditPersister).addUserToken(eq(db.getSession()), newValueCaptor.capture());
Expand All @@ -68,7 +71,9 @@ public void insert_token_is_persisted() {
assertThat(newValue)
.extracting(UserTokenNewValue::getTokenUuid, UserTokenNewValue::getTokenName, UserTokenNewValue::getUserUuid, UserTokenNewValue::getLastConnectionDate)
.containsExactly(userToken.getUuid(), userToken.getName(), userToken.getUserUuid(), userToken.getLastConnectionDate());
assertThat(newValue.toString()).contains("tokenUuid");
assertThat(newValue.toString())
.contains("tokenUuid")
.contains(DateUtils.formatDateTime(userToken.getLastConnectionDate()));
}

@Test
Expand Down

0 comments on commit 4a6a0f2

Please sign in to comment.