Skip to content

Commit

Permalink
use modularized methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Feb 6, 2024
1 parent d4fd63a commit 618df97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
// Update the <%= entityInstance %> using partial update
<%= persistClass %> partialUpdated<%= persistClass %> = new <%= persistClass %>();
Expand Down Expand Up @@ -58,7 +58,7 @@ rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%=
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%= persistClass %> test<%= entityClass %> = <%= entityInstance %>List.get(<%= entityInstance %>List.size() - 1);
<%_ for (field of fields) { _%>
<%_ if (field.fieldTypeZonedDateTime) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ _%>
.exchange()
.expectStatus()
.isCreated()
.expectBody(<%- persistClass %>.class)
.expectBody(<%- restClass %>.class)
.returnResult()
.getResponseBody();
<%_ } else { _%>
Expand Down Expand Up @@ -854,7 +854,7 @@ _%>

@Test<%= transactionalAnnotation %>
void check<%= field.fieldInJavaBeanMethod %>IsRequired() throws Exception {
int databaseSizeBeforeTest = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeTest = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1425,7 +1425,7 @@ _%>
<%_ } _%>
<%= entityInstance %>Repository.<%= saveMethod %>(<%= persistInstance %>)<%= callBlock %>;

int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
<%= entityInstance %>SearchRepository.save(<%= persistInstance %>)<%= callBlock %>;
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
Expand Down Expand Up @@ -1471,7 +1471,7 @@ _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%= persistClass %> test<%= entityClass %> = <%= entityInstance %>List.get(<%= entityInstance %>List.size() - 1);
<%_ for (const field of fieldsToTest) { _%>
<%_ if (field.fieldTypeZonedDateTime) { _%>
Expand Down Expand Up @@ -1509,7 +1509,7 @@ _%>

@Test<%= transactionalAnnotation %>
void putNonExisting<%= entityClass %>() throws Exception {
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1538,8 +1538,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore);
Expand All @@ -1549,7 +1548,7 @@ _%>

@Test<%= transactionalAnnotation %>
void putWithIdMismatch<%= entityClass %>() throws Exception {
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1578,8 +1577,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore);
Expand All @@ -1588,7 +1586,7 @@ _%>

@Test<%= transactionalAnnotation %>
void putWithMissingIdPathParam<%= entityClass %>() throws Exception {
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1617,8 +1615,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore);
Expand Down Expand Up @@ -1664,7 +1661,7 @@ _%>

@Test<%= transactionalAnnotation %>
void patchNonExisting<%= entityClass %>() throws Exception {
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1693,8 +1690,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore);
Expand All @@ -1703,7 +1699,7 @@ _%>

@Test<%= transactionalAnnotation %>
void patchWithIdMismatch<%= entityClass %>() throws Exception {
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1732,8 +1728,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore);
Expand All @@ -1742,7 +1737,7 @@ _%>

@Test<%= transactionalAnnotation %>
void patchWithMissingIdPathParam<%= entityClass %>() throws Exception {
int databaseSizeBeforeUpdate = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeUpdate = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
<%_ } _%>
Expand Down Expand Up @@ -1771,8 +1766,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeUpdate);
assertSameRepositoryCount(databaseSizeBeforeUpdate);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore);
Expand All @@ -1796,7 +1790,7 @@ _%>
<%= entityInstance %>SearchRepository.save(<%= persistInstance %>)<%= callBlock %>;
<%_ } _%>

int databaseSizeBeforeDelete = <%= entityInstance %>Repository.findAll()<%= callListBlock %>.size();
long databaseSizeBeforeDelete = getRepositoryCount();
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeBefore = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeBefore).isEqualTo(databaseSizeBeforeDelete);
Expand All @@ -1818,8 +1812,7 @@ _%>
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
List<<%= persistClass %>> <%= entityInstance %>List = <%= entityInstance %>Repository.findAll()<%= callListBlock %>;
assertThat(<%= entityInstance %>List).hasSize(databaseSizeBeforeDelete - 1);
assertDecrementedRepositoryCount(databaseSizeBeforeDelete);
<%_ if (searchEngineElasticsearch) { _%>
int searchDatabaseSizeAfter = IterableUtil.sizeOf(<%= entityInstance %>SearchRepository.findAll()<%= callListBlock %>);
assertThat(searchDatabaseSizeAfter).isEqualTo(searchDatabaseSizeBefore-1);
Expand Down Expand Up @@ -1889,6 +1882,10 @@ _%>
assertThat(countBefore + 1).isEqualTo(getRepositoryCount());
}

protected void assertDecrementedRepositoryCount(long countBefore) {
assertThat(countBefore - 1).isEqualTo(getRepositoryCount());
}

protected void assertSameRepositoryCount(long countBefore) {
assertThat(countBefore).isEqualTo(getRepositoryCount());
}
Expand Down

0 comments on commit 618df97

Please sign in to comment.