This is an automated email from the ASF dual-hosted git repository. matthieu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit a41c5d0b7d6ff2c45c7c22696f2e7ac7bbb0d2d9 Author: Rémi KOWALSKI <rkowal...@linagora.com> AuthorDate: Thu Dec 12 16:07:21 2019 +0100 JAMES-3009 convert event store api tests to scala --- .../eventsourcing/eventstore/EventStore.scala | 4 +- .../eventstore/EventStoreFailedException.scala | 6 +- .../eventsourcing/eventstore/EventStoreTest.java | 85 ---------------------- .../eventsourcing/eventstore/HistoryTest.java | 84 --------------------- .../eventstore/EventStoreContract.scala | 82 +++++++++++++++++++++ .../eventsourcing/eventstore/HistoryTest.scala | 55 ++++++++++++++ 6 files changed, 142 insertions(+), 174 deletions(-) diff --git a/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStore.scala b/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStore.scala index cf1a903..b90c314 100644 --- a/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStore.scala +++ b/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStore.scala @@ -35,7 +35,7 @@ trait EventStore { * This method should check that no input event has an id already stored and throw otherwise * It should also check that all events belong to the same aggregate */ - def appendAll(events: List[Event]) : Unit + def appendAll(events: List[Event]): Unit - def getEventsOfAggregate(aggregateId: AggregateId) : History + def getEventsOfAggregate(aggregateId: AggregateId): History } \ No newline at end of file diff --git a/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStoreFailedException.scala b/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStoreFailedException.scala index 2549ea1..7583525 100644 --- a/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStoreFailedException.scala +++ b/event-sourcing/event-store-api/src/main/scala/org/apache/james/eventsourcing/eventstore/EventStoreFailedException.scala @@ -1,4 +1,4 @@ -/** ************************************************************** + /*************************************************************** * Licensed to the Apache Software Foundation (ASF) under one * * or more contributor license agreements. See the NOTICE file * * distributed with this work for additional information * @@ -7,7 +7,7 @@ * "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 * + * 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 * @@ -15,7 +15,7 @@ * KIND, either express or implied. See the License for the * * specific language governing permissions and limitations * * under the License. * - * ***************************************************************/ + ****************************************************************/ package org.apache.james.eventsourcing.eventstore case class EventStoreFailedException(message: String) extends RuntimeException(message) \ No newline at end of file diff --git a/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/EventStoreTest.java b/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/EventStoreTest.java deleted file mode 100644 index b4b37ba..0000000 --- a/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/EventStoreTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you 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.apache.james.eventsourcing.eventstore; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import org.apache.james.eventsourcing.EventId; -import org.apache.james.eventsourcing.TestAggregateId; -import org.apache.james.eventsourcing.TestEvent; -import org.junit.jupiter.api.Test; - -public interface EventStoreTest { - - TestAggregateId AGGREGATE_1 = TestAggregateId.apply(1); - TestAggregateId AGGREGATE_2 = TestAggregateId.apply(2); - - @Test - default void getEventsOfAggregateShouldThrowOnNullAggregateId(EventStore testee) { - assertThatThrownBy(() -> testee.getEventsOfAggregate(null)) - .isInstanceOf(NullPointerException.class); - } - - @Test - default void appendShouldThrowWhenEventFromSeveralAggregates(EventStore testee) { - TestEvent event1 = new TestEvent(EventId.first(), AGGREGATE_1, "first"); - TestEvent event2 = new TestEvent(event1.eventId().next(), AGGREGATE_2, "second"); - assertThatThrownBy(() -> testee.appendAll(event1, event2)).isInstanceOf(IllegalArgumentException.class); - } - - @Test - default void appendShouldDoNothingOnEmptyEventList(EventStore testee) { - assertThatCode(testee::appendAll).doesNotThrowAnyException(); - } - - @Test - default void appendShouldThrowWhenTryingToRewriteHistory(EventStore testee) { - TestEvent event1 = new TestEvent(EventId.first(), AGGREGATE_1, "first"); - testee.append(event1); - TestEvent event2 = new TestEvent(EventId.first(), AGGREGATE_1, "second"); - assertThatThrownBy(() -> testee.append(event2)).isInstanceOf(EventStoreFailedException.class); - } - - @Test - default void getEventsOfAggregateShouldReturnEmptyHistoryWhenUnknown(EventStore testee) { - assertThat(testee.getEventsOfAggregate(AGGREGATE_1)).isEqualTo(History.empty()); - } - - @Test - default void getEventsOfAggregateShouldReturnAppendedEvent(EventStore testee) { - TestEvent event = new TestEvent(EventId.first(), AGGREGATE_1, "first"); - testee.append(event); - assertThat(testee.getEventsOfAggregate(AGGREGATE_1)) - .isEqualTo(History.of(event)); - } - - @Test - default void getEventsOfAggregateShouldReturnAppendedEvents(EventStore testee) { - TestEvent event1 = new TestEvent(EventId.first(), AGGREGATE_1, "first"); - TestEvent event2 = new TestEvent(event1.eventId().next(), AGGREGATE_1, "second"); - testee.append(event1); - testee.append(event2); - assertThat(testee.getEventsOfAggregate(AGGREGATE_1)) - .isEqualTo(History.of(event1, event2)); - } - -} \ No newline at end of file diff --git a/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java b/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java deleted file mode 100644 index adec969..0000000 --- a/event-sourcing/event-store-api/src/test/java/org/apache/james/eventsourcing/eventstore/HistoryTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you 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.apache.james.eventsourcing.eventstore; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import org.apache.james.eventsourcing.EventId; -import org.apache.james.eventsourcing.TestAggregateId; -import org.apache.james.eventsourcing.TestEvent; -import org.junit.jupiter.api.Test; - -import scala.compat.java8.OptionConverters; - -class HistoryTest { - - @Test - void emptyShouldGenerateAnEmptyHistory() { - assertThat(History.empty()) - .isEqualTo(History.of()); - } - - @Test - void getVersionShouldReturnEmptyWhenEmpty() { - assertThat(OptionConverters.toJava(History.empty() - .getVersion())) - .isEmpty(); - } - - @Test - void getVersionShouldReturnSingleEventIdWhenSingleEvent() { - assertThat(OptionConverters.toJava(History - .of(new TestEvent(EventId.first(), - TestAggregateId.apply(42), - "any")) - .getVersion())) - .contains(EventId.first()); - } - - @Test - void getVersionShouldReturnHighestEventId() { - TestEvent event1 = new TestEvent(EventId.first(), - TestAggregateId.apply(42), - "any"); - TestEvent event2 = new TestEvent(event1.eventId().next(), - TestAggregateId.apply(42), - "any"); - - assertThat(OptionConverters.toJava(History.of(event1, event2) - .getVersion())) - .contains(event2.eventId()); - } - - @Test - void duplicateHistoryShouldThrow() { - TestEvent event1 = new TestEvent(EventId.first(), - TestAggregateId.apply(42), - "any"); - TestEvent event2 = new TestEvent(EventId.first(), - TestAggregateId.apply(42), - "any"); - - assertThatThrownBy(() -> History.of(event1, event2)) - .isInstanceOf(EventStoreFailedException.class); - } - -} diff --git a/event-sourcing/event-store-api/src/test/scala/org/apache/james/eventsourcing/eventstore/EventStoreContract.scala b/event-sourcing/event-store-api/src/test/scala/org/apache/james/eventsourcing/eventstore/EventStoreContract.scala new file mode 100644 index 0000000..f519a9c --- /dev/null +++ b/event-sourcing/event-store-api/src/test/scala/org/apache/james/eventsourcing/eventstore/EventStoreContract.scala @@ -0,0 +1,82 @@ + /*************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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.apache.james.eventsourcing.eventstore + +import org.apache.james.eventsourcing.{EventId, TestAggregateId, TestEvent} +import org.assertj.core.api.Assertions.{assertThat, assertThatCode, assertThatThrownBy} +import org.junit.jupiter.api.Test + +object EventStoreContract { + val AGGREGATE_1 = TestAggregateId(1) + val AGGREGATE_2 = TestAggregateId(2) +} + +trait EventStoreContract { + + @Test + def getEventsOfAggregateShouldThrowOnNullAggregateId(testee: EventStore) : Unit = + assertThatThrownBy(() => testee.getEventsOfAggregate(null)) + .isInstanceOf(classOf[NullPointerException]) + + @Test + def appendShouldThrowWhenEventFromSeveralAggregates(testee: EventStore) : Unit = { + val event1 = TestEvent(EventId.first, EventStoreContract.AGGREGATE_1, "first") + val event2 = TestEvent(event1.eventId.next, EventStoreContract.AGGREGATE_2, "second") + assertThatThrownBy(() => testee.appendAll(event1, event2)) + .isInstanceOf(classOf[IllegalArgumentException]) + } + + @Test + def appendShouldDoNothingOnEmptyEventList(testee: EventStore) : Unit = + assertThatCode(() => testee.appendAll()) + .doesNotThrowAnyException() + + @Test + def appendShouldThrowWhenTryingToRewriteHistory(testee: EventStore) : Unit = { + val event1 = TestEvent(EventId.first, EventStoreContract.AGGREGATE_1, "first") + testee.append(event1) + val event2 = TestEvent(EventId.first, EventStoreContract.AGGREGATE_1, "second") + assertThatThrownBy( + () => testee.append(event2)) + .isInstanceOf(classOf[EventStoreFailedException]) + } + + @Test + def getEventsOfAggregateShouldReturnEmptyHistoryWhenUnknown(testee: EventStore) : Unit = + assertThat(testee.getEventsOfAggregate(EventStoreContract.AGGREGATE_1)) + .isEqualTo(History.empty) + + @Test + def getEventsOfAggregateShouldReturnAppendedEvent(testee: EventStore) : Unit = { + val event = TestEvent(EventId.first, EventStoreContract.AGGREGATE_1, "first") + testee.append(event) + assertThat(testee.getEventsOfAggregate(EventStoreContract.AGGREGATE_1)) + .isEqualTo(History.of(event)) + } + + @Test + def getEventsOfAggregateShouldReturnAppendedEvents(testee: EventStore) : Unit = { + val event1 = TestEvent(EventId.first, EventStoreContract.AGGREGATE_1, "first") + val event2 = TestEvent(event1.eventId.next, EventStoreContract.AGGREGATE_1, "second") + testee.append(event1) + testee.append(event2) + assertThat(testee.getEventsOfAggregate(EventStoreContract.AGGREGATE_1)) + .isEqualTo(History.of(event1, event2)) + } +} \ No newline at end of file diff --git a/event-sourcing/event-store-api/src/test/scala/org/apache/james/eventsourcing/eventstore/HistoryTest.scala b/event-sourcing/event-store-api/src/test/scala/org/apache/james/eventsourcing/eventstore/HistoryTest.scala new file mode 100644 index 0000000..edd5d5e --- /dev/null +++ b/event-sourcing/event-store-api/src/test/scala/org/apache/james/eventsourcing/eventstore/HistoryTest.scala @@ -0,0 +1,55 @@ + /*************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you 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.apache.james.eventsourcing.eventstore + +import org.apache.james.eventsourcing.{EventId, TestAggregateId, TestEvent} +import org.assertj.core.api.Assertions.{assertThat, assertThatThrownBy} +import org.junit.jupiter.api.Test + +class HistoryTest { + + @Test + def emptyShouldGenerateAnEmptyHistory() : Unit = assertThat(History.empty) + .isEqualTo(History.of()) + + @Test + def getVersionShouldReturnEmptyWhenEmpty() : Unit = assertThat(History.empty.getVersion) + .isEqualTo(None) + + @Test + def getVersionShouldReturnSingleEventIdWhenSingleEvent() : Unit = + assertThat(History.of(TestEvent(EventId.first, TestAggregateId(42), "any")).getVersion) + .isEqualTo(Some(EventId.first)) + + @Test + def getVersionShouldReturnHighestEventId() : Unit = { + val event1 = TestEvent(EventId.first, TestAggregateId(42), "any") + val event2 = TestEvent(event1.eventId.next, TestAggregateId(42), "any") + assertThat(History.of(event1, event2).getVersion) + .isEqualTo(Some(event2.eventId)) + } + + @Test + def duplicateHistoryShouldThrow() : Unit = { + val event1 = TestEvent(EventId.first, TestAggregateId(42), "any") + val event2 = TestEvent(EventId.first, TestAggregateId(42), "any") + assertThatThrownBy(() => History.of(event1, event2)) + .isInstanceOf(classOf[EventStoreFailedException]) + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org