Skip to content

Commit

Permalink
- proper categorization of unit tests
Browse files Browse the repository at this point in the history
- super #tearDown as last message call in #tearDown
- super #setUp as first message call in #setUp
- formatting

Fix #101
Fix #102
Fix #103
  • Loading branch information
astares committed Jun 26, 2023
1 parent f0863e1 commit 123d754
Show file tree
Hide file tree
Showing 84 changed files with 543 additions and 413 deletions.
10 changes: 6 additions & 4 deletions src/Glorp-Integration-Tests/GlorpCacheTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ GlorpCacheTest class >> resources [
^Array with: GlorpSessionResource
]

{ #category : #support }
{ #category : #running }
GlorpCacheTest >> setUp [

super setUp.
system cachePolicy: CachePolicy new.
session := GlorpSessionResource current newSession.
session system: system.
cache := session privateGetCache.
cache := session privateGetCache
]

{ #category : #support }
{ #category : #running }
GlorpCacheTest >> tearDown [
super tearDown.

session reset.
session := nil.
super tearDown
]

{ #category : #tests }
Expand Down
54 changes: 29 additions & 25 deletions src/Glorp-Integration-Tests/GlorpCompositeKeyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@ Class {
#category : #'Glorp-Integration-Tests-Database'
}

{ #category : #setup }
{ #category : #running }
GlorpCompositeKeyTest >> setUp [

super setUp.
system := (GlorpCompositeKeyDescriptorSystem forPlatform: session platform).
session system: system.
session beginTransaction.
session transact: [session register: system example1].
session reset.
system := GlorpCompositeKeyDescriptorSystem forPlatform: session platform.

session
system: system;
beginTransaction;
transact: [ session register: system example1 ];
reset
]

{ #category : #setup }
{ #category : #running }
GlorpCompositeKeyTest >> tearDown [

session rollbackTransaction.
session resetPermissions.
super tearDown.
super tearDown
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testAlsoFetch [
| users |
users := session read: GlorpUser.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testBasicReadFolder [
| folders |
folders := (session read: GlorpFolder) asSortedCollection: [:a :b | a name <= b name].
Expand All @@ -36,7 +40,7 @@ GlorpCompositeKeyTest >> testBasicReadFolder [
self assert: folders last name = 'Two'.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testBasicReadMessage [
| messages |
messages := (session read: GlorpMessage) asSortedCollection: [:a :b | a subject <= b subject].
Expand All @@ -46,7 +50,7 @@ GlorpCompositeKeyTest >> testBasicReadMessage [
self assert: messages last subject = 'goes in folder 2'.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testBasicReadUser [
| users |
users := (session read: GlorpUser) asSortedCollection: [:a :b | a id <= b id].
Expand All @@ -55,7 +59,7 @@ GlorpCompositeKeyTest >> testBasicReadUser [
self assert: users last name = 'User Two'.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testFaulting [
| users user1 sortedFolders user2 |
users := session read: GlorpUser.
Expand All @@ -67,7 +71,7 @@ GlorpCompositeKeyTest >> testFaulting [
self assert: user2 folders first messages first subject = 'goes in folder 2'.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testFolderIdentity [
| folders |
folders := session read: GlorpFolder.
Expand All @@ -80,7 +84,7 @@ GlorpCompositeKeyTest >> testFolderIdentity [
self assert: otherIndividualFolder == individualFolder].
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testMessageCacheHit [

| messages |
Expand All @@ -102,7 +106,7 @@ GlorpCompositeKeyTest >> testMessageCacheHit [
self assert: otherIndividualMessage identicalTo: individualMessage ]
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testMessageIdentity [
| messages |
messages := session read: GlorpMessage.
Expand All @@ -115,7 +119,7 @@ GlorpCompositeKeyTest >> testMessageIdentity [
self assert: otherIndividualMessage == individualMessage].
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testReadWithCacheHitFromExpression [
| message |
session reset.
Expand All @@ -125,7 +129,7 @@ GlorpCompositeKeyTest >> testReadWithCacheHitFromExpression [
session readOneOf: GlorpFolder where: [:each | each user id = 1 & (each name = 'One')].
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testReadWithCacheHitFromJoin [
| message |
session reset.
Expand All @@ -135,7 +139,7 @@ GlorpCompositeKeyTest >> testReadWithCacheHitFromJoin [
self assert: message folder name = 'One'.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testReadWithCacheHitFromParameterizedExpression [
| message query |
session reset.
Expand All @@ -146,7 +150,7 @@ GlorpCompositeKeyTest >> testReadWithCacheHitFromParameterizedExpression [
query executeWithParameters: #(1 'One') in: session.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testReadWithJoins [
| users |
users := session read: GlorpUser where: [:each | each folders anySatisfyJoin: [:eachFolder |
Expand All @@ -155,7 +159,7 @@ GlorpCompositeKeyTest >> testReadWithJoins [
self assert: users first id = 1.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testReadWithSubselect [
| users |
users := session read: GlorpUser where: [:each | each folders anySatisfyExists: [:eachFolder |
Expand All @@ -164,7 +168,7 @@ GlorpCompositeKeyTest >> testReadWithSubselect [
self assert: users first id = 1.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testReadWithSubselectAndINClause [
| users |
self should: [
Expand All @@ -176,7 +180,7 @@ GlorpCompositeKeyTest >> testReadWithSubselectAndINClause [
raise: GlorpInvalidExpressionError.
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testUserIdentity [
| users |
users := session read: GlorpUser.
Expand All @@ -196,7 +200,7 @@ GlorpCompositeKeyTest >> testUserIdentity [
self assert: otherIndividualUser == individualUser].
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testUserIdentityViaMessage [
| users |
users := session read: GlorpUser.
Expand All @@ -212,7 +216,7 @@ GlorpCompositeKeyTest >> testUserIdentityViaMessage [
self assert: eachMessage user yourSelf == each]]].
]

{ #category : #'tests- basic reading' }
{ #category : #'tests - basic reading' }
GlorpCompositeKeyTest >> testUserIdentityViaMessageInUnitOfWork [
session beginUnitOfWork.
[self testUserIdentityViaMessage] ensure: [session rollbackUnitOfWork].
Expand Down
10 changes: 6 additions & 4 deletions src/Glorp-Integration-Tests/GlorpConditionalMappingTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ Class {
#category : #'Glorp-Integration-Tests-Database'
}

{ #category : #support }
{ #category : #running }
GlorpConditionalMappingTest >> setUp [

super setUp.
descriptor := system descriptorFor: GlorpPassenger.
mapping := descriptor newMapping: ConditionalMapping.
mapping conditionalField: (descriptor primaryTable fieldNamed: 'ID').
mapping if: #testIDLessThan5: then: (mapping1 := DirectMapping from: #blah to: (descriptor primaryTable fieldNamed: 'ID')).
mapping if: #testIDMoreThan5: then: (mapping2 := DirectMapping from: #bletch to: (descriptor primaryTable fieldNamed: 'NAME')).
mapping otherwise: (mapping3 := DirectMapping from: #bazoomer to: (descriptor primaryTable fieldNamed: 'ID')).
mapping conditionalMethod: #id.
mapping conditionalMethod: #id
]

{ #category : #support }
{ #category : #running }
GlorpConditionalMappingTest >> setUpNew [

"Set up using the newer protocol"
newMapping := descriptor newMapping: ConditionalMapping.
newMapping
Expand All @@ -38,7 +40,7 @@ GlorpConditionalMappingTest >> setUpNew [
if: [:value | value = 1]
useMapping: (mapping1 := DirectMapping from: #blah to: (descriptor primaryTable fieldNamed: 'ID')).
newMapping if: #testIDMoreThan5: then: (mapping2 := DirectMapping from: #bletch to: (descriptor primaryTable fieldNamed: 'NAME')).
newMapping otherwise: (mapping3 := DirectMapping from: #bazoomer to: (descriptor primaryTable fieldNamed: 'ID')).
newMapping otherwise: (mapping3 := DirectMapping from: #bazoomer to: (descriptor primaryTable fieldNamed: 'ID'))
]

{ #category : #tests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ GlorpConstantValueInRelationshipTest class >> resources [
^Array with: GlorpDatabaseLoginResource with: GlorpDemoTablePopulatorResource.
]

{ #category : #support }
{ #category : #accessing }
GlorpConstantValueInRelationshipTest >> idsFor: aCollection [

^(aCollection collect: [:each | each id]) asSortedCollection asArray.
^ (aCollection collect: [:each | each id]) asSortedCollection asArray
]

{ #category : #support }
{ #category : #accessing }
GlorpConstantValueInRelationshipTest >> sampleWorker [

| worker job3 |
Expand All @@ -34,11 +34,13 @@ GlorpConstantValueInRelationshipTest >> sampleWorker [
^worker.
]

{ #category : #support }
{ #category : #running }
GlorpConstantValueInRelationshipTest >> setUp [

super setUp.
system := GlorpWorkerDescriptorSystem forPlatform: GlorpDatabaseLoginResource defaultLogin database.
session := GlorpSessionResource current newSession.
session system: system.
session system: system
]

{ #category : #tests }
Expand Down Expand Up @@ -86,7 +88,7 @@ GlorpConstantValueInRelationshipTest >> testWrite [
] ensure: [session rollbackTransaction].
]

{ #category : #support }
{ #category : #accessing }
GlorpConstantValueInRelationshipTest >> writeTestData [

session writeRow: system exampleWorkerRow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ Class {
#category : #'Glorp-Integration-Tests-Database'
}

{ #category : #support }
{ #category : #running }
GlorpCursoredCollectionDBTest >> setUp [

super setUp.
session := GlorpSessionResource current newSession.
session beginTransaction.
self writePersonRows.
self writePersonRows
]

{ #category : #support }
{ #category : #running }
GlorpCursoredCollectionDBTest >> tearDown [

session rollbackTransaction.
super tearDown.
super tearDown
]

{ #category : #tests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,17 @@ GlorpCursoredCollectionTest >> mockStream2 [
^ReadStream on: rows.
]

{ #category : #support }
{ #category : #running }
GlorpCursoredCollectionTest >> setUp [

| query |
super setUp.
session := GlorpSessionResource current newSession.
((session descriptorFor: GlorpCustomer) mappingForAttributeNamed: #name) shouldProxy: false.
query := Query read: GlorpPerson.
query session: session.
query prepare.
stream := GlorpCursoredStream on: self mockStream for: (query sqlWith: nil) accessor: nil.
stream := GlorpCursoredStream on: self mockStream for: (query sqlWith: nil) accessor: nil
]

{ #category : #tests }
Expand Down
4 changes: 2 additions & 2 deletions src/Glorp-Integration-Tests/GlorpDatabaseBasicTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ GlorpDatabaseBasicTest >> databaseLoginResource [
^GlorpDatabaseLoginResource current.
]

{ #category : #support }
{ #category : #running }
GlorpDatabaseBasicTest >> setUp [

super setUp.
system := GlorpDemoDescriptorSystem forPlatform: GlorpDatabaseLoginResource defaultLogin database.
system := GlorpDemoDescriptorSystem forPlatform: GlorpDatabaseLoginResource defaultLogin database
]

{ #category : #tests }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GlorpDatabaseLoginTest >> accessor [
^accessor.
]

{ #category : #support }
{ #category : #running }
GlorpDatabaseLoginTest >> setUp [
super setUp.
login := GlorpDatabaseLoginResource defaultLogin copy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ GlorpDatabaseSequenceTest >> row2Value [
^row2 atFieldNamed: 'ID'.
]

{ #category : #setup }
{ #category : #running }
GlorpDatabaseSequenceTest >> setUp [

super setUp.
table := session system tableNamed: 'BANK_TRANS'.
sequence := (table fieldNamed: 'ID') type sequence.
row1 := DatabaseRow newForTable: table.
row2 := DatabaseRow newForTable: table.
row2 := DatabaseRow newForTable: table
]

{ #category : #tests }
Expand Down
9 changes: 5 additions & 4 deletions src/Glorp-Integration-Tests/GlorpDatabaseSessionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ GlorpDatabaseSessionTest class >> resources [
^Array with: GlorpSessionResource.
]

{ #category : #support }
{ #category : #running }
GlorpDatabaseSessionTest >> setUp [

super setUp.
session := GlorpSessionResource current newSession.
session := GlorpSessionResource current newSession
]

{ #category : #support }
{ #category : #running }
GlorpDatabaseSessionTest >> tearDown [
super tearDown.

session reset.
session := nil.
super tearDown
]

{ #category : #tests }
Expand Down
Loading

0 comments on commit 123d754

Please sign in to comment.