3232import org .junit .jupiter .api .DisplayName ;
3333import org .junit .jupiter .api .Test ;
3434import org .springframework .beans .factory .annotation .Autowired ;
35- import org .springframework .data .couchbase .CouchbaseClientFactory ;
36- import org .springframework .data .couchbase .core .CouchbaseTemplate ;
37- import org .springframework .data .couchbase .domain .User ;
38- import org .springframework .data .couchbase .domain .UserRepository ;
35+ import org .springframework .data .couchbase .domain .UserCol ;
36+ import org .springframework .data .couchbase .domain .UserColRepository ;
3937import org .springframework .data .couchbase .transaction .error .TransactionSystemUnambiguousException ;
4038import org .springframework .data .couchbase .util .ClusterType ;
39+ import org .springframework .data .couchbase .util .CollectionAwareIntegrationTests ;
4140import org .springframework .data .couchbase .util .IgnoreWhen ;
42- import org .springframework .data .couchbase .util .JavaIntegrationTests ;
4341import org .springframework .stereotype .Service ;
4442import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
45- import org .springframework .transaction .annotation .EnableTransactionManagement ;
4643import org .springframework .transaction .annotation .Transactional ;
4744
4845/**
5148 * @author Michael Reiche
5249 */
5350@ IgnoreWhen (clusterTypes = ClusterType .MOCKED )
54- @ SpringJUnitConfig (
55- classes = { TransactionsConfig . class , CouchbaseTransactionalRepositoryIntegrationTests .UserService .class })
56- public class CouchbaseTransactionalRepositoryIntegrationTests extends JavaIntegrationTests {
51+ @ SpringJUnitConfig (classes = { TransactionsConfig . class ,
52+ CouchbaseTransactionalRepositoryCollectionIntegrationTests .UserService .class })
53+ public class CouchbaseTransactionalRepositoryCollectionIntegrationTests extends CollectionAwareIntegrationTests {
5754 // intellij flags "Could not autowire" when config classes are specified with classes={...}. But they are populated.
58- @ Autowired UserRepository userRepo ;
59- @ Autowired CouchbaseClientFactory couchbaseClientFactory ;
55+ @ Autowired UserColRepository userRepo ;
6056 @ Autowired UserService userService ;
61- @ Autowired CouchbaseTemplate operations ;
57+ // @Autowired CouchbaseTemplate operations;
6258
6359 @ BeforeAll
6460 public static void beforeAll () {
@@ -77,9 +73,9 @@ public void afterEachTest() {
7773
7874 @ Test
7975 public void findByFirstname () {
80- operations . insertById (User .class ).one (new User (UUID .randomUUID ().toString (), "Ada" , "Lovelace" ));
76+ userRepo . getOperations (). insertById (UserCol .class ).one (new UserCol (UUID .randomUUID ().toString (), "Ada" , "Lovelace" ));
8177
82- List <User > users = userService .findByFirstname ("Ada" );
78+ List <UserCol > users = userService .findByFirstname ("Ada" );
8379
8480 assertNotEquals (0 , users .size ());
8581 }
@@ -91,19 +87,19 @@ public void save() {
9187 userService .run (repo -> {
9288 assertInTransaction ();
9389
94- User user0 = repo .save (new User (id , "Ada" , "Lovelace" ));
90+ UserCol user0 = repo .save (new UserCol (id , "Ada" , "Lovelace" ));
9591
9692 assertInTransaction ();
9793
9894 // read your own write
99- User user1 = operations . findById (User .class ).one (id );
95+ UserCol user1 = userRepo . getOperations (). findById (UserCol .class ).one (id );
10096 assertNotNull (user1 );
10197
10298 assertInTransaction ();
10399
104100 });
105101
106- User user = operations . findById (User .class ).one (id );
102+ UserCol user = userRepo . getOperations (). findById (UserCol .class ).one (id );
107103 assertNotNull (user );
108104 }
109105
@@ -114,26 +110,26 @@ public void saveRolledBack() {
114110
115111 assertThrowsWithCause (() -> {
116112 userService .run (repo -> {
117- User user = repo .save (new User (id , "Ada" , "Lovelace" ));
113+ UserCol user = repo .save (new UserCol (id , "Ada" , "Lovelace" ));
118114 SimulateFailureException .throwEx ("fail" );
119115 });
120116 }, TransactionSystemUnambiguousException .class , SimulateFailureException .class );
121117
122- User user = operations . findById (User .class ).one (id );
118+ UserCol user = userRepo . getOperations (). findById (UserCol .class ).one (id );
123119 assertNull (user );
124120 }
125121
126122 @ Service // this will work in the unit tests even without @Service because of explicit loading by @SpringJUnitConfig
127123 static class UserService {
128- @ Autowired UserRepository userRepo ;
124+ @ Autowired UserColRepository userRepo ;
129125
130126 @ Transactional
131- public void run (Consumer <UserRepository > callback ) {
127+ public void run (Consumer <UserColRepository > callback ) {
132128 callback .accept (userRepo );
133129 }
134130
135131 @ Transactional
136- public List <User > findByFirstname (String name ) {
132+ public List <UserCol > findByFirstname (String name ) {
137133 return userRepo .findByFirstname (name );
138134 }
139135
0 commit comments