http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectReceivedCargoTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectReceivedCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectReceivedCargoTest.java deleted file mode 100644 index 1d7b2d8..0000000 --- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectReceivedCargoTest.java +++ /dev/null @@ -1,286 +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.zest.sample.dcicargo.sample_b.context.test.handling.inspection.event; - -import org.junit.Before; -import org.junit.Test; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectReceivedCargo; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisdirectedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.NextHandlingEvent; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD; - -/** - * {@link InspectReceivedCargo} tests - */ -public class InspectReceivedCargoTest extends TestApplication -{ - private HandlingEventAggregateRoot HANDLING_EVENTS; - - @Before - public void prepareTest() - throws Exception - { - super.prepareTest(); - UnitOfWork uow = uowf.currentUnitOfWork(); - HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID ); - CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID ); - - // Create new cargo - routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, TODAY, deadline = DAY24 ); - delivery = delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, unknownLeg ); - cargo = CARGOS.createCargo( routeSpec, delivery, "Received_CARGO" ); - trackingId = cargo.trackingId().get(); - } - - @Test - public void precondition_1_NotHandledBefore() - throws Exception - { - // Handle - cargo.itinerary().set( itinerary ); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 ); - cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg2, - nextHandlingEvent( LOAD, CHICAGO, DAY5, V201 ) ) ); - - assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 ); - assertDelivery( UNLOAD, CHICAGO, DAY5, V201, - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg2, - LOAD, CHICAGO, DAY5, V201 ); - - // Receive cargo again - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY2, DAY2, trackingId, RECEIVE, HONGKONG, noVoyage ); - thrown.expect( InspectionFailedException.class, "INTERNAL ERROR: Can't receive cargo again" ); - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - } - - @Test - public void deviation_2a_NotRouted_MissingItinerary() - throws Exception - { - // Cargo not routed - cargo.itinerary().set( null ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, leg1 ) ); - - // Receive cargo in Hong Kong (without an itinerary!) - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage ); - - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - - assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage, - IN_PORT, notArrived, - NOT_ROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - - @Test - public void deviation_2b_Misrouted_ReceiveLocation_CargoOrigin() - throws Exception - { - // Misroute cargo - assign unsatisfying itinerary not going to Stockholm - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, MISROUTED, unknownLeg ) ); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - - // Receive in cargo origin (Hong Kong) having a wrong itinerary - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage ); - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - - // Remains misrouted and directed - assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage, - IN_PORT, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - - @Test - public void deviation_2b_Misrouted_ReceiveLocationOfWrongItinerary_Midpoint() - throws Exception - { - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, MISROUTED, leg1 ) ); - - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, NEWYORK, noVoyage ); - - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - - // Remains misrouted and directed - assertDelivery( RECEIVE, NEWYORK, DAY1, noVoyage, - IN_PORT, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - - @Test - public void deviation_2b_Misrouted_ReceiveLocationOfWrongItinerary_Destination() - throws Exception - { - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, MISROUTED, unknownLeg ) ); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - - // Receipt in cargo destination = no transportation. - // This must be a mistake. Cargo owner should be notified. - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, STOCKHOLM, noVoyage ); - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - - // Remains misrouted and directed - assertDelivery( RECEIVE, STOCKHOLM, DAY1, noVoyage, - IN_PORT, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - - @Test - public void deviation_2b_Misrouted_ReceiveLocationOfWrongItinerary_UnplannedLocation() - throws Exception - { - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, MISROUTED, unknownLeg ) ); - - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HANGZHOU, noVoyage ); - - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - - // Remains misrouted and directed - assertDelivery( RECEIVE, HANGZHOU, DAY1, noVoyage, - IN_PORT, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - - @Test - public void deviation_3a_Misdirected_ReceiveLocationOfCorrectItinerary_Midpoint() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, ROUTED, leg1 ) ); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - ROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - - // Receive cargo in some location of valid itinerary - should this be accepted?! - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, NEWYORK, noVoyage ); - try - { - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( CargoMisdirectedException e ) - { - assertMessage( e, "MISDIRECTED! Itinerary expected receipt in Hongkong (CNHKG)" ); - - // Now routed but misdirected - assertDelivery( RECEIVE, NEWYORK, DAY1, noVoyage, - IN_PORT, notArrived, - ROUTED, misdirected, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - } - - @Test - public void deviation_3a_Misdirected_ReceiveLocationOfCorrectItinerary_Destination() - throws Exception - { - // Assign satisfying route going to Stockholm - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, ROUTED, leg1 ) ); - - // Receipt in cargo/routeSpec destination = no transportation. - // This must be a unintended booking. Cargo owner should be notified. - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, STOCKHOLM, noVoyage ); - try - { - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( CargoMisdirectedException e ) - { - assertMessage( e, "MISDIRECTED! Itinerary expected receipt in Hongkong (CNHKG)" ); - assertDelivery( RECEIVE, STOCKHOLM, DAY1, noVoyage, - IN_PORT, notArrived, - ROUTED, misdirected, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - } - - @Test - public void deviation_3a_Misdirected_UnexpectedReceiveLocation() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, ROUTED, leg1 ) ); - - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HANGZHOU, noVoyage ); - thrown.expect( CargoMisdirectedException.class, "MISDIRECTED! Itinerary expected receipt in Hongkong (CNHKG)" ); - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - } - - @Test - public void successful_Receipt() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, ROUTED, leg1 ) ); - - // Receive cargo as planned in origin - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage ); - new InspectReceivedCargo( cargo, handlingEvent ).inspect(); - - // Itinerary calculations - NextHandlingEvent nextLoad = cargo.delivery().get().nextHandlingEvent().get(); - assertThat( nextLoad.location().get(), is( equalTo( itinerary.firstLeg().loadLocation().get() ) ) ); - assertThat( nextLoad.date().get(), is( equalTo( itinerary.firstLeg().loadDate().get() ) ) ); - assertThat( nextLoad.voyage().get(), is( equalTo( itinerary.firstLeg().voyage().get() ) ) ); - - assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage, - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - LOAD, HONGKONG, DAY1, V201 ); - } -}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnhandledCargoTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnhandledCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnhandledCargoTest.java deleted file mode 100644 index 2697b36..0000000 --- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnhandledCargoTest.java +++ /dev/null @@ -1,130 +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.zest.sample.dcicargo.sample_b.context.test.handling.inspection.event; - -import java.time.LocalDate; -import org.junit.Before; -import org.junit.Test; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectUnhandledCargo; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot; - -import static org.junit.Assert.fail; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE; - -/** - * {@link InspectUnhandledCargo} tests - */ -public class InspectUnhandledCargoTest extends TestApplication -{ - private HandlingEventAggregateRoot HANDLING_EVENTS; - - @Before - public void prepareTest() - throws Exception - { - super.prepareTest(); - UnitOfWork uow = uowf.currentUnitOfWork(); - HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID ); - CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID ); - - // Create new cargo - routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 ); - delivery = delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, leg1 ); - cargo = CARGOS.createCargo( routeSpec, delivery, "Claimed_CARGO" ); - trackingId = cargo.trackingId().get(); - } - - @Test - public void precondition_CannotInspectUnloadInDestinationHere() - throws Exception - { - // Can't inspect handled cargo here... - cargo.itinerary().set( itinerary ); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage ); - cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg1, unknownNextHandlingEvent ) ); - try - { - new InspectUnhandledCargo( cargo ).inspect(); - fail(); - } - catch( InspectionFailedException e ) - { - assertMessage( e, "INTERNAL ERROR: Can only inspect unhandled cargo" ); - } - } - - @Test - public void deviation_2a_NotRouted() - throws Exception - { - // Cargo not routed - cargo.itinerary().set( null ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, leg1 ) ); - - new InspectUnhandledCargo( cargo ).inspect(); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - NOT_ROUTED, directed, unknownETA, unknownLeg, - RECEIVE, HONGKONG, noSpecificDate, noVoyage ); - } - - @Test - public void deviation_2b_Misrouted() - throws Exception - { - // Misroute cargo - assign unsatisfying itinerary not going to Stockholm - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, MISROUTED, leg1 ) ); - - new InspectUnhandledCargo( cargo ).inspect(); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - RECEIVE, HONGKONG, noSpecificDate, noVoyage ); - } - - @Test - public void step_2_Routed() - throws Exception - { - // Assign satisfying route going to Stockholm - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, ROUTED, leg1 ) ); - - new InspectUnhandledCargo( cargo ).inspect(); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - RECEIVE, HONGKONG, noSpecificDate, noVoyage ); - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnloadedCargoTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnloadedCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnloadedCargoTest.java deleted file mode 100644 index 3c7d7a0..0000000 --- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectUnloadedCargoTest.java +++ /dev/null @@ -1,345 +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.zest.sample.dcicargo.sample_b.context.test.handling.inspection.event; - -import java.time.LocalDate; -import org.junit.Before; -import org.junit.Test; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectUnloadedCargo; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisdirectedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisroutedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoNotRoutedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Leg; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD; - -/** - * {@link InspectUnloadedCargo} tests - */ -public class InspectUnloadedCargoTest extends TestApplication -{ - private HandlingEventAggregateRoot HANDLING_EVENTS; - - @Before - public void prepareTest() - throws Exception - { - super.prepareTest(); - UnitOfWork uow = uowf.currentUnitOfWork(); - HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID ); - CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID ); - - // Create new cargo - routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 ); - delivery = delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg1 ); - cargo = CARGOS.createCargo( routeSpec, delivery, "Unloaded_CARGO" ); - trackingId = cargo.trackingId().get(); - } - - @Test - public void precondition_CannotInspectUnloadInDestinationHere() - throws Exception - { - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, UNLOAD, STOCKHOLM, V205 ); - try - { - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( InspectionFailedException e ) - { - assertMessage( e, "INTERNAL ERROR: Can only inspect unloaded cargo that hasn't arrived at destination" ); - } - } - - @Test - public void deviation_2a_NotRouted() - throws Exception - { - // Cargo not routed - cargo.itinerary().set( null ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, NOT_ROUTED, leg1 ) ); - - // Unload in Chicago (without an itinerary!) - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 ); - try - { - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( CargoNotRoutedException e ) - { - assertMessage( e, "NOT ROUTED while being handled!" ); - - // An unexpected unload shouldn't be considered an itinerary progress - legIndex stays unchanged - assertDelivery( UNLOAD, CHICAGO, DAY5, V201, - IN_PORT, notArrived, - NOT_ROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - } - - @Test - public void deviation_2b_Misrouted_UnloadLocationOfWrongItinerary_Origin() - throws Exception - { - // Misroute cargo - assign unsatisfying itinerary not going to Stockholm - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, MISROUTED, leg1 ) ); - - // Unload in Hong Kong (with wrong itinerary) - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, UNLOAD, HONGKONG, V201 ); - try - { - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( CargoMisroutedException e ) - { - assertMessage( e, "MISROUTED! Route specification is not satisfied with itinerary" ); - - // An unexpected unload shouldn't be considered an itinerary progress - legIndex stays unchanged - assertDelivery( UNLOAD, HONGKONG, DAY1, V201, - IN_PORT, notArrived, - MISROUTED, directed, unknownETA, unknownLeg, - unknownNextHandlingEvent ); - } - } - - @Test - public void deviation_2b_Misrouted_UnloadLocationOfWrongItinerary_OtherItineraryLocation() - throws Exception - { - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, MISROUTED, leg1 ) ); - - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, UNLOAD, NEWYORK, V201 ); - thrown.expect( CargoMisroutedException.class, "MISROUTED! Route specification is not satisfied with itinerary" ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - } - - @Test - public void deviation_2b_Misrouted_UnloadLocationOfWrongItinerary_UnplannedLocation() - throws Exception - { - cargo.itinerary().set( wrongItinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, MISROUTED, leg1 ) ); - - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, UNLOAD, ROTTERDAM, V204 ); - thrown.expect( CargoMisroutedException.class, "MISROUTED! Route specification is not satisfied with itinerary" ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - } - - @Test - public void step_2_Routed_UnloadedInPlannedLocation() - throws Exception - { - // Assign satisfying route going to Stockholm - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg1 ) ); - - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - - // Itinerary progresses to next leg - assertDelivery( UNLOAD, CHICAGO, DAY5, V201, - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg2, - LOAD, CHICAGO, DAY5, V201 ); - } - - @Test - public void deviation_3x_InternalError_InvalidItineraryProgressIndex() - throws Exception - { - cargo.itinerary().set( itinerary ); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 ); - - Integer badLegIndex = 7; - cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived, - ROUTED, directed, unknownETA, badLegIndex, - unknownNextHandlingEvent ) ); - try - { - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( InspectionFailedException e ) - { - assertMessage( e, "INTERNAL ERROR: Itinerary progress index '7' is invalid!" ); - assertDelivery( UNLOAD, CHICAGO, DAY5, V201, - IN_PORT, notArrived, - ROUTED, directed, unknownETA, badLegIndex, - unknownNextHandlingEvent ); - } - } - - @Test - public void deviation_3a_ReRouted_UnloadInNewOrigin() - throws Exception - { - // Re-route with new satisfying itinerary - cargo.itinerary().set( itinerary ); - - // Cargo was re-route on board a carrier - cargo.delivery().set( delivery( null, ONBOARD_CARRIER, notArrived, - ROUTED, misdirected, itinerary.eta(), leg3, - nextHandlingEvent( UNLOAD, HONGKONG, DAY6, V201 ) ) ); - - // Unload in new route specification origin (load location of itinerary leg 1) - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, UNLOAD, HONGKONG, V204 ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - - // Itinerary progress starts over from leg 1 again - assertDelivery( UNLOAD, HONGKONG, DAY1, V204, - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - LOAD, HONGKONG, DAY1, V201 ); - } - - @Test - public void deviation_3b_Misdirected_UnexpectedUnloadLocation_Origin() - throws Exception - { - // Going fine so far - cargo.itinerary().set( itinerary ); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, LOAD, CHICAGO, V201 ); - cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived, - ROUTED, directed, itinerary.eta(), leg2, - nextHandlingEvent( UNLOAD, NEWYORK, DAY6, V201 ) ) ); - - // Unexpected unload in origin - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY6, DAY6, trackingId, UNLOAD, HONGKONG, V201 ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - - // Itinerary progress starts over from leg 1 again - assertDelivery( UNLOAD, HONGKONG, DAY6, V201, - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - LOAD, HONGKONG, DAY1, V201 ); - } - - @Test - public void deviation_3b_Misdirected_UnexpectedUnloadLocation_PreviousInItinerary() - throws Exception - { - // Move the cargo ahead on the route. Third leg of itinerary expects unload in Dallas. - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg3 ) ); - - // Unexpected unload in previous unload location of itinerary. - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, UNLOAD, NEWYORK, V201 ); - try - { - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - fail(); - } - catch( CargoMisdirectedException e ) - { - assertMessage( e, "MISDIRECTED! Itinerary expected unload in USDAL" ); - assertDelivery( UNLOAD, NEWYORK, DAY7, V201, // Itinerary expected: UNLOAD, DALLAS, DAY8, V202 - IN_PORT, notArrived, - ROUTED, misdirected, itinerary.eta(), leg3, - unknownNextHandlingEvent ); - } - } - - @Test - public void deviation_3b_Misdirected_UnexpectedUnloadLocation_NextInItinerary() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg3 ) ); - - // Unexpected load in next load location of itinerary (onto expected voyage) - can't jump ahead in route plan. - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, UNLOAD, GOTHENBURG, V202 ); - thrown.expect( CargoMisdirectedException.class, "MISDIRECTED! Itinerary expected unload in USDAL" ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - } - - @Test - public void deviation_3b_Misdirected_UnexpectedUnloadLocation_Unplanned() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg3 ) ); - - // Unexpected load in unplanned location (onto expected voyage) - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, UNLOAD, HAMBURG, V202 ); - thrown.expect( CargoMisdirectedException.class, "MISDIRECTED! Itinerary expected unload in USDAL" ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - } - - @Test - public void deviation_3c_ExpectedUnloadLocation_UnexpectedUnloadVoyage() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg3 ) ); - - // Unload in expected location but from unexpected voyage - do we care? For now not. - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY10, DAY10, trackingId, UNLOAD, DALLAS, V205 ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - - // Itinerary should have progressed to leg 4 - assertDelivery( UNLOAD, DALLAS, DAY10, V205, // Itinerary expected: UNLOAD, DALLAS, DAY8, V202 - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg4, - LOAD, DALLAS, DAY10, V202 ); // leg 4 load location - } - - @Test - public void success_Unload() - throws Exception - { - cargo.itinerary().set( itinerary ); - cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg4 ) ); - - // Expected unload in leg 4 unload location (Rotterdam) - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY17, DAY17, trackingId, UNLOAD, ROTTERDAM, V202 ); - new InspectUnloadedCargo( cargo, handlingEvent ).inspect(); - - // Itinerary should have progressed to leg 5 - Leg nextCarrierMovement = itinerary.leg( cargo.delivery().get().itineraryProgressIndex().get() ); - assertThat( nextCarrierMovement.loadLocation().get(), is( equalTo( ROTTERDAM ) ) ); - assertThat( nextCarrierMovement.loadDate().get(), is( equalTo( DAY20 ) ) ); - assertThat( nextCarrierMovement.voyage().get(), is( equalTo( V203 ) ) ); - - assertDelivery( UNLOAD, ROTTERDAM, DAY17, V202, - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg5, - LOAD, ROTTERDAM, DAY20, V203 ); // leg 5 load location - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/parsing/ParseHandlingEventDataTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/parsing/ParseHandlingEventDataTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/parsing/ParseHandlingEventDataTest.java deleted file mode 100644 index 751bd11..0000000 --- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/parsing/ParseHandlingEventDataTest.java +++ /dev/null @@ -1,142 +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.zest.sample.dcicargo.sample_b.context.test.handling.parsing; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import org.junit.Before; -import org.junit.Test; -import org.apache.zest.api.constraint.ConstraintViolationException; -import org.apache.zest.api.service.ServiceReference; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.ParseHandlingEventData; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.exception.InvalidHandlingEventDataException; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot; - -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED; - -/** - * {@link ParseHandlingEventData} tests - */ -public class ParseHandlingEventDataTest extends TestApplication -{ - private static ParseHandlingEventData handlingEventParser; - private static String completionDate; - - @Before - public void prepareTest() - throws Exception - { - super.prepareTest(); - TestApplication.setup(); - UnitOfWork uow = uowf.currentUnitOfWork(); - CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID ); - - // Create new cargo - routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 ); - delivery = delivery( TODAY, NOT_RECEIVED, ROUTED, unknownLeg ); - cargo = CARGOS.createCargo( routeSpec, delivery, "ABC" ); - trackingId = cargo.trackingId().get(); - trackingIdString = trackingId.id().get(); - cargo.itinerary().set( itinerary ); - completionDate = LocalDate.now().toString(); - - // Start ParseHandlingEventData service - ServiceReference<ParseHandlingEventData> ParseHandlingEventDataRef = - serviceFinder.findService( ParseHandlingEventData.class ); - handlingEventParser = ParseHandlingEventDataRef.get(); - } - - // Null - - @Test - public void deviation_2a_Null_CompletionTimeString() - throws Exception - { - thrown.expect( ConstraintViolationException.class, "constraint \"not optional(param1)\", for value 'null'" ); - handlingEventParser.parse( null, trackingIdString, "RECEIVE", "CNHKG", null ); - } - - @Test - public void deviation_2a_Null_TrackingIdString() - throws Exception - { - thrown.expect( ConstraintViolationException.class, "constraint \"not optional(param2)\", for value 'null'" ); - handlingEventParser.parse( completionDate, null, "RECEIVE", "CNHKG", null ); - } - - // etc... - - @Test - public void step_2_Null_VoyageNumberString() - throws Exception - { - // No voyage number string is ok - handlingEventParser.parse( completionDate, trackingIdString, "RECEIVE", "CNHKG", null ); - } - - // Empty - - @Test - public void deviation_2a_Empty_CompletionTimeString() - throws Exception - { - thrown.expect( ConstraintViolationException.class, "NotEmpty()(param1)\", for value ' '" ); - handlingEventParser.parse( " ", trackingIdString, "RECEIVE", "CNHKG", null ); - } - - @Test - public void step_2_Empty_VoyageNumberString() - throws Exception - { - // Empty voyage number string is ok - handlingEventParser.parse( completionDate, trackingIdString, "RECEIVE", "CNHKG", " " ); - } - - // Basic type conversion - - @Test - public void deviation_3a_TypeConversion_CompletionTimeString() - throws Exception - { - thrown.expect( InvalidHandlingEventDataException.class, - "Invalid date format: '5/27/2011' must be on ISO 8601 format yyyy-MM-dd HH:mm" ); - handlingEventParser.parse( "5/27/2011", trackingIdString, "RECEIVE", "CNHKG", null ); - } - - @Test - public void deviation_3a_TypeConversion_HandlingEventTypeString() - throws Exception - { - thrown.expect( InvalidHandlingEventDataException.class, "No enum const" ); - handlingEventParser.parse( completionDate, trackingIdString, "HAND_OVER", "CNHKG", null ); - } - - // Successful parsing - - @Test - public void success_Parsing() - throws Exception - { - handlingEventParser.parse( completionDate, trackingIdString, "RECEIVE", "CNHKG", null ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/registration/RegisterHandlingEventTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/registration/RegisterHandlingEventTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/registration/RegisterHandlingEventTest.java deleted file mode 100644 index 394c418..0000000 --- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/registration/RegisterHandlingEventTest.java +++ /dev/null @@ -1,233 +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.zest.sample.dcicargo.sample_b.context.test.handling.registration; - -import java.time.LocalDate; -import org.apache.zest.api.query.Query; -import org.apache.zest.api.unitofwork.UnitOfWork; -import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.parsing.dto.ParsedHandlingEventData; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.RegisterHandlingEvent; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.AlreadyClaimedException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.DuplicateEventException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.MissingVoyageNumberException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.UnknownCargoException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.UnknownLocationException; -import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.registration.exception.UnknownVoyageException; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot; -import org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEvent; -import org.junit.Before; -import org.junit.Test; - -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CLAIM; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CUSTOMS; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD; -import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE; - -/** - * {@link RegisterHandlingEvent} tests - * - * FIXME: Every test method call the one above to allow ordered execution, ie. tests are not indepedants ! - */ -public class RegisterHandlingEventTest extends TestApplication -{ - private ParsedHandlingEventData parsedEventData; - private UnitOfWork tempUow; - private HandlingEventAggregateRoot HANDLING_EVENTS; - - @Before - public void prepareTest() - throws Exception - { - super.prepareTest(); - UnitOfWork uow = uowf.currentUnitOfWork(); - HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID ); - CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID ); - - // Create new cargo - routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 ); - delivery = delivery( TODAY, NOT_RECEIVED, ROUTED, unknownLeg ); - cargo = CARGOS.createCargo( routeSpec, delivery, "ABC" ); - cargo.itinerary().set( itinerary ); - trackingId = cargo.trackingId().get(); - } - - @Test - public void deviation_1a_UnknownCargo() - throws Exception - { - parsedEventData = parsedHandlingEventData( DAY1, DAY1, "XXX", RECEIVE, "CNHKG", null ); - thrown.expect( UnknownCargoException.class, "Found no cargo with tracking id 'XXX'." ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_2a_UnknownUnlocode() - throws Exception - { - deviation_1a_UnknownCargo(); - - parsedEventData = parsedHandlingEventData( DAY1, DAY1, "ABC", RECEIVE, "ZZZZZ", null ); - thrown.expect( UnknownLocationException.class, "Found no location with UN locode 'ZZZZZ'." ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_3a_VoyageNumber_SilentlySkipIfNotRequired() - throws Exception - { - deviation_2a_UnknownUnlocode(); - - parsedEventData = parsedHandlingEventData( DAY1, DAY1, "ABC", RECEIVE, "CNHKG", "V201" ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_3b_VoyageNumber_Missing() - throws Exception - { - deviation_3a_VoyageNumber_SilentlySkipIfNotRequired(); - - parsedEventData = parsedHandlingEventData( DAY1, DAY1, "ABC", LOAD, "CNHKG", null ); - thrown.expect( MissingVoyageNumberException.class, "Missing voyage number. Handling event LOAD requires a voyage." ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_3c_VoyageNumber_Unknown() - throws Exception - { - deviation_3b_VoyageNumber_Missing(); - - parsedEventData = parsedHandlingEventData( DAY1, DAY1, "ABC", LOAD, "CNHKG", "V600S" ); - thrown.expect( UnknownVoyageException.class, "Found no voyage with voyage number 'V600S'." ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_4a_DuplicateEvent_Receive() - throws Exception - { - deviation_3c_VoyageNumber_Unknown(); - UnitOfWork uow = uowf.currentUnitOfWork(); - - // Receive 1st time (store event so that it turns up in query) - uow.complete(); - tempUow = uowf.newUnitOfWork(); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage ); - tempUow.complete(); - - // Receive 2nd time - parsedEventData = parsedHandlingEventData( DAY2, DAY2, "ABC", RECEIVE, "CNHKG", null ); - thrown.expect( DuplicateEventException.class, "Cargo can't be received more than once" ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_4a_DuplicateEvent_Customs() - throws Exception - { - deviation_4a_DuplicateEvent_Receive(); - UnitOfWork uow = uowf.currentUnitOfWork(); - - uow.complete(); - // In customs 1st time - tempUow = uowf.newUnitOfWork(); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, CUSTOMS, HONGKONG, noVoyage ); - tempUow.complete(); - - // In customs 2nd time - parsedEventData = parsedHandlingEventData( DAY2, DAY2, "ABC", CUSTOMS, "CNHKG", null ); - thrown.expect( DuplicateEventException.class, "Cargo can't be in customs more than once" ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_4a_DuplicateEvent_Claim() - throws Exception - { - deviation_4a_DuplicateEvent_Customs(); - UnitOfWork uow = uowf.currentUnitOfWork(); - - uow.complete(); - // Claimed 1st time - tempUow = uowf.newUnitOfWork(); - handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, CLAIM, HONGKONG, noVoyage ); - tempUow.complete(); - - // Claimed 2nd time - parsedEventData = parsedHandlingEventData( DAY2, DAY2, "ABC", CLAIM, "CNHKG", null ); - thrown.expect( DuplicateEventException.class, "Cargo can't be claimed more than once" ); - new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void deviation_5a_NoHandlingAfterClaim() - throws Exception - { - deviation_4a_DuplicateEvent_Claim(); - - // Try loading (saved claim event in previous test will prevent this) - parsedEventData = parsedHandlingEventData( DAY2, DAY2, "ABC", LOAD, "CNHKG", "V201" ); - thrown.expect( AlreadyClaimedException.class, "LOAD handling event can't be registered after cargo has been claimed" ); - new RegisterHandlingEvent( parsedEventData ).getEvent(); - } - - @Test - public void successfull_Registration() - throws Exception - { - deviation_5a_NoHandlingAfterClaim(); - - // Delete handling events from memory - tempUow = uowf.newUnitOfWork(); - Query<HandlingEvent> events = tempUow.newQuery( qbf.newQueryBuilder( HandlingEvent.class ) ); - for( HandlingEvent event : events ) - { - tempUow.remove( event ); - } - tempUow.complete(); - - cargo.delivery().set( delivery( null, NOT_RECEIVED, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - nextHandlingEvent( RECEIVE, HONGKONG, DAY1, noVoyage ) ) ); - - assertDelivery( null, null, null, null, - NOT_RECEIVED, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - RECEIVE, HONGKONG, DAY1, noVoyage ); - - parsedEventData = parsedHandlingEventData( DAY1, DAY1, "ABC", RECEIVE, "CNHKG", null ); - handlingEvent = new RegisterHandlingEvent( parsedEventData ).getEvent(); - - cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - nextHandlingEvent( LOAD, HONGKONG, DAY1, V201 ) ) ); - - assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage, // Handling event has been registered - IN_PORT, notArrived, - ROUTED, directed, itinerary.eta(), leg1, - LOAD, HONGKONG, DAY1, V201 ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/infrastructure/testing/ExpectedException.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/infrastructure/testing/ExpectedException.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/infrastructure/testing/ExpectedException.java deleted file mode 100644 index 6e82c94..0000000 --- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/infrastructure/testing/ExpectedException.java +++ /dev/null @@ -1,103 +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.zest.sample.dcicargo.sample_b.infrastructure.testing; - -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -/** - * ExpectedException. - * <p> - * Wrapper of {@link org.junit.rules.ExpectedException} in order to provide custom - * expected exception one-liners for convenience. - * </p> - * <p> - * If you're checking certain DomainSpecificException often, you could wrap it here too... - * </p> - * <p> - * See <a href="http://alexruiz.developerblogs.com/?p=1530">http://alexruiz.developerblogs.com/?p=1530</a> - * </p> - * <p> - * NOTE! - * </p> - * <p> - * 1. the check for the expected exception must be immediately above the code that is expected to throw such exception - * </p> - * <p> - * 2. the line of code that is expected to throw an exception should be the last line in the test method - * </p> - * <p> - * See <a href="http://java.dzone.com/articles/unexpected-behavior-junits">http://java.dzone.com/articles/unexpected-behavior-junits</a> - * </p> - * <p> - */ -public class ExpectedException implements TestRule -{ - private final org.junit.rules.ExpectedException delegate = org.junit.rules.ExpectedException.none(); - - public static ExpectedException none() - { - return new ExpectedException(); - } - - private ExpectedException() {} - - public Statement apply( Statement base, Description description ) - { - return delegate.apply( base, description ); - } - - // This one saves a little typing :-) - public void expect( Class<? extends Throwable> type, String substringOfMessage ) - { - expect( type ); - expectMessage( substringOfMessage ); - } - - public void expectAssertionError( String message ) - { - expect( AssertionError.class ); - expectMessage( message ); - } - - public void expectNullPointerException( String message ) - { - expect( NullPointerException.class ); - expectMessage( message ); - } - - public void expect( Throwable error ) - { - expect( error.getClass() ); - expectMessage( error.getMessage() ); - } - - - public void expect( Class<? extends Throwable> type ) - { - delegate.expect( type ); - } - - public void expectMessage( String message ) - { - delegate.expectMessage( message ); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext.java ---------------------------------------------------------------------- diff --git a/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext.java b/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext.java index 527fba4..f633113 100644 --- a/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext.java +++ b/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext.java @@ -22,6 +22,7 @@ package org.apache.zest.dci.moneytransfer.context; import java.util.ArrayList; import java.util.List; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.injection.scope.This; import org.apache.zest.api.mixin.Mixins; @@ -132,8 +133,8 @@ public class PayBillsContext { // Creditor retrieval could be a use case in itself... List<BalanceData> creditors = new ArrayList<BalanceData>(); - creditors.add( uowf.currentUnitOfWork().get( CreditorRolemap.class, "BakerAccount" ) ); - creditors.add( uowf.currentUnitOfWork().get( CreditorRolemap.class, "ButcherAccount" ) ); + creditors.add( uowf.currentUnitOfWork().get( CreditorRolemap.class, new StringIdentity( "BakerAccount" ) ) ); + creditors.add( uowf.currentUnitOfWork().get( CreditorRolemap.class, new StringIdentity( "ButcherAccount" ) ) ); return creditors; } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext2.java ---------------------------------------------------------------------- diff --git a/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext2.java b/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext2.java index 36fdb53..9625349 100644 --- a/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext2.java +++ b/samples/dci/src/main/java/org/apache/zest/dci/moneytransfer/context/PayBillsContext2.java @@ -22,6 +22,7 @@ package org.apache.zest.dci.moneytransfer.context; import java.util.ArrayList; import java.util.List; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; import org.apache.zest.dci.moneytransfer.domain.data.BalanceData; @@ -124,9 +125,9 @@ public class PayBillsContext2 private List<BalanceData> getCreditors() { // Creditor retrieval could be a use case in itself... - List<BalanceData> creditors = new ArrayList<BalanceData>(); - creditors.add( uowf.currentUnitOfWork().get( BalanceData.class, "BakerAccount" ) ); - creditors.add( uowf.currentUnitOfWork().get( BalanceData.class, "ButcherAccount" ) ); + List<BalanceData> creditors = new ArrayList<>(); + creditors.add( uowf.currentUnitOfWork().get( BalanceData.class, new StringIdentity( "BakerAccount" ) ) ); + creditors.add( uowf.currentUnitOfWork().get( BalanceData.class, new StringIdentity( "ButcherAccount" ) ) ); return creditors; } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/AccountIds.java ---------------------------------------------------------------------- diff --git a/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/AccountIds.java b/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/AccountIds.java new file mode 100644 index 0000000..437c551 --- /dev/null +++ b/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/AccountIds.java @@ -0,0 +1,13 @@ +package org.apache.zest.dci.moneytransfer.test; + +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; + +public interface AccountIds +{ + Identity SAVINGS_ACCOUNT_ID = new StringIdentity( "SavingsAccountId" ); + Identity CHECKING_ACCOUNT_ID = new StringIdentity( "CheckingAccountId" ); + Identity CREDITOR_ID1 = new StringIdentity( "BakerAccount" ); + Identity CREDITOR_ID2 = new StringIdentity( "ButcherAccount" ); + +} http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest.java ---------------------------------------------------------------------- diff --git a/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest.java b/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest.java index a955dd6..1ab2511 100644 --- a/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest.java +++ b/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest.java @@ -21,7 +21,6 @@ package org.apache.zest.dci.moneytransfer.test; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -47,12 +46,9 @@ import static org.apache.zest.api.usecase.UsecaseBuilder.newUsecase; * Test of TransferMoneyContext */ public class TransferMoneyTest + implements AccountIds { private static SingletonAssembler assembler; - public static final String SAVINGS_ACCOUNT_ID = "SavingsAccountId"; - public static final String CHECKING_ACCOUNT_ID = "CheckingAccountId"; - public static final String CREDITOR_ID1 = "BakerAccount"; - public static final String CREDITOR_ID2 = "ButcherAccount"; private static UnitOfWorkFactory uowf; @BeforeClass @@ -64,7 +60,6 @@ public class TransferMoneyTest public void assemble( ModuleAssembly module ) throws AssemblyException { - module.withDefaultUnitOfWorkFactory(); module.entities( CheckingAccountRolemap.class, SavingsAccountRolemap.class, http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest2.java ---------------------------------------------------------------------- diff --git a/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest2.java b/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest2.java index ba1bbef..b589bd6 100644 --- a/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest2.java +++ b/samples/dci/src/test/java/org/apache/zest/dci/moneytransfer/test/TransferMoneyTest2.java @@ -21,7 +21,6 @@ package org.apache.zest.dci.moneytransfer.test; import org.apache.zest.api.unitofwork.UnitOfWorkFactory; -import org.apache.zest.bootstrap.unitofwork.DefaultUnitOfWorkAssembler; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -46,12 +45,9 @@ import static org.apache.zest.api.usecase.UsecaseBuilder.newUsecase; * Test of TransferMoneyContext */ public class TransferMoneyTest2 + implements AccountIds { private static Module module; - public static final String SAVINGS_ACCOUNT_ID = "SavingsAccountId"; - public static final String CHECKING_ACCOUNT_ID = "CheckingAccountId"; - public static final String CREDITOR_ID1 = "BakerAccount"; - public static final String CREDITOR_ID2 = "ButcherAccount"; private static UnitOfWorkFactory uowf; @BeforeClass @@ -63,7 +59,6 @@ public class TransferMoneyTest2 public void assemble( ModuleAssembly module ) throws AssemblyException { - module.withDefaultUnitOfWorkFactory(); module.entities( CheckingAccountEntity.class, SavingsAccountEntity.class, http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Forums.java ---------------------------------------------------------------------- diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Forums.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Forums.java index a67ddb3..8bd3b0f 100644 --- a/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Forums.java +++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Forums.java @@ -20,6 +20,8 @@ package org.apache.zest.sample.forum.data.entity; import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.query.Query; @@ -36,7 +38,7 @@ import static org.apache.zest.api.query.QueryExpressions.templateFor; public interface Forums extends Administrators, EntityComposite { - String FORUMS_ID = "forums"; + Identity FORUMS_ID = new StringIdentity( "forums" ); public Query<Forum> forums(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Users.java ---------------------------------------------------------------------- diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Users.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Users.java index bcc2fbf..43bf7eb 100644 --- a/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Users.java +++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/data/entity/Users.java @@ -21,6 +21,8 @@ package org.apache.zest.sample.forum.data.entity; import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityComposite; +import org.apache.zest.api.identity.Identity; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.query.Query; @@ -39,7 +41,7 @@ import static org.apache.zest.api.query.QueryExpressions.templateFor; public interface Users extends EntityComposite, Events { - String USERS_ID = "users"; + Identity USERS_ID = new StringIdentity( "users" ); Query<User> users(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/BoardResource.java ---------------------------------------------------------------------- diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/BoardResource.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/BoardResource.java index aea7991..2a19701 100644 --- a/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/BoardResource.java +++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/BoardResource.java @@ -19,6 +19,7 @@ */ package org.apache.zest.sample.forum.rest.resource.forum; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.library.rest.server.api.ContextResource; import org.apache.zest.library.rest.server.api.ObjectSelection; import org.apache.zest.library.rest.server.api.SubResources; @@ -36,7 +37,7 @@ public class BoardResource public void resource( String segment ) throws ResourceException { - selectFromManyAssociation( ObjectSelection.current().get( Forum.class ).boards(), segment ); + selectFromManyAssociation( ObjectSelection.current().get( Forum.class ).boards(), new StringIdentity( segment ) ); subResource( BoardResource.class ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumResource.java ---------------------------------------------------------------------- diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumResource.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumResource.java index ee97c13..6b60f0b 100644 --- a/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumResource.java +++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumResource.java @@ -19,6 +19,7 @@ */ package org.apache.zest.sample.forum.rest.resource.forum; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.library.rest.server.api.ContextResource; import org.apache.zest.library.rest.server.api.ObjectSelection; import org.apache.zest.library.rest.server.api.SubResources; @@ -36,7 +37,7 @@ public class ForumResource public void resource( String segment ) throws ResourceException { - selectFromManyAssociation( ObjectSelection.current().get( Forum.class ).boards(), segment ); + selectFromManyAssociation( ObjectSelection.current().get( Forum.class ).boards(), new StringIdentity( segment ) ); subResource( BoardResource.class ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumsResource.java ---------------------------------------------------------------------- diff --git a/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumsResource.java b/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumsResource.java index f2554bb..1d3bf10 100644 --- a/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumsResource.java +++ b/samples/forum/src/main/java/org/apache/zest/sample/forum/rest/resource/forum/ForumsResource.java @@ -19,6 +19,7 @@ */ package org.apache.zest.sample.forum.rest.resource.forum; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.library.rest.server.api.ContextResource; import org.apache.zest.library.rest.server.api.SubResources; import org.apache.zest.sample.forum.data.entity.Forum; @@ -35,7 +36,7 @@ public class ForumsResource public void resource( String segment ) throws ResourceException { - select( Forum.class, segment ); + select( Forum.class, new StringIdentity( segment ) ); subResource( ForumResource.class ); } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/RentalShop.java ---------------------------------------------------------------------- diff --git a/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/RentalShop.java b/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/RentalShop.java index def525e..92696ce 100644 --- a/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/RentalShop.java +++ b/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/RentalShop.java @@ -24,7 +24,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.time.Instant; import java.time.LocalDate; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -161,7 +160,7 @@ public interface RentalShop { MessageDigest md; md = MessageDigest.getInstance( "MD5" ); - md.update( instance.identity().get().getBytes() ); + md.update( instance.identity().get().toBytes() ); StringBuilder buf = new StringBuilder(); byte[] data = md.digest(); for( int i = 0; i < 4; i++ ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/dev/InitialData.java ---------------------------------------------------------------------- diff --git a/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/dev/InitialData.java b/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/dev/InitialData.java index 37ce428..e28a461 100644 --- a/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/dev/InitialData.java +++ b/samples/rental/src/main/java/org/apache/zest/sample/rental/domain/dev/InitialData.java @@ -24,6 +24,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.Random; import org.apache.zest.api.composite.TransientComposite; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.unitofwork.UnitOfWork; @@ -197,7 +198,7 @@ public interface InitialData private RentalShop createShop( UnitOfWork uow ) throws UnitOfWorkCompletionException { - return uow.newEntity( RentalShop.class, "SHOP" ); + return uow.newEntity( RentalShop.class, new StringIdentity( "SHOP" ) ); } private void createCustomers( RentalShop shop ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/rental/src/main/java/org/apache/zest/sample/rental/web/BookingPage.java ---------------------------------------------------------------------- diff --git a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/BookingPage.java b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/BookingPage.java index 85273c3..c7d22cb 100644 --- a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/BookingPage.java +++ b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/BookingPage.java @@ -20,6 +20,7 @@ package org.apache.zest.sample.rental.web; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; import org.apache.zest.api.unitofwork.UnitOfWork; @@ -51,7 +52,7 @@ public interface BookingPage Element result = dom.createElementNS( Page.XHTML, "div" ); String bookingId = context.path(); UnitOfWork uow = uowf.currentUnitOfWork(); - Booking booking = uow.get( Booking.class, bookingId ); + Booking booking = uow.get( Booking.class, new StringIdentity( bookingId ) ); Car car = booking.car().get(); createChildNode( dom, result, car.model().get() ); createChildNode( dom, result, car.licensePlate().get() ); @@ -72,7 +73,7 @@ public interface BookingPage Element result = dom.createElementNS( Page.XHTML, "div" ); String bookingId = context.path(); UnitOfWork uow = uowf.currentUnitOfWork(); - Booking booking = uow.get( Booking.class, bookingId ); + Booking booking = uow.get( Booking.class, new StringIdentity( bookingId ) ); Customer customer = booking.customer().get(); createChildNode( dom, result, customer.name().get() ); createChildNode( dom, result, customer.address().get().line1().get() ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/rental/src/main/java/org/apache/zest/sample/rental/web/MainPage.java ---------------------------------------------------------------------- diff --git a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/MainPage.java b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/MainPage.java index 3e4efee..2172a5d 100644 --- a/samples/rental/src/main/java/org/apache/zest/sample/rental/web/MainPage.java +++ b/samples/rental/src/main/java/org/apache/zest/sample/rental/web/MainPage.java @@ -23,6 +23,7 @@ package org.apache.zest.sample.rental.web; import java.text.MessageFormat; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.mixin.Mixins; @@ -58,7 +59,7 @@ public interface MainPage ArrayList<Node> nodes = new ArrayList<Node>(); Document dom = context.dom(); UnitOfWork uow = uowf.currentUnitOfWork(); - RentalShop shop = uow.get( RentalShop.class, "SHOP" ); + RentalShop shop = uow.get( RentalShop.class, new StringIdentity( "SHOP" ) ); for( Booking booking : shop.findAllBookings() ) { String plate = booking.car().get().licensePlate().get(); @@ -103,7 +104,7 @@ public interface MainPage private String createLink( Booking booking ) { String pageUrl = urlService.createLink( bookingPage ); - String entityId = booking.identity().get(); + String entityId = booking.identity().get().toString(); return pageUrl + "/" + entityId; } } http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/sql-support/src/main/java/org/apache/zest/sample/sqlsupport/Main.java ---------------------------------------------------------------------- diff --git a/samples/sql-support/src/main/java/org/apache/zest/sample/sqlsupport/Main.java b/samples/sql-support/src/main/java/org/apache/zest/sample/sqlsupport/Main.java index 087562f..c28ae99 100644 --- a/samples/sql-support/src/main/java/org/apache/zest/sample/sqlsupport/Main.java +++ b/samples/sql-support/src/main/java/org/apache/zest/sample/sqlsupport/Main.java @@ -115,8 +115,7 @@ public class Main { UnitOfWork uow = persistenceModule.unitOfWorkFactory().newUnitOfWork(); try { - SQLConfiguration config = uow.get( SQLConfiguration.class, - PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY ); + SQLConfiguration config = uow.get( SQLConfiguration.class, PostgreSQLEntityStoreAssembler.DEFAULT_ENTITYSTORE_IDENTITY ); Connection connection = persistenceModule.findService( DataSource.class ).get().getConnection(); connection.setAutoCommit( false ); connection.setReadOnly( false ); @@ -142,7 +141,7 @@ public class Main { UnitOfWork uow = persistenceModule.unitOfWorkFactory().newUnitOfWork(); try { - SQLConfiguration config = uow.get( SQLConfiguration.class, PostgreSQLIndexQueryAssembler.DEFAULT_IDENTITY ); + SQLConfiguration config = uow.get( SQLConfiguration.class, PostgreSQLIndexQueryAssembler.DEFAULT_IDENTITY ); Connection connection = persistenceModule.findService( DataSource.class ).get().getConnection(); connection.setAutoCommit( false ); connection.setReadOnly( false ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index 564e461..2f367d3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -33,7 +33,6 @@ include 'core:functional', 'libraries:invocation-cache', 'libraries:lang-groovy', 'libraries:lang-javascript', - 'libraries:lang-scala', 'libraries:jmx', 'libraries:locking', 'libraries:logging', @@ -82,8 +81,6 @@ include 'core:functional', 'extensions:valueserialization-stax', 'manual', 'samples:dci', - 'samples:dci-cargo:dcisample_a', - 'samples:dci-cargo:dcisample_b', 'samples:forum', 'samples:rental', 'samples:sql-support', http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/tests/performance/src/main/java/org/apache/zest/test/performance/entitystore/AbstractEntityStorePerformanceTest.java ---------------------------------------------------------------------- diff --git a/tests/performance/src/main/java/org/apache/zest/test/performance/entitystore/AbstractEntityStorePerformanceTest.java b/tests/performance/src/main/java/org/apache/zest/test/performance/entitystore/AbstractEntityStorePerformanceTest.java index 8507079..5fb876b 100644 --- a/tests/performance/src/main/java/org/apache/zest/test/performance/entitystore/AbstractEntityStorePerformanceTest.java +++ b/tests/performance/src/main/java/org/apache/zest/test/performance/entitystore/AbstractEntityStorePerformanceTest.java @@ -25,6 +25,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.Random; import java.util.concurrent.Callable; +import org.apache.zest.api.identity.StringIdentity; import org.apache.zest.api.service.ServiceFinder; import org.apache.zest.api.structure.Application; import org.apache.zest.api.structure.Module; @@ -242,7 +243,7 @@ public abstract class AbstractEntityStorePerformanceTest UnitOfWork uow = uowf.newUnitOfWork( newUsecase( "readEntityWithComplexType PREPARE " + bulk ) ); for( int i = 0; i < ITERATIONS; i++ ) { - ComplexProduct product = uow.newEntity( ComplexProduct.class, "product" + i ); + ComplexProduct product = uow.newEntity( ComplexProduct.class, new StringIdentity( "product" + i ) ); product.name().set( "Product " + i ); if( i % 1000 == 0 ) @@ -264,7 +265,7 @@ public abstract class AbstractEntityStorePerformanceTest String id = rnd.nextInt( ITERATIONS ) + ""; for( int i = 0; i < ITERATIONS; i++ ) { - ComplexProduct product = uow.get( ComplexProduct.class, "product" + id ); + ComplexProduct product = uow.get( ComplexProduct.class, new StringIdentity( "product" + id ) ); product.name().get(); if( i % 100 == 0 ) {
