Skip to content

Commit

Permalink
Cleanup tests - part 4
Browse files Browse the repository at this point in the history
  • Loading branch information
astares committed Jun 26, 2023
1 parent 9b9bfb9 commit fc8c47e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ Extension { #name : #GlorpDescriptorValidationTest }

{ #category : #'*Glorp-Integration-Tests' }
GlorpDescriptorValidationTest >> testValidatingExistingDescriptors [

| session |
session := GlorpSessionResource current newSession.
GlorpTestDescriptorSystem allSubclasses do: [:each |
session system: (each forPlatform: (OraclePlatform new)).
session system validate].
session system validate]
]
48 changes: 27 additions & 21 deletions src/Glorp-Unit-Tests/GlorpDescriptorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ GlorpDescriptorTest >> errorSignal [

{ #category : #tests }
GlorpDescriptorTest >> testAllClassesAndNames [

| identity1 identity2 identity3 |
system flushAllClasses.
identity1 := system allClasses.
identity2 := system allClasses.
system flushAllClasses.
identity3 := system allClasses.
self assert: identity1 == identity2.
self assert: identity1 identicalTo: identity2.
self assert: identity1 ~~ identity3.
self should: [system allClassNames] raise: Dialect error.
self should: [ system allClassNames ] raise: Dialect error
]

{ #category : #tests }
Expand All @@ -41,7 +42,7 @@ GlorpDescriptorTest >> testBuildBankTransactionAndDependentsFromRow [
session system: system.
transactionDescriptor := system descriptorFor: GlorpBankTransaction.
object := GlorpBankTransaction new.
row := #(99 nil 'CDN' 98 'service charge' 'USD' 97).
row := #( 99 nil 'CDN' 98 'service charge' 'USD' 97 ).
builder := ObjectBuilder new.
builder row: row.
transactionDescriptor populateObject: object inBuilder: builder.
Expand All @@ -52,12 +53,12 @@ GlorpDescriptorTest >> testBuildBankTransactionAndDependentsFromRow [
translations := IdentityDictionary new.
translations at: (table fieldNamed: 'CURRENCY') put: 3.
translations at: (table fieldNamed: 'AMOUNT') put: 4.
builder := ElementBuilder new fieldTranslations: translations; row: row.
moneyDescriptor
populateObject: money1
inBuilder: builder.
self assert: money1 amount = 98.
self assert: money1 currency = #CDN.
builder := ElementBuilder new
fieldTranslations: translations;
row: row.
moneyDescriptor populateObject: money1 inBuilder: builder.
self assert: money1 amount equals: 98.
self assert: money1 currency equals: #CDN
]

{ #category : #tests }
Expand All @@ -72,41 +73,45 @@ GlorpDescriptorTest >> testBuildPersonFromRow [
system tableNamed: 'PERSON'.
object := GlorpPerson new.
builder := ObjectBuilder new.
builder row: #(456 'Ralph' 127).
builder row: #( 456 'Ralph' 127 ).
descriptor populateObject: object inBuilder: builder.
self assert: object class equals: GlorpPerson.
self assert: object id equals: 456.
self assert: object name = 'Ralph'.
self assert: object address getValue == address
self assert: object name equals: 'Ralph'.
self assert: object address getValue identicalTo: address
]

{ #category : #tests }
GlorpDescriptorTest >> testDescriptorIdentity [

| descriptor |
descriptor := system descriptorFor: GlorpCustomer.
self assert: descriptor == (system descriptorFor: GlorpCustomer).
self
assert: descriptor
identicalTo: (system descriptorFor: GlorpCustomer)
]

{ #category : #tests }
GlorpDescriptorTest >> testMappedFields [

| descriptor |
descriptor := system descriptorFor: GlorpBankTransaction.
self assert: (descriptor mappedFields) equals: (descriptor table fields).
self assert: (descriptor mappedFields) equals: (descriptor table fields)
]

{ #category : #tests }
GlorpDescriptorTest >> testMappingForField [

| descriptor mapping |
descriptor := system descriptorFor: GlorpCustomer.
mapping := descriptor
mapping := descriptor
directMappingForField: ((system tableNamed: 'GR_CUSTOMER') fieldNamed: 'ID').
self assert: mapping attributeName equals: #id
]

{ #category : #tests }
GlorpDescriptorTest >> testPrimaryKeyExpressionFor [

| descriptor trans exp |
descriptor := system descriptorFor: GlorpBankTransaction.
trans := GlorpBankTransaction new.
Expand All @@ -116,25 +121,26 @@ GlorpDescriptorTest >> testPrimaryKeyExpressionFor [
basedOn: BaseExpression new
relation: #=.
self assert: exp relation equals: #=.
self assert: exp rightChild value equals: 42.
self assert: exp rightChild value equals: 42
]

{ #category : #tests }
GlorpDescriptorTest >> testPrimaryKeyExpressionForFailing [

| descriptor trans |
descriptor := system descriptorFor: GlorpBankTransaction.
trans := GlorpCustomer new.
self
should:
[descriptor
should: [
descriptor
primaryKeyExpressionFor: trans
basedOn: BaseExpression new
relation: #=]
raise: self errorSignal.
relation: #= ]
raise: self errorSignal
]

{ #category : #tests }
GlorpDescriptorTest >> testPrimaryKeyExpressionForWithCompositeKey [

self unfinished.
self unfinished
]
7 changes: 6 additions & 1 deletion src/Glorp-Unit-Tests/GlorpDescriptorValidationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Class {

{ #category : #testing }
GlorpDescriptorValidationTest >> testJoinDirection [

| descriptor table1 table2 mapping system descriptor2 |
system := DynamicDescriptorSystem new.
descriptor := system addEmptyDescriptorFor: GlorpCustomer.
Expand All @@ -26,11 +27,12 @@ GlorpDescriptorValidationTest >> testJoinDirection [
mapping attributeName: #bar.
mapping referenceClass: GlorpVideoStore.
mapping join: (Join from: (table2 fieldNamed: 'two') to: (table1 fieldNamed: 'one')).
self should: [mapping validate] raise: Dialect error.
self should: [mapping validate] raise: Dialect error
]

{ #category : #testing }
GlorpDescriptorValidationTest >> testValidateDirectInstvarAccessExisting [

| descriptor table mapping system field |
system := DynamicDescriptorSystem new.
descriptor := system addEmptyDescriptorFor: GlorpCustomer.
Expand All @@ -44,6 +46,7 @@ GlorpDescriptorValidationTest >> testValidateDirectInstvarAccessExisting [

{ #category : #testing }
GlorpDescriptorValidationTest >> testValidateDirectInstvarAccessNonExisting [

| descriptor table mapping system field |
system := DynamicDescriptorSystem new.
descriptor := system addEmptyDescriptorFor: GlorpCustomer.
Expand All @@ -57,6 +60,7 @@ GlorpDescriptorValidationTest >> testValidateDirectInstvarAccessNonExisting [

{ #category : #testing }
GlorpDescriptorValidationTest >> testValidateSelectorAccessExisting [

| descriptor table mapping system field |
system := DynamicDescriptorSystem new.
descriptor := system addEmptyDescriptorFor: GlorpCustomer.
Expand All @@ -71,6 +75,7 @@ GlorpDescriptorValidationTest >> testValidateSelectorAccessExisting [

{ #category : #testing }
GlorpDescriptorValidationTest >> testValidateSelectorAccessNonExisting [

| descriptor table mapping system field |
system := DynamicDescriptorSystem new.
descriptor := system addEmptyDescriptorFor: GlorpCustomer.
Expand Down
17 changes: 10 additions & 7 deletions src/Glorp-Unit-Tests/GlorpDialectTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ GlorpDialectTest >> testBlockArgumentCount [

{ #category : #tests }
GlorpDialectTest >> testClassImportLookup [

self
assert: (Dialect
lookupClassNamed: 'AccessCast'
inContextOf: GlorpDescriptorSystemWithNamespaces
ifAbsent: [nil]) == AccessCast
lookupClassNamed: 'AccessCast'
inContextOf: GlorpDescriptorSystemWithNamespaces
ifAbsent: [ nil ]) == AccessCast
description: 'We cannot find a class visible in the environment of this class, not imported'.

self
assert: (Dialect
lookupClassNamed: 'GlorpTestClassInNamespace'
inContextOf: GlorpDescriptorSystemWithNamespaces
ifAbsent: [nil]) == GlorpTestClassInNamespace
description: 'We cannot find a class imported by the class but not visible in its environment'.
lookupClassNamed: 'GlorpTestClassInNamespace'
inContextOf: GlorpDescriptorSystemWithNamespaces
ifAbsent: [ nil ]) == GlorpTestClassInNamespace
description: 'We cannot find a class imported by the class but not visible in its environment'
]

{ #category : #tests }
Expand All @@ -49,5 +51,6 @@ GlorpDialectTest >> testTimeSetMillisecond [

{ #category : #tests }
GlorpDialectTest >> testTokensBasedOn [

self assert: (Dialect tokensBasedOn: '.' in: 'abc.def.ghi') asArray equals: #('abc' 'def' 'ghi')
]
16 changes: 8 additions & 8 deletions src/Glorp-Unit-Tests/GlorpExpressionBasicPropertiesTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,47 @@ GlorpExpressionBasicPropertiesTest >> testHasDescriptorForBase [
| exp |
self assert: base hasDescriptor.
exp := [:a | a ] asGlorpExpressionOn: base.
self assert: exp hasDescriptor.
self assert: exp hasDescriptor
]

{ #category : #tests }
GlorpExpressionBasicPropertiesTest >> testHasDescriptorForDirect [

| exp |
exp := [:a | a id ] asGlorpExpressionOn: base.
self deny: exp hasDescriptor.
self deny: exp hasDescriptor
]

{ #category : #tests }
GlorpExpressionBasicPropertiesTest >> testHasDescriptorForOneToMany [

| exp |
exp := [:a | a emailAddresses ] asGlorpExpressionOn: base.
self assert: exp hasDescriptor.
self assert: exp hasDescriptor
]

{ #category : #tests }
GlorpExpressionBasicPropertiesTest >> testHasDescriptorForOneToOne [

| exp |
exp := [:a | a address ] asGlorpExpressionOn: base.
self assert: exp hasDescriptor.
self assert: exp hasDescriptor
]

{ #category : #tests }
GlorpExpressionBasicPropertiesTest >> testHasDescriptorForPrimaryKeyExpression [

| exp |
exp := Join new.
self deny: exp hasDescriptor.
self deny: exp hasDescriptor
]

{ #category : #tests }
GlorpExpressionBasicPropertiesTest >> testHasDescriptorForRelation [

| exp |
exp := [:a | a = 3] asGlorpExpressionOn: base.
self deny: exp hasDescriptor.
self deny: exp hasDescriptor
]

{ #category : #tests }
Expand All @@ -71,11 +71,11 @@ GlorpExpressionBasicPropertiesTest >> testHasDescriptorForTwoLevelDirect [
| exp |
exp := [:a | a address street] asGlorpExpressionOn: base.
self deny: exp hasDescriptor.
self assert: exp base hasDescriptor.
self assert: exp base hasDescriptor
]

{ #category : #tests }
GlorpExpressionBasicPropertiesTest >> testHasDescriptorForUninitializedBase [

self deny: BaseExpression new hasDescriptor.
self deny: BaseExpression new hasDescriptor
]
13 changes: 9 additions & 4 deletions src/Glorp-Unit-Tests/GlorpExpressionIterationTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ Class {
#category : #'Glorp-Unit-Tests-Tests'
}

{ #category : #tests }
GlorpExpressionIterationTest >> helpTestSingleNodeDo: exp [
self assert: (exp collect: [:each | each]) = (OrderedCollection with: exp)
{ #category : #utilities }
GlorpExpressionIterationTest >> helpTestSingleNodeDo: exp [

self
assert: (exp collect: [ :each | each ])
equals: (OrderedCollection with: exp)
]

{ #category : #tests }
GlorpExpressionIterationTest >> testDoBase [
self helpTestSingleNodeDo:BaseExpression new

self helpTestSingleNodeDo: BaseExpression new
]

{ #category : #tests }
Expand All @@ -27,6 +31,7 @@ GlorpExpressionIterationTest >> testDoCollection [

{ #category : #tests }
GlorpExpressionIterationTest >> testDoConstant [

self helpTestSingleNodeDo: ConstantExpression new
]

Expand Down

0 comments on commit fc8c47e

Please sign in to comment.