Skip to content

Commit

Permalink
Implement #69
Browse files Browse the repository at this point in the history
  • Loading branch information
LabordePierre committed Jan 26, 2023
1 parent 63f158b commit b7ecf0f
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 65 deletions.
2 changes: 0 additions & 2 deletions Molecule-Examples/MolMyAlarmComponentImpl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ MolMyAlarmComponentImpl >> componentInitialize [
time := Time hour: 7 minute: 30 second: 0.
bell := 'Ring ring'.
activate := false.

self forEvents: MolMyLocalTimeEvents useProducer: #default.
]

{ #category : #'life cycle' }
Expand Down
3 changes: 0 additions & 3 deletions Molecule-Examples/MolMyClockComponentImpl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ MolMyClockComponentImpl >> componentInitialize [
useManualTime := false.
timeZone := TimeZone local.
delta := Time hour: 0 minute: 0 second: 0.

self forServices: MolMyServerTimeServices useProvider: #default.
self forEvents: MolMyGlobalTimeEvents useProducer: #default.
]

{ #category : #'life cycle' }
Expand Down
34 changes: 17 additions & 17 deletions Molecule-Tests/MolComponentImplTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ MolComponentImplTest >> testAugmentedClassToAComponentProperties [

"Component name"
self assert: component componentName equals: nil.
component componentName: #default.
self assert: component componentName equals: #default.
component componentName: MolUtils defaultComponentName.
self assert: component componentName equals: MolUtils defaultComponentName.

"Component connector, just test if accessors exists because componentConnector is managed on component instanciation"
self assert: component componentConnector equals: nil.
Expand Down Expand Up @@ -153,17 +153,17 @@ MolComponentImplTest >> testEventsSubscribers [

"Test initial events producer contents : default component name"
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #default.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: MolUtils defaultComponentName.

MolUtils activateComponent: MolCompleteComponentImpl named: #myComponentA.

self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #default.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: MolUtils defaultComponentName.

MolUtils passivateComponent: MolCompleteComponentImpl named: #myComponentA.

self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #default.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: MolUtils defaultComponentName.

MolUtils removeComponent: MolCompleteComponentImpl named: #myComponentA.

Expand Down Expand Up @@ -201,7 +201,7 @@ MolComponentImplTest >> testForEventsAddProducer [
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #(#default #producerA #producerB).

component forEvents: MolUsedEvents addProducer: #default.
component forEvents: MolUsedEvents addProducer: MolUtils defaultComponentName.
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #(#default #producerA #producerB).
]
Expand All @@ -216,7 +216,7 @@ MolComponentImplTest >> testForEventsRemoveAllProducers [

component forEvents: MolUsedEvents removeAllProducers: #(#producerA #producerB #producerC #producerD #producerE #producerF).
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #default.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: MolUtils defaultComponentName.

component forEvents: MolUsedEvents addAllProducers: #(#producerA #producerB #producerC).
component forEvents: MolUsedEvents removeAllProducers: #(#producerA).
Expand Down Expand Up @@ -256,7 +256,7 @@ MolComponentImplTest >> testForEventsRemoveProducer2 [
| component |
component := MolCompleteComponentImpl start: #myComponentA.

component forEvents: MolUsedEvents removeProducer: #default.
component forEvents: MolUsedEvents removeProducer: MolUtils defaultComponentName.
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: nil.
]
Expand Down Expand Up @@ -307,9 +307,9 @@ MolComponentImplTest >> testForEventsUseProducer [
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: nil.

component forEvents: MolUsedEvents useProducer: #default.
component forEvents: MolUsedEvents useProducer: MolUtils defaultComponentName.
self assert: component eventsSubscribers size equals: 1.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: #default.
self assert: (component eventsSubscribers at: MolUsedEvents) equals: MolUtils defaultComponentName.
]

{ #category : #'test - connecting - events producers' }
Expand Down Expand Up @@ -537,17 +537,17 @@ MolComponentImplTest >> testParametersProviders [

"Test initial events producer contents : default component name"
self assert: component parametersProviders size equals: 1.
self assert: (component parametersProviders at: MolUsedParameters) equals: #default.
self assert: (component parametersProviders at: MolUsedParameters) equals: MolUtils defaultComponentName.

MolUtils activateComponent: MolCompleteComponentImpl named: #myComponentA.

self assert: component parametersProviders size equals: 1.
self assert: (component parametersProviders at: MolUsedParameters) equals: #default.
self assert: (component parametersProviders at: MolUsedParameters) equals: MolUtils defaultComponentName.

MolUtils passivateComponent: MolCompleteComponentImpl named: #myComponentA.

self assert: component parametersProviders size equals: 1.
self assert: (component parametersProviders at: MolUsedParameters) equals: #default.
self assert: (component parametersProviders at: MolUsedParameters) equals: MolUtils defaultComponentName.

MolUtils removeComponent: MolCompleteComponentImpl named: #myComponentA.

Expand All @@ -567,17 +567,17 @@ MolComponentImplTest >> testServicesProviders [

"Test initial events producer contents : default component name"
self assert: component servicesProviders size equals: 1.
self assert: (component servicesProviders at: MolUsedServices) equals: #default.
self assert: (component servicesProviders at: MolUsedServices) equals: MolUtils defaultComponentName.

MolUtils activateComponent: MolCompleteComponentImpl named: #myComponentA.

self assert: component servicesProviders size equals: 1.
self assert: (component servicesProviders at: MolUsedServices) equals: #default.
self assert: (component servicesProviders at: MolUsedServices) equals: MolUtils defaultComponentName.

MolUtils passivateComponent: MolCompleteComponentImpl named: #myComponentA.

self assert: component servicesProviders size equals: 1.
self assert: (component servicesProviders at: MolUsedServices) equals: #default.
self assert: (component servicesProviders at: MolUsedServices) equals: MolUtils defaultComponentName.

MolUtils removeComponent: MolCompleteComponentImpl named: #myComponentA.

Expand All @@ -602,7 +602,7 @@ MolComponentImplTest >> testStart2 [
component := MolCompleteComponentImpl start.
self assert: (MolUtils instanceOf: MolCompleteComponentImpl) notNil.
self assert: component isComponent.
self assert: component componentName equals: #default.
self assert: component componentName equals: MolUtils defaultComponentName.

component := MolCompleteComponentImpl start: #compA.
self assert: (MolUtils instanceOf: MolCompleteComponentImpl named: #compA) notNil.
Expand Down
22 changes: 11 additions & 11 deletions Molecule-Tests/MolEventSubscriberTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ MolEventSubscriberTest >> testAddOriginator [
eventSubscriber addOriginator: nil.
self assert: eventSubscriber originators isEmpty.

eventSubscriber addOriginator: #default.
eventSubscriber addOriginator: MolUtils defaultComponentName.
self assert: eventSubscriber originators isEmpty.

eventSubscriber addOriginator: component.
Expand All @@ -51,7 +51,7 @@ MolEventSubscriberTest >> testAddOriginators [
componentB := MolCompleteComponentImpl new componentName: #compB.
eventSubscriber := MolEventSubscriber new.

eventSubscriber addOriginators: (OrderedCollection with: #default with: nil).
eventSubscriber addOriginators: (OrderedCollection with: MolUtils defaultComponentName with: nil).
self assert: eventSubscriber originators isEmpty.

eventSubscriber addOriginators: (OrderedCollection with: componentA with: componentB).
Expand Down Expand Up @@ -107,7 +107,7 @@ MolEventSubscriberTest >> testIncludesOriginator [

eventSubscriber := MolEventSubscriber events: componentEvents originators: subscribers.
self assert: (eventSubscriber includesOriginator: nil) equals: false.
self assert: (eventSubscriber includesOriginator: #default) equals: false.
self assert: (eventSubscriber includesOriginator: MolUtils defaultComponentName) equals: false.
self assert: (eventSubscriber includesOriginator: component).
]

Expand Down Expand Up @@ -181,7 +181,7 @@ MolEventSubscriberTest >> testRelease [
| subscribers componentEvents eventSubscriber |
subscribers := OrderedCollection new.
componentEvents := MolUsedChildEvents.
subscribers := OrderedCollection with: #default.
subscribers := OrderedCollection with: MolUtils defaultComponentName.
eventSubscriber := MolEventSubscriber events: componentEvents originators: subscribers.

eventSubscriber release.
Expand All @@ -201,25 +201,25 @@ MolEventSubscriberTest >> testSubscribe [
self assert: eventSubscriber observersConnection isEmpty.
self assert: eventSubscriber originators size equals: 1.
self assert: eventSubscriber originators first equals: component.
self assert: (eventSubscriber originatorsLinks at: #default) equals: component.
self assert: (eventSubscriber originatorsLinks at: MolUtils defaultComponentName) equals: component.

eventSubscriber subscribe: component.
self assert: (component isSubscribed: MolUsedEvents) equals: true.
self assert: (eventSubscriber observersConnection includesKey: component).
self assert: (eventSubscriber observersConnection at: component) size equals: 1.
self assert: ((eventSubscriber observersConnection at: component) includes: #default).
self assert: ((eventSubscriber observersConnection at: component) includes: MolUtils defaultComponentName).
self assert: eventSubscriber originators size equals: 1.
self assert: eventSubscriber originators first equals: component.
self assert: (eventSubscriber originatorsLinks at: #default) equals: component.
self assert: (eventSubscriber originatorsLinks at: MolUtils defaultComponentName) equals: component.

eventSubscriber subscribe: component.
self assert: (component isSubscribed: MolUsedEvents) equals: true.
self assert: (eventSubscriber observersConnection includesKey: component).
self assert: (eventSubscriber observersConnection at: component) size equals: 1.
self assert: ((eventSubscriber observersConnection at: component) includes: #default).
self assert: ((eventSubscriber observersConnection at: component) includes: MolUtils defaultComponentName).
self assert: eventSubscriber originators size equals: 1.
self assert: eventSubscriber originators first equals: component.
self assert: (eventSubscriber originatorsLinks at: #default) equals: component.
self assert: (eventSubscriber originatorsLinks at: MolUtils defaultComponentName) equals: component.

]

Expand Down Expand Up @@ -264,14 +264,14 @@ MolEventSubscriberTest >> testUnsubscribe [
self assert: eventSubscriber observersConnection isEmpty.
self assert: eventSubscriber originators size equals: 1.
self assert: eventSubscriber originators first equals: component.
self assert: (eventSubscriber originatorsLinks at: #default) equals: component.
self assert: (eventSubscriber originatorsLinks at: MolUtils defaultComponentName) equals: component.

eventSubscriber unsubscribe: component.
self assert: (component isSubscribed: MolUsedEvents) equals: false.
self assert: eventSubscriber observersConnection isEmpty.
self assert: eventSubscriber originators size equals: 1.
self assert: eventSubscriber originators first equals: component.
self assert: (eventSubscriber originatorsLinks at: #default) equals: component.
self assert: (eventSubscriber originatorsLinks at: MolUtils defaultComponentName) equals: component.
]

{ #category : #test }
Expand Down
14 changes: 7 additions & 7 deletions Molecule-Tests/MolHomeServicesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MolHomeServicesTest >> testActivateComponent [
component := manager homeServices instanciateComponent: MolCompleteComponentImpl.
manager homeServices activateComponent: MolCompleteComponentImpl.

self assert: component componentName equals: #default.
self assert: component componentName equals: MolUtils defaultComponentName.
self assert: (component componentConnector isKindOf: MolComponentConnector).
self assert: component eventsNotifiers notEmpty.
self assert: component eventsSubscribers notEmpty.
Expand All @@ -54,16 +54,16 @@ MolHomeServicesTest >> testActivateComponentAugmentedClass [
component := manager homeServices instanciateComponent: MolAugmentedClassToAComponent.
manager homeServices activateComponent: MolAugmentedClassToAComponent.

self assert: component componentName equals: #default.
self assert: component componentName equals: MolUtils defaultComponentName.
self assert: (component componentConnector isKindOf: MolComponentConnector).
self assert: component eventsNotifiers notEmpty.
self assert: component eventsSubscribers notEmpty.
self assert: component parametersProviders notEmpty.
self assert: component servicesProviders notEmpty.

component forServices: MolServicesTest useProvider: #default.
component forEvents: MolEventsTest useProducer: #default.
component forParameters: MolParametersTest useProvider: #default.
component forServices: MolServicesTest useProvider: MolUtils defaultComponentName.
component forEvents: MolEventsTest useProducer: MolUtils defaultComponentName.
component forParameters: MolParametersTest useProvider: MolUtils defaultComponentName.
]

{ #category : #tests }
Expand Down Expand Up @@ -91,7 +91,7 @@ MolHomeServicesTest >> testInstanciateComponent [
manager deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
component := manager homeServices instanciateComponent: MolCompleteComponentImpl.

self assert: component componentName equals: #default.
self assert: component componentName equals: MolUtils defaultComponentName.
self assert: (component componentConnector isKindOf: MolComponentConnector).
self assert: component eventsNotifiers notEmpty.
self assert: component eventsSubscribers notEmpty.
Expand Down Expand Up @@ -212,7 +212,7 @@ MolHomeServicesTest >> testPassivateComponent [
manager homeServices activateComponent: MolCompleteComponentImpl.
manager homeServices passivateComponent: MolCompleteComponentImpl.

self assert: component componentName equals: #default.
self assert: component componentName equals: MolUtils defaultComponentName.
self assert: (component componentConnector isKindOf: MolComponentConnector).
self assert: component eventsNotifiers notEmpty.
self assert: component eventsSubscribers notEmpty.
Expand Down
10 changes: 5 additions & 5 deletions Molecule-Tests/MolLocatorServicesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ MolLocatorServicesTest >> testSearchComponentTypeImplementorFor [
MolLocatorServicesTest >> testSearchComponentTypeImplementorForNamed [
| manager component myComponent |
manager := MolComponentManager default.
component := manager locatorServices searchComponentTypeImplementorFor: MolCompleteComponent named: #default.
component := manager locatorServices searchComponentTypeImplementorFor: MolCompleteComponent.
self assert: component isNil.

manager deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
myComponent := manager homeServices instanciateComponent: MolCompleteComponentImpl.
component := manager locatorServices searchComponentTypeImplementorFor: MolCompleteComponent named: #default.
component := manager locatorServices searchComponentTypeImplementorFor: MolCompleteComponent.

self assert: component notNil.
self assert: component identicalTo: myComponent.
Expand All @@ -122,7 +122,7 @@ MolLocatorServicesTest >> testSearchEventsSubscriberForNamed [
| eventSubscriber component |

component := MolUtils startComponent: MolCompleteComponentImpl.
eventSubscriber := MolComponentManager default locatorServices searchEventsSubscriberFor: MolUsedEvents named: #default.
eventSubscriber := MolComponentManager default locatorServices searchEventsSubscriberFor: MolUsedEvents.

self assert: eventSubscriber isNotFoundEventsSubscriber not.
self assert: (eventSubscriber isKindOf: MolEventSubscriber).
Expand Down Expand Up @@ -151,7 +151,7 @@ MolLocatorServicesTest >> testSearchParametersProviderForNamed [
manager := MolComponentManager default.
manager deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
manager homeServices instanciateComponent: MolCompleteComponentImpl.
parametersProvider := manager locatorServices searchParametersProviderFor: MolUsedParameters named: #default.
parametersProvider := manager locatorServices searchParametersProviderFor: MolUsedParameters.

self assert: parametersProvider isNotFoundParameters not.
self assert: (parametersProvider isKindOf: MolCompleteComponentImpl).
Expand All @@ -177,7 +177,7 @@ MolLocatorServicesTest >> testSearchServicesProviderForNamed [
manager := MolComponentManager default.
manager deploymentServices deployComponentImplementation: MolCompleteComponentImpl.
manager homeServices instanciateComponent: MolCompleteComponentImpl.
servicesProvider := manager locatorServices searchServicesProviderFor: MolUsedServices named: #default.
servicesProvider := manager locatorServices searchServicesProviderFor: MolUsedServices.

self assert: servicesProvider isNotFoundServices not.
self assert: (servicesProvider isKindOf: MolCompleteComponentImpl).
Expand Down
4 changes: 1 addition & 3 deletions Molecule-Tests/MolServicesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ MolServicesTest >> testTableProvideServicesToSeveralUsers [
user1 := manager homeServices instanciateComponent: MolMyUserComponentImpl named: #user1.
user2 := manager homeServices instanciateComponent: MolMyUserComponentImpl named: #user2.

"Subscriptions"
user1 forServices: MolMyTableServices useProvider: #default.
user2 forServices: MolMyTableServices useProvider: #default.
"Auto subscriptions, because of using default component name"

"Activation"
manager homeServices activateComponent: MolMyTableComponentImpl.
Expand Down
6 changes: 3 additions & 3 deletions Molecule/MolComponentConnector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ MolComponentConnector >> connectComponent: aComponent [
parametersProviders := self class defaultParametersProviders.

aComponent class allProducedEvents do: [ :evt | eventsNotifiers at: evt put: (MolEventNotifier interface: evt originator: aComponent)].
aComponent class allUsedServices do: [ :svc | servicesProviders at: svc put: #default].
aComponent class allConsumedEvents do: [ :evt | eventsSubscribers at: evt put: #default].
aComponent class allUsedParameters do: [ :svc | parametersProviders at: svc put: #default].
aComponent class allUsedServices do: [ :svc | servicesProviders at: svc put: MolUtils defaultComponentName].
aComponent class allConsumedEvents do: [ :evt | eventsSubscribers at: evt put: MolUtils defaultComponentName].
aComponent class allUsedParameters do: [ :svc | parametersProviders at: svc put: MolUtils defaultComponentName].

]

Expand Down
Loading

0 comments on commit b7ecf0f

Please sign in to comment.