From 1259d9c2600ff75b4f37b45cfb34b45ccb137731 Mon Sep 17 00:00:00 2001 From: Agustin Tarda Date: Sun, 19 May 2019 11:48:10 -0300 Subject: [PATCH 1/8] Comenzamos el desarrollo de la api --- ...ESTfulControllerSpecificationTest.class.st | 18 +++ ...ulControllerSpecificationTest.extension.st | 14 +++ .../PeopleRESTfulControllerTest.class.st | 32 +++++ .../PersonSystemTest.class.st | 106 ---------------- .../TeamsAPI-Core-Tests/PersonTest.class.st | 21 ---- .../TeamSystemTest.class.st | 114 ------------------ source/TeamsAPI-Core-Tests/TeamTest.class.st | 29 ----- .../ManifestTeamsAPISystem.class.st | 17 --- ...pleRESTfulControllerSpecification.class.st | 35 ++++++ source/TeamsAPI-Core/Person.class.st | 51 -------- source/TeamsAPI-Core/PersonSystem.class.st | 49 -------- source/TeamsAPI-Core/Team.class.st | 38 ------ source/TeamsAPI-Core/TeamSystem.class.st | 47 -------- .../TeamsRESTfulController.class.st | 5 + 14 files changed, 104 insertions(+), 472 deletions(-) create mode 100644 source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st create mode 100644 source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st create mode 100644 source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st delete mode 100644 source/TeamsAPI-Core-Tests/PersonSystemTest.class.st delete mode 100644 source/TeamsAPI-Core-Tests/PersonTest.class.st delete mode 100644 source/TeamsAPI-Core-Tests/TeamSystemTest.class.st delete mode 100644 source/TeamsAPI-Core-Tests/TeamTest.class.st delete mode 100644 source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st create mode 100644 source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st delete mode 100644 source/TeamsAPI-Core/Person.class.st delete mode 100644 source/TeamsAPI-Core/PersonSystem.class.st delete mode 100644 source/TeamsAPI-Core/Team.class.st delete mode 100644 source/TeamsAPI-Core/TeamSystem.class.st create mode 100644 source/TeamsAPI-Core/TeamsRESTfulController.class.st diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st new file mode 100644 index 0000000..9363354 --- /dev/null +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st @@ -0,0 +1,18 @@ +Class { + #name : #PeopleRESTfulControllerSpecificationTest, + #superclass : #TestCase, + #category : #'TeamsAPI-Core-Tests' +} + +{ #category : #'*TeamsAPI-Core-Tests' } +PeopleRESTfulControllerSpecificationTest >> testTemplate [ + + | spec | + + spec := PeopleRESTfulControllerSpecification new. + + self + assert: spec addTemplate equals: '/people/'; + assert: spec listTemplate equals: '/people'; + assert: spec detailTemplate equals: '/people/' +] diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st new file mode 100644 index 0000000..5a875ec --- /dev/null +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st @@ -0,0 +1,14 @@ +Extension { #name : #PeopleRESTfulControllerSpecificationTest } + +{ #category : #'*TeamsAPI-Core-Tests' } +PeopleRESTfulControllerSpecificationTest >> testTemplate [ + + | spec | + + spec := PeopleRESTfulControllerSpecification new. + + self + assert: spec addTemplate equals: '/people/'; + assert: spec listTemplate equals: '/people'; + assert: spec detailTemplate equals: '/people/' +] diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st new file mode 100644 index 0000000..869b1f0 --- /dev/null +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st @@ -0,0 +1,32 @@ +Class { + #name : #PeopleRESTfulControllerTest, + #superclass : #TestCase, + #instVars : [ + 'resourceController' + ], + #category : #'TeamsAPI-Core-Tests' +} + +{ #category : #test } +PeopleRESTfulControllerTest >> baseUrl [ + + ^'https://teamsAPI.com' + + +] + +{ #category : #test } +PeopleRESTfulControllerTest >> setUp [ + + super setUp. + self setUpResourceController. + resourceController serverUrl: self baseUrl asZnUrl. + self assert: resourceController orders isEmpty + + +] + +{ #category : #test } +PeopleRESTfulControllerTest >> setUpResourceController [ + resourceController := TeamsRESTfulController new +] diff --git a/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st b/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st deleted file mode 100644 index d21fc8a..0000000 --- a/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st +++ /dev/null @@ -1,106 +0,0 @@ -" -A PersonSystemTest is a test class for testing the behavior of PersonSystem -" -Class { - #name : #PersonSystemTest, - #superclass : #TestCase, - #instVars : [ - 'rootSystem' - ], - #category : #'TeamsAPI-Core-Tests' -} - -{ #category : #acccessing } -PersonSystemTest >> lucasRojas [ - ^ Person - named: 'Lucas' - surnamed: 'Rojas' - withEmailAddress: 'l.rojas@gmail.com' -] - -{ #category : #acccessing } -PersonSystemTest >> personSystem [ - ^ rootSystem systemImplementing: #PersonSystemInterface -] - -{ #category : #initializing } -PersonSystemTest >> setUp [ - super setUp. - rootSystem := CompositeSystem new. - rootSystem - register: PersonSystem new; - register: TeamSystem new; - startUp -] - -{ #category : #tests } -PersonSystemTest >> testAddPerson [ - | person personSystem | - person := self lucasRojas. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - assertCollection: personSystem people - hasSameElements: (Array with: person) -] - -{ #category : #tests } -PersonSystemTest >> testDeletePerson [ - | person personSystem | - person := self lucasRojas. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - assertCollection: personSystem people - hasSameElements: (Array with: person). - personSystem stopManagingPerson: person. - self assert: personSystem people isEmpty -] - -{ #category : #tests } -PersonSystemTest >> testFailToDeletePersonAlreadyDeleted [ - | person personSystem | - person := self lucasRojas. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - assertCollection: personSystem people - hasSameElements: (Array with: person). - personSystem stopManagingPerson: person. - self - assert: personSystem people isEmpty; - should: [ personSystem stopManagingPerson: person ] - raise: AssertionFailed - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: - 'TStop managing person failed because it does not exist in the system.' ] -] - -{ #category : #tests } -PersonSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ - | person personSystem personWithSameEmail | - person := self lucasRojas. - personWithSameEmail := Person - named: 'Lucia' - surnamed: 'Rojas' - withEmailAddress: 'l.rojas@gmail.com'. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - should: [ personSystem startManagingPerson: personWithSameEmail ] - raise: Exception - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: - 'There''s already a person registered in our system with the email address: l.rojas@gmail.com.' ]; - assertCollection: personSystem people - hasSameElements: (Array with: person) -] - -{ #category : #tests } -PersonSystemTest >> testGetPeopleOnEmptySystem [ - self assert: self personSystem people isEmpty -] diff --git a/source/TeamsAPI-Core-Tests/PersonTest.class.st b/source/TeamsAPI-Core-Tests/PersonTest.class.st deleted file mode 100644 index 3fd7f07..0000000 --- a/source/TeamsAPI-Core-Tests/PersonTest.class.st +++ /dev/null @@ -1,21 +0,0 @@ -Class { - #name : #PersonTest, - #superclass : #TestCase, - #category : #'TeamsAPI-Core-Tests' -} - -{ #category : #tests } -PersonTest >> testInstanceCreation [ - | person personName personEmail personLastName | - personName := 'La Raulito'. - personLastName := 'Perez'. - personEmail := 'laraulitoperez@gmail.com'. - person := Person - named: personName - surnamed: personLastName - withEmailAddress: personEmail. - self - assert: person name equals: personName; - assert: person lastName equals: personLastName; - assert: person emailAddress equals: personEmail -] diff --git a/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st b/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st deleted file mode 100644 index 457a90d..0000000 --- a/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st +++ /dev/null @@ -1,114 +0,0 @@ -" -A TeamSystemTest is a test class for testing the behavior of TeamSystem -" -Class { - #name : #TeamSystemTest, - #superclass : #TestCase, - #instVars : [ - 'person', - 'anotherPerson', - 'rootSystem' - ], - #category : #'TeamsAPI-Core-Tests' -} - -{ #category : #running } -TeamSystemTest >> setUp [ - super setUp. - person := Person - named: 'Lucas' - surnamed: 'Rojas' - withEmailAddress: 'l.rojas@gmail.com'. - anotherPerson := Person - named: 'Rocio' - surnamed: 'Pasco' - withEmailAddress: 'r.pasco@gmail.com'. - rootSystem := CompositeSystem new. - rootSystem - register: PersonSystem new; - register: TeamSystem new; - startUp -] - -{ #category : #tests } -TeamSystemTest >> teamSystem [ - ^ rootSystem systemImplementing: #TeamSystemInterface -] - -{ #category : #tests } -TeamSystemTest >> testAddTeam [ - | team teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - assertCollection: teamSystem teams - hasSameElements: (Array with: team) -] - -{ #category : #tests } -TeamSystemTest >> testDeleteATeamAlreadyDeleted [ - | team teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - assertCollection: teamSystem teams - hasSameElements: (Array with: team). - teamSystem stopManagingTeam: team. - self - assert: teamSystem teams isEmpty; - should: [ teamSystem stopManagingTeam: team ] - raise: AssertionFailed - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: 'TStop managing team failed because it does not exist in the system.' ] -] - -{ #category : #tests } -TeamSystemTest >> testDeleteTeam [ - | team teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - assertCollection: teamSystem teams - hasSameElements: (Array with: team). - teamSystem stopManagingTeam: team. - self assert: teamSystem teams isEmpty -] - -{ #category : #tests } -TeamSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ - | team teamWithSameName teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamWithSameName := Team - named: 'Linces' - composedBy: (OrderedCollection with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - should: [ teamSystem startManagingTeam: teamWithSameName ] - raise: Exception - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: - 'There''s already a team registered in our system with the name: Linces.' ]; - assertCollection: teamSystem teams - hasSameElements: (Array with: team) -] - -{ #category : #tests } -TeamSystemTest >> testGetTeamsOnEmptySystem [ - self assert: self teamSystem teams isEmpty -] diff --git a/source/TeamsAPI-Core-Tests/TeamTest.class.st b/source/TeamsAPI-Core-Tests/TeamTest.class.st deleted file mode 100644 index ce3ca10..0000000 --- a/source/TeamsAPI-Core-Tests/TeamTest.class.st +++ /dev/null @@ -1,29 +0,0 @@ -Class { - #name : #TeamTest, - #superclass : #TestCase, - #instVars : [ - 'defaultPerson' - ], - #category : #'TeamsAPI-Core-Tests' -} - -{ #category : #initialization } -TeamTest >> setUp [ - super setUp. - - defaultPerson := Person - named: 'Agustin' - surnamed: 'Tarda' - withEmailAddress: 'a.e.tarda@gmail.com' -] - -{ #category : #tests } -TeamTest >> testInstanceCreation [ - | teamMembers teamName team | - teamMembers := OrderedCollection with: defaultPerson. - teamName := 'Linces'. - team := Team named: teamName composedBy: teamMembers. - self - assert: team name equals: teamName; - assert: team members equals: teamMembers -] diff --git a/source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st b/source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st deleted file mode 100644 index 4788cf3..0000000 --- a/source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st +++ /dev/null @@ -1,17 +0,0 @@ -Class { - #name : #ManifestTeamsAPISystem, - #superclass : #PackageManifest, - #category : #'TeamsAPI-Core' -} - -{ #category : #'class initialization' } -ManifestTeamsAPISystem class >> initialize [ - - Kepler - registerInterfaceAt: #PersonSystemInterface - named: 'Person Management' - declaring: #(#startManagingPerson: #stopManagingPerson: #people); - registerInterfaceAt: #TeamSystemInterface - named: 'Team Management' - declaring: #(#startManagingTeam: #stopManagingTeam: #teams) -] diff --git a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st new file mode 100644 index 0000000..af43402 --- /dev/null +++ b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st @@ -0,0 +1,35 @@ +Class { + #name : #PeopleRESTfulControllerSpecification, + #superclass : #ResourceRESTfulControllerSpecification, + #category : #'TeamsAPI-Core' +} + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> addTemplate [ + + ^'<1s>/%<<2s>:IsInteger>' expandMacrosWith: self endpoint with: self identifierKey +] + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> detailTemplate [ + + ^ '<1s>/%<<2s>:IsInteger>' expandMacrosWith: self endpoint with: self identifierKey +] + +{ #category : #'private - accessing' } +PeopleRESTfulControllerSpecification >> endpoint [ + + ^'/people' +] + +{ #category : #'private - accessing' } +PeopleRESTfulControllerSpecification >> identifierKey [ + + ^#identifier +] + +{ #category : #acccessing } +PeopleRESTfulControllerSpecification >> listTemplate [ + + ^self endpoint +] diff --git a/source/TeamsAPI-Core/Person.class.st b/source/TeamsAPI-Core/Person.class.st deleted file mode 100644 index b18079e..0000000 --- a/source/TeamsAPI-Core/Person.class.st +++ /dev/null @@ -1,51 +0,0 @@ -Class { - #name : #Person, - #superclass : #Object, - #instVars : [ - 'name', - 'lastName', - 'emailAddress' - ], - #category : #'TeamsAPI-Core' -} - -{ #category : #'private-assertions' } -Person class >> assertNotEmpty: aString forField: aFieldName [ - AssertionChecker - enforce: [ aString notEmpty ] - because: ('A person''s <1s> can''t be empty.' expandMacrosWith: aFieldName) -] - -{ #category : #'instance creation' } -Person class >> named: aName surnamed: aSurName withEmailAddress: anEmailAddress [ - self - assertNotEmpty: aName forField: 'name'; - assertNotEmpty: aSurName forField: 'surname'; - assertNotEmpty: anEmailAddress forField: 'email adress'. - ^ self new - initializeNamed: aName - surnamed: aSurName - withEmailAddress: anEmailAddress -] - -{ #category : #accessing } -Person >> emailAddress [ - ^ emailAddress -] - -{ #category : #initialization } -Person >> initializeNamed: aName surnamed: aLastName withEmailAddress: anEmailAddress [ - name := aName. - lastName := aLastName. - emailAddress := anEmailAddress -] - -{ #category : #accessing } -Person >> lastName [ - ^ lastName -] - -{ #category : #accessing } -Person >> name [ - ^ name -] diff --git a/source/TeamsAPI-Core/PersonSystem.class.st b/source/TeamsAPI-Core/PersonSystem.class.st deleted file mode 100644 index 5a142cd..0000000 --- a/source/TeamsAPI-Core/PersonSystem.class.st +++ /dev/null @@ -1,49 +0,0 @@ -Class { - #name : #PersonSystem, - #superclass : #SubsystemImplementation, - #instVars : [ - 'people' - ], - #category : #'TeamsAPI-Core' -} - -{ #category : #installing } -PersonSystem >> dependencies [ - ^ #() -] - -{ #category : #installing } -PersonSystem >> implementedInterfaces [ - ^ #(#PersonSystemInterface) -] - -{ #category : #installing } -PersonSystem >> initialize [ - super initialize. - people := OrderedCollection new -] - -{ #category : #accessing } -PersonSystem >> people [ - ^ people -] - -{ #category : #accessing } -PersonSystem >> startManagingPerson: aPerson [ - AssertionChecker - enforce: [ people - noneSatisfy: [ :person | person emailAddress = aPerson emailAddress ] ] - because: - ('There''s already a person registered in our system with the email address: <1s>.' - expandMacrosWith: aPerson emailAddress). - people add: aPerson -] - -{ #category : #accessing } -PersonSystem >> stopManagingPerson: aPerson [ - AssertionChecker - enforce: [ people anySatisfy: [ :person | person = aPerson ] ] - because: - 'TStop managing person failed because it does not exist in the system.'. - people remove: aPerson -] diff --git a/source/TeamsAPI-Core/Team.class.st b/source/TeamsAPI-Core/Team.class.st deleted file mode 100644 index d031471..0000000 --- a/source/TeamsAPI-Core/Team.class.st +++ /dev/null @@ -1,38 +0,0 @@ -Class { - #name : #Team, - #superclass : #Object, - #instVars : [ - 'name', - 'members' - ], - #category : #'TeamsAPI-Core' -} - -{ #category : #'instance creatio' } -Team class >> assertNotEmpty: aStringOrCollection forField: aFieldName [ - AssertionChecker - enforce: [ aStringOrCollection notEmpty ] - because: ('A team''s <1s> can''t be empty.' expandMacrosWith: aFieldName) -] - -{ #category : #'instance creatio' } -Team class >> named: aName composedBy: aPersonsCollection [ - self assertNotEmpty: aName forField: 'name'. - ^ self new initializeNamed: aName composedBy: aPersonsCollection -] - -{ #category : #initialization } -Team >> initializeNamed: aName composedBy: aPersonsCollection [ - name := aName. - members := aPersonsCollection -] - -{ #category : #accessing } -Team >> members [ - ^ members -] - -{ #category : #accessing } -Team >> name [ - ^ name -] diff --git a/source/TeamsAPI-Core/TeamSystem.class.st b/source/TeamsAPI-Core/TeamSystem.class.st deleted file mode 100644 index 48e9b0f..0000000 --- a/source/TeamsAPI-Core/TeamSystem.class.st +++ /dev/null @@ -1,47 +0,0 @@ -Class { - #name : #TeamSystem, - #superclass : #SubsystemImplementation, - #instVars : [ - 'teams' - ], - #category : #'TeamsAPI-Core' -} - -{ #category : #installing } -TeamSystem >> dependencies [ - ^ #() -] - -{ #category : #initialization } -TeamSystem >> implementedInterfaces [ - ^ #(#TeamSystemInterface) -] - -{ #category : #initialization } -TeamSystem >> initialize [ - super initialize. - teams := OrderedCollection new -] - -{ #category : #adding } -TeamSystem >> startManagingTeam: aTeam [ - AssertionChecker - enforce: [ teams noneSatisfy: [ :team | team name = aTeam name ] ] - because: - ('There''s already a team registered in our system with the name: <1s>.' - expandMacrosWith: aTeam name). - teams add: aTeam -] - -{ #category : #adding } -TeamSystem >> stopManagingTeam: aTeam [ - AssertionChecker - enforce: [ teams anySatisfy: [ :team | aTeam = team ] ] - because: 'TStop managing team failed because it does not exist in the system.'. - teams remove: aTeam -] - -{ #category : #accessing } -TeamSystem >> teams [ - ^ teams -] diff --git a/source/TeamsAPI-Core/TeamsRESTfulController.class.st b/source/TeamsAPI-Core/TeamsRESTfulController.class.st new file mode 100644 index 0000000..3c1d2d6 --- /dev/null +++ b/source/TeamsAPI-Core/TeamsRESTfulController.class.st @@ -0,0 +1,5 @@ +Class { + #name : #TeamsRESTfulController, + #superclass : #ResourceRESTfulController, + #category : #'TeamsAPI-Core' +} From aec64dc35dc07fe9baa473ff3e8a0c15eb4b1c66 Mon Sep 17 00:00:00 2001 From: Agustin Tarda Date: Sun, 19 May 2019 11:59:28 -0300 Subject: [PATCH 2/8] Se crearon packages diferentes para el modelo --- .../PersonSystemTest.class.st | 106 ++++++++++++++++ source/TeamsModel-Tests/PersonTest.class.st | 21 ++++ .../TeamsModel-Tests/TeamSystemTest.class.st | 114 ++++++++++++++++++ source/TeamsModel-Tests/TeamTest.class.st | 29 +++++ source/TeamsModel-Tests/package.st | 1 + .../ManifestTeamsAPISystem.class.st | 17 +++ source/TeamsModel/Person.class.st | 51 ++++++++ source/TeamsModel/PersonSystem.class.st | 49 ++++++++ source/TeamsModel/Team.class.st | 38 ++++++ source/TeamsModel/TeamSystem.class.st | 47 ++++++++ source/TeamsModel/package.st | 1 + 11 files changed, 474 insertions(+) create mode 100644 source/TeamsModel-Tests/PersonSystemTest.class.st create mode 100644 source/TeamsModel-Tests/PersonTest.class.st create mode 100644 source/TeamsModel-Tests/TeamSystemTest.class.st create mode 100644 source/TeamsModel-Tests/TeamTest.class.st create mode 100644 source/TeamsModel-Tests/package.st create mode 100644 source/TeamsModel/ManifestTeamsAPISystem.class.st create mode 100644 source/TeamsModel/Person.class.st create mode 100644 source/TeamsModel/PersonSystem.class.st create mode 100644 source/TeamsModel/Team.class.st create mode 100644 source/TeamsModel/TeamSystem.class.st create mode 100644 source/TeamsModel/package.st diff --git a/source/TeamsModel-Tests/PersonSystemTest.class.st b/source/TeamsModel-Tests/PersonSystemTest.class.st new file mode 100644 index 0000000..c0743e7 --- /dev/null +++ b/source/TeamsModel-Tests/PersonSystemTest.class.st @@ -0,0 +1,106 @@ +" +A PersonSystemTest is a test class for testing the behavior of PersonSystem +" +Class { + #name : #PersonSystemTest, + #superclass : #TestCase, + #instVars : [ + 'rootSystem' + ], + #category : #'TeamsModel-Tests' +} + +{ #category : #acccessing } +PersonSystemTest >> lucasRojas [ + ^ Person + named: 'Lucas' + surnamed: 'Rojas' + withEmailAddress: 'l.rojas@gmail.com' +] + +{ #category : #acccessing } +PersonSystemTest >> personSystem [ + ^ rootSystem systemImplementing: #PersonSystemInterface +] + +{ #category : #initializing } +PersonSystemTest >> setUp [ + super setUp. + rootSystem := CompositeSystem new. + rootSystem + register: PersonSystem new; + register: TeamSystem new; + startUp +] + +{ #category : #tests } +PersonSystemTest >> testAddPerson [ + | person personSystem | + person := self lucasRojas. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + assertCollection: personSystem people + hasSameElements: (Array with: person) +] + +{ #category : #tests } +PersonSystemTest >> testDeletePerson [ + | person personSystem | + person := self lucasRojas. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + assertCollection: personSystem people + hasSameElements: (Array with: person). + personSystem stopManagingPerson: person. + self assert: personSystem people isEmpty +] + +{ #category : #tests } +PersonSystemTest >> testFailToDeletePersonAlreadyDeleted [ + | person personSystem | + person := self lucasRojas. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + assertCollection: personSystem people + hasSameElements: (Array with: person). + personSystem stopManagingPerson: person. + self + assert: personSystem people isEmpty; + should: [ personSystem stopManagingPerson: person ] + raise: AssertionFailed + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: + 'TStop managing person failed because it does not exist in the system.' ] +] + +{ #category : #tests } +PersonSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ + | person personSystem personWithSameEmail | + person := self lucasRojas. + personWithSameEmail := Person + named: 'Lucia' + surnamed: 'Rojas' + withEmailAddress: 'l.rojas@gmail.com'. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + should: [ personSystem startManagingPerson: personWithSameEmail ] + raise: Exception + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: + 'There''s already a person registered in our system with the email address: l.rojas@gmail.com.' ]; + assertCollection: personSystem people + hasSameElements: (Array with: person) +] + +{ #category : #tests } +PersonSystemTest >> testGetPeopleOnEmptySystem [ + self assert: self personSystem people isEmpty +] diff --git a/source/TeamsModel-Tests/PersonTest.class.st b/source/TeamsModel-Tests/PersonTest.class.st new file mode 100644 index 0000000..3447146 --- /dev/null +++ b/source/TeamsModel-Tests/PersonTest.class.st @@ -0,0 +1,21 @@ +Class { + #name : #PersonTest, + #superclass : #TestCase, + #category : #'TeamsModel-Tests' +} + +{ #category : #tests } +PersonTest >> testInstanceCreation [ + | person personName personEmail personLastName | + personName := 'La Raulito'. + personLastName := 'Perez'. + personEmail := 'laraulitoperez@gmail.com'. + person := Person + named: personName + surnamed: personLastName + withEmailAddress: personEmail. + self + assert: person name equals: personName; + assert: person lastName equals: personLastName; + assert: person emailAddress equals: personEmail +] diff --git a/source/TeamsModel-Tests/TeamSystemTest.class.st b/source/TeamsModel-Tests/TeamSystemTest.class.st new file mode 100644 index 0000000..70c2cc8 --- /dev/null +++ b/source/TeamsModel-Tests/TeamSystemTest.class.st @@ -0,0 +1,114 @@ +" +A TeamSystemTest is a test class for testing the behavior of TeamSystem +" +Class { + #name : #TeamSystemTest, + #superclass : #TestCase, + #instVars : [ + 'person', + 'anotherPerson', + 'rootSystem' + ], + #category : #'TeamsModel-Tests' +} + +{ #category : #running } +TeamSystemTest >> setUp [ + super setUp. + person := Person + named: 'Lucas' + surnamed: 'Rojas' + withEmailAddress: 'l.rojas@gmail.com'. + anotherPerson := Person + named: 'Rocio' + surnamed: 'Pasco' + withEmailAddress: 'r.pasco@gmail.com'. + rootSystem := CompositeSystem new. + rootSystem + register: PersonSystem new; + register: TeamSystem new; + startUp +] + +{ #category : #tests } +TeamSystemTest >> teamSystem [ + ^ rootSystem systemImplementing: #TeamSystemInterface +] + +{ #category : #tests } +TeamSystemTest >> testAddTeam [ + | team teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + assertCollection: teamSystem teams + hasSameElements: (Array with: team) +] + +{ #category : #tests } +TeamSystemTest >> testDeleteATeamAlreadyDeleted [ + | team teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + assertCollection: teamSystem teams + hasSameElements: (Array with: team). + teamSystem stopManagingTeam: team. + self + assert: teamSystem teams isEmpty; + should: [ teamSystem stopManagingTeam: team ] + raise: AssertionFailed + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: 'TStop managing team failed because it does not exist in the system.' ] +] + +{ #category : #tests } +TeamSystemTest >> testDeleteTeam [ + | team teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + assertCollection: teamSystem teams + hasSameElements: (Array with: team). + teamSystem stopManagingTeam: team. + self assert: teamSystem teams isEmpty +] + +{ #category : #tests } +TeamSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ + | team teamWithSameName teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamWithSameName := Team + named: 'Linces' + composedBy: (OrderedCollection with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + should: [ teamSystem startManagingTeam: teamWithSameName ] + raise: Exception + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: + 'There''s already a team registered in our system with the name: Linces.' ]; + assertCollection: teamSystem teams + hasSameElements: (Array with: team) +] + +{ #category : #tests } +TeamSystemTest >> testGetTeamsOnEmptySystem [ + self assert: self teamSystem teams isEmpty +] diff --git a/source/TeamsModel-Tests/TeamTest.class.st b/source/TeamsModel-Tests/TeamTest.class.st new file mode 100644 index 0000000..a9b88df --- /dev/null +++ b/source/TeamsModel-Tests/TeamTest.class.st @@ -0,0 +1,29 @@ +Class { + #name : #TeamTest, + #superclass : #TestCase, + #instVars : [ + 'defaultPerson' + ], + #category : #'TeamsModel-Tests' +} + +{ #category : #initialization } +TeamTest >> setUp [ + super setUp. + + defaultPerson := Person + named: 'Agustin' + surnamed: 'Tarda' + withEmailAddress: 'a.e.tarda@gmail.com' +] + +{ #category : #tests } +TeamTest >> testInstanceCreation [ + | teamMembers teamName team | + teamMembers := OrderedCollection with: defaultPerson. + teamName := 'Linces'. + team := Team named: teamName composedBy: teamMembers. + self + assert: team name equals: teamName; + assert: team members equals: teamMembers +] diff --git a/source/TeamsModel-Tests/package.st b/source/TeamsModel-Tests/package.st new file mode 100644 index 0000000..bb629e8 --- /dev/null +++ b/source/TeamsModel-Tests/package.st @@ -0,0 +1 @@ +Package { #name : #'TeamsModel-Tests' } diff --git a/source/TeamsModel/ManifestTeamsAPISystem.class.st b/source/TeamsModel/ManifestTeamsAPISystem.class.st new file mode 100644 index 0000000..48ac181 --- /dev/null +++ b/source/TeamsModel/ManifestTeamsAPISystem.class.st @@ -0,0 +1,17 @@ +Class { + #name : #ManifestTeamsAPISystem, + #superclass : #PackageManifest, + #category : #TeamsModel +} + +{ #category : #'class initialization' } +ManifestTeamsAPISystem class >> initialize [ + + Kepler + registerInterfaceAt: #PersonSystemInterface + named: 'Person Management' + declaring: #(#startManagingPerson: #stopManagingPerson: #people); + registerInterfaceAt: #TeamSystemInterface + named: 'Team Management' + declaring: #(#startManagingTeam: #stopManagingTeam: #teams) +] diff --git a/source/TeamsModel/Person.class.st b/source/TeamsModel/Person.class.st new file mode 100644 index 0000000..d1662fb --- /dev/null +++ b/source/TeamsModel/Person.class.st @@ -0,0 +1,51 @@ +Class { + #name : #Person, + #superclass : #Object, + #instVars : [ + 'name', + 'lastName', + 'emailAddress' + ], + #category : #TeamsModel +} + +{ #category : #'private-assertions' } +Person class >> assertNotEmpty: aString forField: aFieldName [ + AssertionChecker + enforce: [ aString notEmpty ] + because: ('A person''s <1s> can''t be empty.' expandMacrosWith: aFieldName) +] + +{ #category : #'instance creation' } +Person class >> named: aName surnamed: aSurName withEmailAddress: anEmailAddress [ + self + assertNotEmpty: aName forField: 'name'; + assertNotEmpty: aSurName forField: 'surname'; + assertNotEmpty: anEmailAddress forField: 'email adress'. + ^ self new + initializeNamed: aName + surnamed: aSurName + withEmailAddress: anEmailAddress +] + +{ #category : #accessing } +Person >> emailAddress [ + ^ emailAddress +] + +{ #category : #initialization } +Person >> initializeNamed: aName surnamed: aLastName withEmailAddress: anEmailAddress [ + name := aName. + lastName := aLastName. + emailAddress := anEmailAddress +] + +{ #category : #accessing } +Person >> lastName [ + ^ lastName +] + +{ #category : #accessing } +Person >> name [ + ^ name +] diff --git a/source/TeamsModel/PersonSystem.class.st b/source/TeamsModel/PersonSystem.class.st new file mode 100644 index 0000000..3c14d94 --- /dev/null +++ b/source/TeamsModel/PersonSystem.class.st @@ -0,0 +1,49 @@ +Class { + #name : #PersonSystem, + #superclass : #SubsystemImplementation, + #instVars : [ + 'people' + ], + #category : #TeamsModel +} + +{ #category : #installing } +PersonSystem >> dependencies [ + ^ #() +] + +{ #category : #installing } +PersonSystem >> implementedInterfaces [ + ^ #(#PersonSystemInterface) +] + +{ #category : #installing } +PersonSystem >> initialize [ + super initialize. + people := OrderedCollection new +] + +{ #category : #accessing } +PersonSystem >> people [ + ^ people +] + +{ #category : #accessing } +PersonSystem >> startManagingPerson: aPerson [ + AssertionChecker + enforce: [ people + noneSatisfy: [ :person | person emailAddress = aPerson emailAddress ] ] + because: + ('There''s already a person registered in our system with the email address: <1s>.' + expandMacrosWith: aPerson emailAddress). + people add: aPerson +] + +{ #category : #accessing } +PersonSystem >> stopManagingPerson: aPerson [ + AssertionChecker + enforce: [ people anySatisfy: [ :person | person = aPerson ] ] + because: + 'TStop managing person failed because it does not exist in the system.'. + people remove: aPerson +] diff --git a/source/TeamsModel/Team.class.st b/source/TeamsModel/Team.class.st new file mode 100644 index 0000000..fe494ca --- /dev/null +++ b/source/TeamsModel/Team.class.st @@ -0,0 +1,38 @@ +Class { + #name : #Team, + #superclass : #Object, + #instVars : [ + 'name', + 'members' + ], + #category : #TeamsModel +} + +{ #category : #'instance creatio' } +Team class >> assertNotEmpty: aStringOrCollection forField: aFieldName [ + AssertionChecker + enforce: [ aStringOrCollection notEmpty ] + because: ('A team''s <1s> can''t be empty.' expandMacrosWith: aFieldName) +] + +{ #category : #'instance creatio' } +Team class >> named: aName composedBy: aPersonsCollection [ + self assertNotEmpty: aName forField: 'name'. + ^ self new initializeNamed: aName composedBy: aPersonsCollection +] + +{ #category : #initialization } +Team >> initializeNamed: aName composedBy: aPersonsCollection [ + name := aName. + members := aPersonsCollection +] + +{ #category : #accessing } +Team >> members [ + ^ members +] + +{ #category : #accessing } +Team >> name [ + ^ name +] diff --git a/source/TeamsModel/TeamSystem.class.st b/source/TeamsModel/TeamSystem.class.st new file mode 100644 index 0000000..a314d89 --- /dev/null +++ b/source/TeamsModel/TeamSystem.class.st @@ -0,0 +1,47 @@ +Class { + #name : #TeamSystem, + #superclass : #SubsystemImplementation, + #instVars : [ + 'teams' + ], + #category : #TeamsModel +} + +{ #category : #installing } +TeamSystem >> dependencies [ + ^ #() +] + +{ #category : #initialization } +TeamSystem >> implementedInterfaces [ + ^ #(#TeamSystemInterface) +] + +{ #category : #initialization } +TeamSystem >> initialize [ + super initialize. + teams := OrderedCollection new +] + +{ #category : #adding } +TeamSystem >> startManagingTeam: aTeam [ + AssertionChecker + enforce: [ teams noneSatisfy: [ :team | team name = aTeam name ] ] + because: + ('There''s already a team registered in our system with the name: <1s>.' + expandMacrosWith: aTeam name). + teams add: aTeam +] + +{ #category : #adding } +TeamSystem >> stopManagingTeam: aTeam [ + AssertionChecker + enforce: [ teams anySatisfy: [ :team | aTeam = team ] ] + because: 'TStop managing team failed because it does not exist in the system.'. + teams remove: aTeam +] + +{ #category : #accessing } +TeamSystem >> teams [ + ^ teams +] diff --git a/source/TeamsModel/package.st b/source/TeamsModel/package.st new file mode 100644 index 0000000..3d775d7 --- /dev/null +++ b/source/TeamsModel/package.st @@ -0,0 +1 @@ +Package { #name : #TeamsModel } From 04dc9194214184d955fc99f8a7ce62f4e22e95ff Mon Sep 17 00:00:00 2001 From: Agustin Tarda Date: Tue, 21 May 2019 16:13:36 -0300 Subject: [PATCH 3/8] Add creation test in progress --- .../PeopleRESTfulControllerTest.class.st | 40 +++++++++++++++---- .../PeopleRESTfulController.class.st | 39 ++++++++++++++++++ ...pleRESTfulControllerSpecification.class.st | 12 +++++- .../TeamsRESTfulController.class.st | 12 ++++++ ...amsRESTfulControllerSpecification.class.st | 5 +++ 5 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 source/TeamsAPI-Core/PeopleRESTfulController.class.st create mode 100644 source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st index 869b1f0..5ad2984 100644 --- a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st @@ -1,32 +1,58 @@ Class { #name : #PeopleRESTfulControllerTest, - #superclass : #TestCase, - #instVars : [ - 'resourceController' - ], + #superclass : #ResourceRESTfulControllerTest, #category : #'TeamsAPI-Core-Tests' } { #category : #test } PeopleRESTfulControllerTest >> baseUrl [ - ^'https://teamsAPI.com' + ^'https://teamsAPI.com' asZnUrl ] +{ #category : #'block support' } +PeopleRESTfulControllerTest >> defaultPersonMediaType [ + ^ resourceController specification personVersion1dot0dot0MediaType +] + +{ #category : #'block support' } +PeopleRESTfulControllerTest >> requestToCreatePersonFrom: json [ + ^ self requestToPOST: json as: self defaultPersonMediaType +] + { #category : #test } PeopleRESTfulControllerTest >> setUp [ super setUp. self setUpResourceController. resourceController serverUrl: self baseUrl asZnUrl. - self assert: resourceController orders isEmpty + self assert: resourceController people isEmpty ] { #category : #test } PeopleRESTfulControllerTest >> setUpResourceController [ - resourceController := TeamsRESTfulController new + resourceController := PeopleRESTfulController new +] + +{ #category : #tests } +PeopleRESTfulControllerTest >> testPersonCreation [ + | response | + response := resourceController + createPersonBasedOn: + (self + requestToCreatePersonFrom: + '{"name":"Roberto", "lastName":"Rodriguez","email":"r.rodriguez@gmail.com"}') + within: self newHttpRequestContext. + self + assert: response isSuccess; + assert: response status equals: 201; + assertUrl: response location + equals: 'http://people.example.com/people/1'; + assert: response hasEntity; + assert: resourceController people size equals: 1; + assert: resourceController people first name equals: 'Roberto' ] diff --git a/source/TeamsAPI-Core/PeopleRESTfulController.class.st b/source/TeamsAPI-Core/PeopleRESTfulController.class.st new file mode 100644 index 0000000..64533bd --- /dev/null +++ b/source/TeamsAPI-Core/PeopleRESTfulController.class.st @@ -0,0 +1,39 @@ +Class { + #name : #PeopleRESTfulController, + #superclass : #ResourceRESTfulController, + #instVars : [ + 'people' + ], + #category : #'TeamsAPI-Core' +} + +{ #category : #'private - support' } +PeopleRESTfulController >> createPersonBasedOn: anHttpRequest within: aContext [ + ^ self + withCreatedResourceDo: [ :resource | + | newPerson | + newPerson := Person + named: resource name + surnamed: resource lastName + withEmailAddress: resource email. + people add: newPerson ] + decodedUsing: self specification personMappingKey + basedOn: anHttpRequest + within: aContext +] + +{ #category : #accesing } +PeopleRESTfulController >> initialize [ + super initialize. + people := OrderedCollection new +] + +{ #category : #accesing } +PeopleRESTfulController >> people [ + ^people +] + +{ #category : #specification } +PeopleRESTfulController >> specification [ + ^ PeopleRESTfulControllerSpecification new +] diff --git a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st index af43402..2ddfc0f 100644 --- a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st +++ b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st @@ -28,8 +28,18 @@ PeopleRESTfulControllerSpecification >> identifierKey [ ^#identifier ] -{ #category : #acccessing } +{ #category : #accessing } PeopleRESTfulControllerSpecification >> listTemplate [ ^self endpoint ] + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> personMappingKey [ + ^ #person +] + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> personVersion1dot0dot0MediaType [ + ^ 'application/vnd.stargate.person+json;version=1.0.0' asMediaType +] diff --git a/source/TeamsAPI-Core/TeamsRESTfulController.class.st b/source/TeamsAPI-Core/TeamsRESTfulController.class.st index 3c1d2d6..a673aa4 100644 --- a/source/TeamsAPI-Core/TeamsRESTfulController.class.st +++ b/source/TeamsAPI-Core/TeamsRESTfulController.class.st @@ -3,3 +3,15 @@ Class { #superclass : #ResourceRESTfulController, #category : #'TeamsAPI-Core' } + +{ #category : #initialization } +TeamsRESTfulController >> initialize [ + super initialize. + +] + +{ #category : #specification } +TeamsRESTfulController >> specification [ + + ^ TeamsRESTfulControllerSpecification new +] diff --git a/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st b/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st new file mode 100644 index 0000000..05dbaa8 --- /dev/null +++ b/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st @@ -0,0 +1,5 @@ +Class { + #name : #TeamsRESTfulControllerSpecification, + #superclass : #ResourceRESTfulControllerSpecification, + #category : #'TeamsAPI-Core' +} From 24a435bf6fe34467ff75b37e730b5a4e42077ab3 Mon Sep 17 00:00:00 2001 From: JuanEscalada Date: Tue, 21 May 2019 16:35:52 -0300 Subject: [PATCH 4/8] Fix Baseline --- source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st b/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st index d71f6a2..756be40 100644 --- a/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st +++ b/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st @@ -19,8 +19,11 @@ BaselineOfTeamsApi >> baseline: spec [ { #category : #accessing } BaselineOfTeamsApi >> baselineTeamsApi: spec [ + spec - package: 'TeamsAPI-Core' with: [ spec requires: #('Kepler') ]; + package: 'TeamsModel'; + package: 'TeamsAPI-Core' + with: [ spec requires: #('TeamsModel' 'Kepler') ]; group: 'Deployment' with: 'TeamsAPI-Core'; package: 'TeamsAPI-Core-Tests' with: [ spec requires: 'Deployment' ]; From fa8146afbb50cd222681b3be0df0076df1a1eece Mon Sep 17 00:00:00 2001 From: JuanEscalada Date: Tue, 21 May 2019 16:45:16 -0300 Subject: [PATCH 5/8] Fix baseline --- source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st b/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st index 756be40..7ea2a3f 100644 --- a/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st +++ b/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st @@ -22,12 +22,13 @@ BaselineOfTeamsApi >> baselineTeamsApi: spec [ spec package: 'TeamsModel'; + package: 'TeamsModel-Tests'; package: 'TeamsAPI-Core' with: [ spec requires: #('TeamsModel' 'Kepler') ]; - group: 'Deployment' with: 'TeamsAPI-Core'; package: 'TeamsAPI-Core-Tests' with: [ spec requires: 'Deployment' ]; - group: 'Tests' with: 'TeamsAPI-Core-Tests' + group: 'Deployment' with: #('TeamsAPI-Core' 'TeamsModel'); + group: 'Tests' with: #('TeamsAPI-Core-Tests' 'TeamsModel-Tests') ] { #category : #accessing } From 749780545c5c69c6735d6d13eb28fc70a742fab7 Mon Sep 17 00:00:00 2001 From: JuanEscalada Date: Tue, 21 May 2019 17:26:51 -0300 Subject: [PATCH 6/8] Se mueven clases de package y se agregan tags, se arregla baseline --- .../BaselineOfTeamsApi.class.st | 11 +- ...ESTfulControllerSpecificationTest.class.st | 4 +- ...ulControllerSpecificationTest.extension.st | 14 --- .../PeopleRESTfulControllerTest.class.st | 29 ++--- .../PersonSystemTest.class.st | 106 ++++++++++++++++ .../TeamsAPI-Core-Tests/PersonTest.class.st | 21 ++++ .../TeamSystemTest.class.st | 114 ++++++++++++++++++ source/TeamsAPI-Core-Tests/TeamTest.class.st | 29 +++++ .../ManifestTeamsAPISystem.class.st | 17 +++ .../PeopleRESTfulController.class.st | 4 +- ...pleRESTfulControllerSpecification.class.st | 26 ++-- source/TeamsAPI-Core/Person.class.st | 51 ++++++++ source/TeamsAPI-Core/PersonSystem.class.st | 49 ++++++++ source/TeamsAPI-Core/Team.class.st | 38 ++++++ source/TeamsAPI-Core/TeamSystem.class.st | 47 ++++++++ .../TeamsRESTfulController.class.st | 2 +- ...amsRESTfulControllerSpecification.class.st | 2 +- 17 files changed, 511 insertions(+), 53 deletions(-) delete mode 100644 source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st create mode 100644 source/TeamsAPI-Core-Tests/PersonSystemTest.class.st create mode 100644 source/TeamsAPI-Core-Tests/PersonTest.class.st create mode 100644 source/TeamsAPI-Core-Tests/TeamSystemTest.class.st create mode 100644 source/TeamsAPI-Core-Tests/TeamTest.class.st create mode 100644 source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st create mode 100644 source/TeamsAPI-Core/Person.class.st create mode 100644 source/TeamsAPI-Core/PersonSystem.class.st create mode 100644 source/TeamsAPI-Core/Team.class.st create mode 100644 source/TeamsAPI-Core/TeamSystem.class.st diff --git a/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st b/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st index 7ea2a3f..c9c4433 100644 --- a/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st +++ b/source/BaselineOfTeamsApi/BaselineOfTeamsApi.class.st @@ -21,14 +21,11 @@ BaselineOfTeamsApi >> baseline: spec [ BaselineOfTeamsApi >> baselineTeamsApi: spec [ spec - package: 'TeamsModel'; - package: 'TeamsModel-Tests'; - package: 'TeamsAPI-Core' - with: [ spec requires: #('TeamsModel' 'Kepler') ]; + package: 'TeamsAPI-Core' with: [ spec requires: #('Kepler') ]; package: 'TeamsAPI-Core-Tests' - with: [ spec requires: 'Deployment' ]; - group: 'Deployment' with: #('TeamsAPI-Core' 'TeamsModel'); - group: 'Tests' with: #('TeamsAPI-Core-Tests' 'TeamsModel-Tests') + with: [ spec requires: #('Deployment') ]; + group: 'Deployment' with: #('TeamsAPI-Core'); + group: 'Tests' with: #('TeamsAPI-Core-Tests') ] { #category : #accessing } diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st index 9363354..f6ae792 100644 --- a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.class.st @@ -1,10 +1,10 @@ Class { #name : #PeopleRESTfulControllerSpecificationTest, #superclass : #TestCase, - #category : #'TeamsAPI-Core-Tests' + #category : #'TeamsAPI-Core-Tests-Controllers' } -{ #category : #'*TeamsAPI-Core-Tests' } +{ #category : #'as yet unclassified' } PeopleRESTfulControllerSpecificationTest >> testTemplate [ | spec | diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st deleted file mode 100644 index 5a875ec..0000000 --- a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerSpecificationTest.extension.st +++ /dev/null @@ -1,14 +0,0 @@ -Extension { #name : #PeopleRESTfulControllerSpecificationTest } - -{ #category : #'*TeamsAPI-Core-Tests' } -PeopleRESTfulControllerSpecificationTest >> testTemplate [ - - | spec | - - spec := PeopleRESTfulControllerSpecification new. - - self - assert: spec addTemplate equals: '/people/'; - assert: spec listTemplate equals: '/people'; - assert: spec detailTemplate equals: '/people/' -] diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st index 5ad2984..12945a1 100644 --- a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st @@ -1,15 +1,13 @@ Class { #name : #PeopleRESTfulControllerTest, #superclass : #ResourceRESTfulControllerTest, - #category : #'TeamsAPI-Core-Tests' + #category : #'TeamsAPI-Core-Tests-Controllers' } { #category : #test } PeopleRESTfulControllerTest >> baseUrl [ - ^'https://teamsAPI.com' asZnUrl - - + ^ 'https://localhost' asZnUrl ] { #category : #'block support' } @@ -18,34 +16,31 @@ PeopleRESTfulControllerTest >> defaultPersonMediaType [ ] { #category : #'block support' } -PeopleRESTfulControllerTest >> requestToCreatePersonFrom: json [ - ^ self requestToPOST: json as: self defaultPersonMediaType -] +PeopleRESTfulControllerTest >> requestToCreatePersonFrom: json [ -{ #category : #test } -PeopleRESTfulControllerTest >> setUp [ - - super setUp. - self setUpResourceController. - resourceController serverUrl: self baseUrl asZnUrl. - self assert: resourceController people isEmpty - - + ^ self requestToPOST: json as: self defaultPersonMediaType ] { #category : #test } PeopleRESTfulControllerTest >> setUpResourceController [ + resourceController := PeopleRESTfulController new ] { #category : #tests } PeopleRESTfulControllerTest >> testPersonCreation [ + | response | + response := resourceController createPersonBasedOn: (self requestToCreatePersonFrom: - '{"name":"Roberto", "lastName":"Rodriguez","email":"r.rodriguez@gmail.com"}') + (NeoJSONObject new + at: #name put: 'Roberto'; + at: #lastName put: 'Rodriguez'; + at: #email put: 'r.rodriguez@gmail.com'; + yourself)) within: self newHttpRequestContext. self assert: response isSuccess; diff --git a/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st b/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st new file mode 100644 index 0000000..faa4a5f --- /dev/null +++ b/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st @@ -0,0 +1,106 @@ +" +A PersonSystemTest is a test class for testing the behavior of PersonSystem +" +Class { + #name : #PersonSystemTest, + #superclass : #TestCase, + #instVars : [ + 'rootSystem' + ], + #category : #'TeamsAPI-Core-Tests-Systems' +} + +{ #category : #acccessing } +PersonSystemTest >> lucasRojas [ + ^ Person + named: 'Lucas' + surnamed: 'Rojas' + withEmailAddress: 'l.rojas@gmail.com' +] + +{ #category : #acccessing } +PersonSystemTest >> personSystem [ + ^ rootSystem systemImplementing: #PersonSystemInterface +] + +{ #category : #initializing } +PersonSystemTest >> setUp [ + super setUp. + rootSystem := CompositeSystem new. + rootSystem + register: PersonSystem new; + register: TeamSystem new; + startUp +] + +{ #category : #tests } +PersonSystemTest >> testAddPerson [ + | person personSystem | + person := self lucasRojas. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + assertCollection: personSystem people + hasSameElements: (Array with: person) +] + +{ #category : #tests } +PersonSystemTest >> testDeletePerson [ + | person personSystem | + person := self lucasRojas. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + assertCollection: personSystem people + hasSameElements: (Array with: person). + personSystem stopManagingPerson: person. + self assert: personSystem people isEmpty +] + +{ #category : #tests } +PersonSystemTest >> testFailToDeletePersonAlreadyDeleted [ + | person personSystem | + person := self lucasRojas. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + assertCollection: personSystem people + hasSameElements: (Array with: person). + personSystem stopManagingPerson: person. + self + assert: personSystem people isEmpty; + should: [ personSystem stopManagingPerson: person ] + raise: AssertionFailed + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: + 'TStop managing person failed because it does not exist in the system.' ] +] + +{ #category : #tests } +PersonSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ + | person personSystem personWithSameEmail | + person := self lucasRojas. + personWithSameEmail := Person + named: 'Lucia' + surnamed: 'Rojas' + withEmailAddress: 'l.rojas@gmail.com'. + personSystem := self personSystem. + personSystem startManagingPerson: person. + self + should: [ personSystem startManagingPerson: personWithSameEmail ] + raise: Exception + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: + 'There''s already a person registered in our system with the email address: l.rojas@gmail.com.' ]; + assertCollection: personSystem people + hasSameElements: (Array with: person) +] + +{ #category : #tests } +PersonSystemTest >> testGetPeopleOnEmptySystem [ + self assert: self personSystem people isEmpty +] diff --git a/source/TeamsAPI-Core-Tests/PersonTest.class.st b/source/TeamsAPI-Core-Tests/PersonTest.class.st new file mode 100644 index 0000000..86cfbd8 --- /dev/null +++ b/source/TeamsAPI-Core-Tests/PersonTest.class.st @@ -0,0 +1,21 @@ +Class { + #name : #PersonTest, + #superclass : #TestCase, + #category : #'TeamsAPI-Core-Tests-Model' +} + +{ #category : #tests } +PersonTest >> testInstanceCreation [ + | person personName personEmail personLastName | + personName := 'La Raulito'. + personLastName := 'Perez'. + personEmail := 'laraulitoperez@gmail.com'. + person := Person + named: personName + surnamed: personLastName + withEmailAddress: personEmail. + self + assert: person name equals: personName; + assert: person lastName equals: personLastName; + assert: person emailAddress equals: personEmail +] diff --git a/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st b/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st new file mode 100644 index 0000000..ce03b6c --- /dev/null +++ b/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st @@ -0,0 +1,114 @@ +" +A TeamSystemTest is a test class for testing the behavior of TeamSystem +" +Class { + #name : #TeamSystemTest, + #superclass : #TestCase, + #instVars : [ + 'person', + 'anotherPerson', + 'rootSystem' + ], + #category : #'TeamsAPI-Core-Tests-Systems' +} + +{ #category : #running } +TeamSystemTest >> setUp [ + super setUp. + person := Person + named: 'Lucas' + surnamed: 'Rojas' + withEmailAddress: 'l.rojas@gmail.com'. + anotherPerson := Person + named: 'Rocio' + surnamed: 'Pasco' + withEmailAddress: 'r.pasco@gmail.com'. + rootSystem := CompositeSystem new. + rootSystem + register: PersonSystem new; + register: TeamSystem new; + startUp +] + +{ #category : #tests } +TeamSystemTest >> teamSystem [ + ^ rootSystem systemImplementing: #TeamSystemInterface +] + +{ #category : #tests } +TeamSystemTest >> testAddTeam [ + | team teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + assertCollection: teamSystem teams + hasSameElements: (Array with: team) +] + +{ #category : #tests } +TeamSystemTest >> testDeleteATeamAlreadyDeleted [ + | team teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + assertCollection: teamSystem teams + hasSameElements: (Array with: team). + teamSystem stopManagingTeam: team. + self + assert: teamSystem teams isEmpty; + should: [ teamSystem stopManagingTeam: team ] + raise: AssertionFailed + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: 'TStop managing team failed because it does not exist in the system.' ] +] + +{ #category : #tests } +TeamSystemTest >> testDeleteTeam [ + | team teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + assertCollection: teamSystem teams + hasSameElements: (Array with: team). + teamSystem stopManagingTeam: team. + self assert: teamSystem teams isEmpty +] + +{ #category : #tests } +TeamSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ + | team teamWithSameName teamSystem | + team := Team + named: 'Linces' + composedBy: (OrderedCollection with: person with: anotherPerson). + teamWithSameName := Team + named: 'Linces' + composedBy: (OrderedCollection with: anotherPerson). + teamSystem := self teamSystem. + teamSystem startManagingTeam: team. + self + should: [ teamSystem startManagingTeam: teamWithSameName ] + raise: Exception + withExceptionDo: [ :signal | + self + assert: signal messageText + equals: + 'There''s already a team registered in our system with the name: Linces.' ]; + assertCollection: teamSystem teams + hasSameElements: (Array with: team) +] + +{ #category : #tests } +TeamSystemTest >> testGetTeamsOnEmptySystem [ + self assert: self teamSystem teams isEmpty +] diff --git a/source/TeamsAPI-Core-Tests/TeamTest.class.st b/source/TeamsAPI-Core-Tests/TeamTest.class.st new file mode 100644 index 0000000..2dfce73 --- /dev/null +++ b/source/TeamsAPI-Core-Tests/TeamTest.class.st @@ -0,0 +1,29 @@ +Class { + #name : #TeamTest, + #superclass : #TestCase, + #instVars : [ + 'defaultPerson' + ], + #category : #'TeamsAPI-Core-Tests-Model' +} + +{ #category : #initialization } +TeamTest >> setUp [ + super setUp. + + defaultPerson := Person + named: 'Agustin' + surnamed: 'Tarda' + withEmailAddress: 'a.e.tarda@gmail.com' +] + +{ #category : #tests } +TeamTest >> testInstanceCreation [ + | teamMembers teamName team | + teamMembers := OrderedCollection with: defaultPerson. + teamName := 'Linces'. + team := Team named: teamName composedBy: teamMembers. + self + assert: team name equals: teamName; + assert: team members equals: teamMembers +] diff --git a/source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st b/source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st new file mode 100644 index 0000000..c547d75 --- /dev/null +++ b/source/TeamsAPI-Core/ManifestTeamsAPISystem.class.st @@ -0,0 +1,17 @@ +Class { + #name : #ManifestTeamsAPISystem, + #superclass : #PackageManifest, + #category : #'TeamsAPI-Core-Systems' +} + +{ #category : #'class initialization' } +ManifestTeamsAPISystem class >> initialize [ + + Kepler + registerInterfaceAt: #PersonSystemInterface + named: 'Person Management' + declaring: #(#startManagingPerson: #stopManagingPerson: #people); + registerInterfaceAt: #TeamSystemInterface + named: 'Team Management' + declaring: #(#startManagingTeam: #stopManagingTeam: #teams) +] diff --git a/source/TeamsAPI-Core/PeopleRESTfulController.class.st b/source/TeamsAPI-Core/PeopleRESTfulController.class.st index 64533bd..a2a72cd 100644 --- a/source/TeamsAPI-Core/PeopleRESTfulController.class.st +++ b/source/TeamsAPI-Core/PeopleRESTfulController.class.st @@ -4,14 +4,16 @@ Class { #instVars : [ 'people' ], - #category : #'TeamsAPI-Core' + #category : #'TeamsAPI-Core-Controllers' } { #category : #'private - support' } PeopleRESTfulController >> createPersonBasedOn: anHttpRequest within: aContext [ + ^ self withCreatedResourceDo: [ :resource | | newPerson | + newPerson := Person named: resource name surnamed: resource lastName diff --git a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st index 2ddfc0f..9bc2853 100644 --- a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st +++ b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st @@ -1,45 +1,51 @@ Class { #name : #PeopleRESTfulControllerSpecification, #superclass : #ResourceRESTfulControllerSpecification, - #category : #'TeamsAPI-Core' + #category : #'TeamsAPI-Core-Controllers' } { #category : #accessing } PeopleRESTfulControllerSpecification >> addTemplate [ - - ^'<1s>/%<<2s>:IsInteger>' expandMacrosWith: self endpoint with: self identifierKey + + ^ '<1s>/%<<2s>:IsInteger>' + expandMacrosWith: self endpoint + with: self identifierKey ] { #category : #accessing } PeopleRESTfulControllerSpecification >> detailTemplate [ - ^ '<1s>/%<<2s>:IsInteger>' expandMacrosWith: self endpoint with: self identifierKey + ^ '<1s>/%<<2s>:IsInteger>' + expandMacrosWith: self endpoint + with: self identifierKey ] { #category : #'private - accessing' } PeopleRESTfulControllerSpecification >> endpoint [ - - ^'/people' + + ^ '/people' ] { #category : #'private - accessing' } PeopleRESTfulControllerSpecification >> identifierKey [ - - ^#identifier + + ^ #identifier ] { #category : #accessing } PeopleRESTfulControllerSpecification >> listTemplate [ - - ^self endpoint + + ^ self endpoint ] { #category : #accessing } PeopleRESTfulControllerSpecification >> personMappingKey [ + ^ #person ] { #category : #accessing } PeopleRESTfulControllerSpecification >> personVersion1dot0dot0MediaType [ + ^ 'application/vnd.stargate.person+json;version=1.0.0' asMediaType ] diff --git a/source/TeamsAPI-Core/Person.class.st b/source/TeamsAPI-Core/Person.class.st new file mode 100644 index 0000000..a2b2421 --- /dev/null +++ b/source/TeamsAPI-Core/Person.class.st @@ -0,0 +1,51 @@ +Class { + #name : #Person, + #superclass : #Object, + #instVars : [ + 'name', + 'lastName', + 'emailAddress' + ], + #category : #'TeamsAPI-Core-Model' +} + +{ #category : #'private-assertions' } +Person class >> assertNotEmpty: aString forField: aFieldName [ + AssertionChecker + enforce: [ aString notEmpty ] + because: ('A person''s <1s> can''t be empty.' expandMacrosWith: aFieldName) +] + +{ #category : #'instance creation' } +Person class >> named: aName surnamed: aSurName withEmailAddress: anEmailAddress [ + self + assertNotEmpty: aName forField: 'name'; + assertNotEmpty: aSurName forField: 'surname'; + assertNotEmpty: anEmailAddress forField: 'email adress'. + ^ self new + initializeNamed: aName + surnamed: aSurName + withEmailAddress: anEmailAddress +] + +{ #category : #accessing } +Person >> emailAddress [ + ^ emailAddress +] + +{ #category : #initialization } +Person >> initializeNamed: aName surnamed: aLastName withEmailAddress: anEmailAddress [ + name := aName. + lastName := aLastName. + emailAddress := anEmailAddress +] + +{ #category : #accessing } +Person >> lastName [ + ^ lastName +] + +{ #category : #accessing } +Person >> name [ + ^ name +] diff --git a/source/TeamsAPI-Core/PersonSystem.class.st b/source/TeamsAPI-Core/PersonSystem.class.st new file mode 100644 index 0000000..4890971 --- /dev/null +++ b/source/TeamsAPI-Core/PersonSystem.class.st @@ -0,0 +1,49 @@ +Class { + #name : #PersonSystem, + #superclass : #SubsystemImplementation, + #instVars : [ + 'people' + ], + #category : #'TeamsAPI-Core-Systems' +} + +{ #category : #installing } +PersonSystem >> dependencies [ + ^ #() +] + +{ #category : #installing } +PersonSystem >> implementedInterfaces [ + ^ #(#PersonSystemInterface) +] + +{ #category : #installing } +PersonSystem >> initialize [ + super initialize. + people := OrderedCollection new +] + +{ #category : #accessing } +PersonSystem >> people [ + ^ people +] + +{ #category : #accessing } +PersonSystem >> startManagingPerson: aPerson [ + AssertionChecker + enforce: [ people + noneSatisfy: [ :person | person emailAddress = aPerson emailAddress ] ] + because: + ('There''s already a person registered in our system with the email address: <1s>.' + expandMacrosWith: aPerson emailAddress). + people add: aPerson +] + +{ #category : #accessing } +PersonSystem >> stopManagingPerson: aPerson [ + AssertionChecker + enforce: [ people anySatisfy: [ :person | person = aPerson ] ] + because: + 'TStop managing person failed because it does not exist in the system.'. + people remove: aPerson +] diff --git a/source/TeamsAPI-Core/Team.class.st b/source/TeamsAPI-Core/Team.class.st new file mode 100644 index 0000000..13c66a9 --- /dev/null +++ b/source/TeamsAPI-Core/Team.class.st @@ -0,0 +1,38 @@ +Class { + #name : #Team, + #superclass : #Object, + #instVars : [ + 'name', + 'members' + ], + #category : #'TeamsAPI-Core-Model' +} + +{ #category : #'instance creatio' } +Team class >> assertNotEmpty: aStringOrCollection forField: aFieldName [ + AssertionChecker + enforce: [ aStringOrCollection notEmpty ] + because: ('A team''s <1s> can''t be empty.' expandMacrosWith: aFieldName) +] + +{ #category : #'instance creatio' } +Team class >> named: aName composedBy: aPersonsCollection [ + self assertNotEmpty: aName forField: 'name'. + ^ self new initializeNamed: aName composedBy: aPersonsCollection +] + +{ #category : #initialization } +Team >> initializeNamed: aName composedBy: aPersonsCollection [ + name := aName. + members := aPersonsCollection +] + +{ #category : #accessing } +Team >> members [ + ^ members +] + +{ #category : #accessing } +Team >> name [ + ^ name +] diff --git a/source/TeamsAPI-Core/TeamSystem.class.st b/source/TeamsAPI-Core/TeamSystem.class.st new file mode 100644 index 0000000..af1bb10 --- /dev/null +++ b/source/TeamsAPI-Core/TeamSystem.class.st @@ -0,0 +1,47 @@ +Class { + #name : #TeamSystem, + #superclass : #SubsystemImplementation, + #instVars : [ + 'teams' + ], + #category : #'TeamsAPI-Core-Systems' +} + +{ #category : #installing } +TeamSystem >> dependencies [ + ^ #() +] + +{ #category : #initialization } +TeamSystem >> implementedInterfaces [ + ^ #(#TeamSystemInterface) +] + +{ #category : #initialization } +TeamSystem >> initialize [ + super initialize. + teams := OrderedCollection new +] + +{ #category : #adding } +TeamSystem >> startManagingTeam: aTeam [ + AssertionChecker + enforce: [ teams noneSatisfy: [ :team | team name = aTeam name ] ] + because: + ('There''s already a team registered in our system with the name: <1s>.' + expandMacrosWith: aTeam name). + teams add: aTeam +] + +{ #category : #adding } +TeamSystem >> stopManagingTeam: aTeam [ + AssertionChecker + enforce: [ teams anySatisfy: [ :team | aTeam = team ] ] + because: 'TStop managing team failed because it does not exist in the system.'. + teams remove: aTeam +] + +{ #category : #accessing } +TeamSystem >> teams [ + ^ teams +] diff --git a/source/TeamsAPI-Core/TeamsRESTfulController.class.st b/source/TeamsAPI-Core/TeamsRESTfulController.class.st index a673aa4..c911d9b 100644 --- a/source/TeamsAPI-Core/TeamsRESTfulController.class.st +++ b/source/TeamsAPI-Core/TeamsRESTfulController.class.st @@ -1,7 +1,7 @@ Class { #name : #TeamsRESTfulController, #superclass : #ResourceRESTfulController, - #category : #'TeamsAPI-Core' + #category : #'TeamsAPI-Core-Controllers' } { #category : #initialization } diff --git a/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st b/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st index 05dbaa8..6d2a0e9 100644 --- a/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st +++ b/source/TeamsAPI-Core/TeamsRESTfulControllerSpecification.class.st @@ -1,5 +1,5 @@ Class { #name : #TeamsRESTfulControllerSpecification, #superclass : #ResourceRESTfulControllerSpecification, - #category : #'TeamsAPI-Core' + #category : #'TeamsAPI-Core-Controllers' } From 65ba6c32540ad4ef2c5d9e81c1de76276f847eb7 Mon Sep 17 00:00:00 2001 From: JuanEscalada Date: Tue, 21 May 2019 17:30:09 -0300 Subject: [PATCH 7/8] Se quitan packages que ya no tienen sentido --- .../PersonSystemTest.class.st | 106 ---------------- source/TeamsModel-Tests/PersonTest.class.st | 21 ---- .../TeamsModel-Tests/TeamSystemTest.class.st | 114 ------------------ source/TeamsModel-Tests/TeamTest.class.st | 29 ----- source/TeamsModel-Tests/package.st | 1 - .../ManifestTeamsAPISystem.class.st | 17 --- source/TeamsModel/Person.class.st | 51 -------- source/TeamsModel/PersonSystem.class.st | 49 -------- source/TeamsModel/Team.class.st | 38 ------ source/TeamsModel/TeamSystem.class.st | 47 -------- source/TeamsModel/package.st | 1 - 11 files changed, 474 deletions(-) delete mode 100644 source/TeamsModel-Tests/PersonSystemTest.class.st delete mode 100644 source/TeamsModel-Tests/PersonTest.class.st delete mode 100644 source/TeamsModel-Tests/TeamSystemTest.class.st delete mode 100644 source/TeamsModel-Tests/TeamTest.class.st delete mode 100644 source/TeamsModel-Tests/package.st delete mode 100644 source/TeamsModel/ManifestTeamsAPISystem.class.st delete mode 100644 source/TeamsModel/Person.class.st delete mode 100644 source/TeamsModel/PersonSystem.class.st delete mode 100644 source/TeamsModel/Team.class.st delete mode 100644 source/TeamsModel/TeamSystem.class.st delete mode 100644 source/TeamsModel/package.st diff --git a/source/TeamsModel-Tests/PersonSystemTest.class.st b/source/TeamsModel-Tests/PersonSystemTest.class.st deleted file mode 100644 index c0743e7..0000000 --- a/source/TeamsModel-Tests/PersonSystemTest.class.st +++ /dev/null @@ -1,106 +0,0 @@ -" -A PersonSystemTest is a test class for testing the behavior of PersonSystem -" -Class { - #name : #PersonSystemTest, - #superclass : #TestCase, - #instVars : [ - 'rootSystem' - ], - #category : #'TeamsModel-Tests' -} - -{ #category : #acccessing } -PersonSystemTest >> lucasRojas [ - ^ Person - named: 'Lucas' - surnamed: 'Rojas' - withEmailAddress: 'l.rojas@gmail.com' -] - -{ #category : #acccessing } -PersonSystemTest >> personSystem [ - ^ rootSystem systemImplementing: #PersonSystemInterface -] - -{ #category : #initializing } -PersonSystemTest >> setUp [ - super setUp. - rootSystem := CompositeSystem new. - rootSystem - register: PersonSystem new; - register: TeamSystem new; - startUp -] - -{ #category : #tests } -PersonSystemTest >> testAddPerson [ - | person personSystem | - person := self lucasRojas. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - assertCollection: personSystem people - hasSameElements: (Array with: person) -] - -{ #category : #tests } -PersonSystemTest >> testDeletePerson [ - | person personSystem | - person := self lucasRojas. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - assertCollection: personSystem people - hasSameElements: (Array with: person). - personSystem stopManagingPerson: person. - self assert: personSystem people isEmpty -] - -{ #category : #tests } -PersonSystemTest >> testFailToDeletePersonAlreadyDeleted [ - | person personSystem | - person := self lucasRojas. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - assertCollection: personSystem people - hasSameElements: (Array with: person). - personSystem stopManagingPerson: person. - self - assert: personSystem people isEmpty; - should: [ personSystem stopManagingPerson: person ] - raise: AssertionFailed - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: - 'TStop managing person failed because it does not exist in the system.' ] -] - -{ #category : #tests } -PersonSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ - | person personSystem personWithSameEmail | - person := self lucasRojas. - personWithSameEmail := Person - named: 'Lucia' - surnamed: 'Rojas' - withEmailAddress: 'l.rojas@gmail.com'. - personSystem := self personSystem. - personSystem startManagingPerson: person. - self - should: [ personSystem startManagingPerson: personWithSameEmail ] - raise: Exception - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: - 'There''s already a person registered in our system with the email address: l.rojas@gmail.com.' ]; - assertCollection: personSystem people - hasSameElements: (Array with: person) -] - -{ #category : #tests } -PersonSystemTest >> testGetPeopleOnEmptySystem [ - self assert: self personSystem people isEmpty -] diff --git a/source/TeamsModel-Tests/PersonTest.class.st b/source/TeamsModel-Tests/PersonTest.class.st deleted file mode 100644 index 3447146..0000000 --- a/source/TeamsModel-Tests/PersonTest.class.st +++ /dev/null @@ -1,21 +0,0 @@ -Class { - #name : #PersonTest, - #superclass : #TestCase, - #category : #'TeamsModel-Tests' -} - -{ #category : #tests } -PersonTest >> testInstanceCreation [ - | person personName personEmail personLastName | - personName := 'La Raulito'. - personLastName := 'Perez'. - personEmail := 'laraulitoperez@gmail.com'. - person := Person - named: personName - surnamed: personLastName - withEmailAddress: personEmail. - self - assert: person name equals: personName; - assert: person lastName equals: personLastName; - assert: person emailAddress equals: personEmail -] diff --git a/source/TeamsModel-Tests/TeamSystemTest.class.st b/source/TeamsModel-Tests/TeamSystemTest.class.st deleted file mode 100644 index 70c2cc8..0000000 --- a/source/TeamsModel-Tests/TeamSystemTest.class.st +++ /dev/null @@ -1,114 +0,0 @@ -" -A TeamSystemTest is a test class for testing the behavior of TeamSystem -" -Class { - #name : #TeamSystemTest, - #superclass : #TestCase, - #instVars : [ - 'person', - 'anotherPerson', - 'rootSystem' - ], - #category : #'TeamsModel-Tests' -} - -{ #category : #running } -TeamSystemTest >> setUp [ - super setUp. - person := Person - named: 'Lucas' - surnamed: 'Rojas' - withEmailAddress: 'l.rojas@gmail.com'. - anotherPerson := Person - named: 'Rocio' - surnamed: 'Pasco' - withEmailAddress: 'r.pasco@gmail.com'. - rootSystem := CompositeSystem new. - rootSystem - register: PersonSystem new; - register: TeamSystem new; - startUp -] - -{ #category : #tests } -TeamSystemTest >> teamSystem [ - ^ rootSystem systemImplementing: #TeamSystemInterface -] - -{ #category : #tests } -TeamSystemTest >> testAddTeam [ - | team teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - assertCollection: teamSystem teams - hasSameElements: (Array with: team) -] - -{ #category : #tests } -TeamSystemTest >> testDeleteATeamAlreadyDeleted [ - | team teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - assertCollection: teamSystem teams - hasSameElements: (Array with: team). - teamSystem stopManagingTeam: team. - self - assert: teamSystem teams isEmpty; - should: [ teamSystem stopManagingTeam: team ] - raise: AssertionFailed - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: 'TStop managing team failed because it does not exist in the system.' ] -] - -{ #category : #tests } -TeamSystemTest >> testDeleteTeam [ - | team teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - assertCollection: teamSystem teams - hasSameElements: (Array with: team). - teamSystem stopManagingTeam: team. - self assert: teamSystem teams isEmpty -] - -{ #category : #tests } -TeamSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ - | team teamWithSameName teamSystem | - team := Team - named: 'Linces' - composedBy: (OrderedCollection with: person with: anotherPerson). - teamWithSameName := Team - named: 'Linces' - composedBy: (OrderedCollection with: anotherPerson). - teamSystem := self teamSystem. - teamSystem startManagingTeam: team. - self - should: [ teamSystem startManagingTeam: teamWithSameName ] - raise: Exception - withExceptionDo: [ :signal | - self - assert: signal messageText - equals: - 'There''s already a team registered in our system with the name: Linces.' ]; - assertCollection: teamSystem teams - hasSameElements: (Array with: team) -] - -{ #category : #tests } -TeamSystemTest >> testGetTeamsOnEmptySystem [ - self assert: self teamSystem teams isEmpty -] diff --git a/source/TeamsModel-Tests/TeamTest.class.st b/source/TeamsModel-Tests/TeamTest.class.st deleted file mode 100644 index a9b88df..0000000 --- a/source/TeamsModel-Tests/TeamTest.class.st +++ /dev/null @@ -1,29 +0,0 @@ -Class { - #name : #TeamTest, - #superclass : #TestCase, - #instVars : [ - 'defaultPerson' - ], - #category : #'TeamsModel-Tests' -} - -{ #category : #initialization } -TeamTest >> setUp [ - super setUp. - - defaultPerson := Person - named: 'Agustin' - surnamed: 'Tarda' - withEmailAddress: 'a.e.tarda@gmail.com' -] - -{ #category : #tests } -TeamTest >> testInstanceCreation [ - | teamMembers teamName team | - teamMembers := OrderedCollection with: defaultPerson. - teamName := 'Linces'. - team := Team named: teamName composedBy: teamMembers. - self - assert: team name equals: teamName; - assert: team members equals: teamMembers -] diff --git a/source/TeamsModel-Tests/package.st b/source/TeamsModel-Tests/package.st deleted file mode 100644 index bb629e8..0000000 --- a/source/TeamsModel-Tests/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : #'TeamsModel-Tests' } diff --git a/source/TeamsModel/ManifestTeamsAPISystem.class.st b/source/TeamsModel/ManifestTeamsAPISystem.class.st deleted file mode 100644 index 48ac181..0000000 --- a/source/TeamsModel/ManifestTeamsAPISystem.class.st +++ /dev/null @@ -1,17 +0,0 @@ -Class { - #name : #ManifestTeamsAPISystem, - #superclass : #PackageManifest, - #category : #TeamsModel -} - -{ #category : #'class initialization' } -ManifestTeamsAPISystem class >> initialize [ - - Kepler - registerInterfaceAt: #PersonSystemInterface - named: 'Person Management' - declaring: #(#startManagingPerson: #stopManagingPerson: #people); - registerInterfaceAt: #TeamSystemInterface - named: 'Team Management' - declaring: #(#startManagingTeam: #stopManagingTeam: #teams) -] diff --git a/source/TeamsModel/Person.class.st b/source/TeamsModel/Person.class.st deleted file mode 100644 index d1662fb..0000000 --- a/source/TeamsModel/Person.class.st +++ /dev/null @@ -1,51 +0,0 @@ -Class { - #name : #Person, - #superclass : #Object, - #instVars : [ - 'name', - 'lastName', - 'emailAddress' - ], - #category : #TeamsModel -} - -{ #category : #'private-assertions' } -Person class >> assertNotEmpty: aString forField: aFieldName [ - AssertionChecker - enforce: [ aString notEmpty ] - because: ('A person''s <1s> can''t be empty.' expandMacrosWith: aFieldName) -] - -{ #category : #'instance creation' } -Person class >> named: aName surnamed: aSurName withEmailAddress: anEmailAddress [ - self - assertNotEmpty: aName forField: 'name'; - assertNotEmpty: aSurName forField: 'surname'; - assertNotEmpty: anEmailAddress forField: 'email adress'. - ^ self new - initializeNamed: aName - surnamed: aSurName - withEmailAddress: anEmailAddress -] - -{ #category : #accessing } -Person >> emailAddress [ - ^ emailAddress -] - -{ #category : #initialization } -Person >> initializeNamed: aName surnamed: aLastName withEmailAddress: anEmailAddress [ - name := aName. - lastName := aLastName. - emailAddress := anEmailAddress -] - -{ #category : #accessing } -Person >> lastName [ - ^ lastName -] - -{ #category : #accessing } -Person >> name [ - ^ name -] diff --git a/source/TeamsModel/PersonSystem.class.st b/source/TeamsModel/PersonSystem.class.st deleted file mode 100644 index 3c14d94..0000000 --- a/source/TeamsModel/PersonSystem.class.st +++ /dev/null @@ -1,49 +0,0 @@ -Class { - #name : #PersonSystem, - #superclass : #SubsystemImplementation, - #instVars : [ - 'people' - ], - #category : #TeamsModel -} - -{ #category : #installing } -PersonSystem >> dependencies [ - ^ #() -] - -{ #category : #installing } -PersonSystem >> implementedInterfaces [ - ^ #(#PersonSystemInterface) -] - -{ #category : #installing } -PersonSystem >> initialize [ - super initialize. - people := OrderedCollection new -] - -{ #category : #accessing } -PersonSystem >> people [ - ^ people -] - -{ #category : #accessing } -PersonSystem >> startManagingPerson: aPerson [ - AssertionChecker - enforce: [ people - noneSatisfy: [ :person | person emailAddress = aPerson emailAddress ] ] - because: - ('There''s already a person registered in our system with the email address: <1s>.' - expandMacrosWith: aPerson emailAddress). - people add: aPerson -] - -{ #category : #accessing } -PersonSystem >> stopManagingPerson: aPerson [ - AssertionChecker - enforce: [ people anySatisfy: [ :person | person = aPerson ] ] - because: - 'TStop managing person failed because it does not exist in the system.'. - people remove: aPerson -] diff --git a/source/TeamsModel/Team.class.st b/source/TeamsModel/Team.class.st deleted file mode 100644 index fe494ca..0000000 --- a/source/TeamsModel/Team.class.st +++ /dev/null @@ -1,38 +0,0 @@ -Class { - #name : #Team, - #superclass : #Object, - #instVars : [ - 'name', - 'members' - ], - #category : #TeamsModel -} - -{ #category : #'instance creatio' } -Team class >> assertNotEmpty: aStringOrCollection forField: aFieldName [ - AssertionChecker - enforce: [ aStringOrCollection notEmpty ] - because: ('A team''s <1s> can''t be empty.' expandMacrosWith: aFieldName) -] - -{ #category : #'instance creatio' } -Team class >> named: aName composedBy: aPersonsCollection [ - self assertNotEmpty: aName forField: 'name'. - ^ self new initializeNamed: aName composedBy: aPersonsCollection -] - -{ #category : #initialization } -Team >> initializeNamed: aName composedBy: aPersonsCollection [ - name := aName. - members := aPersonsCollection -] - -{ #category : #accessing } -Team >> members [ - ^ members -] - -{ #category : #accessing } -Team >> name [ - ^ name -] diff --git a/source/TeamsModel/TeamSystem.class.st b/source/TeamsModel/TeamSystem.class.st deleted file mode 100644 index a314d89..0000000 --- a/source/TeamsModel/TeamSystem.class.st +++ /dev/null @@ -1,47 +0,0 @@ -Class { - #name : #TeamSystem, - #superclass : #SubsystemImplementation, - #instVars : [ - 'teams' - ], - #category : #TeamsModel -} - -{ #category : #installing } -TeamSystem >> dependencies [ - ^ #() -] - -{ #category : #initialization } -TeamSystem >> implementedInterfaces [ - ^ #(#TeamSystemInterface) -] - -{ #category : #initialization } -TeamSystem >> initialize [ - super initialize. - teams := OrderedCollection new -] - -{ #category : #adding } -TeamSystem >> startManagingTeam: aTeam [ - AssertionChecker - enforce: [ teams noneSatisfy: [ :team | team name = aTeam name ] ] - because: - ('There''s already a team registered in our system with the name: <1s>.' - expandMacrosWith: aTeam name). - teams add: aTeam -] - -{ #category : #adding } -TeamSystem >> stopManagingTeam: aTeam [ - AssertionChecker - enforce: [ teams anySatisfy: [ :team | aTeam = team ] ] - because: 'TStop managing team failed because it does not exist in the system.'. - teams remove: aTeam -] - -{ #category : #accessing } -TeamSystem >> teams [ - ^ teams -] diff --git a/source/TeamsModel/package.st b/source/TeamsModel/package.st deleted file mode 100644 index 3d775d7..0000000 --- a/source/TeamsModel/package.st +++ /dev/null @@ -1 +0,0 @@ -Package { #name : #TeamsModel } From b36429594f7e123ba8016ca436eca9bb42a3f0ec Mon Sep 17 00:00:00 2001 From: JuanEscalada Date: Tue, 21 May 2019 19:11:08 -0300 Subject: [PATCH 8/8] Se hacen renames varios, se agrega comportamiento a controller de persona, se agregan configuraciones de media types a specification de persona, se agrega test y se arregla test que fallaba. --- .../PeopleRESTfulControllerTest.class.st | 75 ++++++++++++++--- ...st => PersonManagementSystemTest.class.st} | 22 ++--- ...s.st => TeamManagementSystemTest.class.st} | 20 ++--- .../PeopleManagementSystem.class.st | 79 +++++++++++++++++ .../PeopleRESTfulController.class.st | 84 +++++++++++++++---- ...pleRESTfulControllerSpecification.class.st | 65 +++++++++++++- source/TeamsAPI-Core/Person.class.st | 15 +++- source/TeamsAPI-Core/PersonSystem.class.st | 49 ----------- ...class.st => TeamManagementSystem.class.st} | 20 +++-- 9 files changed, 324 insertions(+), 105 deletions(-) rename source/TeamsAPI-Core-Tests/{PersonSystemTest.class.st => PersonManagementSystemTest.class.st} (81%) rename source/TeamsAPI-Core-Tests/{TeamSystemTest.class.st => TeamManagementSystemTest.class.st} (84%) create mode 100644 source/TeamsAPI-Core/PeopleManagementSystem.class.st delete mode 100644 source/TeamsAPI-Core/PersonSystem.class.st rename source/TeamsAPI-Core/{TeamSystem.class.st => TeamManagementSystem.class.st} (67%) diff --git a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st index 12945a1..3b209b2 100644 --- a/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st +++ b/source/TeamsAPI-Core-Tests/PeopleRESTfulControllerTest.class.st @@ -1,13 +1,16 @@ Class { #name : #PeopleRESTfulControllerTest, #superclass : #ResourceRESTfulControllerTest, + #instVars : [ + 'peopleManagementSystem' + ], #category : #'TeamsAPI-Core-Tests-Controllers' } { #category : #test } PeopleRESTfulControllerTest >> baseUrl [ - ^ 'https://localhost' asZnUrl + ^ 'http://people.mercap.net' asZnUrl ] { #category : #'block support' } @@ -15,16 +18,66 @@ PeopleRESTfulControllerTest >> defaultPersonMediaType [ ^ resourceController specification personVersion1dot0dot0MediaType ] +{ #category : #'block support' } +PeopleRESTfulControllerTest >> registerPerson: aPerson [ + + peopleManagementSystem startManagingPerson: aPerson +] + { #category : #'block support' } PeopleRESTfulControllerTest >> requestToCreatePersonFrom: json [ ^ self requestToPOST: json as: self defaultPersonMediaType ] +{ #category : #'block support' } +PeopleRESTfulControllerTest >> requestToGet: aUrl accepting: anAcceptHeader [ + + ^ TeaRequest + fromZnRequest: + ((ZnRequest get: aUrl) + setAccept: anAcceptHeader; + yourself) +] + +{ #category : #'block support' } +PeopleRESTfulControllerTest >> requestToGetPeopleAccepting: anAcceptHeader [ + + ^ self requestToGet: self resourceUrl accepting: anAcceptHeader +] + +{ #category : #test } +PeopleRESTfulControllerTest >> setUp [ + + peopleManagementSystem := PeopleManagementSystem new. + super setUp +] + { #category : #test } PeopleRESTfulControllerTest >> setUpResourceController [ - resourceController := PeopleRESTfulController new + resourceController := PeopleRESTfulController + for: peopleManagementSystem +] + +{ #category : #tests } +PeopleRESTfulControllerTest >> testGetWhenNoPeopleRegistered [ + + | response | + + response := resourceController + getPeopleBasedOn: (self requestToGetPeopleAccepting: '*/*') + within: self newHttpRequestContext. + + self + assert: response isSuccess; + assert: response status equals: 200; + assert: response contentType asMediaType + equals: resourceController specification personVersion1dot0dot0MediaType. + + self + withJsonFromContentsIn: response + do: [ :people | self assert: people isEmpty ] ] { #category : #tests } @@ -36,18 +89,20 @@ PeopleRESTfulControllerTest >> testPersonCreation [ createPersonBasedOn: (self requestToCreatePersonFrom: - (NeoJSONObject new - at: #name put: 'Roberto'; - at: #lastName put: 'Rodriguez'; - at: #email put: 'r.rodriguez@gmail.com'; - yourself)) + '{"name":"Roberto","lastName":"Rodriguez","email":"r.rodriguez@gmail.com"}') within: self newHttpRequestContext. self assert: response isSuccess; assert: response status equals: 201; assertUrl: response location - equals: 'http://people.example.com/people/1'; + equals: 'http://people.mercap.net/people/1'; assert: response hasEntity; - assert: resourceController people size equals: 1; - assert: resourceController people first name equals: 'Roberto' + assert: peopleManagementSystem people size equals: 1; + assert: peopleManagementSystem people first name equals: 'Roberto' +] + +{ #category : #test } +PeopleRESTfulControllerTest >> urlOf: aPerson [ + + ^ (self resourceUrl / aPerson uuid asString) asString ] diff --git a/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st b/source/TeamsAPI-Core-Tests/PersonManagementSystemTest.class.st similarity index 81% rename from source/TeamsAPI-Core-Tests/PersonSystemTest.class.st rename to source/TeamsAPI-Core-Tests/PersonManagementSystemTest.class.st index faa4a5f..7211ab6 100644 --- a/source/TeamsAPI-Core-Tests/PersonSystemTest.class.st +++ b/source/TeamsAPI-Core-Tests/PersonManagementSystemTest.class.st @@ -2,7 +2,7 @@ A PersonSystemTest is a test class for testing the behavior of PersonSystem " Class { - #name : #PersonSystemTest, + #name : #PersonManagementSystemTest, #superclass : #TestCase, #instVars : [ 'rootSystem' @@ -11,7 +11,7 @@ Class { } { #category : #acccessing } -PersonSystemTest >> lucasRojas [ +PersonManagementSystemTest >> lucasRojas [ ^ Person named: 'Lucas' surnamed: 'Rojas' @@ -19,22 +19,22 @@ PersonSystemTest >> lucasRojas [ ] { #category : #acccessing } -PersonSystemTest >> personSystem [ +PersonManagementSystemTest >> personSystem [ ^ rootSystem systemImplementing: #PersonSystemInterface ] { #category : #initializing } -PersonSystemTest >> setUp [ +PersonManagementSystemTest >> setUp [ super setUp. rootSystem := CompositeSystem new. rootSystem - register: PersonSystem new; - register: TeamSystem new; + register: PeopleManagementSystem new; + register: TeamManagementSystem new; startUp ] { #category : #tests } -PersonSystemTest >> testAddPerson [ +PersonManagementSystemTest >> testAddPerson [ | person personSystem | person := self lucasRojas. personSystem := self personSystem. @@ -45,7 +45,7 @@ PersonSystemTest >> testAddPerson [ ] { #category : #tests } -PersonSystemTest >> testDeletePerson [ +PersonManagementSystemTest >> testDeletePerson [ | person personSystem | person := self lucasRojas. personSystem := self personSystem. @@ -58,7 +58,7 @@ PersonSystemTest >> testDeletePerson [ ] { #category : #tests } -PersonSystemTest >> testFailToDeletePersonAlreadyDeleted [ +PersonManagementSystemTest >> testFailToDeletePersonAlreadyDeleted [ | person personSystem | person := self lucasRojas. personSystem := self personSystem. @@ -79,7 +79,7 @@ PersonSystemTest >> testFailToDeletePersonAlreadyDeleted [ ] { #category : #tests } -PersonSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ +PersonManagementSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ | person personSystem personWithSameEmail | person := self lucasRojas. personWithSameEmail := Person @@ -101,6 +101,6 @@ PersonSystemTest >> testFailWhenAddingAPersonWithSameEmailAddress [ ] { #category : #tests } -PersonSystemTest >> testGetPeopleOnEmptySystem [ +PersonManagementSystemTest >> testGetPeopleOnEmptySystem [ self assert: self personSystem people isEmpty ] diff --git a/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st b/source/TeamsAPI-Core-Tests/TeamManagementSystemTest.class.st similarity index 84% rename from source/TeamsAPI-Core-Tests/TeamSystemTest.class.st rename to source/TeamsAPI-Core-Tests/TeamManagementSystemTest.class.st index ce03b6c..56ee420 100644 --- a/source/TeamsAPI-Core-Tests/TeamSystemTest.class.st +++ b/source/TeamsAPI-Core-Tests/TeamManagementSystemTest.class.st @@ -2,7 +2,7 @@ A TeamSystemTest is a test class for testing the behavior of TeamSystem " Class { - #name : #TeamSystemTest, + #name : #TeamManagementSystemTest, #superclass : #TestCase, #instVars : [ 'person', @@ -13,7 +13,7 @@ Class { } { #category : #running } -TeamSystemTest >> setUp [ +TeamManagementSystemTest >> setUp [ super setUp. person := Person named: 'Lucas' @@ -25,18 +25,18 @@ TeamSystemTest >> setUp [ withEmailAddress: 'r.pasco@gmail.com'. rootSystem := CompositeSystem new. rootSystem - register: PersonSystem new; - register: TeamSystem new; + register: PeopleManagementSystem new; + register: TeamManagementSystem new; startUp ] { #category : #tests } -TeamSystemTest >> teamSystem [ +TeamManagementSystemTest >> teamSystem [ ^ rootSystem systemImplementing: #TeamSystemInterface ] { #category : #tests } -TeamSystemTest >> testAddTeam [ +TeamManagementSystemTest >> testAddTeam [ | team teamSystem | team := Team named: 'Linces' @@ -49,7 +49,7 @@ TeamSystemTest >> testAddTeam [ ] { #category : #tests } -TeamSystemTest >> testDeleteATeamAlreadyDeleted [ +TeamManagementSystemTest >> testDeleteATeamAlreadyDeleted [ | team teamSystem | team := Team named: 'Linces' @@ -71,7 +71,7 @@ TeamSystemTest >> testDeleteATeamAlreadyDeleted [ ] { #category : #tests } -TeamSystemTest >> testDeleteTeam [ +TeamManagementSystemTest >> testDeleteTeam [ | team teamSystem | team := Team named: 'Linces' @@ -86,7 +86,7 @@ TeamSystemTest >> testDeleteTeam [ ] { #category : #tests } -TeamSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ +TeamManagementSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ | team teamWithSameName teamSystem | team := Team named: 'Linces' @@ -109,6 +109,6 @@ TeamSystemTest >> testFailToAddTeamWithNamedAlreadyUsed [ ] { #category : #tests } -TeamSystemTest >> testGetTeamsOnEmptySystem [ +TeamManagementSystemTest >> testGetTeamsOnEmptySystem [ self assert: self teamSystem teams isEmpty ] diff --git a/source/TeamsAPI-Core/PeopleManagementSystem.class.st b/source/TeamsAPI-Core/PeopleManagementSystem.class.st new file mode 100644 index 0000000..7b7c58a --- /dev/null +++ b/source/TeamsAPI-Core/PeopleManagementSystem.class.st @@ -0,0 +1,79 @@ +Class { + #name : #PeopleManagementSystem, + #superclass : #SubsystemImplementation, + #instVars : [ + 'people', + 'uuidProvider' + ], + #category : #'TeamsAPI-Core-Systems' +} + +{ #category : #installing } +PeopleManagementSystem >> dependencies [ + ^ #() +] + +{ #category : #installing } +PeopleManagementSystem >> getNewUUID [ + + | newId | + + newId := uuidProvider. + uuidProvider := newId + 1. + ^ newId +] + +{ #category : #installing } +PeopleManagementSystem >> implementedInterfaces [ + ^ #(#PersonSystemInterface) +] + +{ #category : #installing } +PeopleManagementSystem >> initialize [ + + super initialize. + uuidProvider := 1. + people := OrderedCollection new +] + +{ #category : #accessing } +PeopleManagementSystem >> name [ + + ^ 'People Management System' +] + +{ #category : #accessing } +PeopleManagementSystem >> people [ + ^ people +] + +{ #category : #accessing } +PeopleManagementSystem >> personIdentifiedBy: anUUID ifFound: aFoundBlock ifNone: aNoneFoundBlock [ + + ^ people + detect: [ :person | person uuid = anUUID ] + ifFound: aFoundBlock + ifNone: aNoneFoundBlock +] + +{ #category : #accessing } +PeopleManagementSystem >> startManagingPerson: aPerson [ + + AssertionChecker + enforce: [ people + noneSatisfy: [ :person | person emailAddress = aPerson emailAddress ] ] + because: + ('There''s already a person registered in our system with the email address: <1s>.' + expandMacrosWith: aPerson emailAddress). + aPerson uuid: self getNewUUID. + people add: aPerson +] + +{ #category : #accessing } +PeopleManagementSystem >> stopManagingPerson: aPerson [ + AssertionChecker + enforce: [ people anySatisfy: [ :person | person = aPerson ] ] + because: + 'TStop managing person failed because it does not exist in the system.'. + people remove: aPerson +] diff --git a/source/TeamsAPI-Core/PeopleRESTfulController.class.st b/source/TeamsAPI-Core/PeopleRESTfulController.class.st index a2a72cd..4fa9f57 100644 --- a/source/TeamsAPI-Core/PeopleRESTfulController.class.st +++ b/source/TeamsAPI-Core/PeopleRESTfulController.class.st @@ -2,37 +2,89 @@ Class { #name : #PeopleRESTfulController, #superclass : #ResourceRESTfulController, #instVars : [ - 'people' + 'peopleManagementSystem' ], #category : #'TeamsAPI-Core-Controllers' } +{ #category : #'instance creation' } +PeopleRESTfulController class >> for: aPeopleManagementSystem [ + + ^ self new initializeFor: aPeopleManagementSystem +] + { #category : #'private - support' } PeopleRESTfulController >> createPersonBasedOn: anHttpRequest within: aContext [ ^ self - withCreatedResourceDo: [ :resource | - | newPerson | - - newPerson := Person - named: resource name - surnamed: resource lastName - withEmailAddress: resource email. - people add: newPerson ] + withCreatedResourceDo: [ :newPerson | + peopleManagementSystem startManagingPerson: newPerson. + newPerson ] decodedUsing: self specification personMappingKey basedOn: anHttpRequest within: aContext ] -{ #category : #accesing } -PeopleRESTfulController >> initialize [ - super initialize. - people := OrderedCollection new +{ #category : #'private - accessing' } +PeopleRESTfulController >> entityTagOf: aResource encodedAs: mediaType [ + + ^ ZnETag with: (MD5 hashMessage: aResource printString) hex +] + +{ #category : #'private - support' } +PeopleRESTfulController >> getPeopleBasedOn: aTeaRequest within: aContext [ + + ^ self + get: [ peopleManagementSystem people ] + asCollectionEncodedUsing: self specification peopleMappingKey + basedOn: aTeaRequest + within: aContext ] -{ #category : #accesing } -PeopleRESTfulController >> people [ - ^people +{ #category : #'private - support' } +PeopleRESTfulController >> getPersonBasedOn: anHttpRequest within: aContext [ + + ^ self + get: [ | uuid | + + uuid := UUID fromString: (anHttpRequest at: #identifier). + peopleManagementSystem + personIdentifiedBy: uuid + ifFound: #yourself + ifNone: [ ObjectNotFound signal ] ] + encodedUsing: self specification personMappingKey + basedOn: anHttpRequest + within: aContext +] + +{ #category : #'private - support' } +PeopleRESTfulController >> initializeFor: aPeopleManagementSystem [ + + peopleManagementSystem := aPeopleManagementSystem +] + +{ #category : #'private - accessing' } +PeopleRESTfulController >> locationOf: aResource [ + + | baseUrl | + + baseUrl := (baseUrlOptional withContentDo: #yourself ifUnused: [ '' ]) + asZnUrl. + + ^ baseUrl / self specification endpoint + / aResource uuid printString asZnUrl +] + +{ #category : #'private - accessing' } +PeopleRESTfulController >> provideHypermediaPolicy [ + + ^ HypermediaDrivenRESTfulControllerPolicy for: self +] + +{ #category : #'private - accessing' } +PeopleRESTfulController >> providePaginationPolicy [ + + ^ RESTfulControllerDoNotPaginateCollectionsPolicy for: self ] { #category : #specification } diff --git a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st index 9bc2853..eb24fc7 100644 --- a/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st +++ b/source/TeamsAPI-Core/PeopleRESTfulControllerSpecification.class.st @@ -4,6 +4,63 @@ Class { #category : #'TeamsAPI-Core-Controllers' } +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> addJsonPeopleVersion1dot0dot0MappingIn: aBuilder [ + + self + addJsonPeopleVersion1dot0dot0MappingIn: aBuilder + withHypermediaFrom: [ :resource :context :mapping | + mapping + mapAsHypermediaControls: [ :period | context hypermediaControlsFor: period ] ] + encoding: self peopleMappingKey +] + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> addJsonPeopleVersion1dot0dot0MappingIn: aBuilder withHypermediaFrom: hypermediaControlsMapping encoding: aMappingKey [ + + aBuilder + addDefaultRuleToEncode: aMappingKey + to: self personVersion1dot0dot0MediaType + using: [ :resource :context | + String + streamContents: [ :stream | + (NeoJSONWriter on: stream) + for: Person + do: [ :mapping | + mapping mapAccessors: #(#name #lastName #email). + hypermediaControlsMapping + value: resource + value: context + value: mapping ]; + nextPut: resource ] ] +] + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> addJsonPersonVersion1dot0dot0DecoderMappingIn: aBuilder [ + + aBuilder + addDefaultRuleToDecode: self personVersion1dot0dot0MediaType + to: self personMappingKey + using: [ :json :context | + | raw | + + raw := NeoJSONObject fromString: json. + Person + named: raw name + surnamed: raw lastName + withEmailAddress: raw email ] +] + +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> addJsonPersonVersion1dot0dot0MappingIn: aBuilder [ + + self + addJsonPeopleVersion1dot0dot0MappingIn: aBuilder + withHypermediaFrom: + [ :resource :context :mapping | mapping mapHypermediaControlsIn: context ] + encoding: self personMappingKey +] + { #category : #accessing } PeopleRESTfulControllerSpecification >> addTemplate [ @@ -38,10 +95,16 @@ PeopleRESTfulControllerSpecification >> listTemplate [ ^ self endpoint ] +{ #category : #accessing } +PeopleRESTfulControllerSpecification >> peopleMappingKey [ + + ^ 'people' +] + { #category : #accessing } PeopleRESTfulControllerSpecification >> personMappingKey [ - ^ #person + ^ 'person' ] { #category : #accessing } diff --git a/source/TeamsAPI-Core/Person.class.st b/source/TeamsAPI-Core/Person.class.st index a2b2421..63bd019 100644 --- a/source/TeamsAPI-Core/Person.class.st +++ b/source/TeamsAPI-Core/Person.class.st @@ -4,7 +4,8 @@ Class { #instVars : [ 'name', 'lastName', - 'emailAddress' + 'emailAddress', + 'uuid' ], #category : #'TeamsAPI-Core-Model' } @@ -49,3 +50,15 @@ Person >> lastName [ Person >> name [ ^ name ] + +{ #category : #Accessing } +Person >> uuid [ + + ^ uuid +] + +{ #category : #Accessing } +Person >> uuid: anInteger [ + + uuid := anInteger +] diff --git a/source/TeamsAPI-Core/PersonSystem.class.st b/source/TeamsAPI-Core/PersonSystem.class.st deleted file mode 100644 index 4890971..0000000 --- a/source/TeamsAPI-Core/PersonSystem.class.st +++ /dev/null @@ -1,49 +0,0 @@ -Class { - #name : #PersonSystem, - #superclass : #SubsystemImplementation, - #instVars : [ - 'people' - ], - #category : #'TeamsAPI-Core-Systems' -} - -{ #category : #installing } -PersonSystem >> dependencies [ - ^ #() -] - -{ #category : #installing } -PersonSystem >> implementedInterfaces [ - ^ #(#PersonSystemInterface) -] - -{ #category : #installing } -PersonSystem >> initialize [ - super initialize. - people := OrderedCollection new -] - -{ #category : #accessing } -PersonSystem >> people [ - ^ people -] - -{ #category : #accessing } -PersonSystem >> startManagingPerson: aPerson [ - AssertionChecker - enforce: [ people - noneSatisfy: [ :person | person emailAddress = aPerson emailAddress ] ] - because: - ('There''s already a person registered in our system with the email address: <1s>.' - expandMacrosWith: aPerson emailAddress). - people add: aPerson -] - -{ #category : #accessing } -PersonSystem >> stopManagingPerson: aPerson [ - AssertionChecker - enforce: [ people anySatisfy: [ :person | person = aPerson ] ] - because: - 'TStop managing person failed because it does not exist in the system.'. - people remove: aPerson -] diff --git a/source/TeamsAPI-Core/TeamSystem.class.st b/source/TeamsAPI-Core/TeamManagementSystem.class.st similarity index 67% rename from source/TeamsAPI-Core/TeamSystem.class.st rename to source/TeamsAPI-Core/TeamManagementSystem.class.st index af1bb10..c01e5fc 100644 --- a/source/TeamsAPI-Core/TeamSystem.class.st +++ b/source/TeamsAPI-Core/TeamManagementSystem.class.st @@ -1,5 +1,5 @@ Class { - #name : #TeamSystem, + #name : #TeamManagementSystem, #superclass : #SubsystemImplementation, #instVars : [ 'teams' @@ -8,23 +8,29 @@ Class { } { #category : #installing } -TeamSystem >> dependencies [ +TeamManagementSystem >> dependencies [ ^ #() ] { #category : #initialization } -TeamSystem >> implementedInterfaces [ +TeamManagementSystem >> implementedInterfaces [ ^ #(#TeamSystemInterface) ] { #category : #initialization } -TeamSystem >> initialize [ +TeamManagementSystem >> initialize [ super initialize. teams := OrderedCollection new ] +{ #category : #accessing } +TeamManagementSystem >> name [ + + ^ 'Teams Management System' +] + { #category : #adding } -TeamSystem >> startManagingTeam: aTeam [ +TeamManagementSystem >> startManagingTeam: aTeam [ AssertionChecker enforce: [ teams noneSatisfy: [ :team | team name = aTeam name ] ] because: @@ -34,7 +40,7 @@ TeamSystem >> startManagingTeam: aTeam [ ] { #category : #adding } -TeamSystem >> stopManagingTeam: aTeam [ +TeamManagementSystem >> stopManagingTeam: aTeam [ AssertionChecker enforce: [ teams anySatisfy: [ :team | aTeam = team ] ] because: 'TStop managing team failed because it does not exist in the system.'. @@ -42,6 +48,6 @@ TeamSystem >> stopManagingTeam: aTeam [ ] { #category : #accessing } -TeamSystem >> teams [ +TeamManagementSystem >> teams [ ^ teams ]