Skip to content

Commit 5e7bb5d

Browse files
Added Record tests
1 parent 8a0d905 commit 5e7bb5d

File tree

3 files changed

+121
-1
lines changed

3 files changed

+121
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © 2023 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.repositories;
17+
18+
import java.util.List;
19+
20+
21+
public record CustomerAsRecord(String firstName, String lastName)
22+
{
23+
@SuppressWarnings("OptionalGetWithoutIsPresent")
24+
public CustomerAsRecord getCustomerWithFirstName(
25+
final List<CustomerAsRecord> customers,
26+
final String firstNameToFind)
27+
{
28+
return customers.stream().filter(customer -> customer.firstName.equals(firstNameToFind)).findFirst().get();
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright © 2023 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.repositories;
17+
18+
import java.util.Optional;
19+
20+
import org.springframework.data.repository.CrudRepository;
21+
22+
23+
public interface CustomerAsRecordRepository extends CrudRepository<CustomerAsRecord, String>
24+
{
25+
Optional<CustomerAsRecord> findByFirstName(String firstName);
26+
}

spring-data-eclipse-store/src/test/java/software/xdev/spring/data/eclipse/store/integration/tests/SimpleSingleTest.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
import java.util.List;
1919
import java.util.Optional;
2020

21+
import jakarta.inject.Inject;
22+
2123
import org.junit.jupiter.api.Assertions;
2224
import org.junit.jupiter.api.Test;
2325
import org.springframework.beans.factory.annotation.Autowired;
2426

25-
import jakarta.inject.Inject;
2627
import software.xdev.spring.data.eclipse.store.helper.TestData;
2728
import software.xdev.spring.data.eclipse.store.helper.TestUtil;
2829
import software.xdev.spring.data.eclipse.store.integration.DefaultTestAnnotations;
2930
import software.xdev.spring.data.eclipse.store.integration.repositories.Customer;
31+
import software.xdev.spring.data.eclipse.store.integration.repositories.CustomerAsRecord;
32+
import software.xdev.spring.data.eclipse.store.integration.repositories.CustomerAsRecordRepository;
3033
import software.xdev.spring.data.eclipse.store.integration.repositories.CustomerNotCrud;
3134
import software.xdev.spring.data.eclipse.store.integration.repositories.CustomerNotCrudRepository;
3235
import software.xdev.spring.data.eclipse.store.integration.repositories.CustomerRepository;
@@ -38,6 +41,8 @@ class SimpleSingleTest
3841
{
3942
@Inject
4043
private CustomerRepository repository;
44+
@Inject
45+
private CustomerAsRecordRepository recordRepository;
4146

4247
@Inject
4348
private EclipseStoreStorage storage;
@@ -54,6 +59,65 @@ void testNullFindAll()
5459
);
5560
}
5661

62+
@Test
63+
void testBasicSaveAndFindSingleRecords()
64+
{
65+
final CustomerAsRecord customer = new CustomerAsRecord(TestData.FIRST_NAME, TestData.LAST_NAME);
66+
this.recordRepository.save(customer);
67+
68+
TestUtil.doBeforeAndAfterRestartOfDatastore(
69+
this.storage,
70+
() -> {
71+
final List<CustomerAsRecord> customers = TestUtil.iterableToList(this.recordRepository.findAll());
72+
Assertions.assertEquals(1, customers.size());
73+
Assertions.assertEquals(customer, customers.get(0));
74+
}
75+
);
76+
}
77+
78+
@Test
79+
void testBasicSaveAndFindMultipleRecords()
80+
{
81+
final CustomerAsRecord customer = new CustomerAsRecord(TestData.FIRST_NAME, TestData.LAST_NAME);
82+
this.recordRepository.save(customer);
83+
final CustomerAsRecord customer2 = new CustomerAsRecord(null, null);
84+
this.recordRepository.save(customer2);
85+
86+
TestUtil.doBeforeAndAfterRestartOfDatastore(
87+
this.storage,
88+
() -> {
89+
final List<CustomerAsRecord> customers = TestUtil.iterableToList(this.recordRepository.findAll());
90+
final CustomerAsRecord foundCustomer =
91+
customers.stream().filter(c -> TestData.FIRST_NAME.equals(c.firstName())).findFirst().get();
92+
final CustomerAsRecord foundCustomer2 =
93+
customers.stream().filter(c -> c.firstName() == null).findFirst().get();
94+
Assertions.assertEquals(2, customers.size());
95+
Assertions.assertEquals(customer, foundCustomer);
96+
Assertions.assertEquals(customer2, foundCustomer2);
97+
}
98+
);
99+
}
100+
101+
@Test
102+
void testBasicSaveAndFindByFirstNameRecords()
103+
{
104+
final CustomerAsRecord customer = new CustomerAsRecord(TestData.FIRST_NAME, TestData.LAST_NAME);
105+
this.recordRepository.save(customer);
106+
final CustomerAsRecord customer2 =
107+
new CustomerAsRecord(TestData.FIRST_NAME_ALTERNATIVE, TestData.LAST_NAME_ALTERNATIVE);
108+
this.recordRepository.save(customer2);
109+
110+
TestUtil.doBeforeAndAfterRestartOfDatastore(
111+
this.storage,
112+
() -> {
113+
final Optional<CustomerAsRecord> foundCustomer =
114+
this.recordRepository.findByFirstName(TestData.FIRST_NAME);
115+
Assertions.assertTrue(foundCustomer.isPresent());
116+
Assertions.assertEquals(customer, foundCustomer.get());
117+
}
118+
);
119+
}
120+
57121
@SuppressWarnings("DataFlowIssue")
58122
@Test
59123
void testNullSave()

0 commit comments

Comments
 (0)