use of com.fasterxml.jackson.core.JsonParseException in project herd by FINRAOS.
the class TagServiceIndexTest method testIndexSpotCheckMostRecentValidationTagsObjectMappingException.
@Test
public void testIndexSpotCheckMostRecentValidationTagsObjectMappingException() throws Exception {
// Create a tag type entity.
TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
// Create two root tag entities for the tag type with tag display name in reverse order.
List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_DESCRIPTION_2));
// Mock the call to external methods
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class)).thenReturn(10);
when(tagDao.getMostRecentTags(10)).thenReturn(rootTagEntities);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("DOCUMENT_TYPE");
when(jsonHelper.objectToJson(any())).thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
when(indexFunctionsDao.isValidDocumentIndex(any(), any(), any(), any())).thenReturn(false);
// Call the method under test
boolean isSpotCheckMostRecentValid = tagService.indexSpotCheckMostRecentValidationTags(SEARCH_INDEX_TYPE_TAG);
assertThat("Tag service index spot check most recent validation is true when it should have been false.", isSpotCheckMostRecentValid, is(false));
// Verify the calls to external methods
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
verify(tagDao).getMostRecentTags(10);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
verifyNoMoreInteractions(tagDao, indexFunctionsDao, configurationHelper, jsonHelper, tagHelper);
}
use of com.fasterxml.jackson.core.JsonParseException in project herd by FINRAOS.
the class BusinessObjectDefinitionHelperTest method testExecuteFunctionForBusinessObjectDefinitionEntitiesJsonParseException.
@Test
public void testExecuteFunctionForBusinessObjectDefinitionEntitiesJsonParseException() {
// Create a list of business object definition entities.
final List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntities = Collections.unmodifiableList(Arrays.asList(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()), businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE_2, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes2())));
businessObjectDefinitionEntities.forEach(entity -> {
entity.setDescriptiveBusinessObjectFormat(new BusinessObjectFormatEntity());
entity.getDescriptiveBusinessObjectFormat().setSchemaColumns(new ArrayList<>());
entity.setSubjectMatterExperts(new ArrayList<>());
});
// Mock the external calls.
when(jsonHelper.objectToJson(any())).thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
// Execute a function for all business object definition entities.
businessObjectDefinitionHelper.executeFunctionForBusinessObjectDefinitionEntities(SEARCH_INDEX_NAME, SEARCH_INDEX_DOCUMENT_TYPE, businessObjectDefinitionEntities, (indexName, documentType, id, json) -> {
});
// Verify the external calls.
verify(jsonHelper, times(businessObjectDefinitionEntities.size())).objectToJson(any());
verifyNoMoreInteractions(alternateKeyHelper, jsonHelper);
}
use of com.fasterxml.jackson.core.JsonParseException in project light-rest-4j by networknt.
the class SchemaValidator method doValidate.
private Status doValidate(final String value, final Object schema) {
requireNonNull(schema, "A schema is required");
Status status = null;
Set<ValidationMessage> processingReport = null;
try {
final JsonNode schemaObject = Json.mapper().readTree(Json.pretty(schema));
if (api != null) {
if (this.definitions == null) {
this.definitions = Json.mapper().readTree(Json.pretty(api.getDefinitions()));
}
((ObjectNode) schemaObject).set(DEFINITIONS_FIELD, this.definitions);
}
JsonSchema jsonSchema = JsonSchemaFactory.getInstance().getSchema(schemaObject);
String normalisedValue = value;
if (schema instanceof StringProperty) {
normalisedValue = Util.quote(value);
}
final JsonNode content = Json.mapper().readTree(normalisedValue);
processingReport = jsonSchema.validate(content);
} catch (JsonParseException e) {
return new Status(VALIDATOR_SCHEMA_INVALID_JSON, e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
if (processingReport != null && processingReport.size() > 0) {
ValidationMessage vm = processingReport.iterator().next();
status = new Status(VALIDATOR_SCHEMA, vm.getMessage());
}
return status;
}
use of com.fasterxml.jackson.core.JsonParseException in project underlx by underlx.
the class API method postPairRequest.
public Pair postPairRequest(PairRequest request) throws APIException {
try {
byte[] content = mapper.writeValueAsBytes(request);
InputStream is = postRequest(endpoint.resolve("pair"), content, false);
return mapper.readValue(is, Pair.class);
} catch (JsonParseException e) {
throw new APIException(e).addInfo("Parse exception");
} catch (JsonMappingException e) {
throw new APIException(e).addInfo("Mapping exception");
} catch (IOException e) {
throw new APIException(e).addInfo("IOException");
}
}
use of com.fasterxml.jackson.core.JsonParseException in project underlx by underlx.
the class API method postFeedback.
public Feedback postFeedback(Feedback request) throws APIException {
try {
byte[] content = mapper.writeValueAsBytes(request);
InputStream is = postRequest(endpoint.resolve("feedback"), content, true);
return mapper.readValue(is, Feedback.class);
} catch (JsonParseException e) {
throw new APIException(e).addInfo("Parse exception");
} catch (JsonMappingException e) {
throw new APIException(e).addInfo("Mapping exception");
} catch (IOException e) {
throw new APIException(e).addInfo("IOException");
}
}
Aggregations