-
1. Re: Arquillian Persistency Extension: yaml and backreferences
bmajsak Oct 30, 2012 10:19 AM (in response to mjaskowski)Hi Maciej,
YAML files used by APE are plain DBunit DataSets meaning, they are db / row oriented (rdbms entities, not Java objects). You need to refer to other entries using foreign keys, as you would do in plain SQL. I hope I got your concern right
Cheers,
Bartosz
-
2. Re: Arquillian Persistency Extension: yaml and backreferences
mjaskowski Oct 31, 2012 5:30 AM (in response to bmajsak)Nope you didn't
in plain sql i would:
insert into A(id) values(1);
insert into B(id, a_id) values(2,1);
update table A where id = 1 set b_id = 2;
given there are foreign keys between a_id and A and b_id and B that's the only way to this (unless you consider turning off the foreign keys alltogether)
how can I do that using yml in APE?
-
3. Re: Arquillian Persistency Extension: yaml and backreferences
bmajsak Oct 31, 2012 11:36 AM (in response to mjaskowski)Ok, got me
Not sure if it's even possible with pure YAML, because it's more something like chicken-egg problem (not that it's not doable, only to describe how YAML parsers are working)
I'm afraid you need to define the alias first before you reference to it, so something like this won't work
A:
- id: 2
b_id: *b_id
B:
- id: &b_id 1
a_id: 2
On the other hand I can't really see how dbunit would process such data set, when it's anyway going row-by-row. Conclusion: turning off integrity check might be the only option if you want to use single data set.
However, you can provide two data sets, one with raw data and second one with updated relationships. For this purpose you should define insert strategy as @SeedDataUsing(REFRESH) - this will update existing rows and insert those which are not existing yet (if any)
HTH
-
4. Re: Arquillian Persistency Extension: yaml and backreferences
mjaskowski Nov 2, 2012 4:29 AM (in response to bmajsak)However, you can provide two data sets, one with raw data and second one with updated relationships.
That sounds like a solution.
For this purpose you should define insert strategy as @SeedDataUsing(REFRESH) - this will update existing rows and insert those which are not existing yet (if any)
Mmm... an internet search didn't help me find @SeedDataUsing annotation.
I had a look at the source code but I still wonder how to make it work? I mean: I need to have e.g.
@UsingDataSet
(
"datasets/data.yml")
@SeedDataUsing(DataSeedStrategy.DEFAULT
)
@UsingDataSet
(
"datasets/references.yml")
@SeedDataUsing(DataSeedStrategy.REFRESH
)
I can't do it on one test method, can I? It wouldn't look good to split it between class annotation and method annotation too, right? How to handle it then?
-
5. Re: Arquillian Persistency Extension: yaml and backreferences
bmajsak Nov 2, 2012 5:41 AM (in response to mjaskowski)How about having such a construct?
@UsingDataSet
({
"datasets/data.yml",
"datasets/references.yml" })@SeedDataUsing(DataSeedStrategy.REFRESH
)
the order of data sets should be preserved.
You can also put @SeedDataUsing on the class levelso it will become the default if not defined otherwise on the method level.
HTH