-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathXapiClientAutoConfigurationBaseUrlTest.java
More file actions
72 lines (62 loc) · 2.4 KB
/
XapiClientAutoConfigurationBaseUrlTest.java
File metadata and controls
72 lines (62 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright 2016-2025 Berry Cloud Ltd. All rights reserved.
*/
package dev.learning.xapi.client.configuration;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.Is.is;
import dev.learning.xapi.client.XapiClient;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.http.codec.autoconfigure.CodecsAutoConfiguration;
import org.springframework.boot.jackson2.autoconfigure.Jackson2AutoConfiguration;
import org.springframework.boot.reactor.autoconfigure.ReactorAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
/**
* XapiClientAutoConfigurationBaseUrl Test.
*
* @author István Rátkai (Selindek)
*/
@DisplayName("XapiClientAutoConfigurationBaseUrl Test")
@SpringBootTest(
classes = {
XapiClientAutoConfiguration.class,
WebClientTestConfiguration.class,
CodecsAutoConfiguration.class,
ReactorAutoConfiguration.class,
Jackson2AutoConfiguration.class
},
properties = {"xapi.client.baseUrl = http://127.0.0.1:55123/"})
class XapiClientAutoConfigurationBaseUrlTest {
@Autowired private XapiClient client;
private static MockWebServer mockWebServer;
@BeforeAll
static void setUp() throws Exception {
mockWebServer = new MockWebServer();
mockWebServer.start(55123);
}
@AfterAll
static void tearDown() throws Exception {
mockWebServer.shutdown();
}
@Test
void whenConfiguringXapiClientThenBaseUrlIsSet() throws InterruptedException {
// When Configuring XapiClient
mockWebServer.enqueue(new MockResponse().setStatus("HTTP/1.1 200 OK"));
client.getStatement(r -> r.id("4df42866-40e7-45b6-bf7c-8d5fccbdccd6")).block();
final var recordedRequest = mockWebServer.takeRequest();
// Then BaseUrl Is Set (Request was sent to the proper url)
assertThat(
recordedRequest.getRequestUrl().toString(),
anyOf(
is(
"http://127.0.0.1:55123/statements?statementId=4df42866-40e7-45b6-bf7c-8d5fccbdccd6"),
is(
"http://localhost:55123/statements?statementId=4df42866-40e7-45b6-bf7c-8d5fccbdccd6")));
}
}