/*
 * Copyright (c) 2010-2018. Axon Framework
 *
 * 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
 *
 *    http://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 org.axonframework.eventsourcing.eventstore.jpa;

import org.axonframework.eventhandling.DomainEventMessage;
import org.axonframework.eventhandling.GenericDomainEventMessage;
import org.axonframework.messaging.MetaData;
import org.axonframework.serialization.Serializer;
import org.axonframework.serialization.xml.XStreamSerializer;
import org.junit.jupiter.api.*;

import java.time.Instant;
import java.util.Collections;

import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.*;

/**
 * @author Allard Buijze
 */
class DomainEventEntryTest {

    @Test
    void testDomainEventEntry_WrapEventsCorrectly() {
        Serializer serializer = XStreamSerializer.builder().build();

        String payload = "Payload";
        MetaData metaData = new MetaData(Collections.singletonMap("Key", "Value"));
        DomainEventMessage<String> event = new GenericDomainEventMessage<>("type", randomUUID().toString(), 2L, payload,
                                                                           metaData, randomUUID().toString(),
                                                                           Instant.now());

        DomainEventEntry eventEntry = new DomainEventEntry(event, serializer);

        assertEquals(event.getAggregateIdentifier(), eventEntry.getAggregateIdentifier());
        assertEquals(event.getSequenceNumber(), eventEntry.getSequenceNumber());
        assertEquals(event.getTimestamp(), eventEntry.getTimestamp());
        assertEquals(payload, serializer.deserialize(eventEntry.getPayload()));
        assertEquals(metaData, serializer.deserialize(eventEntry.getMetaData()));
        assertEquals(byte[].class, eventEntry.getPayload().getContentType());
    }
}

@@ -24,10 +24,10 @@
 0-20
+2
 1
-8
 . Ax
@@ -658,16 +658,63 @@
 e.jpa;%0A%0A
+import org.axonframework.common.DateTimeUtils;%0A
 import o
@@ -822,32 +822,93 @@
 inEventMessage;%0A
+import org.axonframework.eventsourcing.utils.TestSerializer;%0A
 import org.axonf
@@ -991,70 +991,8 @@
 er;%0A
-import org.axonframework.serialization.xml.XStreamSerializer;%0A
 impo
@@ -1173,16 +1173,74 @@
 *;%0A%0A/**%0A
+ * Test class validating the %7B@link DomainEventEntry%7D.%0A *%0A
  * @auth
@@ -1290,16 +1290,101 @@
 Test %7B%0A%0A
+    private final Serializer serializer = TestSerializer.secureXStreamSerializer();%0A%0A
     @Tes
@@ -1418,9 +1418,8 @@
 ntry
-_
 Wrap
@@ -1450,69 +1450,189 @@
     
-Serializer serializer = XStreamSerializer.builder().build();%0A
+Instant testTimestamp = Instant.now();%0A%0A        String expectedType = %22type%22;%0A        String expectedAggregateId = randomUUID().toString();%0A        long expectedSequenceNumber = 2L;
 %0A   
@@ -1643,17 +1643,25 @@
  String 
-p
+expectedP
 ayload =
@@ -1689,17 +1689,25 @@
 etaData 
-m
+expectedM
 etaData 
@@ -1776,205 +1776,148 @@
     
-DomainEventMessage%3CString%3E event = new GenericDomainEventMessage%3C%3E(%22type%22, randomUUID().toString(), 2L, payload,%0A                                                                           metaData,
+Instant expectedTimestamp = DateTimeUtils.parseInstant(DateTimeUtils.formatInstant(testTimestamp));%0A        String expectedEventIdentifier =
  ran
@@ -1936,17 +1936,18 @@
 String()
-,
+;%0A
 %0A       
@@ -1951,88 +1951,253 @@
     
-                                                                   Instant.now()
+DomainEventMessage%3CString%3E testEvent = new GenericDomainEventMessage%3C%3E(%0A                expectedType, expectedAggregateId, expectedSequenceNumber, expectedPayload, expectedMetaData,%0A                expectedEventIdentifier, testTimestamp%0A        
 );%0A%0A
@@ -2221,26 +2221,22 @@
 ntEntry 
-eventEntry
+result
  = new D
@@ -2251,17 +2251,21 @@
 ntEntry(
-e
+testE
 vent, se
@@ -2302,49 +2302,88 @@
 ls(e
-vent.getAggregateIdentifier(), eventEntry
+xpectedType, result.getType());%0A        assertEquals(expectedAggregateId, result
 .get
@@ -2428,24 +2428,23 @@
 Equals(e
-vent.get
+xpected
 Sequence
@@ -2449,30 +2449,24 @@
 ceNumber
-(), eventEntry
+, result
 .getSequ
@@ -2506,39 +2506,108 @@
 ls(e
-vent.getTimestamp(), eventEntry
+xpectedEventIdentifier, result.getEventIdentifier());%0A        assertEquals(expectedTimestamp, result
 .get
@@ -2641,17 +2641,25 @@
 tEquals(
-p
+expectedP
 ayload, 
@@ -2677,34 +2677,30 @@
 deserialize(
-eventEntry
+result
 .getPayload(
@@ -2729,65 +2729,57 @@
 als(
-metaData, serializer.deserialize(eventEntry.getMetaData()
+byte%5B%5D.class, result.getPayload().getContentType(
 ));%0A
@@ -2803,61 +2803,69 @@
 als(
-byte%5B%5D.class, eventEntry.getPayload().getContentType(
+expectedMetaData, serializer.deserialize(result.getMetaData()
 ));%0A

Fix java 11 test issue