getMapper(dbSession).insert(almSettingDto);
if (auditPersister != null) {
- auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(),
- almSettingDto.getKey()));
+ auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto));
}
}
getMapper(dbSession).deleteByKey(almSettingDto.getKey());
if (auditPersister != null) {
- auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(),
- almSettingDto.getKey()));
+ auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSettingDto.getUuid(), almSettingDto.getKey()));
}
}
return uuid;
}
- void setUuid(String uuid) {
+ AlmSettingDto setUuid(String uuid) {
this.uuid = uuid;
+ return this;
}
public String getKey() {
this.auditPersister = auditPersister;
}
- public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto,
- String key, String projectName) {
+ public void insertOrUpdate(DbSession dbSession, ProjectAlmSettingDto projectAlmSettingDto, String key, String projectName) {
String uuid = uuidFactory.create();
long now = system2.now();
ProjectAlmSettingMapper mapper = getMapper(dbSession);
projectAlmSettingDto.setUpdatedAt(now);
if (auditPersister != null) {
+ DevOpsPlatformSettingNewValue value = new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName);
if (isUpdate) {
- auditPersister.updateDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(projectAlmSettingDto, key, projectName));
+ auditPersister.updateDevOpsPlatformSetting(dbSession, value);
} else {
- auditPersister.addDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(projectAlmSettingDto.getAlmSettingUuid(),
- projectAlmSettingDto.getProjectUuid(), key, projectName));
+ auditPersister.addDevOpsPlatformSetting(dbSession, value);
}
}
}
}
public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
- deleteByAlmSetting(dbSession, almSetting, false);
- }
-
- public void deleteByAlmSetting(DbSession dbSession, AlmSettingDto almSetting, boolean track) {
getMapper(dbSession).deleteByAlmSettingUuid(almSetting.getUuid());
-
- if (track && auditPersister != null) {
- auditPersister.deleteDevOpsPlatformSetting(dbSession, new DevOpsPlatformSettingNewValue(almSetting.getUuid(),
- almSetting.getKey()));
- }
}
public int countByAlmSetting(DbSession dbSession, AlmSettingDto almSetting) {
this.isMonorepo = dto.getMonorepo();
}
- public DevOpsPlatformSettingNewValue(String devOpsPlatformSettingUuid, String projectUuid, String key, String projectName) {
- this.devOpsPlatformSettingUuid = devOpsPlatformSettingUuid;
- this.key = key;
- this.projectUuid = projectUuid;
- this.projectName = projectName;
- }
-
public DevOpsPlatformSettingNewValue(ProjectDto projectDto) {
this.projectUuid = projectDto.getUuid();
this.projectName = projectDto.getName();
private String projectName;
public WebhookNewValue(WebhookDto dto, @Nullable String projectName) {
- this.webhookUuid = dto.getUuid();
- this.name = dto.getName();
- this.url = dto.getUrl();
- this.projectUuid = dto.getProjectUuid();
- this.projectName = projectName;
+ this(dto.getUuid(), dto.getName(), dto.getProjectUuid(), projectName, dto.getUrl());
}
public WebhookNewValue(String webhookUuid, String webhookName) {
+
this.webhookUuid = webhookUuid;
this.name = webhookName;
}
- public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectName) {
- this(webhookUuid, webhookName);
+ public WebhookNewValue(String webhookUuid, String webhookName, @Nullable String projectUuid, @Nullable String projectName, @Nullable String url) {
+ this.webhookUuid = webhookUuid;
+ this.name = webhookName;
+ this.url = url;
this.projectUuid = projectUuid;
this.projectName = projectName;
}
mapper(dbSession).insert(dto.setCreatedAt(system2.now()).setUpdatedAt(system2.now()));
if (auditPersister != null) {
- auditPersister.addWebhook(dbSession, new WebhookNewValue(dto.getUuid(), dto.getName(),
- dto.getProjectUuid(), projectName));
+ auditPersister.addWebhook(dbSession, new WebhookNewValue(dto, projectName));
}
}
@Test
public void insertAndUpdateArePersisted() {
when(uuidFactory.create()).thenReturn(A_UUID);
- AlmSettingDto almSettingDto = newGithubAlmSettingDto();
+ AlmSettingDto almSettingDto = newGithubAlmSettingDto()
+ .setKey("key")
+ .setAppId("id1")
+ .setClientId("cid1")
+ .setUrl("url");
underTest.insert(dbSession, almSettingDto);
verify(auditPersister).addDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+ .extracting("devOpsPlatformSettingUuid", "key")
.containsExactly(almSettingDto.getUuid(), almSettingDto.getKey());
- assertThat(newValue.toString()).doesNotContain("url");
+ assertThat(newValue).hasToString("{\"devOpsPlatformSettingUuid\": \"1\", \"key\": \"key\", \"devOpsPlatformName\": \"id1\", \"url\": \"url\", \"appId\": \"id1\", \"clientId\": \"cid1\" }");
almSettingDto.setPrivateKey("updated private key");
almSettingDto.setAppId("updated app id");
almSettingDto.setUrl("updated url");
almSettingDto.setPersonalAccessToken("updated pat");
almSettingDto.setKey("updated key");
- system2.setNow(NOW + 1);
underTest.update(dbSession, almSettingDto);
verify(auditPersister).updateDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey,
- DevOpsPlatformSettingNewValue::getAppId, DevOpsPlatformSettingNewValue::getDevOpsPlatformName,
- DevOpsPlatformSettingNewValue::getUrl, DevOpsPlatformSettingNewValue::getClientId)
- .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey(), almSettingDto.getAppId(), almSettingDto.getAppId(),
- almSettingDto.getUrl(), almSettingDto.getClientId());
+ .extracting("devOpsPlatformSettingUuid", "key","appId", "devOpsPlatformName", "url", "clientId")
+ .containsExactly(almSettingDto.getUuid(), almSettingDto.getKey(), almSettingDto.getAppId(), almSettingDto.getAppId(), almSettingDto.getUrl(), almSettingDto.getClientId());
+ assertThat(newValue).hasToString("{\"devOpsPlatformSettingUuid\": \"1\", \"key\": \"updated key\", \"devOpsPlatformName\": \"updated app id\", "
+ + "\"url\": \"updated url\", \"appId\": \"updated app id\", \"clientId\": \"cid1\" }");
}
@Test
verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
+ .extracting("devOpsPlatformSettingUuid", "key")
.containsExactly(almSettingDto.getUuid(), almSettingDto.getKey());
assertThat(newValue.toString()).doesNotContain("url");
}
}
@Test
- public void deleteByAlmSettingWhenNotTracked() {
+ public void deleteByAlmSettingNotTracked() {
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
underTest.deleteByAlmSetting(dbSession, githubAlmSetting);
verifyNoInteractions(auditPersister);
}
-
- @Test
- public void deleteByAlmSettingWhenTracked() {
- AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
- underTest.deleteByAlmSetting(dbSession, githubAlmSetting, true);
-
- verify(auditPersister).deleteDevOpsPlatformSetting(eq(dbSession), newValueCaptor.capture());
- DevOpsPlatformSettingNewValue newValue = newValueCaptor.getValue();
- assertThat(newValue)
- .extracting(DevOpsPlatformSettingNewValue::getDevOpsPlatformSettingUuid, DevOpsPlatformSettingNewValue::getKey)
- .containsExactly(githubAlmSetting.getUuid(), githubAlmSetting.getKey());
- assertThat(newValue.toString()).doesNotContain("url");
- }
-
}
import static org.mockito.Mockito.verify;
public class WebhookDaoWithPersisterTest {
- private AuditPersister auditPersister = mock(AuditPersister.class);
+ private final AuditPersister auditPersister = mock(AuditPersister.class);
@Rule
public final DbTester dbTester = DbTester.create(System2.INSTANCE, auditPersister);
assertThat(newValue)
.extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName)
.containsExactly(dto.getUuid(), dto.getName());
- assertThat(newValue.toString()).doesNotContain("url");
+ assertThat(newValue).hasToString("{\"webhookUuid\": \"UUID_1\", \"name\": \"NAME_1\", \"url\": \"URL_1\" }");
}
@Test
verify(auditPersister).addWebhook(eq(dbSession), newValueCaptor.capture());
WebhookNewValue newValue = newValueCaptor.getValue();
assertThat(newValue)
- .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getProjectUuid,
- WebhookNewValue::getProjectName)
+ .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectName)
.containsExactly(dto.getUuid(), dto.getName(), dto.getProjectUuid(), "project_name");
- assertThat(newValue.toString()).doesNotContain("url");
+ assertThat(newValue).hasToString("{\"webhookUuid\": \"UUID_1\", \"name\": \"NAME_1\", \"url\": \"URL_1\", \"projectUuid\": \"UUID_2\", \"projectName\": \"project_name\" }");
}
@Test
- public void updateWebhookIsPersisted() {
+ public void updateGlobalWebhookIsPersisted() {
WebhookDto dto = webhookDbTester.insertGlobalWebhook();
dto = dto
.setName("a-fancy-webhook")
assertThat(newValue)
.extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getUrl)
.containsExactly(dto.getUuid(), dto.getName(), dto.getUrl());
- assertThat(newValue.toString()).doesNotContain("projectUuid");
+ assertThat(newValue).hasToString("{\"webhookUuid\": \"" + dto.getUuid() + "\", \"name\": \"a-fancy-webhook\", \"url\": \"http://www.fancy-webhook.io\" }");
+ }
+
+ @Test
+ public void updateProjectWebhookIsPersisted() {
+ WebhookDto dto = webhookDbTester.insertGlobalWebhook();
+ dto = dto
+ .setName("a-fancy-webhook")
+ .setUrl("http://www.fancy-webhook.io")
+ .setSecret(null);
+
+ underTest.update(dbSession, dto, "project");
+
+ verify(auditPersister).updateWebhook(eq(dbSession), newValueCaptor.capture());
+ WebhookNewValue newValue = newValueCaptor.getValue();
+ assertThat(newValue)
+ .extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName, WebhookNewValue::getUrl)
+ .containsExactly(dto.getUuid(), dto.getName(), dto.getUrl());
+ assertThat(newValue).hasToString("{\"webhookUuid\": \"" + dto.getUuid() +"\", \"name\": \"a-fancy-webhook\", \"url\": \"http://www.fancy-webhook.io\", \"projectName\": \"project\" }");
}
@Test
public void deleteProjectWebhooksIsPersisted() {
- ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
+ ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(p -> p.setUuid("puuid").setName("pname"));
webhookDbTester.insertWebhook(projectDto);
underTest.deleteByProject(dbSession, projectDto);
assertThat(newValue)
.extracting(WebhookNewValue::getProjectUuid, WebhookNewValue::getProjectName)
.containsExactly(projectDto.getUuid(), projectDto.getName());
- assertThat(newValue.toString()).doesNotContain("webhookUuid");
+ assertThat(newValue).hasToString("{\"projectUuid\": \"puuid\", \"projectName\": \"pname\" }");
}
@Test
assertThat(newValue)
.extracting(WebhookNewValue::getWebhookUuid, WebhookNewValue::getName)
.containsExactly(dto.getUuid(), dto.getName());
- assertThat(newValue.toString()).doesNotContain("url");
+ assertThat(newValue).hasToString("{\"webhookUuid\": \"" + dto.getUuid() + "\", \"name\": \"" + dto.getName() + "\" }");
}
}