Two domains that need to communicate together.
We represent each domain in an hexagon in order to isolate them.
Implement the communication between two domains that are in the same deployment unit (modular monolith).
We want to verify the format of the business partner code.
There can be multiple reasons to have multiple hexagons:
- In the near future, we will have to implement more controls regarding business partners
- Dedicated team will be in charge of the 2nd hexagon
- 2nd hexagon will be replaced by an external system
- 2nd hexagon will be deployed as dedicated unit (a micro-service usable by other projects)
For now the format we want to check is:
- total length is 20 characters
- example: 'FIHEL-partner 496871'
At the end of the kata you will be able to check your code by using this URL in a browser:
http://localhost:8080/booking/create/{businessPartnerCode}
It should create with a booking with a quantity of 1 and return the sum of all the quantities
- Create
businesspartner
package (new package for booking management)
- Create the
businesspartner.port.in
package - Create the
ForCheckingBusinessPartnerCode
interface - Add the method
boolean isValid(String code)
- Create the
BusinessPartnerVerifier
class in thebusinesspartner
package - Annotate this class with the
@Service
annotation - Add the
implements ForCheckingBusinessPartnerCode
toBusinessPartnerVerifier
- Implement the method with a fake body
- Create the
BusinessPartnerVerifierTest
- Create test methods (case true/false)
- Implement the rule in the
BusinessPartnerVerifier
class BusinessPartnerVerifierTest {
private BusinessPartnerVerifier businessPartnerVerifier = new BusinessPartnerVerifier();
@Test
void isValid_returnsTrue_whenCodeIs20CharactersLong() {
boolean result = businessPartnerVerifier.isValid("12345678901234567890");
assertThat(result).isTrue();
}
@Test
void isValid_returnsFalse_whenCodeIs5CharactersLong() {
boolean result = businessPartnerVerifier.isValid("12345");
assertThat(result).isFalse();
}
}
- Create the
ForVerifyingBusinessPartner
interface in thebooking.port.out
package - Add the method
boolean validate(String code)
- Inject the
ForVerifyingBusinessPartner
in theBookingManager
- Add the call of the method
validate()
in theBookingManager
and do not create booking if false - In
BookingManagerTest
fix the compilation problem by creating a fakeForVerifyingBusinessPartner
implementation that always returns true - In
BookingRestController
inject theForVerifyingBusinessPartner
using constructor injection
- Create the
InMemoryBusinessPartnerVerifier
class - Add the
implements ForVerifyingBusinessPartner
toInMemoryBusinessPartnerVerifier
- Override the method (with an empty body)
- Add the
@Repository
annotation to the class
- Create
businesspartner.adapter.in
package - Create the
ProvideBusinessPartnerVerifier
class - Inject
ForCheckingBusinessPartnerCode
toProvideBusinessPartnerVerifier
- Create a
public boolean validate(String code)
method - Call the validate method from
ForCheckingBusinessPartnerCode
- Add the
@Component
annotation to the class
Possible implementations:
- Point to point:
out
knowsin
- Direct in memory
- Publish / subscribe:
out
publishes,in
subscribes- Inversion of Dependency
In adapter out
, inject the adapter in
.
In adapter out
create a new interface and implement it the adapter in
Inject the new interface in the InMemoryBusinessPartnerVerifier
using Spring