Skip to content

Commit 18e205e

Browse files
committed
Added tests for generation of linked classes based on shape link. Closes #4
1 parent 126359c commit 18e205e

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.herminiogarcia.dmaog
2+
3+
class FilmAndActorCodeGenerationTest extends FilmCodeGenerationTest {
4+
5+
override val rules =
6+
"""
7+
|PREFIX : <http://example.com/>
8+
|PREFIX dbr: <http://dbpedia.org/resource/>
9+
|PREFIX schema: <http://schema.org/>
10+
|PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
11+
|SOURCE films_xml_file <http://shexml.herminiogarcia.com/files/films.xml>
12+
|SOURCE films_json_file <http://shexml.herminiogarcia.com/files/films.json>
13+
|ITERATOR film_xml <xpath: //film> {
14+
| FIELD id <@id>
15+
| FIELD name <name>
16+
| FIELD year <year>
17+
| FIELD country <country>
18+
| FIELD directors <crew/directors/director>
19+
| FIELD screenwritters <crew//screenwritter>
20+
| FIELD music <crew/music>
21+
| FIELD photography <crew/photography>
22+
| ITERATOR actors <cast/actor> {
23+
| FIELD name <name>
24+
| FIELD role <role>
25+
| FIELD film <../../@id>
26+
| }
27+
| ITERATOR actresses <cast/actress> {
28+
| FIELD name <name>
29+
| FIELD role <role>
30+
| FIELD film <../../@id>
31+
| }
32+
|}
33+
|ITERATOR film_json <jsonpath: $.films[*]> {
34+
| PUSHED_FIELD id <id>
35+
| FIELD name <name>
36+
| FIELD year <year>
37+
| FIELD country <country>
38+
| FIELD directors <crew.director>
39+
| FIELD screenwritters <crew.screenwritter>
40+
| FIELD music <crew.music>
41+
| FIELD photography <crew.cinematography>
42+
| ITERATOR actors <cast[*]> {
43+
| FIELD name <name>
44+
| FIELD role <role>
45+
| POPPED_FIELD film <id>
46+
| }
47+
|}
48+
|EXPRESSION films <films_xml_file.film_xml UNION films_json_file.film_json>
49+
|
50+
|:Films :[films.id] {
51+
| a :Film ;
52+
| schema:name [films.name] ;
53+
| :year [films.year] xsd:integer ;
54+
| schema:countryOfOrigin dbr:[films.country] ;
55+
| schema:director dbr:[films.directors] ;
56+
| :screenwritter dbr:[films.screenwritters] ;
57+
| schema:musicBy dbr:[films.music] ;
58+
| :cinematographer dbr:[films.photography] ;
59+
| schema:actor @:Actor ;
60+
| schema:actor @:Actress ;
61+
|}
62+
|
63+
|:Actor dbr:[films.actors.name] {
64+
| a :Actor ;
65+
| :name [films.actors.name] ;
66+
| :appear_on :[films.actors.film] ;
67+
|}
68+
|
69+
|:Actress dbr:[films.actresses.name] {
70+
| a :Actor ;
71+
| :name [films.actresses.name] ;
72+
| :appear_on :[films.actresses.film] ;
73+
|}
74+
|""".stripMargin
75+
76+
test("Actor class name and package are correctly generated") {
77+
val content = loadClass("Actor")
78+
assert(content.contains("public class Actor"))
79+
assert(content.contains("package com.example;"))
80+
}
81+
82+
test("Film to Actor relation is correctly generated") {
83+
val content = loadClass("Film")
84+
85+
assert(content.contains("private List<IRIValue> schemaActor;"))
86+
87+
val setSchemaActor = "public Film setSchemaActor\\(List<IRIValue> schemaActor\\)[ \r\n]*[{][ \r\n]*this.schemaActor = schemaActor;[ \r\n]*return this;[ \r\n]*[}]".r
88+
assert(setSchemaActor.findFirstIn(content).isDefined)
89+
90+
val getSchemaActor = "public List<IRIValue> getSchemaActor\\(\\)[ \r\n]*[{][ \r\n]*return this.schemaActor;[ \r\n]*[}]".r
91+
assert(getSchemaActor.findFirstIn(content).isDefined)
92+
}
93+
94+
test("Actor attributes are correctly generated") {
95+
val content = loadClass("Actor")
96+
97+
assert(content.contains("public final static String rdfType = \"http://example.com/Actor\";"))
98+
assert(content.contains("public final static String subjectPrefix = \"http://dbpedia.org/resource/\";"))
99+
100+
assert(content.contains("private String name;"))
101+
assert(content.contains("private IRIValue appear_on;"))
102+
assert(content.contains("private IRIValue id;"))
103+
}
104+
105+
test("Actor constructor is correctly generated") {
106+
val content = loadClass("Actor")
107+
108+
assert("public Actor\\(\\)[ \r\n]*[{][ \r\n]*[}]".r.findFirstIn(content).isDefined)
109+
}
110+
111+
test("Actor setters are correctly generated") {
112+
val content = loadClass("Actor")
113+
val setName = "public Actor setName\\(String name\\)[ \r\n]*[{][ \r\n]*this.name = name;[ \r\n]*return this;[ \r\n]*[}]".r
114+
val setAppear_on = "public Actor setAppear_on\\(IRIValue appear_on\\)[ \r\n]*[{][ \r\n]*this.appear_on = appear_on;[ \r\n]*return this;[ \r\n]*[}]".r
115+
val setId = "public Actor setId\\(IRIValue id\\)[ \r\n]*[{][ \r\n]*this.id = id;[ \r\n]*return this;[ \r\n]*[}]".r
116+
117+
assert(setName.findFirstIn(content).isDefined)
118+
assert(setAppear_on.findFirstIn(content).isDefined)
119+
assert(setId.findFirstIn(content).isDefined)
120+
}
121+
122+
test("Actor getters are correctly generated") {
123+
val content = loadClass("Actor")
124+
val getName = "public String getName\\(\\)[ \r\n]*[{][ \r\n]*return this.name;[ \r\n]*[}]".r
125+
val getAppear_on = "public IRIValue getAppear_on\\(\\)[ \r\n]*[{][ \r\n]*return this.appear_on;[ \r\n]*[}]".r
126+
val getId = "public IRIValue getId\\(\\)[ \r\n]*[{][ \r\n]*return this.id;[ \r\n]*[}]".r
127+
128+
assert(getName.findFirstIn(content).isDefined)
129+
assert(getAppear_on.findFirstIn(content).isDefined)
130+
assert(getId.findFirstIn(content).isDefined)
131+
}
132+
133+
}

0 commit comments

Comments
 (0)