Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:
- php: 7.3

env:
- SYMFONY_VERSION=2.8.* SYMFONY_PHPUNIT_VERSION=6.5
- SYMFONY_VERSION=2.8.* SYMFONY_PHPUNIT_VERSION=6.5 COMPOSER_ROOT_VERSION=v1.26.0

before_install:
- phpenv config-add travis/z_php.ini
Expand Down
2 changes: 1 addition & 1 deletion Core/Handlers/MessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private function addCommonErrorHeadersToEnvelope(ErrorExchangeEnvelope $envelope
$envelope->setHeader(RetryExchangeEnvelope::HEADER_LAST_RETRY_AT, round(microtime(true) * 1000));
}

$envelope->setHeader(ErrorExchangeEnvelope::HEADER_CREATED_AT, round(microtime(true) * 1000));
$envelope->setHeader(ErrorExchangeEnvelope::HEADER_CREATED_AT, \round(\microtime(true) * 1000));
$envelope->setHeader(ErrorExchangeEnvelope::HEADER_ERROR_MESSAGE, $errorDescription);
$envelope->setHeader(ErrorExchangeEnvelope::HEADER_ERROR_PROCESSOR_ID, $processor->getId());
$envelope->setHeader(ErrorExchangeEnvelope::HEADER_ERROR_PROCESSOR_DESCRIPTION, $processor->getDescription());
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/default_configured_consumers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ smartbox_integration_framework:
description: A Generic Consumer for csv files
calls:
- [ setId, ['smartesb.consumers.generic_csv']]
- [setConfigurableStepsProvider,[@smartesb.steps_provider.csv_file]]
- [setConfigurableStepsProvider,['@smartesb.steps_provider.csv_file']]

options:
stop_on_eof: true
Expand All @@ -22,9 +22,9 @@ smartbox_integration_framework:
query_steps:
- read_lines:
result_name: processed_lines
max_lines: eval: options['batch_size']
max_lines: "eval: options['batch_size']"

query_result:
lines: eval: results['processed_lines']
lines: "eval: results['processed_lines']"

on_consume: ~
4 changes: 2 additions & 2 deletions Resources/config/default_configured_producers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ smartbox_integration_framework:
class: "%smartesb.producers.csv.class%"
description: Producer to write out csv files
calls:
- [ setId, ['smartesb.producers.generic_csv']]
- [ setId, ["smartesb.producers.generic_csv"]]
- [setConfigurableStepsProvider,["@smartesb.steps_provider.csv_file"]]

options:
Expand All @@ -22,5 +22,5 @@ smartbox_integration_framework:
description: Append lines to the csv file
steps:
- append_lines:
rows: eval: body['lines']
rows: "eval: body['lines']"
response: []
2 changes: 1 addition & 1 deletion Resources/config/default_routing_itineraries.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
auto_generated_routes:
resource: @smartesb.map.itineraries
resource: '@smartesb.map.itineraries'
type: itineraries
1 change: 1 addition & 0 deletions SmartboxIntegrationFrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Smartbox\Integration\FrameworkBundle\DependencyInjection\CompilerPasses\EventDeferringCompilerPass;
use Smartbox\Integration\FrameworkBundle\DependencyInjection\CompilerPasses\MockWebserviceClientsCompilerPass;
use Smartbox\Integration\FrameworkBundle\DependencyInjection\CompilerPasses\SmokeTestCleaningPass;
use Smartbox\Integration\FrameworkBundle\DependencyInjection\CompilerPasses\SmokeTestConnectivityCompilerPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
2 changes: 2 additions & 0 deletions Tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public function registerBundles()
new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new \JMS\SerializerBundle\JMSSerializerBundle(),
new \BeSimple\SoapBundle\BeSimpleSoapBundle(),
new \Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),

new \Smartbox\CoreBundle\SmartboxCoreBundle(),
new \Smartbox\Integration\FrameworkBundle\SmartboxIntegrationFrameworkBundle(),
new \Smartbox\Integration\CamelConfigBundle\SmartboxIntegrationCamelConfigBundle(),
];
}

Expand Down
42 changes: 42 additions & 0 deletions Tests/App/Entity/EntityX.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Smartbox\Integration\FrameworkBundle\Tests\App\Entity;

use JMS\Serializer\Annotation as JMS;
use Smartbox\CoreBundle\Type\Entity;

/**
* Class EntityX.
*/
class EntityX extends Entity
{
public function __construct($x = 0)
{
$this->x = $x;
}

/**
* @JMS\Type("integer")
* @JMS\Expose
* @JMS\Groups({"logs"})
*
* @var int
*/
protected $x = 0;

/**
* @return int
*/
public function getX()
{
return $this->x;
}

/**
* @param int $x
*/
public function setX($x)
{
$this->x = $x;
}
}
88 changes: 88 additions & 0 deletions Tests/App/Producers/ErrorTriggerProducer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Smartbox\Integration\FrameworkBundle\Tests\App\Producers;

