// Path: src/test/java/org/fuin/ddd4j/test/VendorId.java
// @Immutable
// @XmlJavaTypeAdapter(VendorIdConverter.class)
// public final class VendorId extends AbstractUuidValueObject implements AggregateRootId, ValueObjectWithBaseType<UUID> {
// 
//     private static final long serialVersionUID = 1000L;
// 
//     /** Type of entity this identifier represents. */
//     public static final EntityType ENTITY_TYPE = new StringBasedEntityType("Vendor");
// 
//     private final UUID uuid;
// 
//     /**
//      * Default constructor.
//      */
//     public VendorId() {
//         super();
//         uuid = UUID.randomUUID();
//     }
// 
//     /**
//      * Constructor with UUID.
//      * 
//      * @param uuid
//      *            UUID.
//      */
//     public VendorId(@NotNull final UUID uuid) {
//         super();
//         Contract.requireArgNotNull("uuid", uuid);
//         this.uuid = uuid;
//     }
// 
//     @Override
//     public final UUID asBaseType() {
//         return uuid;
//     }
// 
//     @Override
//     public final EntityType getType() {
//         return ENTITY_TYPE;
//     }
// 
//     @Override
//     public final String asTypedString() {
//         return getType() + " " + asString();
//     }
// 
//     @Override
//     public final String asString() {
//         return uuid.toString();
//     }
// 
//     @Override
//     public final String toString() {
//         return uuid.toString();
//     }
// 
// }


import org.fuin.ddd4j.test.VendorId;
import org.junit.Test;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import static org.assertj.core.api.Assertions.assertThat;
import static org.fuin.utils4j.JaxbUtils.marshal;
import static org.fuin.utils4j.JaxbUtils.unmarshal;
import static org.fuin.utils4j.Utils4J.deserialize;
import static org.fuin.utils4j.Utils4J.serialize;
import java.util.UUID;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import org.eclipse.yasson.FieldAccessStrategy;
                        + "<msg>Expected version 47 for Vendor (4dcf4c2c-10e1-4db9-ba9e-d1e644e9d119), but was 102</msg>"
                        + "<sid>DDD4J-AGGREGATE_VERSION_CONFLICT</sid>" + "<aggregate-type>Vendor</aggregate-type>"
                        + "<aggregate-id>4dcf4c2c-10e1-4db9-ba9e-d1e644e9d119</aggregate-id>" + "<expected>47</expected>"
                        + "<actual>102</actual>" + "</aggregate-version-conflict-exception>")
                .withTest(xml).ignoreWhitespace().build();

        assertThat(documentDiff.hasDifferences()).describedAs(documentDiff.toString()).isFalse();

        // TEST
        final AggregateVersionConflictException.Data data = unmarshal(xml, AggregateVersionConflictException.Data.class);
        final AggregateVersionConflictException copy = data.toException();

        // VERIFY
        assertThat(copy.getShortId()).isEqualTo(original.getShortId());
        assertThat(copy.getAggregateType()).isEqualTo(original.getAggregateType());
        assertThat(copy.getAggregateId()).isEqualTo(original.getAggregateId());
        assertThat(copy.getMessage()).isEqualTo(original.getMessage());
        assertThat(copy.getExpected()).isEqualTo(original.getExpected());
        assertThat(copy.getActual()).isEqualTo(original.getActual());

    }

    @Test
    public final void testMarshalUnmarshalJSON() throws Exception {

        // PREPARE
        final AggregateVersionConflictException original = new AggregateVersionConflictException(VendorId.ENTITY_TYPE,
                new VendorId(UUID.fromString("4dcf4c2c-10e1-4db9-ba9e-d1e644e9d119")), 47, 102);

        // TEST
// Path: src/test/java/org/fuin/ddd4j/test/VendorId.java
// @Immutable
// @XmlJavaTypeAdapter(VendorIdConverter.class)
// public final class VendorId extends AbstractUuidValueObject implements AggregateRootId, ValueObjectWithBaseType<UUID> {
// 
//     private static final long serialVersionUID = 1000L;
// 
//     /** Type of entity this identifier represents. */
//     public static final EntityType ENTITY_TYPE = new StringBasedEntityType("Vendor");
// 
//     private final UUID uuid;
// 
//     /**
//      * Default constructor.
//      */
//     public VendorId() {
//         super();
//         uuid = UUID.randomUUID();
//     }
// 
//     /**
//      * Constructor with UUID.
//      * 
//      * @param uuid
//      *            UUID.
//      */
//     public VendorId(@NotNull final UUID uuid) {
//         super();
//         Contract.requireArgNotNull("uuid", uuid);
//         this.uuid = uuid;
//     }
// 
//     @Override
//     public final UUID asBaseType() {
//         return uuid;
//     }
// 
//     @Override
//     public final EntityType getType() {
//         return ENTITY_TYPE;
//     }
// 
//     @Override
//     public final String asTypedString() {
//         return getType() + " " + asString();
//     }
// 
//     @Override
//     public final String asString() {
//         return uuid.toString();
//     }
// 
//     @Override
//     public final String toString() {
//         return uuid.toString();
//     }
// 
// }


// Path: src/test/java/org/fuin/ddd4j/ddd/AggregateVersionConflictExceptionTest.java
import org.fuin.ddd4j.test.VendorId;
import org.junit.Test;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import static org.assertj.core.api.Assertions.assertThat;
import static org.fuin.utils4j.JaxbUtils.marshal;
import static org.fuin.utils4j.JaxbUtils.unmarshal;
import static org.fuin.utils4j.Utils4J.deserialize;
import static org.fuin.utils4j.Utils4J.serialize;
import java.util.UUID;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import org.eclipse.yasson.FieldAccessStrategy;

                        + "<msg>Expected version 47 for Vendor (4dcf4c2c-10e1-4db9-ba9e-d1e644e9d119), but was 102</msg>"
                        + "<sid>DDD4J-AGGREGATE_VERSION_CONFLICT</sid>" + "<aggregate-type>Vendor</aggregate-type>"
                        + "<aggregate-id>4dcf4c2c-10e1-4db9-ba9e-d1e644e9d119</aggregate-id>" + "<expected>47</expected>"
                        + "<actual>102</actual>" + "</aggregate-version-conflict-exception>")
                .withTest(xml).ignoreWhitespace().build();

        assertThat(documentDiff.hasDifferences()).describedAs(documentDiff.toString()).isFalse();

        // TEST
        final AggregateVersionConflictException.Data data = unmarshal(xml, AggregateVersionConflictException.Data.class);
        final AggregateVersionConflictException copy = data.toException();

        // VERIFY
        assertThat(copy.getShortId()).isEqualTo(original.getShortId());
        assertThat(copy.getAggregateType()).isEqualTo(original.getAggregateType());
        assertThat(copy.getAggregateId()).isEqualTo(original.getAggregateId());
        assertThat(copy.getMessage()).isEqualTo(original.getMessage());
        assertThat(copy.getExpected()).isEqualTo(original.getExpected());
        assertThat(copy.getActual()).isEqualTo(original.getActual());

    }

    @Test
    public final void testMarshalUnmarshalJSON() throws Exception {

        // PREPARE
        final AggregateVersionConflictException original = new AggregateVersionConflictException(VendorId.ENTITY_TYPE,
                new VendorId(UUID.fromString("4dcf4c2c-10e1-4db9-ba9e-d1e644e9d119")), 47, 102);

        // TEST
        final String json = jsonb().toJson(original.getData());