<%#
 Copyright 2013-2025 the original author or authors from the JHipster project.

 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
long databaseSizeBeforeUpdate = getRepositoryCount();

// Update the <%= entityInstance %> using partial update
<%= persistClass %> partialUpdated<%= persistClass %> = new <%= persistClass %>();
partialUpdated<%= persistClass %>.set<%= primaryKey.nameCapitalized %>(<%= persistInstance %>.get<%= primaryKey.nameCapitalized %>());
<%_ fieldsToUpdate = fields.filter(field => field.includeField) %>
<%_ if (fluentMethods && fieldsToUpdate.length > 0) { _%>
    partialUpdated<%= persistClass %><% for (field of fieldsToUpdate) { %>
        .<%= field.fieldName %>(<%= 'UPDATED_' + field.fieldNameUnderscored.toUpperCase() %>)<% if (field.fieldWithContentType && (!field.options || !field.options.customWrapType)) { %>
            .<%= field.fieldName %>ContentType(<%= 'UPDATED_' + field.fieldNameUnderscored.toUpperCase() %>_CONTENT_TYPE)<% } %><% } %>;
<%_ } else { _%>
  <%_ for (field of fieldsToUpdate) { _%>
    <%_ if (field.includeField) { %>
    partialUpdated<%= persistClass %>.set<%= field.fieldInJavaBeanMethod %>(<%= field.updateWithValue %>);
      <%_ if (field.fieldWithContentType) { _%>
        partialUpdated<%= persistClass %>.set<%= field.fieldInJavaBeanMethod %>ContentType(<%= field.updateWithValue %>_CONTENT_TYPE);
      <%_ } _%>
    <%_ } _%>
  <%_ } _%>
<%_ } _%>

<%_ if (reactive) { _%>
webTestClient
.patch()
.uri(ENTITY_API_URL_ID, partialUpdated<%= persistClass %>.get<%= primaryKey.nameCapitalized %>())
.contentType(MediaType.valueOf("application/merge-patch+json"))
.bodyValue(om.writeValueAsBytes(<%= 'partialUpdated' + persistClass %>))
.exchange()
.expectStatus()
.isOk();
<%_ } else { _%>
rest<%= entityClass %>MockMvc.perform(patch(ENTITY_API_URL_ID, partialUpdated<%= persistClass %>.get<%= primaryKey.nameCapitalized %>())<% if (authenticationUsesCsrf) { %>.with(csrf())<% }%>
.contentType("application/merge-patch+json")
.content(om.writeValueAsBytes(<%= 'partialUpdated' + persistClass %>)))
.andExpect(status().isOk());
<%_ } _%>

// Validate the <%= entityClass %> in the database
<%_ if (databaseTypeCouchbase) { _%>
SecurityContextHolder.setContext(TestSecurityContextHolder.getContext());
<%_ } _%>