use JMS\Serializer\Annotation as JMS;
use Smartbox\Integration\FrameworkBundle\Tests\App\Entity\EntityX;
use Smartbox\Integration\FrameworkBundle\Configurability\ConfigurableInterface;
use Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointInterface;
use Smartbox\Integration\FrameworkBundle\Core\Exchange;
use Smartbox\Integration\FrameworkBundle\Core\Producers\Producer;
use Smartbox\Integration\FrameworkBundle\Core\Protocols\Protocol;
use Smartbox\Integration\FrameworkBundle\Tests\Fixtures\Exceptions\SampleRecoverableException;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Class ErrorTriggerProducer.
*/
class ErrorTriggerProducer extends Producer implements ConfigurableInterface
{
/**
* @JMS\Exclude
*
* @var array
*/
public static $count = 0;

const OPTION_RECOVERABLE = 'recoverable';
const OPTION_FORCE = 'force';
const OPTION_NUMBER_ERRORS = 'nb_errors';

/**
* Sends an exchange to the producer.
*
* @param \Smartbox\Integration\FrameworkBundle\Core\Exchange $ex
*
* @throws \Exception
*/
public function send(Exchange $ex, EndpointInterface $endpoint)
{
$options = $endpoint->getOptions();

if (self::$count < @$options[self::OPTION_NUMBER_ERRORS] || @$options[self::OPTION_FORCE]) {
$ex->getIn()->setBody(new EntityX(666));
++self::$count;

if (@$options[self::OPTION_RECOVERABLE]) {
throw new SampleRecoverableException('test recoverable exception');
}

throw new \RuntimeException('test exception');
}
}

/**
* Key-Value array with the option name as key and the details as value.
*
* [OptionName => [description, array of valid values],..]
*
* @return array
*/
public function getOptionsDescriptions()
{
$options = [
self::OPTION_RECOVERABLE => ['Whether the errors triggered are recoverable or not', []],
self::OPTION_FORCE => ['Force to throw the exception every time, not only "n" number of times', []],
self::OPTION_NUMBER_ERRORS => ['Define the number of times the exception will be throw', []]
];

return $options;
}

/**
* With this method this class can configure an OptionsResolver that will be used to validate the options.
*
* @param OptionsResolver $resolver
*
* @return mixed
*/
public function configureOptionsResolver(OptionsResolver $resolver)
{
$resolver->setRequired(self::OPTION_RECOVERABLE);
$resolver->setDefault(Protocol::OPTION_EXCHANGE_PATTERN, Protocol::EXCHANGE_PATTERN_IN_ONLY);
$resolver->setDefault(self::OPTION_RECOVERABLE, false);
$resolver->setDefault(self::OPTION_FORCE, false);
$resolver->setAllowedValues(Protocol::OPTION_EXCHANGE_PATTERN, [Protocol::EXCHANGE_PATTERN_IN_ONLY]);
$resolver->setDefault(self::OPTION_NUMBER_ERRORS, 1);
}
}
93 changes: 93 additions & 0 deletions Tests/App/Producers/HelperProducer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Smartbox\Integration\FrameworkBundle\Tests\App\Producers;

use Smartbox\Integration\FrameworkBundle\Tests\App\Entity\EntityX;
use Smartbox\Integration\FrameworkBundle\Configurability\ConfigurableInterface;
use Smartbox\Integration\FrameworkBundle\Core\Endpoints\EndpointInterface;
use Smartbox\Integration\FrameworkBundle\Core\Exchange;
use Smartbox\Integration\FrameworkBundle\Core\Producers\Producer;
use Smartbox\Integration\FrameworkBundle\Core\Producers\ProducerInterface;
use Smartbox\Integration\FrameworkBundle\Core\Protocols\Protocol;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Class HelperProducer.
*/
class HelperProducer extends Producer implements ProducerInterface, ConfigurableInterface
{
const OPTION_OPERATION = 'operation';
const OPTION_OPERAND = 'operand';

const OPERATION_MULTIPLY = 'multiply';
const OPERATION_ADD = 'add';

/**
* Sends an exchange to the producer.
*
* @param Exchange $ex
*
* @throws \Exception
*/
public function send(Exchange $ex, EndpointInterface $endpoint)
{
$options = $endpoint->getOptions();

/** @var EntityX $x */
$x = $ex->getIn()->getBody();
if (empty($x) || !($x instanceof EntityX)) {
throw new \InvalidArgumentException('Expected entity of type EntityX');
}

$operand = (int) @$options[self::OPTION_OPERAND];

switch (@$options[self::OPTION_OPERATION]) {
case self::OPERATION_MULTIPLY:
$message = $this->messageFactory->createMessage(new EntityX($x->getX() * $operand));
$ex->setOut($message);
break;
case self::OPERATION_ADD:
$message = $this->messageFactory->createMessage(new EntityX($x->getX() + $operand));
$ex->setOut($message);
break;
}
}

/**
* Key-Value array with the option name as key and the details as value.
*
* [OptionName => [description, array of valid values],..]
*
* @return array
*/
public function getOptionsDescriptions()
{
$options = [
self::OPTION_OPERATION => ['Operation to apply to the EntityX in the body of the incoming messages', [
self::OPERATION_ADD => 'Adds <comment>operand</comment> to the entityX value',
self::OPERATION_MULTIPLY => 'Multiplies <comment>operand</comment> by the entityX value',
]],
self::OPTION_OPERAND => ['Operand to use (number)', []],
];

return $options;
}

/**
* With this method this class can configure an OptionsResolver that will be used to validate the options.
*
* @param OptionsResolver $resolver
*
* @return mixed
*/
public function configureOptionsResolver(OptionsResolver $resolver)
{
$resolver->setRequired(self::OPTION_OPERATION);
$resolver->setAllowedValues(self::OPTION_OPERATION, [self::OPERATION_ADD, self::OPERATION_MULTIPLY]);

$resolver->setRequired(self::OPTION_OPERAND);
$resolver->setAllowedTypes(self::OPTION_OPERAND, ['numeric']);

$resolver->setDefault(Protocol::OPTION_EXCHANGE_PATTERN, Protocol::EXCHANGE_PATTERN_IN_OUT);
}
}
Loading