-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathDefaultImportScanServiceTest.java
98 lines (82 loc) · 2.78 KB
/
DefaultImportScanServiceTest.java
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// SPDX-FileCopyrightText: the secureCodeBox authors
//
// SPDX-License-Identifier: Apache-2.0
package io.securecodebox.persistence.defectdojo.service;
import io.securecodebox.persistence.defectdojo.config.Config;
import io.securecodebox.persistence.defectdojo.http.ProxyConfig;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for {@link DefaultImportScanService}
*/
class DefaultImportScanServiceTest {
private final Config config = new Config(
"http://localhost",
"apiKey",
23
);
private final DefaultImportScanService sut = new DefaultImportScanService(config, ProxyConfig.NULL);
@Test
void constructorShouldThrowExceptionOnNullConfig() {
assertThrows(NullPointerException.class, () -> {
new DefaultImportScanService(null, ProxyConfig.NULL);
});
}
@Test
void constructorShouldThrowExceptionOnNullProxyConfig() {
assertThrows(NullPointerException.class, () -> {
new DefaultImportScanService(Config.NULL, null);
});
}
@Test
void createDefectDojoAuthorizationHeaders_apiKeyFromConfigShouldBePresentAsAuthHEader() {
final var authorizationHeaders = sut.createDefectDojoAuthorizationHeaders();
assertAll(
() -> assertThat(authorizationHeaders.size(), is(1)),
() -> assertThat(authorizationHeaders.get(HttpHeaders.AUTHORIZATION).get(0), is("Token apiKey"))
);
}
@Test
void shouldConfigureProxySettings_trueIfProxyConfigIsComplete() {
final var proxyConfig = ProxyConfig.builder()
.user("user")
.password("pw")
.host("host")
.port(42)
.build();
final var innerSut = new DefaultImportScanService(config, proxyConfig);
assertThat(innerSut.shouldConfigureProxySettings(), is(true));
}
@Test
void shouldConfigureProxySettings_falseIfProxyConfigIsIncomplete() {
final var proxyConfig = ProxyConfig.builder()
.build();
final var innerSut = new DefaultImportScanService(config, proxyConfig);
assertThat(innerSut.shouldConfigureProxySettings(), is(false));
}
@Test
void generateApiUrl() {
assertThat(sut.generateApiUrl("foo"), is("http://localhost/api/v2/foo/"));
}
@Test
@Disabled("Not implemented yet")
void importScan_shouldPassImportScanAsEndpoint() {
}
@Test
@Disabled("Not implemented yet")
void importScan_shouldPassEngagementIdAsEngagement() {
}
@Test
@Disabled("Not implemented yet")
void reimportScan_shouldPassReimportScanAsEndpoint() {
}
@Test
@Disabled("Not implemented yet")
void reimportScan_shouldPassEngagementIdAsTest() {
}
}