Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

III-1686: Projection of organizer labels has recently changed, so det… #6

Merged
merged 4 commits into from
Dec 9, 2016
Merged
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
3 changes: 2 additions & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CultuurNet\UDB3\EventSourcing\ExecutionContextMetadataEnricher;
use CultuurNet\UDB3\LabelCollection;
use CultuurNet\UDB3\SimpleEventBus;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\StaticallyConfiguredSagaNamespacedEventsMetadataFactory;
use CultuurNet\UDB3\UiTPASService\Permissions\DefaultEventPermission;
use CultuurNet\UDB3\UiTPASService\Permissions\UDB3EventPermission;
use CultuurNet\UDB3\UiTPASService\Sync\SyncCommandHandler;
Expand Down Expand Up @@ -469,7 +470,7 @@ function (Application $app) {
$app['saga_repository'],
new Broadway\UuidGenerator\Rfc4122\Version4Generator()
),
new \Broadway\Saga\Metadata\StaticallyConfiguredSagaMetadataFactory(),
new StaticallyConfiguredSagaNamespacedEventsMetadataFactory(),
new EventDispatcher()
);
}
Expand Down
46 changes: 46 additions & 0 deletions src/Broadway/Saga/NamespacedEventsMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Broadway\Saga;

use Broadway\Saga\MetadataInterface;

/**
* Copied from Broadway\Saga\Metadata\Metadata and modified to work with
* namespaced event names.
*/
class NamespacedEventsMetadata implements MetadataInterface
{
private $criteria;

/**
* @param array $criteria
*/
public function __construct($criteria)
{
$this->criteria = $criteria;
}

/**
* {@inheritDoc}
*/
public function handles($event)
{
$eventName = get_class($event);

return isset($this->criteria[$eventName]);
}

/**
* {@inheritDoc}
*/
public function criteria($event)
{
$eventName = get_class($event);

if (! isset($this->criteria[$eventName])) {
throw new \RuntimeException(sprintf("No criteria for event '%s'.", $eventName));
}

return $this->criteria[$eventName]($event);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace CultuurNet\UDB3\UiTPASService\Broadway\Saga;

use Broadway\Saga\Metadata\MetadataFactoryInterface;
use Broadway\Saga\Metadata\StaticallyConfiguredSagaInterface;

/**
* Copied from Broadway\Saga\Metadata\StaticallyConfiguredSagaMetadataFactory
* and modified to return an instance of NamespacedEventsMetadata.
*/
class StaticallyConfiguredSagaNamespacedEventsMetadataFactory implements MetadataFactoryInterface
{
/**
* {@inheritDoc}
*/
public function create($saga)
{
if (!($saga instanceof StaticallyConfiguredSagaInterface)) {
throw new \RuntimeException(
sprintf('Provided saga of class %s must implement %s', $saga, StaticallyConfiguredSagaInterface::class)
);
}

$criteria = $saga::configuration();

return new NamespacedEventsMetadata($criteria);
}
}
2 changes: 1 addition & 1 deletion src/Specification/IsUiTPASOrganizerAccordingToJSONLD.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function isSatisfiedBy($organizerId)
$uitpasLabelsPresentOnOrganizer = array_filter(
$organizerLabels,
function ($label) {
$label = new Label($label->name);
$label = new Label($label);
return $this->uitpasLabels->contains($label);
}
);
Expand Down
18 changes: 9 additions & 9 deletions src/UiTPASEventSaga.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ public static function configuration()
};

return [
'EventCreated' => $initialEventCallback,
'EventImportedFromUDB2' => $initialEventCallback,
'EventUpdatedFromUDB2' => $updateFromUdb2Callback,
'OrganizerUpdated' => $offerEventCallback,
'OrganizerDeleted' => $offerEventCallback,
'PriceInfoUpdated' => $offerEventCallback,
'UiTPASAggregateCreated' => $uitpasAggregateEventCallback,
'DistributionKeysUpdated' => $uitpasAggregateEventCallback,
'DistributionKeysCleared' => $uitpasAggregateEventCallback,
EventCreated::class => $initialEventCallback,
EventImportedFromUDB2::class => $initialEventCallback,
EventUpdatedFromUDB2::class => $updateFromUdb2Callback,
OrganizerUpdated::class => $offerEventCallback,
OrganizerDeleted::class => $offerEventCallback,
PriceInfoUpdated::class => $offerEventCallback,
UiTPASAggregateCreated::class => $uitpasAggregateEventCallback,
DistributionKeysUpdated::class => $uitpasAggregateEventCallback,
DistributionKeysCleared::class => $uitpasAggregateEventCallback,
];
}

