File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
main/java/com/checkmarx/ast/wrapper
test/java/com/checkmarx/ast Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .checkmarx .ast .wrapper ;
2+
3+ import lombok .NonNull ;
4+ import org .slf4j .Logger ;
5+ import org .slf4j .LoggerFactory ;
6+
7+ import java .io .IOException ;
8+ import java .util .ArrayList ;
9+ import java .util .Arrays ;
10+ import java .util .List ;
11+
12+ public class CxThinWrapper {
13+
14+ @ NonNull
15+ private final Logger logger ;
16+ @ NonNull
17+ private final String executable ;
18+
19+ public CxThinWrapper () throws IOException {
20+ this (LoggerFactory .getLogger (CxWrapper .class ));
21+ }
22+
23+ public CxThinWrapper (@ NonNull Logger logger ) throws IOException {
24+ this .logger = logger ;
25+ this .executable = Execution .getTempBinary ();
26+ this .logger .info ("using executable: " + executable );
27+ }
28+
29+ public String run (@ NonNull String arguments ) throws CxException , IOException , InterruptedException {
30+ this .logger .info ("executing thin wrapper command" );
31+ List <String > argv = new ArrayList <>();
32+ argv .add (executable );
33+ argv .addAll (Arrays .asList (arguments .split (" " )));
34+ return Execution .executeCommand (argv , logger , (line ) -> line );
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ package com .checkmarx .ast ;
2+
3+ import com .checkmarx .ast .scan .Scan ;
4+ import com .checkmarx .ast .wrapper .CxException ;
5+ import com .checkmarx .ast .wrapper .CxThinWrapper ;
6+ import lombok .SneakyThrows ;
7+ import org .junit .Assert ;
8+ import org .junit .Test ;
9+
10+ import java .util .List ;
11+
12+ public class ThinWrapperTest extends BaseTest {
13+
14+ @ SneakyThrows
15+ @ Test
16+ public void testThinWrapper () {
17+ CxThinWrapper wrapper = new CxThinWrapper (getLogger ());
18+ String result = wrapper .run ("scan list --format json --filter limit=10" );
19+ List <Scan > scanList = Scan .listFromLine (result );
20+ Assert .assertTrue (scanList .size () <= 10 );
21+ }
22+
23+ @ SneakyThrows
24+ @ Test
25+ public void testThinWrapperFail () {
26+ CxThinWrapper wrapper = new CxThinWrapper (getLogger ());
27+ String arguments = "scan create -s . --project-name thin-wrapper-test --sast-preset invalid-preset" ;
28+ CxException e = Assert .assertThrows (CxException .class , () -> wrapper .run (arguments ));
29+ Assert .assertTrue (e .getMessage ().contains ("--sast-preset" ));
30+ }
31+ }
You can’t perform that action at this time.
0 commit comments