Skip to content

Commit f5cf81b

Browse files
Added new tests for transactions with version
1 parent 38062f4 commit f5cf81b

22 files changed

+432
-102
lines changed

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/transactions/Account.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,12 @@
1717

1818
import java.math.BigDecimal;
1919

20-
import jakarta.persistence.Id;
2120

22-
23-
public class Account
21+
public interface Account
2422
{
25-
@Id
26-
private int id;
27-
28-
private BigDecimal balance;
29-
30-
public Account(final int id, final BigDecimal balance)
31-
{
32-
this.id = id;
33-
this.balance = balance;
34-
}
35-
36-
public int getId()
37-
{
38-
return this.id;
39-
}
40-
41-
public void setId(final int id)
42-
{
43-
this.id = id;
44-
}
23+
int getId();
4524

46-
public BigDecimal getBalance()
47-
{
48-
return this.balance;
49-
}
25+
BigDecimal getBalance();
5026

51-
public void setBalance(final BigDecimal balance)
52-
{
53-
this.balance = balance;
54-
}
27+
void setBalance(final BigDecimal balance);
5528
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.transactions;
17+
18+
import java.math.BigDecimal;
19+
20+
import jakarta.persistence.Id;
21+
22+
23+
public class AccountNoVersion implements Account
24+
{
25+
@Id
26+
private int id;
27+
28+
private BigDecimal balance;
29+
30+
public AccountNoVersion(final int id, final BigDecimal balance)
31+
{
32+
this.id = id;
33+
this.balance = balance;
34+
}
35+
36+
@Override
37+
public int getId()
38+
{
39+
return this.id;
40+
}
41+
42+
public void setId(final int id)
43+
{
44+
this.id = id;
45+
}
46+
47+
@Override
48+
public BigDecimal getBalance()
49+
{
50+
return this.balance;
51+
}
52+
53+
@Override
54+
public void setBalance(final BigDecimal balance)
55+
{
56+
this.balance = balance;
57+
}
58+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.transactions;
1717

18-
import org.springframework.data.repository.CrudRepository;
18+
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository;
1919

2020

21-
public interface AccountRepository extends CrudRepository<Account, Integer>
21+
public interface AccountNoVersionRepository extends EclipseStoreRepository<AccountNoVersion, Integer>
2222
{
2323
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.transactions;
17+
18+
import java.math.BigDecimal;
19+
20+
import jakarta.persistence.Id;
21+
import jakarta.persistence.Version;
22+
23+
24+
public class AccountWithVersion implements Account
25+
{
26+
@Id
27+
private int id;
28+
29+
@Version
30+
private long version;
31+
32+
private BigDecimal balance;
33+
34+
public AccountWithVersion(final int id, final BigDecimal balance)
35+
{
36+
this.id = id;
37+
this.balance = balance;
38+
}
39+
40+
@Override
41+
public int getId()
42+
{
43+
return this.id;
44+
}
45+
46+
public void setId(final int id)
47+
{
48+
this.id = id;
49+
}
50+
51+
@Override
52+
public BigDecimal getBalance()
53+
{
54+
return this.balance;
55+
}
56+
57+
@Override
58+
public void setBalance(final BigDecimal balance)
59+
{
60+
this.balance = balance;
61+
}
62+
63+
public long getVersion()
64+
{
65+
return this.version;
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.transactions;
17+
18+
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository;
19+
20+
21+
public interface AccountWithVersionRepository extends EclipseStoreRepository<AccountWithVersion, Integer>
22+
{
23+
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/isolated/tests/transactions/TransactionsAnnotationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
@Transactional
3434
class TransactionsAnnotationTest
3535
{
36-
private final AccountRepository repository;
36+
private final AccountNoVersionRepository repository;
3737

3838
@Autowired
39-
public TransactionsAnnotationTest(final AccountRepository repository)
39+
public TransactionsAnnotationTest(final AccountNoVersionRepository repository)
4040
{
4141
this.repository = repository;
4242
}
@@ -45,8 +45,8 @@ public TransactionsAnnotationTest(final AccountRepository repository)
4545
void accountTransactionUnexpectedErrorAnnotation()
4646
{
4747
Assertions.assertThrows(RuntimeException.class, () -> {
48-
final Account account1 = new Account(3, BigDecimal.TEN);
49-
final Account account2 = new Account(4, BigDecimal.ZERO);
48+
final AccountNoVersion account1 = new AccountNoVersion(3, BigDecimal.TEN);
49+
final AccountNoVersion account2 = new AccountNoVersion(4, BigDecimal.ZERO);
5050
this.repository.saveAll(List.of(account1, account2));
5151

5252
throw new RuntimeException("Unexpected error");

0 commit comments

Comments
 (0)