From 7cfe8176281198b3859e9ef2158e8ed05c08975b Mon Sep 17 00:00:00 2001 From: Chris Rohr <51920+chrisrohr@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:41:36 -0400 Subject: [PATCH] Code review updates --- .../champagne/dao/HostDaoTest.java | 34 +++++++------ .../champagne/util/TestObjects.java | 50 +++++++++++-------- 2 files changed, 48 insertions(+), 36 deletions(-) diff --git a/service/src/test/java/org/kiwiproject/champagne/dao/HostDaoTest.java b/service/src/test/java/org/kiwiproject/champagne/dao/HostDaoTest.java index 4c231235..a009b5bd 100644 --- a/service/src/test/java/org/kiwiproject/champagne/dao/HostDaoTest.java +++ b/service/src/test/java/org/kiwiproject/champagne/dao/HostDaoTest.java @@ -27,7 +27,7 @@ @DisplayName("HostDao") class HostDaoTest { - + @RegisterExtension static final PostgresLiquibaseTestExtension POSTGRES = new PostgresLiquibaseTestExtension("migrations.xml"); @@ -57,16 +57,16 @@ 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); @@ -74,9 +74,9 @@ void shouldInsertHostSuccessfully() { 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); } } @@ -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 @@ -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(); diff --git a/service/src/test/java/org/kiwiproject/champagne/util/TestObjects.java b/service/src/test/java/org/kiwiproject/champagne/util/TestObjects.java index 642818fb..7492258e 100644 --- a/service/src/test/java/org/kiwiproject/champagne/util/TestObjects.java +++ b/service/src/test/java/org/kiwiproject/champagne/util/TestObjects.java @@ -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") @@ -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) @@ -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) @@ -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) @@ -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)