11package io .securecodebox .persistence .defectdojo .service ;
22
3+ import io .securecodebox .persistence .defectdojo .ScanType ;
34import io .securecodebox .persistence .defectdojo .config .DefectDojoConfig ;
5+ import io .securecodebox .persistence .defectdojo .models .ScanFile ;
6+ import lombok .Getter ;
7+ import org .junit .jupiter .api .Disabled ;
48import org .junit .jupiter .api .Test ;
59
10+ import java .util .Collections ;
11+ import java .util .HashMap ;
12+ import java .util .Map ;
13+
614import static org .junit .jupiter .api .Assertions .*;
715import static org .hamcrest .MatcherAssert .assertThat ;
816import static org .hamcrest .Matchers .*;
17+ import static org .mockito .Mockito .*;
18+ import static org .mockito .Mockito .times ;
919
1020/**
1121 * Tests for {@link ImportScanService}.
1222 */
1323class ImportScanServiceTest {
1424
25+ private final ImportScanServiceStub sut = new ImportScanServiceStub ();
26+
1527 @ Test
1628 void createDefault_throwsExceptionIfNullPassedIn () {
1729 assertThrows (NullPointerException .class , () -> {
@@ -35,4 +47,60 @@ void createDefault_passesConfig() {
3547 () -> assertThat (sut .getDefectDojoUrl (), is (config .getUrl ())),
3648 () -> assertThat (sut .getDefectDojoApiKey (), is (config .getApiKey ())));
3749 }
50+
51+ @ Test
52+ void importScan_withoutOptionsShouldPassEmptyMap () {
53+ assertThat (sut .getOptions (), is (nullValue ()));
54+
55+ sut .importScan (new ScanFile ("content" ),42L , 43L , "1.1.2023" , ScanType .AUDIT_JS_SCAN , 23L );
56+
57+ assertThat (sut .getOptions (), equalTo (Collections .EMPTY_MAP ));
58+ }
59+
60+ @ Test
61+ void importScan_withoutOptionsShouldPassModifiableMap () {
62+ assertThat (sut .getOptions (), is (nullValue ()));
63+
64+ sut .importScan (new ScanFile ("content" ),42L , 43L , "1.1.2023" , ScanType .AUDIT_JS_SCAN , 23L );
65+ sut .getOptions ().put ("foo" , "bar" );
66+
67+ assertThat (sut .getOptions (), hasEntry ("foo" , "bar" ));
68+ }
69+
70+ @ Test
71+ void reimportScan_withoutOptionsShouldPassEmptyMap () {
72+ assertThat (sut .getOptions (), is (nullValue ()));
73+
74+ sut .reimportScan (new ScanFile ("content" ),42L , 43L , "1.1.2023" , ScanType .AUDIT_JS_SCAN , 23L );
75+
76+ assertThat (sut .getOptions (), equalTo (Collections .EMPTY_MAP ));
77+ }
78+
79+ @ Test
80+ void reimportScan_withoutOptionsShouldPassModifiableMap () {
81+ assertThat (sut .getOptions (), is (nullValue ()));
82+
83+ sut .reimportScan (new ScanFile ("content" ),42L , 43L , "1.1.2023" , ScanType .AUDIT_JS_SCAN , 23L );
84+ sut .getOptions ().put ("foo" , "bar" );
85+
86+ assertThat (sut .getOptions (), hasEntry ("foo" , "bar" ));
87+ }
88+
89+ private static final class ImportScanServiceStub implements ImportScanService {
90+
91+ @ Getter
92+ private Map <String , String > options ;
93+
94+ @ Override
95+ public ImportScanResponse importScan (ScanFile scanFile , long engagementId , long lead , String currentDate , ScanType scanType , long testType , Map <String , String > options ) {
96+ this .options = options ;
97+ return null ;
98+ }
99+
100+ @ Override
101+ public ImportScanResponse reimportScan (ScanFile scanFile , long testId , long lead , String currentDate , ScanType scanType , long testType , Map <String , String > options ) {
102+ this .options = options ;
103+ return null ;
104+ }
105+ }
38106}
0 commit comments