<%#
 Copyright 2013-2024 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.
-%>
package <%= entityAbsolutePackage %>.domain;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.assertj.core.api.Assertions.assertThat;

<%_ if (anyFieldIsBigDecimal) { _%>
import static <%- packageName %>.domain.AssertUtils.bigDecimalCompareTo;
<%_ } _%>
<%_ if (anyFieldIsZonedDateTime) { _%>
import static <%- packageName %>.domain.AssertUtils.zonedDataTimeSameInstant;
<%_ } _%>

public class <%= persistClass %>Asserts {

    /**
     * Asserts that the entity has all properties (fields/relationships) set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assert<%- persistClass %>AllPropertiesEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
        assert<%- persistClass %>AutoGeneratedPropertiesEquals(expected, actual);
        assert<%- persistClass %>AllUpdatablePropertiesEquals(expected, actual);
    }

    /**
     * Asserts that the entity has all updatable properties (fields/relationships) set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assert<%- persistClass %>AllUpdatablePropertiesEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
        assert<%- persistClass %>UpdatableFieldsEquals(expected, actual);
        assert<%- persistClass %>UpdatableRelationshipsEquals(expected, actual);
    }
<%_ if (!embedded && primaryKey.derived) { _%>

    /**
     * Asserts that the derived primary key is set correctly.
     *
     * @param entityToPersist the entity used to persist
     * @param persisted the persisted entity
     */
    public static void assert<%- persistClass %>MapsIdRelationshipPersistedValue(<%- persistClass %> entityToPersist, <%- persistClass %> persisted) {
        // Validate the id for MapsId, the ids must be same
        assertThat(entityToPersist.get<%= primaryKey.relationships[0].propertyJavaBeanName %>().get<%= primaryKey.nameCapitalized %>()).isEqualTo(persisted.get<%= primaryKey.nameCapitalized %>());
    }
<%_ } _%>

    /**
     * Asserts that the entity has all the auto generated properties (fields/relationships) set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assert<%- persistClass %>AutoGeneratedPropertiesEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
<%_ if (fields.some(field => !field.transient && field.autoGenerate)) { _%>
        assertThat(expected)
            .as("Verify <%- persistClass %> auto generated properties")
  <%_ for (const field of fields.filter(field => !field.transient && field.autoGenerate)) { _%>
            .satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
  <%_ } _%>
  <%_ for (const relationship of relationships.filter(relationship => (!embedded || relationship.otherEntity.embedded) && relationship.autoGenerate && !relationship.otherEntity.builtInUser)) { _%>
            .satisfies(e -> assertThat(e.get<%- relationship.propertyJavaBeanName %>()).as("check <%- relationship.propertyName %>").isEqualTo(actual.get<%- relationship.propertyJavaBeanName %>()))
  <%_ } _%>
        ;
<%_ } _%>
    }

    /**
     * Asserts that the entity has all the updatable fields set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assert<%- persistClass %>UpdatableFieldsEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
<%_ if (fields.some(field => !field.transient && !field.autoGenerate)) { _%>
        assertThat(expected)
            .as("Verify <%- persistClass %> relevant properties")
  <%_ for (const field of fields.filter(field => !field.transient && !field.autoGenerate)) { _%>
    <%_ if (field.fieldTypeZonedDateTime) { _%>
            .satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").usingComparator(zonedDataTimeSameInstant).isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
    <%_ } else if (field.fieldTypeBigDecimal) { _%>
            .satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").usingComparator(bigDecimalCompareTo).isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
    <%_ } else { _%>
            .satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>()).as("check <%- field.propertyName %>").isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>()))
      <%_ if (field.fieldTypeBinary && !field.blobContentTypeText) { _%>
            .satisfies(e -> assertThat(e.get<%- field.fieldInJavaBeanMethod %>ContentType()).as("check <%- field.propertyName %> contenty type").isEqualTo(actual.get<%- field.fieldInJavaBeanMethod %>ContentType()))
      <%_ } -%>
    <%_ } -%>
  <%_ } -%>
        ;
<%_ } _%>
    }

    /**
     * Asserts that the entity has all the updatable relationships set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assert<%- persistClass %>UpdatableRelationshipsEquals(<%- persistClass %> expected, <%- persistClass %> actual) {
<%_ if (relationships.some(relationship => relationship.persistableRelationship && !(!relationship.ownerSide && (relationship.options?.source?.annotationOnSource?.includes('relateByIdEntity') || relationship.options?.source?.annotationOnSource?.includes('unidirectional'))) && !relationship.id && !relationship.autoGenerate && !relationship.otherEntity.builtInUser)) { _%>
        assertThat(expected)
            .as("Verify <%- persistClass %> relationships")
  <%_ for (const relationship of relationships
          .filter(relationship => !(relationship.relationshipRightSide && relationship.options?.source?.annotationOnSource?.includes('relateByIdEntity')))
          .filter(relationship => !(relationship.relationshipRightSide && relationship.options?.source?.annotationOnSource?.includes('unidirectional')))
          .filter(relationship => (!embedded || relationship.otherEntity.embedded) && relationship.persistableRelationship && !relationship.id && !relationship.autoGenerate && !relationship.otherEntity.builtInUser)) { _%>
            .satisfies(e -> assertThat(e.get<%- relationship.propertyJavaBeanName %>()).as("check <%- relationship.propertyName %>").isEqualTo(actual.get<%- relationship.propertyJavaBeanName %>()))
  <%_ } _%>
        ;
<%_ } _%>
    }
}
