1/*!
2  @header FTCreateGraphTEST
3  @abstract Module of FT
4
5  @availability OS X, GNUstep
6  @copyright 2004, 2005 Free Software Foundation, Inc.
7
8  Author: Oliver Langer
9
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24  <pre>
25  -------------------------------------------------------------------------
26  Modification history
27
28  23.02.05 ola     initial version
29  -------------------------------------------------------------------------
30  </pre>
31*/
32#include <Encore/Encore.h>
33#include "FTCreateGraphTEST.h"
34
35@implementation FTCreateGraphTEST
36
37- testGraphCreation {
38  id <FTGraphManager> graphManager;
39  id <FTGraph> graph;
40  id <FTId> graphId;
41  id <FTId> nid1,nid2,nid3,e1, e2;
42  id <FTObjectToIdMapper> objectToIdMapper;
43  id <FTObjectToIdMapper> graphIdMapper;
44  id <FTNode> n1,n2,n3;
45  id <FTEdge> edge;
46  id <FTTransaction> transaction;
47  id <ECIterator> nodeIterator;
48
49  NSLog( @"FTCreateGraphTEST::testGraphCreation: BEGINNING...." );
50
51  EC_AUTORELEASEPOOL_BEGIN
52  objectToIdMapper = [session defaultObjectToIdMapper];
53  graphManager = [session graphManager];
54
55  NSLog( @"Now creating graph..." );
56  transaction = [session beginTransactionWithParent: nil
57    withSettings: nil];
58
59  graphId = [objectToIdMapper mapObject: @"firstGraph"];
60  graph = [graphManager createGraphWithId: graphId];
61  ECAssertTrue( nil != graph, @"Graph creation failed!" );
62
63  NSLog( @"Now creating some nodes..." );
64  graphIdMapper = [[graph objectToIdMapper] retain];
65  ECAssertTrue( nil != graphIdMapper,
66     @"getting objectToIdMapper of graph FAILED" );
67
68  NSLog( @"Creating nodes and relationships..." );
69  nid1 = [graphIdMapper mapObject: @"fatherNode"];
70  nid2 = [graphIdMapper mapObject: @"child_1_Node"];
71  nid3 = [graphIdMapper mapObject: @"child_2_Node"];
72  e1 = [graphIdMapper mapObject: @"edge1"];
73  e2 = [graphIdMapper mapObject: @"edge2"];
74
75  n1 = [graph createNodeWithId: nid1];
76  n2 = [graph createNodeWithId: nid2];
77  n3 = [graph createNodeWithId: nid3];
78
79  NSLog( @"Created nodes n1, n2, n3" );
80
81  edge = [n1 createAndAppendEdgeWithId: e1 withTargetNode: n2];
82  edge = [n1 createAndAppendEdgeWithId: e2 withTargetNode: n3];
83
84  NSLog( @"Performing a commit..." );
85  [transaction commit];
86  NSLog( @"Graph created! Now trying to read the graph" );
87
88  graphId = [objectToIdMapper mapObject: @"firstGraph"];
89  [graph close];
90
91  graphId = [objectToIdMapper mapObject: @"firstGraph"];
92  graph = [graphManager graphWithId: graphId];
93
94  NSLog( @"Got graph! Now reading nodes..." );
95
96  n1 = [graph nodeWithId: nid1];
97  ECAssertTrue( n1 != nil, @"Unable to fetch node with id=\"fatherNode\"" );
98
99  NSLog( @"All nodes loaded!" );
100
101  /**
102   * Now checking links...
103   */
104  NSLog( @"Loading node n2..." );
105
106  nodeIterator = [n1 outgoingNodes];
107  ECAssertTrue( [nodeIterator hasNext], @"Unable to read first node of n1!" );
108  n2 = [nodeIterator next];
109
110  ECAssertTrue( YES == [[n2 nodeId] isEqual: nid2], @"Expected node n2!" );
111  NSLog( @"Node n2 LOADED. Now loading n3..." );
112
113  ECAssertTrue( [nodeIterator hasNext], @"Unable to read second node of n1!" );
114  n3 = [nodeIterator next];
115
116  ECAssertTrue( YES == [[n3 nodeId] isEqual: nid3], @"Expected node n3!" );
117  NSLog( @"Node n3 LOADED." );
118
119  NSLog( @"Closing Graph..." );
120
121  [graph close];
122
123  EC_AUTORELEASEPOOL_END
124  NSLog( @"FTCreateGraphTEST::testGraphCreation: FINISHED" );
125  return self;
126}
127@end
128