Skip to content

Commit 2721aad

Browse files
committed
More complex test for #215
1 parent 7773e05 commit 2721aad

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# These are needed if running in IDE without properties set
1414
/ibderby
1515
derby.log
16+
/bin/

src/test/java/org/apache/ibatis/submitted/ancestor_ref/AncestorRefTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public void testAncestorRef() {
8585
// author and coauthor should have a ref to blog
8686
assertEquals(blog, blog.getAuthor().getBlog());
8787
assertEquals(blog, blog.getCoAuthor().getBlog());
88+
// reputation should point to it author? or fail but do not point to a random one
89+
assertEquals(blog.getAuthor(), blog.getAuthor().getReputation().getAuthor());
90+
assertEquals(blog.getCoAuthor(), blog.getCoAuthor().getReputation().getAuthor());
8891
} finally {
8992
sqlSession.close();
9093
}

src/test/java/org/apache/ibatis/submitted/ancestor_ref/Author.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class Author {
2020
private Integer id;
2121
private String name;
2222
private Blog blog;
23+
private Reputation reputation;
2324

2425
public Integer getId() {
2526
return id;
@@ -44,4 +45,12 @@ public Blog getBlog() {
4445
public void setBlog(Blog blog) {
4546
this.blog = blog;
4647
}
48+
49+
public Reputation getReputation() {
50+
return reputation;
51+
}
52+
53+
public void setReputation(Reputation reputation) {
54+
this.reputation = reputation;
55+
}
4756
}

src/test/java/org/apache/ibatis/submitted/ancestor_ref/CreateDB.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ create table blog (
4545

4646
create table author (
4747
id int,
48-
name varchar(16)
48+
name varchar(16),
49+
reputation int
4950
);
5051

5152
insert into blog (id, title, author_id, co_author_id) values
5253
(1, 'Blog1', 1, 2), (2, 'Blog2', 2, 3);
5354

54-
insert into author (id, name) values
55-
(1, 'Author1'), (2, 'Author2'), (3, 'Author3');
55+
insert into author (id, name, reputation) values
56+
(1, 'Author1', 1), (2, 'Author2', 2), (3, 'Author3', 3);

src/test/java/org/apache/ibatis/submitted/ancestor_ref/Mapper.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,18 @@
7070
<id property="id" column="id" />
7171
<result property="name" column="name" />
7272
<association property="blog" resultMap="blogResult" />
73+
<association property="reputation" resultMap="reputationResult" />
74+
</resultMap>
75+
76+
<resultMap type="org.apache.ibatis.submitted.ancestor_ref.Reputation"
77+
id="reputationResult">
78+
<id property="value" column="reputation" />
79+
<association property="author" resultMap="authorResult" />
7380
</resultMap>
7481

7582
<select id="selectBlog" resultMap="blogResult"><![CDATA[
76-
select id, title, a.id author_id, a.name author_name,
77-
ca.id co_author_id, ca.name co_author_name
83+
select id, title, a.id author_id, a.name author_name, a.reputation author_reputation,
84+
ca.id co_author_id, ca.name co_author_name, ca.reputation co_author_reputation
7885
from blog b
7986
left join author a on a.id = b.author_id
8087
left join author ca on ca.id = b.co_author_id
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.apache.ibatis.submitted.ancestor_ref;
2+
3+
public class Reputation {
4+
5+
private int value;
6+
7+
private Author author;
8+
9+
public int getValue() {
10+
return value;
11+
}
12+
13+
public void setValue(int value) {
14+
this.value = value;
15+
}
16+
17+
public Author getAuthor() {
18+
return author;
19+
}
20+
21+
public void setAuthor(Author author) {
22+
this.author = author;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)