1+ package com .introproventures .graphql .jpa .query .idclass ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import javax .persistence .EntityManager ;
6+
7+ import org .junit .Test ;
8+ import org .junit .runner .RunWith ;
9+ import org .springframework .beans .factory .annotation .Autowired ;
10+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
11+ import org .springframework .boot .test .context .SpringBootTest ;
12+ import org .springframework .context .annotation .Bean ;
13+ import org .springframework .test .context .TestPropertySource ;
14+ import org .springframework .test .context .junit4 .SpringRunner ;
15+
16+ import com .introproventures .graphql .jpa .query .schema .GraphQLExecutor ;
17+ import com .introproventures .graphql .jpa .query .schema .GraphQLSchemaBuilder ;
18+ import com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaExecutor ;
19+ import com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaSchemaBuilder ;
20+
21+ @ RunWith (SpringRunner .class )
22+ @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .NONE ,
23+ properties = "spring.datasource.data=EntityWithIdClassTest.sql" )
24+ @ TestPropertySource ({"classpath:hibernate.properties" })
25+ public class EntityWithIdClassTest {
26+
27+ @ SpringBootApplication
28+ static class Application {
29+ @ Bean
30+ public GraphQLExecutor graphQLExecutor (final GraphQLSchemaBuilder graphQLSchemaBuilder ) {
31+ return new GraphQLJpaExecutor (graphQLSchemaBuilder .build ());
32+ }
33+
34+ @ Bean
35+ public GraphQLSchemaBuilder graphQLSchemaBuilder (final EntityManager entityManager ) {
36+ return new GraphQLJpaSchemaBuilder (entityManager )
37+ .name ("IdClassCompsiteKeysTest" );
38+ }
39+ }
40+
41+ @ Autowired
42+ private GraphQLExecutor executor ;
43+
44+ @ Test
45+ public void querySingularEntityWithIdClass () {
46+ //given
47+ String query = "query {" +
48+ " Account(" +
49+ " accountNumber: \" 1\" " +
50+ " accountType: \" Savings\" " +
51+ " )" +
52+ " {" +
53+ " accountNumber" +
54+ " accountType" +
55+ " description" +
56+ " }" +
57+ "}" ;
58+
59+ String expected = "{Account={accountNumber=1, accountType=Savings, description=Saving account record}}" ;
60+
61+ //when
62+ Object result = executor .execute (query ).getData ();
63+
64+ // then
65+ assertThat (result .toString ()).isEqualTo (expected );
66+ }
67+
68+ @ Test
69+ public void queryEntityWithIdClass () {
70+ //given
71+ String query = "query {" +
72+ " Accounts {" +
73+ " total" +
74+ " pages" +
75+ " select {" +
76+ " accountNumber" +
77+ " accountType" +
78+ " description" +
79+ " }" +
80+ " }" +
81+ "}" ;
82+
83+ String expected = "{Accounts={total=2, pages=1, select=["
84+ + "{accountNumber=1, accountType=Savings, description=Saving account record}, "
85+ + "{accountNumber=2, accountType=Checking, description=Checking account record}"
86+ + "]}}" ;
87+
88+ //when
89+ Object result = executor .execute (query ).getData ();
90+
91+ // then
92+ assertThat (result .toString ()).isEqualTo (expected );
93+ }
94+
95+ @ Test
96+ public void queryEntityWithIdClassWhereCriteriaExpression () {
97+ //given
98+ String query = "query {" +
99+ " Accounts(" +
100+ " where: {" +
101+ " accountNumber: {" +
102+ " EQ: \" 1\" " +
103+ " }" +
104+ " accountType: {" +
105+ " EQ: \" Savings\" " +
106+ " }" +
107+ " })" +
108+ " {" +
109+ " total" +
110+ " pages" +
111+ " select {" +
112+ " accountNumber" +
113+ " accountType" +
114+ " description" +
115+ " }" +
116+ " }" +
117+ "}" ;
118+
119+ String expected = "{Accounts={total=1, pages=1, select=["
120+ + "{accountNumber=1, accountType=Savings, description=Saving account record}"
121+ + "]}}" ;
122+
123+ //when
124+ Object result = executor .execute (query ).getData ();
125+
126+ // then
127+ assertThat (result .toString ()).isEqualTo (expected );
128+ }
129+
130+ }
0 commit comments