use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project core-util by WSO2Telco.
the class YamlReader method getConfiguration.
/**
* Gets the configuration.
*
* @return the configuration
*/
public static ConfigDTO getConfiguration() {
File file = new File(DEVICE_MGT_CONFIG_PATH);
ConfigDTO configPojo = new ConfigDTO();
// jackson databind
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
configPojo = mapper.readValue(file, ConfigDTO.class);
} catch (JsonParseException e) {
log.error("Yaml Parsing Error", e);
} catch (JsonMappingException e) {
log.error("Yaml Mapping Error", e);
} catch (IOException e) {
log.error("Yaml File Error", e);
}
return configPojo;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project n4js by eclipse.
the class StartSessionResource method createEvent.
@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String body) throws ClientResourceException {
final Map<?, ?> values = newHashMap();
try {
if (!isNullOrEmpty(body)) {
values.putAll(mapper.readValue(body, Map.class));
}
} catch (JsonMappingException | JsonParseException e) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} catch (final IOException e) {
throw new ClientResourceException(SC_BAD_REQUEST);
}
final Map<String, String> properties = newHashMap();
if (null != values.get(PROPERTIES)) {
if (!(values.get(PROPERTIES) instanceof Map)) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} else {
((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {
@Override
public void accept(final Entry<?, ?> entry) {
properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
}
});
}
}
return new SessionStartedEvent(sessionId, properties);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project n4js by eclipse.
the class StartTestResource method createEvent.
@Override
@SuppressWarnings("unchecked")
protected TestEvent createEvent(final String sessionId, final String testId, final String body) throws ClientResourceException {
if (isNullOrEmpty(body))
throw new ClientResourceException(SC_BAD_REQUEST);
final Map<?, ?> values = newHashMap();
try {
values.putAll(mapper.readValue(body, Map.class));
} catch (JsonMappingException | JsonParseException e) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} catch (final IOException e) {
throw new ClientResourceException(SC_BAD_REQUEST);
}
final Object value = values.get(TIMEOUT_KEY);
// incorrect schema
if (null == value) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
}
final Map<String, String> properties = newHashMap();
if (null != values.get(PROPERTIES)) {
if (!(values.get(PROPERTIES) instanceof Map)) {
throw new ClientResourceException(SC_UNPROCESSABLE_ENTITY);
} else {
((Map<?, ?>) values.get(PROPERTIES)).entrySet().forEach(new Consumer<Entry<?, ?>>() {
@Override
public void accept(final Entry<?, ?> entry) {
properties.put(valueOf(entry.getKey()), valueOf(entry.getValue()));
}
});
}
}
try {
final long timeout = parseLong(valueOf(value));
return new TestStartedEvent(sessionId, testId, timeout, properties);
} catch (final NumberFormatException e) {
// although schema was valid the data was indeed invalid
throw new ClientResourceException(SC_BAD_REQUEST);
}
}
use of org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.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);
}
Aggregations