From 3edd4cac24e3795523cb0a8c39508159f5a249ec Mon Sep 17 00:00:00 2001 From: Jacek Milewski Date: Sat, 30 Dec 2023 15:09:15 +0100 Subject: [PATCH 1/5] live-repo-start --- .../pricing/price/api/app/PriceService.java | 2 +- ...iceService_applyPercentageFactor_compTest.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java b/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java index 6cbb67a1..2b4829ec 100644 --- a/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java +++ b/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java @@ -31,7 +31,7 @@ public Either> applyPercentageFactor(String itemId, List updatedPrices = priceRepo.findByItemId(itemId).stream() .map(itemPrice -> itemPrice.applyFactor(percentageFactor(percentage, itemPrice))) - .peek(priceRepo::save) + //TODO save in repo .peek(priceUpdateService::updateReadModel) .peek(itemPrice -> eventPublisher.publish(priceChange(itemPrice))) .toList(); diff --git a/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java b/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java index df447a52..33264697 100644 --- a/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java +++ b/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java @@ -28,7 +28,7 @@ void applyPercentageFactor_returnsSingleDiscountedPrice_onValidRequest() { //then assertThat(result).hasRightValueSatisfying(itemPrices -> assertThatPrice(itemPrices.getFirst()) - .isPersistedIn(priceFixtures.itemPriceRepo, SINGULAR) + //TODO test persistence .hasPrice(90_00) .hasId(price.getId()) .hasItemId(price.getItemId()) @@ -43,7 +43,8 @@ void applyPercentageFactor_returnsSingleDiscountedPrice_onValidRequest() { @Test void applyPercentageFactor_publishesPriceChangeEvent_onPriceChange() { //given - ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").inDb(); + //TODO persist price + ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").build(); //when Either> result = priceFixtures.priceService.applyPercentageFactor("item-id", 10); @@ -57,7 +58,8 @@ void applyPercentageFactor_publishesPriceChangeEvent_onPriceChange() { @Test void applyPercentageFactor_updatesReadModel_onPriceChange() { //given - ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").inDb(); + //TODO persist price + ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").build(); //when Either> result = priceFixtures.priceService.applyPercentageFactor("item-id", 10); @@ -70,12 +72,9 @@ void applyPercentageFactor_updatesReadModel_onPriceChange() { @Test void applyPercentageFactor_returnsError_onNoPriceFound() { //when - Either> result = priceFixtures.priceService.applyPercentageFactor("not-existing-id", 10); + //TODO implement //then - assertThat(result) - .hasLeftValueSatisfying(err -> - assertThatError(err) - .isNotFound("No price entries found for requested item. itemId: not-existing-id")); + } } \ No newline at end of file From dc3b665aebc2ecbb5cd797c992dbd29affb266a5 Mon Sep 17 00:00:00 2001 From: Jacek Milewski Date: Sat, 30 Dec 2023 15:09:37 +0100 Subject: [PATCH 2/5] live-repo-done --- .../pricing/price/api/app/PriceService.java | 2 +- ...ceService_applyPercentageFactor_compTest.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java b/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java index 2b4829ec..6cbb67a1 100644 --- a/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java +++ b/services/Pricing/src/main/java/com/bottega/pricing/price/api/app/PriceService.java @@ -31,7 +31,7 @@ public Either> applyPercentageFactor(String itemId, List updatedPrices = priceRepo.findByItemId(itemId).stream() .map(itemPrice -> itemPrice.applyFactor(percentageFactor(percentage, itemPrice))) - //TODO save in repo + .peek(priceRepo::save) .peek(priceUpdateService::updateReadModel) .peek(itemPrice -> eventPublisher.publish(priceChange(itemPrice))) .toList(); diff --git a/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java b/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java index 33264697..5eed2091 100644 --- a/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java +++ b/services/Pricing/src/test/java/com/bottega/pricing/price/api/app/PriceService_applyPercentageFactor_compTest.java @@ -28,7 +28,7 @@ void applyPercentageFactor_returnsSingleDiscountedPrice_onValidRequest() { //then assertThat(result).hasRightValueSatisfying(itemPrices -> assertThatPrice(itemPrices.getFirst()) - //TODO test persistence + .isPersistedIn(priceFixtures.itemPriceRepo, SINGULAR) .hasPrice(90_00) .hasId(price.getId()) .hasItemId(price.getItemId()) @@ -42,9 +42,7 @@ void applyPercentageFactor_returnsSingleDiscountedPrice_onValidRequest() { @Test void applyPercentageFactor_publishesPriceChangeEvent_onPriceChange() { - //given - //TODO persist price - ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").build(); + ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").inDb(); //when Either> result = priceFixtures.priceService.applyPercentageFactor("item-id", 10); @@ -58,8 +56,7 @@ void applyPercentageFactor_publishesPriceChangeEvent_onPriceChange() { @Test void applyPercentageFactor_updatesReadModel_onPriceChange() { //given - //TODO persist price - ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").build(); + ItemPrice price = builders.aPrice().priceForItem(100_00, "item-id").inDb(); //when Either> result = priceFixtures.priceService.applyPercentageFactor("item-id", 10); @@ -72,9 +69,12 @@ void applyPercentageFactor_updatesReadModel_onPriceChange() { @Test void applyPercentageFactor_returnsError_onNoPriceFound() { //when - //TODO implement + Either> result = priceFixtures.priceService.applyPercentageFactor("not-existing-id", 10); //then - + assertThat(result) + .hasLeftValueSatisfying(err -> + assertThatError(err) + .isNotFound("No price entries found for requested item. itemId: not-existing-id")); } } \ No newline at end of file From 40f5502f43f2aa6c7b0fd806d0acfcc4a98e4f81 Mon Sep 17 00:00:00 2001 From: Jacek Milewski Date: Sat, 30 Dec 2023 15:15:30 +0100 Subject: [PATCH 3/5] task-repo-start --- .../com/bottega/sharedlib/infra/repo/InMemoryRepo.java | 6 ++++-- .../bottega/promoter/concert/api/app/ConcertService.java | 2 +- .../api/app/ConcertService_createConcert_compTest.java | 9 ++------- .../bottega/promoter/concert/domain/ConcertFixtures.java | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java b/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java index 7abed31b..4799033f 100644 --- a/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java +++ b/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java @@ -27,7 +27,8 @@ public Iterable saveAll(Iterable entities) { @Override public Optional findById(ID id) { - return Optional.ofNullable(database.get(id)); + //TODO implement + throw new RuntimeException("Not Implemented"); } @Override @@ -37,7 +38,8 @@ public boolean existsById(ID id) { @Override public Iterable findAll() { - return database.values(); + //TODO implement + throw new RuntimeException("Not Implemented"); } @Override diff --git a/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java b/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java index 8d65b4b4..8c551155 100644 --- a/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java +++ b/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java @@ -36,7 +36,7 @@ public Either createConcert(String title, String dateTime, } return concertFactory.createConcert(title, dateTime, promoterAgreement.promoterId()) .peek(concert -> concert.initNewConcert(tagService, categoryService)) - .map(concertRepo::save) + //TODO: save in repo .peek(concert -> eventPublisher.publish(concertCreated(concert, promoterAgreement.profitMarginPercentage()))); } diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java index 59424880..92c099cd 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java @@ -34,7 +34,6 @@ void createConcert_OK() { VavrAssertions.assertThat(result).isRight(); assertThatConcert(concertFixtures.concertRepo.findAll().iterator().next()) - .isPersistedIn(concertFixtures.concertRepo, RepoEntries.SINGULAR) .hasTitle(request.title) .hasIdAsUUID() .hasDate(TEST_TIME_PLUS_30_DAYS) @@ -44,16 +43,12 @@ void createConcert_OK() { @Test void createConcert_persistsConcert_onValidInput() { //given - PromoterAgreement promoterAgreement = builders.aPromoterAgreement().build(); - given(concertFixtures.promoterService.getPromoterAgreement(anyString())).willReturn(promoterAgreement); + //TODO test that concert is persisted in repo //when - Either result = concertFixtures.concertService.createConcert("Woodstock 2000", TEST_TIME_PLUS_30_DAYS.toString(), promoterAgreement.promoterId().asString()); //then - assertThat(result).isRight(); - assertThatConcert(result.get()) - .isPersistedIn(concertFixtures.concertRepo, RepoEntries.SINGULAR); + } @Test diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java index 999627b0..9cc9e78a 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java @@ -55,7 +55,8 @@ public static ConcertFixtures init(SharedFixtures sharedFixtures) { } private static void initInfrastructure(ConcertFixtures concertFixtures) { - concertFixtures.concertRepo = new InMemoryConcertRepo(); + //TODO initialize repo + concertFixtures.concertRepo = null; concertFixtures.categoryRepo = new InMemoryCategoryRepo(); concertFixtures.tagRepo = new InMemoryTagRepo(); } From 0dc28968b67ea98010b899d80c5f103eb79fb5a9 Mon Sep 17 00:00:00 2001 From: Jacek Milewski Date: Sat, 30 Dec 2023 15:16:36 +0100 Subject: [PATCH 4/5] task-repo-tests --- .../api/app/ConcertService_createConcert_compTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java index 92c099cd..59424880 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/api/app/ConcertService_createConcert_compTest.java @@ -34,6 +34,7 @@ void createConcert_OK() { VavrAssertions.assertThat(result).isRight(); assertThatConcert(concertFixtures.concertRepo.findAll().iterator().next()) + .isPersistedIn(concertFixtures.concertRepo, RepoEntries.SINGULAR) .hasTitle(request.title) .hasIdAsUUID() .hasDate(TEST_TIME_PLUS_30_DAYS) @@ -43,12 +44,16 @@ void createConcert_OK() { @Test void createConcert_persistsConcert_onValidInput() { //given - //TODO test that concert is persisted in repo + PromoterAgreement promoterAgreement = builders.aPromoterAgreement().build(); + given(concertFixtures.promoterService.getPromoterAgreement(anyString())).willReturn(promoterAgreement); //when + Either result = concertFixtures.concertService.createConcert("Woodstock 2000", TEST_TIME_PLUS_30_DAYS.toString(), promoterAgreement.promoterId().asString()); //then - + assertThat(result).isRight(); + assertThatConcert(result.get()) + .isPersistedIn(concertFixtures.concertRepo, RepoEntries.SINGULAR); } @Test From e6f954856d78d082b2b0b71492d414e7b10c7f03 Mon Sep 17 00:00:00 2001 From: Jacek Milewski Date: Sat, 30 Dec 2023 15:17:02 +0100 Subject: [PATCH 5/5] task-repo-done --- .../java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java | 6 ++---- .../bottega/promoter/concert/api/app/ConcertService.java | 2 +- .../bottega/promoter/concert/domain/ConcertFixtures.java | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java b/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java index 4799033f..7abed31b 100644 --- a/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java +++ b/libs/SharedLib/src/test/java/com/bottega/sharedlib/infra/repo/InMemoryRepo.java @@ -27,8 +27,7 @@ public Iterable saveAll(Iterable entities) { @Override public Optional findById(ID id) { - //TODO implement - throw new RuntimeException("Not Implemented"); + return Optional.ofNullable(database.get(id)); } @Override @@ -38,8 +37,7 @@ public boolean existsById(ID id) { @Override public Iterable findAll() { - //TODO implement - throw new RuntimeException("Not Implemented"); + return database.values(); } @Override diff --git a/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java b/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java index 8c551155..8d65b4b4 100644 --- a/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java +++ b/services/Promoter/src/main/java/com/bottega/promoter/concert/api/app/ConcertService.java @@ -36,7 +36,7 @@ public Either createConcert(String title, String dateTime, } return concertFactory.createConcert(title, dateTime, promoterAgreement.promoterId()) .peek(concert -> concert.initNewConcert(tagService, categoryService)) - //TODO: save in repo + .map(concertRepo::save) .peek(concert -> eventPublisher.publish(concertCreated(concert, promoterAgreement.profitMarginPercentage()))); } diff --git a/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java b/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java index 9cc9e78a..999627b0 100644 --- a/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java +++ b/services/Promoter/src/test/java/com/bottega/promoter/concert/domain/ConcertFixtures.java @@ -55,8 +55,7 @@ public static ConcertFixtures init(SharedFixtures sharedFixtures) { } private static void initInfrastructure(ConcertFixtures concertFixtures) { - //TODO initialize repo - concertFixtures.concertRepo = null; + concertFixtures.concertRepo = new InMemoryConcertRepo(); concertFixtures.categoryRepo = new InMemoryCategoryRepo(); concertFixtures.tagRepo = new InMemoryTagRepo(); }