Skip to content

Commit

Permalink
Code review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrohr committed Jul 31, 2023
1 parent f51c358 commit 7cfe817
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

@DisplayName("HostDao")
class HostDaoTest {

@RegisterExtension
static final PostgresLiquibaseTestExtension POSTGRES = new PostgresLiquibaseTestExtension("migrations.xml");

Expand Down Expand Up @@ -57,26 +57,26 @@ void shouldInsertHostSuccessfully() {
var beforeInsert = ZonedDateTime.now();

var hostToInsert = Host.builder()
.environmentId(envId)
.hostname("localhost")
.source(Host.Source.CHAMPAGNE)
.build();
.environmentId(envId)
.hostname("localhost")
.source(Host.Source.CHAMPAGNE)
.build();

var id = dao.insertHost(hostToInsert);

var host = handle.select("select * from hosts where id = ?", id)
.map(new HostMapper())
.first();
.map(new HostMapper())
.first();

assertThat(host.getId()).isEqualTo(id);

assertTimeDifferenceWithinTolerance("createdAt", beforeInsert, host.getCreatedAt().atZone(ZoneOffset.UTC), 1000L);
assertTimeDifferenceWithinTolerance("updatedAt", beforeInsert, host.getUpdatedAt().atZone(ZoneOffset.UTC), 1000L);

assertThat(host)
.usingRecursiveComparison()
.ignoringFields("id", "createdAt", "updatedAt")
.isEqualTo(hostToInsert);
.usingRecursiveComparison()
.ignoringFields("id", "createdAt", "updatedAt")
.isEqualTo(hostToInsert);
}
}

Expand All @@ -91,8 +91,8 @@ void shouldReturnListOfHosts() {

var hosts = dao.findHostsByEnvId(envId, systemId);
assertThat(hosts)
.extracting("id", "hostname", "environmentId")
.contains(tuple(hostId, "localhost", envId));
.extracting("id", "hostname", "environmentId")
.contains(tuple(hostId, "localhost", envId));
}

@Test
Expand Down Expand Up @@ -176,10 +176,12 @@ void shouldRemoveAllTagsIfNoneGiven() {
var hostId = insertHostRecord(handle, "localhost", envId, systemId);
var tagId = insertTagRecord(handle, "core", systemId);

handle.createUpdate("insert into host_tags "
+ "(host_id, tag_id) "
+ "values "
+ "(:hostId, :tagId)")
handle.createUpdate("""
insert into host_tags
(host_id, tag_id)
values
(:hostId, :tagId)
""")
.bind("hostId", hostId)
.bind("tagId", tagId)
.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ public static long insertBuildRecord(Handle handle, String identifier, String ve
.deployableSystemId(systemId)
.build();

return handle.createUpdate("insert into builds "
+ "(repo_namespace, repo_name, commit_ref, commit_user, source_branch, component_identifier, component_version, distribution_location, extra_deployment_info, git_provider, deployable_system_id) "
+ "values "
+ "(:repoNamespace, :repoName, :commitRef, :commitUser, :sourceBranch, :componentIdentifier, :componentVersion, :distributionLocation, :extraData, :gitProvider, :deployableSystemId)")
return handle.createUpdate("""
insert into builds
(repo_namespace, repo_name, commit_ref, commit_user, source_branch, component_identifier, component_version, distribution_location, extra_deployment_info, git_provider, deployable_system_id)
values
(:repoNamespace, :repoName, :commitRef, :commitUser, :sourceBranch, :componentIdentifier, :componentVersion, :distributionLocation, :extraData, :gitProvider, :deployableSystemId)
""")
.bindBean(buildToInsert)
.bind("extraData", "{}")
.executeAndReturnGeneratedKeys("id")
Expand All @@ -178,10 +180,12 @@ public static long insertHostRecord(Handle handle, String hostname, long envId,
.deployableSystemId(systemId)
.build();

return handle.createUpdate("insert into hosts "
+ "(environment_id, hostname, source, deployable_system_id) "
+ "values "
+ "(:environmentId, :hostname, :source, :deployableSystemId)")
return handle.createUpdate("""
insert into hosts
(environment_id, hostname, source, deployable_system_id)
values
(:environmentId, :hostname, :source, :deployableSystemId)
""")
.bindBean(hostToInsert)
.executeAndReturnGeneratedKeys("id")
.mapTo(Long.class)
Expand All @@ -195,10 +199,12 @@ public static long insertComponentRecord(Handle handle, String componentName, Lo
.deployableSystemId(deployableSystemId)
.build();

return handle.createUpdate("insert into components "
+ "(component_name, tag_id, deployable_system_id) "
+ "values "
+ "(:componentName, :tagId, :deployableSystemId)")
return handle.createUpdate("""
insert into components
(component_name, tag_id, deployable_system_id)
values
(:componentName, :tagId, :deployableSystemId)
""")
.bindBean(componentToInsert)
.executeAndReturnGeneratedKeys("id")
.mapTo(Long.class)
Expand All @@ -211,10 +217,12 @@ public static long insertTagRecord(Handle handle, String name, Long deployableSy
.deployableSystemId(deployableSystemId)
.build();

return handle.createUpdate("insert into tags "
+ "(name, deployable_system_id) "
+ "values "
+ "(:name, :deployableSystemId)")
return handle.createUpdate("""
insert into tags
(name, deployable_system_id)
values
(:name, :deployableSystemId)
""")
.bindBean(tagToInsert)
.executeAndReturnGeneratedKeys("id")
.mapTo(Long.class)
Expand All @@ -226,10 +234,12 @@ public static long insertDeployableSystem(Handle handle, String name) {
.name(name)
.build();

return handle.createUpdate("insert into deployable_systems "
+ "(name) "
+ "values "
+ "(:name)")
return handle.createUpdate("""
insert into deployable_systems
(name)
values
(:name)
""")
.bindBean(deployableSystemToInsert)
.executeAndReturnGeneratedKeys("id")
.mapTo(Long.class)
Expand Down

0 comments on commit 7cfe817

Please sign in to comment.