agreement-design-prototype 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/agreement-design.gemspec +2 -1
- data/build/build_models.rb +24 -9
- data/gen/data/data.json +1 -0
- data/gen/data/data.yaml +46 -0
- data/gen/data/fm_agreements.jsonlines +2 -0
- data/gen/data/fm_catalogue.jsonlines +1 -0
- data/gen/diagrams/metamodel.dot +45 -0
- data/gen/doc/data.md +44 -0
- data/gen/doc/metamodel.md +99 -57
- data/gen/images/metamodel.jpg +0 -0
- data/model/agreement.rb +95 -43
- data/model/fm.rb +56 -24
- data/model/geographic.rb +30 -0
- data/model/party.rb +14 -12
- data/out/test/data/datatest.json +1 -0
- data/out/test/diagrams/d.dot +16 -30
- data/out/test/doc/doctest.md +17 -19
- data/out/test/doc/modeldoctest.md +62 -0
- data/out/test/images/d.jpg +0 -0
- data/src/api.rb +33 -0
- data/src/data.rb +89 -0
- data/src/data_model.rb +102 -38
- data/src/diagram.rb +61 -95
- data/src/doc.rb +55 -151
- data/src/transform.rb +144 -0
- data/test/data_model_test.rb +43 -65
- data/test/data_test.rb +26 -0
- data/test/diagram_test.rb +2 -5
- data/test/doc_test.rb +15 -9
- data/test/test_model.rb +88 -0
- data/test/transform_test.rb +83 -0
- metadata +21 -5
- data/gen/diagrams/data_model.dot +0 -34
- data/gen/doc/frameworks.md +0 -19
- data/gen/images/data_model.jpg +0 -0
data/test/data_model_test.rb
CHANGED
@@ -1,85 +1,61 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../src/data_model'
|
3
3
|
include DataModel
|
4
|
-
|
5
|
-
DataModel::domain :TestMetamodel do
|
6
|
-
|
7
|
-
datatype :BasicType do
|
8
|
-
attribute :id, String
|
9
|
-
end
|
10
|
-
|
11
|
-
datatype :Table, description: "Test type" do
|
12
|
-
MULT = [0..10]
|
13
|
-
DESC = "table of values"
|
14
|
-
attribute :vals, Integer,
|
15
|
-
multiplicity: MULT,
|
16
|
-
:description => DESC
|
17
|
-
attribute :morevals, String, 2..5, "array of strings"
|
18
|
-
end
|
19
|
-
|
20
|
-
datatype :ReferencingType do
|
21
|
-
attribute :id, String
|
22
|
-
attribute :mate, TestMetamodel::BasicType
|
23
|
-
end
|
24
|
-
|
25
|
-
datatype :DerivedType, extends: TestMetamodel::ReferencingType do
|
26
|
-
attribute :more, String
|
27
|
-
end
|
28
|
-
|
29
|
-
datatype :DerivedTypeNamingClass, extends: TestMetamodel::ReferencingType do
|
30
|
-
attribute :othermore, String
|
31
|
-
end
|
32
|
-
|
33
|
-
datatype :Empty do
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
4
|
+
require 'test_model'
|
38
5
|
|
39
6
|
class DataModelTest < Test::Unit::TestCase
|
40
|
-
|
41
|
-
|
7
|
+
|
42
8
|
def test_metamodel
|
43
|
-
assert(contains(
|
44
|
-
id_t =
|
45
|
-
assert_equal(1..1,
|
9
|
+
assert(contains(TestModel::BasicType, :id), 'has id attribute')
|
10
|
+
id_t = TestModel::BasicType.attributes[:id]
|
11
|
+
assert_equal(1..1, TestModel::BasicType.attributes[:id][:multiplicity], "has default multiplicity")
|
46
12
|
assert(id_t[:type] == String)
|
47
13
|
|
48
|
-
assert_equal(MULT,
|
49
|
-
assert_equal(2..5,
|
50
|
-
assert_equal("Test type",
|
14
|
+
assert_equal(MULT, TestModel::Table.attributes[:vals][:multiplicity]);
|
15
|
+
assert_equal(2..5, TestModel::Table.attributes[:morevals][:multiplicity]);
|
16
|
+
assert_equal("Test type", TestModel::Table.description);
|
51
17
|
|
52
|
-
assert_equal(MULT,
|
53
|
-
assert_equal(DESC,
|
18
|
+
assert_equal(MULT, TestModel::Table.attributes[:vals][:multiplicity], "has multiplicity")
|
19
|
+
assert_equal(DESC, TestModel::Table.attributes[:vals][:description], "has description")
|
54
20
|
|
55
|
-
mate_t =
|
56
|
-
assert(mate_t[:type] ==
|
21
|
+
mate_t = TestModel::ReferencingType.attributes[:mate]
|
22
|
+
assert(mate_t[:type] == TestModel::BasicType)
|
57
23
|
|
58
|
-
assert(contains(
|
59
|
-
assert(contains(
|
60
|
-
assert(contains(
|
61
|
-
assert(contains(TestMetamodel::DerivedTypeNamingClass, :othermore), "has derived attribute")
|
62
|
-
assert(contains(TestMetamodel::DerivedTypeNamingClass, :id), "has derived attribute")
|
24
|
+
assert(contains(TestModel::DerivedType, :more), "has derived attribute")
|
25
|
+
assert(contains(TestModel::DerivedType, :mate), "has derived attribute")
|
26
|
+
assert(contains(TestModel::DerivedType, :id), "has derived attribute")
|
63
27
|
end
|
64
28
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
referencingtype
|
71
|
-
|
72
|
-
|
73
|
-
|
29
|
+
|
30
|
+
def test_model
|
31
|
+
assert_equal(1, TestModel::TESTMODEL.contents[:table][0].attributes[:vals][0], "has vals")
|
32
|
+
assert_equal(2, TestModel::TESTMODEL.contents[:table][0].attributes[:vals][1], "has vals")
|
33
|
+
assert_equal(:content, TestModel::TESTMODEL.contents[:referencingtype][0].attributes[:mate].attributes[:id], "has vals")
|
34
|
+
assert_equal(:content, TestModel::TESTMODEL.contents[:referencingtype][0].mate.id, "has vals")
|
35
|
+
|
36
|
+
TestModel.new :T2 do
|
37
|
+
table do
|
38
|
+
for i in 7..9
|
39
|
+
vals i
|
40
|
+
end
|
74
41
|
end
|
75
42
|
end
|
43
|
+
|
44
|
+
assert_equal(7, TestModel::T2.table[0].vals[0], "block iterate")
|
45
|
+
assert_equal(8, TestModel::T2.table[0].vals[1], "block iterate")
|
46
|
+
|
76
47
|
end
|
77
48
|
|
78
|
-
|
79
|
-
|
80
|
-
assert_equal(
|
81
|
-
|
82
|
-
|
49
|
+
|
50
|
+
def test_kinds
|
51
|
+
assert_equal(:Framework, TestModel::TESTMODEL.kindly[0].kind, "kinds")
|
52
|
+
|
53
|
+
# TODO: assertion on strings that aren't in the selection list
|
54
|
+
# assert_raise() do
|
55
|
+
# TestModel.new :T3 do
|
56
|
+
# kindly {kind :KindNotValid}
|
57
|
+
# end
|
58
|
+
# end
|
83
59
|
end
|
84
60
|
|
85
61
|
private
|
@@ -88,4 +64,6 @@ class DataModelTest < Test::Unit::TestCase
|
|
88
64
|
type.attributes.keys.one? {|k| k == attr}
|
89
65
|
end
|
90
66
|
|
67
|
+
|
68
|
+
|
91
69
|
end
|
data/test/data_test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require_relative '../src/data'
|
3
|
+
require_relative 'test_model'
|
4
|
+
include DataModel
|
5
|
+
|
6
|
+
class DataTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
# Called before every test method runs. Can be used
|
9
|
+
# to set up fixture information.
|
10
|
+
PATH = "out/test/"
|
11
|
+
NAME = "datatest"
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@d = DataFile.new(PATH, NAME)
|
15
|
+
if File.file?(@d.filepath)
|
16
|
+
File.delete(@d.filepath)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_dot
|
21
|
+
assert_equal("#{PATH}data/#{NAME}.json", @d.filepath, "file name")
|
22
|
+
assert(!File.file?(@d.filepath), "no dotfile")
|
23
|
+
@d.output( TestModel::TESTMODEL)
|
24
|
+
assert(File.file?(@d.filepath), "file created")
|
25
|
+
end
|
26
|
+
end
|
data/test/diagram_test.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../src/diagram'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'test_model'
|
4
4
|
include DataModel
|
5
5
|
|
6
|
-
|
7
6
|
class DiagramTest < Test::Unit::TestCase
|
8
7
|
|
9
8
|
# Called before every test method runs. Can be used
|
@@ -25,10 +24,8 @@ class DiagramTest < Test::Unit::TestCase
|
|
25
24
|
assert_equal("out/test/diagrams/d.dot", @d.dotfile, "file format")
|
26
25
|
assert_equal("out/test/images/d.jpg", @d.jpgfile, "file format")
|
27
26
|
assert(!File.file?(@d.dotfile), "no dotfile")
|
28
|
-
@d.describe(
|
27
|
+
@d.describe( TestModel)
|
29
28
|
assert(File.file?(@d.dotfile), "file created")
|
30
29
|
assert(File.file?(@d.jpgfile), "file created")
|
31
|
-
# TODO test the features in the diagram
|
32
|
-
@d.describe( Category, Parties)
|
33
30
|
end
|
34
31
|
end
|
data/test/doc_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require_relative '../src/doc'
|
3
|
-
require_relative '
|
3
|
+
require_relative 'test_model'
|
4
4
|
include DataModel
|
5
5
|
|
6
6
|
class DocTest < Test::Unit::TestCase
|
@@ -9,19 +9,25 @@ class DocTest < Test::Unit::TestCase
|
|
9
9
|
# to set up fixture information.
|
10
10
|
PATH = "out/test/"
|
11
11
|
NAME = "doctest"
|
12
|
+
META = "modeldoctest"
|
12
13
|
|
13
14
|
def setup
|
14
|
-
@d =
|
15
|
-
if File.file?(@d.
|
16
|
-
File.delete(@d.
|
15
|
+
@d = Document.new(PATH, NAME)
|
16
|
+
if File.file?(@d.filepath)
|
17
|
+
File.delete(@d.filepath)
|
18
|
+
end
|
19
|
+
@m = Document.new(PATH, META)
|
20
|
+
if File.file?(@d.filepath)
|
21
|
+
File.delete(@d.filepath)
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
20
|
-
|
21
25
|
def test_dot
|
22
|
-
assert_equal("#{PATH}doc/#{NAME}.md", @d.
|
23
|
-
assert(!File.file?(@d.
|
24
|
-
@d.document(
|
25
|
-
assert(File.file?(@d.
|
26
|
+
assert_equal("#{PATH}doc/#{NAME}.md", @d.filepath, "file name")
|
27
|
+
assert(!File.file?(@d.filepath), "no dotfile")
|
28
|
+
@d.document( TestModel::TESTMODEL)
|
29
|
+
assert(File.file?(@d.filepath), "file created")
|
30
|
+
@m.document_metamodel( TestModel)
|
31
|
+
assert(File.file?(@m.filepath), "file created")
|
26
32
|
end
|
27
33
|
end
|
data/test/test_model.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require_relative '../src/data_model'
|
2
|
+
include DataModel
|
3
|
+
|
4
|
+
domain :TestModel do
|
5
|
+
|
6
|
+
datatype(:ArrayParam,
|
7
|
+
description: "Thing") {
|
8
|
+
attribute :thingname, String
|
9
|
+
}
|
10
|
+
|
11
|
+
datatype :Table, description: "Test type" do
|
12
|
+
MULT = 0..10
|
13
|
+
DESC = "table of values"
|
14
|
+
attribute :vals, Integer,
|
15
|
+
multiplicity: MULT,
|
16
|
+
:description => DESC
|
17
|
+
attribute :morevals, String, 2..5, "array of strings"
|
18
|
+
end
|
19
|
+
|
20
|
+
datatype :BasicType do
|
21
|
+
attribute :id, String
|
22
|
+
end
|
23
|
+
|
24
|
+
datatype :Kindly do
|
25
|
+
attribute :kind, Selection( :Framework, :Lot, :Contract), "semantic version id of the form X.Y.Z"
|
26
|
+
end
|
27
|
+
|
28
|
+
datatype :ReferencingType do
|
29
|
+
attribute :id, String
|
30
|
+
attribute :mate, TestModel::BasicType
|
31
|
+
end
|
32
|
+
|
33
|
+
datatype(:ComplexType,
|
34
|
+
description: "Thing with things") {
|
35
|
+
attribute :string, String
|
36
|
+
attribute :things, TestModel::ArrayParam, ZERO_TO_MANY
|
37
|
+
attribute :thing_id, String, ZERO_TO_MANY, links: TestModel::ArrayParam
|
38
|
+
attribute :strings, String, ZERO_TO_MANY
|
39
|
+
attribute :mustbeafter, Date
|
40
|
+
}
|
41
|
+
|
42
|
+
datatype(:AnotherType,
|
43
|
+
description: "Thing with things") {
|
44
|
+
attribute :string, String
|
45
|
+
}
|
46
|
+
|
47
|
+
datatype :DerivedType, extends: TestModel::ReferencingType do
|
48
|
+
attribute :more, String
|
49
|
+
end
|
50
|
+
|
51
|
+
datatype :Empty do
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
TestModel.new :TESTMODEL do
|
57
|
+
|
58
|
+
complextype do
|
59
|
+
string "ID1"
|
60
|
+
things do
|
61
|
+
thingname "thing1"
|
62
|
+
end
|
63
|
+
things do
|
64
|
+
thingname "thing2"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
anothertype do
|
69
|
+
string "Anotherthing"
|
70
|
+
end
|
71
|
+
|
72
|
+
table do
|
73
|
+
vals 1
|
74
|
+
vals 2
|
75
|
+
end
|
76
|
+
|
77
|
+
referencingtype do
|
78
|
+
id :owner
|
79
|
+
mate do
|
80
|
+
id :content
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
kindly do
|
85
|
+
kind :Framework
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require_relative '../src/doc'
|
3
|
+
require_relative 'test_model'
|
4
|
+
include DataModel
|
5
|
+
|
6
|
+
class TransformTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_model
|
9
|
+
the_model = TestModel::TESTMODEL
|
10
|
+
transform_datamodel(
|
11
|
+
{
|
12
|
+
before_model: lambda do |model:|
|
13
|
+
assert_equal(model, the_model)
|
14
|
+
end,
|
15
|
+
before_group: lambda do |name:, depth: 0|
|
16
|
+
puts "before group #{name}, #{depth}"
|
17
|
+
assert(name = "framework" || name = "lot")
|
18
|
+
return :group_context
|
19
|
+
end,
|
20
|
+
after_group: lambda do |name:, depth:, before:|
|
21
|
+
puts "after group #{name}, #{depth}"
|
22
|
+
assert(before == :group_context)
|
23
|
+
end,
|
24
|
+
before_type: lambda do |type:, depth:, index:, total:|
|
25
|
+
puts "before type #{type}, #{depth}"
|
26
|
+
assert(type.class < DataType)
|
27
|
+
return :type_context
|
28
|
+
end,
|
29
|
+
after_type: lambda do |type:, depth:, before:|
|
30
|
+
puts "after type #{type}, #{depth}"
|
31
|
+
assert(before == :type_context)
|
32
|
+
end,
|
33
|
+
before_array: lambda do |name:, decl:, depth:, total:|
|
34
|
+
puts "before array #{name}, #{decl}, #{depth}"
|
35
|
+
assert(decl.class <= Array)
|
36
|
+
return :array_context
|
37
|
+
end,
|
38
|
+
after_array: lambda do |index:, decl:, depth:, before:|
|
39
|
+
puts "after array #{index}, #{decl}, #{depth}, #{before}"
|
40
|
+
assert(before == :array_context)
|
41
|
+
end,
|
42
|
+
attribute: lambda do |id:, val:, depth: 0, type: 0, index:, total:|
|
43
|
+
puts "attribute #{id}, #{val}, #{depth}, #{type}"
|
44
|
+
end,
|
45
|
+
},
|
46
|
+
the_model)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_metamodel
|
50
|
+
the_model = TestModel
|
51
|
+
transform_metamodel(
|
52
|
+
{
|
53
|
+
before_model: lambda do |model:|
|
54
|
+
assert_equal(model, the_model)
|
55
|
+
end,
|
56
|
+
before_group: lambda do |name:, depth:|
|
57
|
+
assert(false, "shouldn't be called")
|
58
|
+
end,
|
59
|
+
after_group: lambda do |name:, depth:, before:|
|
60
|
+
assert(false, "shouldn't be called")
|
61
|
+
end,
|
62
|
+
before_type: lambda do |type:, depth:, index:, total:|
|
63
|
+
puts "before type #{type}, #{depth}"
|
64
|
+
assert(type <= DataType)
|
65
|
+
return :type_context
|
66
|
+
end,
|
67
|
+
after_type: lambda do |type:, depth:, before: nil|
|
68
|
+
puts "after type #{type}, #{depth}"
|
69
|
+
assert(before == :type_context)
|
70
|
+
end,
|
71
|
+
before_array: lambda do |index:, decl:, depth:|
|
72
|
+
assert(false, "shouldn't be called")
|
73
|
+
end,
|
74
|
+
after_array: lambda do |index:, decl:, depth:, before:|
|
75
|
+
assert(false, "shouldn't be called")
|
76
|
+
end,
|
77
|
+
attribute: lambda do |id:, val:, depth:, type:, index:, total:|
|
78
|
+
puts "attribute #{id}, #{val}, #{depth}, #{type}"
|
79
|
+
end,
|
80
|
+
},
|
81
|
+
the_model)
|
82
|
+
end
|
83
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agreement-design-prototype
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CCS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -35,22 +35,35 @@ files:
|
|
35
35
|
- "./Rakefile"
|
36
36
|
- "./agreement-design.gemspec"
|
37
37
|
- "./build/build_models.rb"
|
38
|
-
- "./gen/
|
39
|
-
- "./gen/
|
38
|
+
- "./gen/data/data.json"
|
39
|
+
- "./gen/data/data.yaml"
|
40
|
+
- "./gen/data/fm_agreements.jsonlines"
|
41
|
+
- "./gen/data/fm_catalogue.jsonlines"
|
42
|
+
- "./gen/diagrams/metamodel.dot"
|
43
|
+
- "./gen/doc/data.md"
|
40
44
|
- "./gen/doc/metamodel.md"
|
41
|
-
- "./gen/images/
|
45
|
+
- "./gen/images/metamodel.jpg"
|
42
46
|
- "./model/agreement.rb"
|
43
47
|
- "./model/fm.rb"
|
48
|
+
- "./model/geographic.rb"
|
44
49
|
- "./model/party.rb"
|
50
|
+
- "./out/test/data/datatest.json"
|
45
51
|
- "./out/test/diagrams/d.dot"
|
46
52
|
- "./out/test/doc/doctest.md"
|
53
|
+
- "./out/test/doc/modeldoctest.md"
|
47
54
|
- "./out/test/images/d.jpg"
|
55
|
+
- "./src/api.rb"
|
56
|
+
- "./src/data.rb"
|
48
57
|
- "./src/data_model.rb"
|
49
58
|
- "./src/diagram.rb"
|
50
59
|
- "./src/doc.rb"
|
60
|
+
- "./src/transform.rb"
|
51
61
|
- "./test/data_model_test.rb"
|
62
|
+
- "./test/data_test.rb"
|
52
63
|
- "./test/diagram_test.rb"
|
53
64
|
- "./test/doc_test.rb"
|
65
|
+
- "./test/test_model.rb"
|
66
|
+
- "./test/transform_test.rb"
|
54
67
|
homepage: https://github.com/Crown-Commercial-Service/cmp-design-prototype/agreement-design
|
55
68
|
licenses:
|
56
69
|
- MIT
|
@@ -79,4 +92,7 @@ summary: Agreement prototype .
|
|
79
92
|
test_files:
|
80
93
|
- "./test/diagram_test.rb"
|
81
94
|
- "./test/data_model_test.rb"
|
95
|
+
- "./test/data_test.rb"
|
82
96
|
- "./test/doc_test.rb"
|
97
|
+
- "./test/transform_test.rb"
|
98
|
+
- "./test/test_model.rb"
|