Search in sources :

Example 26 with JsonParseException

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);
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Test(org.junit.Test)

Example 27 with JsonParseException

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);
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) JsonParseException(com.fasterxml.jackson.core.JsonParseException) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 28 with JsonParseException

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;
}
Also used : Status(com.networknt.status.Status) ValidationMessage(com.networknt.schema.ValidationMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonSchema(com.networknt.schema.JsonSchema) StringProperty(io.swagger.models.properties.StringProperty) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 29 with JsonParseException

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");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Example 30 with JsonParseException

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");
    }
}
Also used : APIException(im.tny.segvault.disturbances.exception.APIException) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException)

Aggregations

JsonParseException (com.fasterxml.jackson.core.JsonParseException)120 IOException (java.io.IOException)59 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)53 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)31 JsonParser (com.fasterxml.jackson.core.JsonParser)21 Map (java.util.Map)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 InputStream (java.io.InputStream)12 HashMap (java.util.HashMap)12 JsonToken (com.fasterxml.jackson.core.JsonToken)11 JsonFactory (com.fasterxml.jackson.core.JsonFactory)9 File (java.io.File)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 JsonLocation (com.fasterxml.jackson.core.JsonLocation)6 Date (java.util.Date)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)4