Skip to content

Commit

Permalink
Added roundabout persistence test
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Jul 25, 2024
1 parent 0d0d93f commit 4cf6ed1
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Class {
OPDirectionalRelationshipController >> createDiagramElement [

super createDiagramElement.
self ensureSourceIn: diagramController.
self ensureTargetIn: diagramController.
^ self diagramElement
source: self source ensureDiagramElement;
target: self target ensureDiagramElement;
Expand Down Expand Up @@ -52,14 +54,6 @@ OPDirectionalRelationshipController >> edgeBuilder [
'Depracated without replacement - use Roassal directly or define own figures'
]

{ #category : 'construction' }
OPDirectionalRelationshipController >> ensureShownDependenciesInDiagram: aDiagramController [

self ensureSourceIn: aDiagramController.
self ensureTargetIn: aDiagramController.
super ensureShownDependenciesInDiagram: aDiagramController
]

{ #category : 'accessing' }
OPDirectionalRelationshipController >> ensureSourceIn: aDiagramController [

Expand Down Expand Up @@ -122,6 +116,14 @@ OPDirectionalRelationshipController >> renderSimplified [
diagramElement := self diagramElementClass renderSimplifiedForController: self.
]

{ #category : 'construction' }
OPDirectionalRelationshipController >> showWithoutDependentInDiagram: aDiagramController [

self ensureSourceIn: aDiagramController.
self ensureTargetIn: aDiagramController.
^ super showWithoutDependentInDiagram: aDiagramController
]

{ #category : 'accessing' }
OPDirectionalRelationshipController >> source [

Expand Down
79 changes: 79 additions & 0 deletions repository/OpenPonk-Core/OPExamplePersistenceTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Class {
#name : 'OPExamplePersistenceTest',
#superclass : 'TestCase',
#instVars : [
'file',
'sourceWorkbench',
'targetWorkbench'
],
#category : 'OpenPonk-Core-Tests',
#package : 'OpenPonk-Core',
#tag : 'Tests'
}

{ #category : 'testing' }
OPExamplePersistenceTest class >> isAbstract [

^ self = OPExamplePersistenceTest
]

{ #category : 'hooks' }
OPExamplePersistenceTest >> createExampleModel [

^ self subclassResponsibility
]

{ #category : 'running' }
OPExamplePersistenceTest >> setUp [

super setUp.
file := FileSystem memory root / 'example-persistence-test.opp'.
file ensureDelete
]

{ #category : 'running' }
OPExamplePersistenceTest >> tearDown [

sourceWorkbench ifNotNil: [ :workbench |
workbench application closeAllWindows.
sourceWorkbench := nil ].
targetWorkbench ifNotNil: [ :workbench |
workbench application closeAllWindows.
targetWorkbench := nil ].
file ifNotNil: [
file ensureDelete.
file := nil ].
Smalltalk garbageCollect.
super tearDown
]

{ #category : 'tests' }
OPExamplePersistenceTest >> testSaveAndLoad [

| sourceModel sourceProject sourceEditor sourceCanvas sourceProjectController sourceShapes targetProject targetEditor targetCanvas targetShapes |
sourceModel := self createExampleModel.
sourceProject := OPProject new
name: 'TestProject';
addModel: sourceModel;
yourself.
sourceWorkbench := sourceProject open.
sourceWorkbench showAllElementsInAllDiagrams.
sourceEditor := sourceWorkbench focusedEditor.
sourceCanvas := sourceEditor canvasPresenter canvas.
sourceShapes := sourceCanvas shapes
collect: [ :each | each class ]
as: Bag.
self denyCollection: sourceShapes equals: Bag empty.
sourceProjectController := sourceWorkbench projectController.
sourceProjectController saveProjectTo: file.

targetProject := OPProjectController fromFile: file.
targetWorkbench := targetProject open.
targetWorkbench showAllElementsInAllDiagrams.
targetEditor := targetWorkbench focusedEditor.
targetCanvas := targetEditor canvasPresenter canvas.
targetShapes := targetCanvas shapes
collect: [ :each | each class ]
as: Bag.
self assertCollection: targetShapes equals: sourceShapes
]
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ OPMementoDirectorySerializer >> saveModelOf: aMemento to: aFolder [
modelSerializer class saveExportInfoTo: aFolder.
(aFolder / 'model' , modelSerializer formatName)
ensureDelete;
writeStreamDo: [ :stream |
writeStreamDo: [ :stream |
stream nextPutAll: (modelSerializer serializeModel: aMemento model) ]
]
4 changes: 2 additions & 2 deletions repository/OpenPonk-Core/OPModelObjectReference.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ OPModelObjectReference >> = otherModelObject [
]

{ #category : 'comparing' }
OPModelObjectReference >> modelObjectFrom: aDictionary [
OPModelObjectReference >> modelObjectFrom: aCollection [

^ aDictionary at: uuid
^ aCollection detect: [ :any | any uuid = uuid ]
]

{ #category : 'printing' }
Expand Down
18 changes: 8 additions & 10 deletions repository/OpenPonk-Core/OPProjectController.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ Class {
{ #category : 'instance creation' }
OPProjectController class >> fromDirectory: aFolder [

^ [ :job |
| materializer |
job title: 'Reading project from file'.
materializer := aFolder files
detect: [ :any |
any basename = OPExportInfo fileName ]
ifFound: [ :exportInfoFile |
OPSerializer forExportInfoFile: exportInfoFile ]
ifNone: [ OPProjectDirectoryMaterializer new ].
materializer loadProjectFrom: aFolder asFileReference ] asJob run
| materializer |
materializer := aFolder files
detect: [ :any |
any basename = OPExportInfo fileName ]
ifFound: [ :exportInfoFile |
OPSerializer forExportInfoFile: exportInfoFile ]
ifNone: [ OPProjectDirectoryMaterializer new ].
^ materializer loadProjectFrom: aFolder asFileReference
]

{ #category : 'opening' }
Expand Down
12 changes: 6 additions & 6 deletions repository/OpenPonk-Core/OPShape.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,18 @@ OPShape >> resizableInteractionTarget [
]

{ #category : 'serialization' }
OPShape >> resolveAllModelElements: aDictionary [
OPShape >> resolveAllModelElements: aCollection [

self resolveModelElements: aDictionary.
self resolveModelElements: aCollection.
self ownedElements do: [ :each |
each resolveAllModelElements: aDictionary ]
each resolveAllModelElements: aCollection ]
]

{ #category : 'serialization' }
OPShape >> resolveModelElements: aDictionary [
OPShape >> resolveModelElements: aCollection [

self modelElements: (self modelElements collect: [ :each |
each modelObjectFrom: aDictionary ])
self modelElements: (self modelElements collect: [ :each |
each modelObjectFrom: aCollection ])
]

{ #category : 'rendering' }
Expand Down
10 changes: 4 additions & 6 deletions repository/OpenPonk-Core/OPStonDiagramSerializer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ OPStonDiagramSerializer >> formatName [
{ #category : 'serialize/materialize' }
OPStonDiagramSerializer >> materializeDiagramOf: aModel from: aStream [

| diagram adapters allModelElements |
| diagram innerElements |
diagram := STON fromStream: aStream.
adapters := OPNavigatorAdapters new.
allModelElements := ((Set with: aModel)
, (adapters allChildrenFor: aModel) collect: [
:each | each uuid -> each ]) asDictionary.
diagram resolveAllModelElements: allModelElements.
innerElements := OPNavigatorAdapters new allChildrenFor: aModel.
diagram resolveAllModelElements:
(innerElements asArray copyWith: aModel).
^ diagram
]

Expand Down
7 changes: 4 additions & 3 deletions repository/OpenPonk-Spec/OPDefaultNavigatorAdapter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ OPDefaultNavigatorAdapter >> displayMapping [
OPProject -> 'Project'}
]

{ #category : 'widget API' }
{ #category : 'testing' }
OPDefaultNavigatorAdapter >> hasMappingFor: anObject in: aModel [

^ {
OPProject.
OPTestContainerModel } anySatisfy: [ :any |
anObject isKindOf: any ]
OPTestContainerModel.
OPTestEntityModel.
OPTestRelationModel } anySatisfy: [ :any | anObject isKindOf: any ]
]

{ #category : 'widget API' }
Expand Down

0 comments on commit 4cf6ed1

Please sign in to comment.