Skip to content

Commit f415534

Browse files
committed
configs
1 parent cfbb53e commit f415534

File tree

5 files changed

+86
-0
lines changed

5 files changed

+86
-0
lines changed

packages/Ecotone/src/Messaging/Config/MessagingSystemConfiguration.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,19 @@ public function process(ContainerBuilder $builder): void
881881
$this->afterCallMethodInterceptors,
882882
);
883883

884+
foreach ($this->gatewayBuilders as $gatewayBuilder) {
885+
if (!isset($this->channelBuilders[$gatewayBuilder->getRequestChannelName()])) {
886+
throw ConfigurationException::create("Gateway {$gatewayBuilder->getInterfaceName()}:{$gatewayBuilder->getRelatedMethodName()} has not existing request channel {$gatewayBuilder->getRequestChannelName()}. Have you forgot to declare some Message Handler for it?");
887+
}
888+
}
889+
foreach ($this->messageHandlerBuilders as $messageHandlerBuilder) {
890+
if ($messageHandlerBuilder instanceof MessageHandlerBuilderWithOutputChannel) {
891+
if (!$this->isChannelDefinedFor($messageHandlerBuilder)) {
892+
throw ConfigurationException::create("Message handler {$messageHandlerBuilder} has not existing output channel {$messageHandlerBuilder->getInputMessageChannelName()}. Have you forgot to declare some Message Handler for it?");
893+
}
894+
}
895+
}
896+
884897
foreach ($this->serviceDefinitions as $id => $definition) {
885898
$messagingBuilder->register($id, $definition);
886899
}
@@ -1074,4 +1087,26 @@ private function getMessageHandlersBasedOnPriority(): array
10741087

10751088
return $messageHandlerBuildersAccordinglyToPriority;
10761089
}
1090+
1091+
public function isChannelDefinedFor(MessageHandlerBuilderWithOutputChannel|MessageHandlerBuilder $messageHandlerBuilder): bool
1092+
{
1093+
if (!$messageHandlerBuilder->getOutputMessageChannelName()) {
1094+
return true;
1095+
}
1096+
1097+
if (isset($this->channelBuilders[$messageHandlerBuilder->getOutputMessageChannelName()])) {
1098+
return true;
1099+
}
1100+
1101+
foreach ($this->messageHandlerBuilders as $comparableHandler) {
1102+
if (
1103+
$comparableHandler->getInputMessageChannelName() === $messageHandlerBuilder->getOutputMessageChannelName()
1104+
&& $comparableHandler->getEndpointId() !== $messageHandlerBuilder->getEndpointId()
1105+
) {
1106+
return true;
1107+
}
1108+
}
1109+
1110+
return false;
1111+
}
10771112
}

packages/Ecotone/src/Messaging/Handler/Gateway/GatewayProxyBuilder.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ public function registerProxy(MessagingContainerBuilder $builder): Reference
281281
return new Reference($this->getReferenceName());
282282
}
283283

284+
public function getRequestChannelName(): string
285+
{
286+
return $this->requestChannelName;
287+
}
288+
284289
public function compile(MessagingContainerBuilder $builder): Definition
285290
{
286291
$interfaceToCallReference = new InterfaceToCallReference($this->interfaceName, $this->methodName);

packages/Ecotone/tests/Lite/EcotoneLiteTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
use Ecotone\Lite\EcotoneLite;
66
use Ecotone\Lite\Test\TestConfiguration;
77
use Ecotone\Messaging\Channel\SimpleMessageChannelBuilder;
8+
use Ecotone\Messaging\Config\ConfigurationException;
89
use Ecotone\Messaging\Config\ConsoleCommandResultSet;
910
use Ecotone\Messaging\Config\ModulePackageList;
1011
use Ecotone\Messaging\Config\ServiceConfiguration;
1112
use PHPUnit\Framework\TestCase;
13+
use Test\Ecotone\Messaging\Fixture\Handler\Gateway\MultipleMethodsGatewayExample;
1214
use Test\Ecotone\Modelling\Fixture\Order\ChannelConfiguration;
1315
use Test\Ecotone\Modelling\Fixture\Order\OrderService;
1416

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test\Ecotone\Messaging\Fixture\InterceptedBridge;
6+
7+
use Ecotone\Messaging\Attribute\Interceptor\Around;
8+
use Ecotone\Messaging\Attribute\ServiceActivator;
9+
use Ecotone\Messaging\Handler\Processor\MethodInvoker\MethodInvocation;
10+
11+
/**
12+
* licence Apache-2.0
13+
*/
14+
final class BridgeExampleIncomplete
15+
{
16+
#[ServiceActivator('bridgeExample', outputChannelName: 'bridgeSum')]
17+
public function result(int $result): int
18+
{
19+
return $result;
20+
}
21+
}

packages/Ecotone/tests/Messaging/Unit/Config/MessagingSystemConfigurationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@
5656
use Test\Ecotone\Messaging\Fixture\Endpoint\ConsumerContinuouslyWorkingService;
5757
use Test\Ecotone\Messaging\Fixture\Handler\DumbMessageHandlerBuilder;
5858
use Test\Ecotone\Messaging\Fixture\Handler\ExceptionMessageHandler;
59+
use Test\Ecotone\Messaging\Fixture\Handler\Gateway\MultipleMethodsGatewayExample;
5960
use Test\Ecotone\Messaging\Fixture\Handler\NoReturnMessageHandler;
6061
use Test\Ecotone\Messaging\Fixture\Handler\Processor\Interceptor\CallWithAnnotationFromMethodInterceptorExample;
6162
use Test\Ecotone\Messaging\Fixture\Handler\Processor\StubCallSavingService;
63+
use Test\Ecotone\Messaging\Fixture\InterceptedBridge\BridgeExample;
64+
use Test\Ecotone\Messaging\Fixture\InterceptedBridge\BridgeExampleIncomplete;
6265
use Test\Ecotone\Messaging\Fixture\SameChannelAndRouting\SomeTestCommandHandler;
6366
use Test\Ecotone\Messaging\Fixture\SameChannelAndRouting\SomeTestEventHandler;
6467
use Test\Ecotone\Messaging\Fixture\Service\CalculatingService;
@@ -2169,4 +2172,24 @@ public function test_throwing_exception_if_registered_event_handler_with_same_ro
21692172
])
21702173
);
21712174
}
2175+
2176+
public function test_throwing_exception_on_lacking_request_channel_for_gateway(): void
2177+
{
2178+
$this->expectException(ConfigurationException::class);
2179+
2180+
EcotoneLite::bootstrapFlowTesting(
2181+
[MultipleMethodsGatewayExample::class],
2182+
[],
2183+
);
2184+
}
2185+
2186+
public function test_throwing_exception_on_lacking_output_channel_for_endpoint(): void
2187+
{
2188+
$this->expectException(ConfigurationException::class);
2189+
2190+
EcotoneLite::bootstrapFlowTesting(
2191+
[BridgeExampleIncomplete::class],
2192+
[],
2193+
);
2194+
}
21722195
}

0 commit comments

Comments
 (0)