Skip to content

Commit a8bce6e

Browse files
committed
Add tests
1 parent 350f5cf commit a8bce6e

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed
Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package com.checkmarx.ast.predicate;
22

3+
import com.checkmarx.ast.utils.JsonParser;
34
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
45
import com.fasterxml.jackson.annotation.JsonInclude;
56
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.fasterxml.jackson.databind.JavaType;
7-
import com.fasterxml.jackson.databind.ObjectMapper;
87
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
98
import com.fasterxml.jackson.databind.type.TypeFactory;
109
import lombok.Value;
11-
import org.apache.commons.lang3.StringUtils;
1210

13-
import java.io.IOException;
1411
import java.util.List;
1512

1613
@Value
@@ -31,33 +28,10 @@ public CustomState(@JsonProperty("id") Long id,
3128
}
3229

3330
public static <T> T fromLine(String line) {
34-
return parse(line, TypeFactory.defaultInstance().constructType(CustomState.class));
31+
return JsonParser.parse(line, TypeFactory.defaultInstance().constructType(CustomState.class));
3532
}
3633

3734
public static <T> List<T> listFromLine(String line) {
38-
return parse(line, TypeFactory.defaultInstance().constructCollectionType(List.class, CustomState.class));
39-
}
40-
41-
protected static <T> T parse(String line, JavaType type) {
42-
T result = null;
43-
try {
44-
if (!StringUtils.isBlank(line) && isValidJSON(line)) {
45-
result = new ObjectMapper().readValue(line, type);
46-
47-
}
48-
} catch (IOException e) {
49-
e.printStackTrace();
50-
}
51-
return result;
52-
}
53-
54-
private static boolean isValidJSON(final String json) {
55-
try {
56-
final ObjectMapper mapper = new ObjectMapper();
57-
mapper.readTree(json);
58-
return true;
59-
} catch (IOException e) {
60-
return false;
61-
}
35+
return JsonParser.parse(line, TypeFactory.defaultInstance().constructCollectionType(List.class, CustomState.class));
6236
}
6337
}

src/main/java/com/checkmarx/ast/wrapper/CxConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class CxConstants {
3333
static final String CMD_TRIAGE = "triage";
3434
static final String SUB_CMD_UPDATE = "update";
3535
static final String SUB_CMD_GET_STATES = "get-states";
36+
static final String ALL_STATES_FLAG = "--all";
3637
static final String CMD_RESULT = "results";
3738
static final String FORMAT = "--format";
3839
static final String SCAN_INFO_FORMAT = "--scan-info-format";

src/main/java/com/checkmarx/ast/wrapper/CxWrapper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,15 @@ public List<Predicate> triageShow(@NonNull UUID projectId, String similarityId,
166166
return Execution.executeCommand(withConfigArguments(arguments), logger, Predicate::listFromLine, Predicate::validator);
167167
}
168168

169-
public List<Predicate> triageGetStates() throws IOException, InterruptedException, CxException {
169+
public List<Predicate> triageGetStates(boolean all) throws IOException, InterruptedException, CxException {
170170
this.logger.info("Executing 'triage get-states' command using the CLI.");
171171

172172
List<String> arguments = new ArrayList<>();
173173
arguments.add(CxConstants.CMD_TRIAGE);
174-
arguments.add(CxConstants.SUB_CMD_SHOW);
174+
arguments.add(CxConstants.SUB_CMD_GET_STATES);
175+
if (all) {
176+
arguments.add(CxConstants.ALL_STATES_FLAG);
177+
}
175178

176179
return Execution.executeCommand(withConfigArguments(arguments), logger, CustomState::listFromLine);
177180
}

src/main/java/com/checkmarx/ast/wrapper/Execution.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static <T> T executeCommand(List<String> arguments,
6464
if (Objects.isNull(customValidator)) {
6565
executionResult = areAllFieldsNotNull(parsedLine) ? parsedLine : null;
6666
} else {
67-
executionResult = (areAllFieldsNotNull(parsedLine) || customValidator.apply(arguments, parsedLine)) ? parsedLine : null;
67+
executionResult = (customValidator.apply(arguments, parsedLine) || areAllFieldsNotNull(parsedLine)) ? parsedLine : null;
6868
}
6969
}
7070
}

src/test/java/com/checkmarx/ast/PredicateTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.checkmarx.ast.results.result.Result;
66
import com.checkmarx.ast.scan.Scan;
77
import com.checkmarx.ast.wrapper.CxConstants;
8+
import org.junit.Ignore;
89
import org.junit.jupiter.api.Assertions;
910
import org.junit.jupiter.api.Test;
1011

@@ -44,4 +45,11 @@ void testTriage() throws Exception {
4445
Assertions.fail("Triage update failed. Should not throw exception");
4546
}
4647
}
48+
49+
@Test
50+
@Ignore("Ignore this tests until get states api will be in production")
51+
void testGetStates() throws Exception {
52+
List<Predicate> states = wrapper.triageGetStates(false);
53+
Assertions.assertNotNull(states);
54+
}
4755
}

0 commit comments

Comments
 (0)