Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DROOLS-7514 strict JSON parsing with Jackson #64

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -17,10 +16,6 @@ public class JsonMapper {
private static final TypeReference<List<Map<String, Object>>> LIST_OF_MAP_OF_STRING_AND_OBJECT = new TypeReference<List<Map<String, Object>>>(){};
private static final TypeReference<Map<String, Object>> MAP_OF_STRING_AND_OBJECT = new TypeReference<Map<String, Object>>(){};
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
static { // most tests contains non-standard JSON; eventually check assumption non-strict json with Ansible team
OBJECT_MAPPER.enable(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES.mappedFeature());
OBJECT_MAPPER.enable(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature());
}
private static final JavaType JACKSON_RAW_LIST = OBJECT_MAPPER.getTypeFactory().constructRawCollectionLikeType(List.class);

public static String toJson(Object object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public class ArrayAccessTest {
public void testArrayAccess() {
RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(JSON1);

List<Match> matchedRules = rulesExecutor.processFacts( "{'host': 'A', 'os': {'array': ['abc']}}" ).join();
List<Match> matchedRules = rulesExecutor.processFacts( "{\"host\": \"A\", \"os\": {\"array\": [\"abc\"]}}" ).join();
assertEquals( 0, matchedRules.size() );

matchedRules = rulesExecutor.processFacts( "{'host': 'B', 'os': {'array': ['abc', 'windows']}}" ).join();
matchedRules = rulesExecutor.processFacts( "{\"host\": \"B\", \"os\": {\"array\": [\"abc\", \"windows\"]}}" ).join();
assertEquals( 1, matchedRules.size() );
assertEquals( "r_0", matchedRules.get(0).getRule().getName() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void testProcessRules() {
assertEquals( 1, matchedRules.size() );
assertEquals( "R1", matchedRules.get(0).getRule().getName() );

matchedRules = rulesExecutor.processFacts( "{ facts: [ { \"sensu\": { \"data\": { \"i\":3 } } }, { \"j\":3 } ] }" ).join();
matchedRules = rulesExecutor.processFacts( "{ \"facts\": [ { \"sensu\": { \"data\": { \"i\":3 } } }, { \"j\":3 } ] }" ).join();
assertEquals( 0, matchedRules.size() );

matchedRules = rulesExecutor.processFacts( "{ \"sensu\": { \"data\": { \"i\":4 } } }" ).join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class MultipleConditionTest {
public void testReadJson() {
RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(JSON1);

List<Match> matchedRules = rulesExecutor.processEvents( "{ events: [ { \"i\":0 }, { \"i\":1 }, { \"i\":2 } ] }" ).join();
List<Match> matchedRules = rulesExecutor.processEvents( "{ \"events\": [ { \"i\":0 }, { \"i\":1 }, { \"i\":2 } ] }" ).join();

assertEquals( 1, matchedRules.size() );
assertEquals( "r_0", matchedRules.get(0).getRule().getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void test() {

RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(json);

List<Match> matchedRules = rulesExecutor.processFacts( "{ \"x\":1, y:null }" ).join();
List<Match> matchedRules = rulesExecutor.processFacts( "{ \"x\":1, \"y\":null }" ).join();
assertEquals( 1, matchedRules.size() );

matchedRules = rulesExecutor.processFacts( "{ \"x\":1 }" ).join();
Expand Down Expand Up @@ -164,7 +164,7 @@ public void testWithSelectAttr() {

RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(json);

List<Match> matchedRules = rulesExecutor.processFacts( "{ \"x\":1, y:null }" ).join();
List<Match> matchedRules = rulesExecutor.processFacts( "{ \"x\":1, \"y\":null }" ).join();
assertEquals( 1, matchedRules.size() );
assertEquals( "r1", matchedRules.get(0).getRule().getName() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void testProcessRules() {
assertEquals( 1, matchedRules.size() );
assertEquals( "R1", matchedRules.get(0).getRule().getName() );

matchedRules = rulesExecutor.processFacts( "{ facts: [ { \"sensu\": { \"data\": { \"i\":3 } } }, { \"j\":3 } ] }" ).join();
matchedRules = rulesExecutor.processFacts( "{ \"facts\": [ { \"sensu\": { \"data\": { \"i\":3 } } }, { \"j\":3 } ] }" ).join();
assertEquals( 0, matchedRules.size() );

matchedRules = rulesExecutor.processFacts( "{ \"sensu\": { \"data\": { \"i\":4 } } }" ).join();
Expand Down