tests: add `test_neo`
[nit.git] / src / test_neo.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Test for neo model saving and loading.
16 module test_neo
17
18 import neo
19 import model_utils
20 import frontend
21
22 var test_name = "test_{get_time.to_s}"
23
24 # init tool
25 var toolcontext = new ToolContext
26 toolcontext.tooldescription = "Usage: neo_saver host port files..."
27 toolcontext.process_options(args)
28 var arguments = toolcontext.option_context.rest
29
30 if arguments.length < 3 then
31 toolcontext.usage
32 exit 0
33 end
34
35 var host = arguments.shift
36 var port = arguments.shift
37 var url = "http://{host}:{port}"
38
39 # parse model
40 toolcontext.info("Parse files...", 1)
41 var org_model = new Model
42 var modelbuilder = new ModelBuilder(org_model, toolcontext)
43 modelbuilder.parse(arguments)
44 modelbuilder.run_phases
45
46 toolcontext.info("Open connection to neo4j on {url} for saving...", 1)
47 var save_client = new Neo4jClient(url)
48 var save_model = new NeoModel(test_name, toolcontext, save_client)
49 save_model.save(org_model)
50
51 toolcontext.info("Open connection to neo4j on {url} for reading...", 1)
52 var read_client = new Neo4jClient(url)
53 var neo_model = new Model
54 var read_model = new NeoModel(test_name, toolcontext, read_client)
55 read_model.load(neo_model)
56
57 # Compare model
58 var sorter = new MEntityNameSorter
59
60 print "mprojects:"
61 var org_mprojects = org_model.mprojects.to_a
62 sorter.sort org_mprojects
63 print org_mprojects.join(" ")
64 var neo_mprojects = neo_model.mprojects.to_a
65 sorter.sort neo_mprojects
66 print neo_mprojects.join(" ")
67
68 print "mmodules:"
69 var org_mmodules = org_model.mmodules.to_a
70 sorter.sort org_mmodules
71 print org_mmodules.join(" ")
72 var neo_mmodules = neo_model.mmodules.to_a
73 sorter.sort neo_mmodules
74 print neo_mmodules.join(" ")
75
76 print "mclasses:"
77 var org_mclasses = org_model.mclasses.to_a
78 sorter.sort org_mclasses
79 print org_mclasses.join(" ")
80 var neo_mclasses = neo_model.mclasses.to_a
81 sorter.sort neo_mclasses
82 print neo_mclasses.join(" ")
83
84 print "mproperties:"
85 var org_mproperties = org_model.mproperties.to_a
86 sorter.sort org_mproperties
87 print org_mproperties.join(" ")
88 var neo_mproperties = neo_model.mproperties.to_a
89 sorter.sort neo_mproperties
90 print neo_mproperties.join(" ")