use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceIndexTest method testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsObjectMappingException.
@Test
public void testIndexSpotCheckPercentageValidationBusinessObjectDefinitionsObjectMappingException() throws Exception {
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList = new ArrayList<>();
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
// Mock the call to external methods
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SPOT_CHECK_PERCENTAGE, Double.class)).thenReturn(0.05);
when(businessObjectDefinitionDao.getPercentageOfAllBusinessObjectDefinitions(0.05)).thenReturn(businessObjectDefinitionEntityList);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_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 isSpotCheckPercentageValid = businessObjectDefinitionService.indexSpotCheckPercentageValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
assertThat("Business object definition service index spot check random validation is true when it should have been false.", isSpotCheckPercentageValid, is(false));
// Verify the calls to external methods
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SPOT_CHECK_PERCENTAGE, Double.class);
verify(businessObjectDefinitionDao).getPercentageOfAllBusinessObjectDefinitions(0.05);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(businessObjectDefinitionHelper, times(2)).safeObjectMapperWriteValueAsString(any(BusinessObjectDefinitionEntity.class));
verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
verifyNoMoreInteractionsHelper();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceIndexTest method testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsObjectMappingException.
@Test
public void testIndexSpotCheckMostRecentValidationBusinessObjectDefinitionsObjectMappingException() throws Exception {
List<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityList = new ArrayList<>();
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
businessObjectDefinitionEntityList.add(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME_2, BDEF_DESCRIPTION_2, businessObjectDefinitionServiceTestHelper.getNewAttributes()));
// Mock the call to external methods
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class)).thenReturn(100);
when(businessObjectDefinitionDao.getMostRecentBusinessObjectDefinitions(100)).thenReturn(businessObjectDefinitionEntityList);
when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn(SEARCH_INDEX_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 isSpotCheckPercentageValid = businessObjectDefinitionService.indexSpotCheckMostRecentValidationBusinessObjectDefinitions(SEARCH_INDEX_NAME);
assertThat("Business object definition service index spot check most recent validation is true when it should have been false.", isSpotCheckPercentageValid, is(false));
// Verify the calls to external methods
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_SPOT_CHECK_MOST_RECENT_NUMBER, Integer.class);
verify(businessObjectDefinitionDao).getMostRecentBusinessObjectDefinitions(100);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(businessObjectDefinitionHelper, times(2)).safeObjectMapperWriteValueAsString(any(BusinessObjectDefinitionEntity.class));
verify(indexFunctionsDao, times(2)).isValidDocumentIndex(any(), any(), any(), any());
verifyNoMoreInteractionsHelper();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project herd by FINRAOS.
the class TagServiceIndexTest method testIndexSpotCheckPercentageValidationTagsObjectMappingException.
@Test
public void testIndexSpotCheckPercentageValidationTagsObjectMappingException() 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_PERCENTAGE, Double.class)).thenReturn(0.2);
when(tagDao.getPercentageOfAllTags(0.2)).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))));
// Call the method under test
boolean isSpotCheckPercentageValid = tagService.indexSpotCheckPercentageValidationTags(SEARCH_INDEX_TYPE_TAG);
assertThat("Tag service index spot check random validation is true when it should have been false.", isSpotCheckPercentageValid, is(false));
// Verify the calls to external methods
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_TAG_SPOT_CHECK_PERCENTAGE, Double.class);
verify(tagDao).getPercentageOfAllTags(0.2);
verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
verify(tagHelper, times(2)).safeObjectMapperWriteValueAsString(any(TagEntity.class));
verifyNoMoreInteractions(tagDao, configurationHelper, jsonHelper);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project herd by FINRAOS.
the class TagHelperTest method testSafeObjectMapperWriteValueAsStringJsonParseException.
@Test
public void testSafeObjectMapperWriteValueAsStringJsonParseException() {
// Create a tag entity.
final TagEntity tagEntity = tagDaoTestHelper.createTagEntity(TAG_TYPE, TAG_CODE, TAG_DISPLAY_NAME, TAG_DESCRIPTION);
// Mock the external calls.
when(jsonHelper.objectToJson(any())).thenThrow(new IllegalStateException(new JsonParseException("Failed to Parse", new JsonLocation("SRC", 100L, 1, 2))));
// Call the method being tested.
String result = tagHelper.safeObjectMapperWriteValueAsString(tagEntity);
// Verify the external calls.
verify(jsonHelper).objectToJson(any());
verifyNoMoreInteractions(alternateKeyHelper, jsonHelper);
// Validate the returned object.
assertEquals("", result);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException in project joynr by bmwcarit.
the class ProxyTest method createProxyAndCallAsyncMethodSuccess.
@Test
public void createProxyAndCallAsyncMethodSuccess() throws Exception {
TestInterface proxy = getTestInterfaceProxy();
// when joynrMessageSender1.sendRequest is called, get the replyCaller from the mock dispatcher and call
// messageCallback on it.
Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws JsonParseException, JsonMappingException, IOException {
// capture the replyCaller passed into the dispatcher for calling later
ArgumentCaptor<ReplyCaller> replyCallerCaptor = ArgumentCaptor.forClass(ReplyCaller.class);
verify(replyCallerDirectory).addReplyCaller(anyString(), replyCallerCaptor.capture(), Mockito.any(ExpiryDate.class));
String requestReplyId = "createProxyAndCallAsyncMethodSuccess_requestReplyId";
// pass the response to the replyCaller
replyCallerCaptor.getValue().messageCallBack(new Reply(requestReplyId, new TextNode(asyncReplyText)));
return null;
}
}).when(requestReplyManager).sendRequest(Mockito.<String>any(), Mockito.<DiscoveryEntryWithMetaInfo>any(), Mockito.<Request>any(), Mockito.<MessagingQos>any());
final Future<String> future = proxy.asyncMethod(callback);
// the test usually takes only 200 ms, so if we wait 1 sec, something has gone wrong
String reply = future.get(1000);
verify(callback).resolve(asyncReplyText);
Assert.assertEquals(RequestStatusCode.OK, future.getStatus().getCode());
Assert.assertEquals(asyncReplyText, reply);
}
Aggregations