Skip to content

Commit 250be38

Browse files
committed
improve customer testst
1 parent 5ccd7fd commit 250be38

2 files changed

Lines changed: 53 additions & 4 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run Local Tests" type="GradleRunConfiguration" factoryName="Gradle">
3+
<ExternalSystemSettings>
4+
<option name="executionName"/>
5+
<option name="externalProjectPath" value="$PROJECT_DIR$"/>
6+
<option name="externalSystemIdString" value="GRADLE"/>
7+
<option name="scriptParameters" value=""/>
8+
<option name="taskDescriptions">
9+
<list/>
10+
</option>
11+
<option name="taskNames">
12+
<list>
13+
<option value=":test"/>
14+
</list>
15+
</option>
16+
<option name="vmOptions"/>
17+
</ExternalSystemSettings>
18+
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
19+
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
20+
<DebugAllEnabled>false</DebugAllEnabled>
21+
<RunAsTest>false</RunAsTest>
22+
<method v="2"/>
23+
</configuration>
24+
</component>

src/test/java/de/kaleidox/workbench/test/api/CustomerApiTest.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.boot.test.context.SpringBootTest;
99
import org.springframework.boot.test.web.client.TestRestTemplate;
1010

11+
import java.util.Arrays;
1112
import java.util.List;
1213

1314
import static org.junit.jupiter.api.Assertions.*;
@@ -18,17 +19,41 @@ public class CustomerApiTest {
1819
public static final Customer FAARQUARDT_CASTLE = new Customer(FAARQUARDT_NAME, "Castle");
1920
public static final Customer FAARQUARDT_HOUSE = new Customer(FAARQUARDT_NAME, "House");
2021

21-
@Autowired
22-
private CustomerRepository customers;
23-
@Autowired
24-
private TestRestTemplate rest;
22+
@Autowired private CustomerRepository customers;
23+
@Autowired private TestRestTemplate rest;
2524

2625
@Test
2726
@Order(0)
2827
void contextLoads() {
2928
assertNotNull(customers);
3029
}
3130

31+
@Test
32+
@Order(1)
33+
void fetchNames() {
34+
var response = rest.getForEntity("http://localhost:8080/api/customers/names", String[].class);
35+
assertTrue(response.getStatusCode().is2xxSuccessful(), "request unsuccessful");
36+
37+
var data = response.getBody();
38+
assertNotNull(data);
39+
assertEquals(1, data.length, "wrong array length");
40+
assertEquals(FAARQUARDT_NAME, data[0], "customer name mismatch");
41+
}
42+
43+
@Test
44+
@Order(2)
45+
void fetchDepartments() {
46+
var response = rest.getForEntity("http://localhost:8080/api/customers/%s/departments".formatted(FAARQUARDT_NAME),
47+
String[].class);
48+
assertTrue(response.getStatusCode().is2xxSuccessful(), "request unsuccessful");
49+
50+
var data = response.getBody();
51+
assertNotNull(data);
52+
assertEquals(2, data.length, "wrong array length");
53+
assertNotEquals(-1, Arrays.binarySearch(data, "Castle"), "department not found");
54+
assertNotEquals(-1, Arrays.binarySearch(data, "House"), "department not found");
55+
}
56+
3257
@Test
3358
@Order(10)
3459
void createCustomers() {

0 commit comments

Comments
 (0)