Expand Down
50 changes: 10 additions & 40 deletions tests/Specification/IsUiTPASOrganizerAccordingToJSONLDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,12 @@ public function it_returns_true_for_organizers_with_an_exact_uitpas_label_match(
$expectedLabelLogContext = $expectedLogContext + [
'uitpas_labels' => $this->uitpasLabels->asArray(),
'extracted_organizer_labels' => [
(object) [
'uuid' => '71945e50-2158-4922-94d2-fd1da6286b51',
'name' => 'foo',
],
(object) [
'uuid' => '12dabcf9-9598-4e8d-8642-c1af42698875',
'name' => 'UiTPAS',
],
(object) [
'uuid' => '9fac1824-8c65-4d0e-845f-9bef03fa05a1',
'name' => 'bar',
],
'foo',
'UiTPAS',
'bar',
],
'organizer_uitpas_labels' => [
(object) [
'uuid' => '12dabcf9-9598-4e8d-8642-c1af42698875',
'name' => 'UiTPAS',
],
'UiTPAS',
],
];

Expand Down Expand Up @@ -175,24 +163,12 @@ public function it_returns_true_for_organizers_with_a_case_insensitive_uitpas_la
$expectedLabelLogContext = $expectedLogContext + [
'uitpas_labels' => $this->uitpasLabels->asArray(),
'extracted_organizer_labels' => [
(object) [
'uuid' => '71945e50-2158-4922-94d2-fd1da6286b51',
'name' => 'foo',
],
(object) [
'uuid' => '12dabcf9-9598-4e8d-8642-c1af42698875',
'name' => 'uitpas',
],
(object) [
'uuid' => '9fac1824-8c65-4d0e-845f-9bef03fa05a1',
'name' => 'bar',
],
'foo',
'uitpas',
'bar',
],
'organizer_uitpas_labels' => [
(object) [
'uuid' => '12dabcf9-9598-4e8d-8642-c1af42698875',
'name' => 'uitpas',
],
'uitpas',
],
];

Expand Down Expand Up @@ -220,14 +196,8 @@ public function it_returns_false_for_organizers_without_uitpas_label()
$expectedLabelLogContext = $expectedLogContext + [
'uitpas_labels' => $this->uitpasLabels->asArray(),
'extracted_organizer_labels' => [
(object) [
'uuid' => '71945e50-2158-4922-94d2-fd1da6286b51',
'name' => 'foo',
],
(object) [
'uuid' => '9fac1824-8c65-4d0e-845f-9bef03fa05a1',
'name' => 'bar',
],
'foo',
'bar',
],
'organizer_uitpas_labels' => [],
];
Expand Down
15 changes: 3 additions & 12 deletions tests/Specification/samples/organizer-with-lowercase-uitpas-label
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
{
"@id": "http://example.com/organizers/dba1c53d-582c-4081-a78c-b4848f9e3653",
"labels": [
{
"uuid": "71945e50-2158-4922-94d2-fd1da6286b51",
"name": "foo"
},
{
"uuid": "12dabcf9-9598-4e8d-8642-c1af42698875",
"name": "uitpas"
},
{
"uuid": "9fac1824-8c65-4d0e-845f-9bef03fa05a1",
"name": "bar"
}
"foo",
"uitpas",
"bar"
]
}
10 changes: 2 additions & 8 deletions tests/Specification/samples/organizer-with-syntax-error
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"@id": "http://example.com/organizers/dba1c53d-582c-4081-a78c-b4848f9e3653",
"labels": [
{
"uuid": "71945e50-2158-4922-94d2-fd1da6286b51",
"name": "foo"
},
{
"uuid": "12dabcf9-9598-4e8d-8642-c1af42698875",
"name": "uitpas"
},
"foo",
"uitpas",
15 changes: 3 additions & 12 deletions tests/Specification/samples/organizer-with-uitpas-label
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
{
"@id": "http://example.com/organizers/dba1c53d-582c-4081-a78c-b4848f9e3653",
"labels": [
{
"uuid": "71945e50-2158-4922-94d2-fd1da6286b51",
"name": "foo"
},
{
"uuid": "12dabcf9-9598-4e8d-8642-c1af42698875",
"name": "UiTPAS"
},
{
"uuid": "9fac1824-8c65-4d0e-845f-9bef03fa05a1",
"name": "bar"
}
"foo",
"UiTPAS",
"bar"
]
}
10 changes: 2 additions & 8 deletions tests/Specification/samples/organizer-without-uitpas-label
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
{
"@id": "http://example.com/organizers/dba1c53d-582c-4081-a78c-b4848f9e3653",
"labels": [
{
"uuid": "71945e50-2158-4922-94d2-fd1da6286b51",
"name": "foo"
},
{
"uuid": "9fac1824-8c65-4d0e-845f-9bef03fa05a1",
"name": "bar"
}
"foo",
"bar"
]
}
5 changes: 2 additions & 3 deletions tests/UiTPASEventSagaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Broadway\CommandHandling\CommandBusInterface;
use Broadway\CommandHandling\Testing\TraceableCommandBus;
use Broadway\EventDispatcher\EventDispatcher;
use Broadway\Saga\Metadata\StaticallyConfiguredSagaMetadataFactory;
use Broadway\Saga\MultipleSagaManager;
use Broadway\Saga\State\InMemoryRepository;
use Broadway\Saga\State\StateManager;
Expand All @@ -25,13 +24,13 @@
use CultuurNet\UDB3\Event\Events\OrganizerUpdated;
use CultuurNet\UDB3\Event\Events\PriceInfoUpdated;
use CultuurNet\UDB3\Event\EventType;
use CultuurNet\UDB3\EventXmlString;
use CultuurNet\UDB3\Location\Location;
use CultuurNet\UDB3\PriceInfo\BasePrice;
use CultuurNet\UDB3\PriceInfo\Price;
use CultuurNet\UDB3\PriceInfo\PriceInfo;
use CultuurNet\UDB3\PriceInfo\Tariff;
use CultuurNet\UDB3\Title;
use CultuurNet\UDB3\UiTPASService\Broadway\Saga\StaticallyConfiguredSagaNamespacedEventsMetadataFactory;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\ClearDistributionKeys;
use CultuurNet\UDB3\UiTPASService\UiTPASAggregate\Command\CreateUiTPASAggregate;
use CultuurNet\UDB3\UiTPASService\Sync\Command\RegisterUiTPASEvent;
Expand Down Expand Up @@ -183,7 +182,7 @@ protected function createScenario()
$sagaStateRepository,
[$saga],
new StateManager($sagaStateRepository, new Version4Generator()),
new StaticallyConfiguredSagaMetadataFactory(),
new StaticallyConfiguredSagaNamespacedEventsMetadataFactory(),
new EventDispatcher()
);
return new Scenario($this, $sagaManager, $traceableCommandBus);
Expand Down