use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class SecurityUserWrapperTest method testCreateBusinessObjectDefinitionWithTrustedUser.
@Test
public void testCreateBusinessObjectDefinitionWithTrustedUser() throws Exception {
// Create and persist database entities required for testing.
namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
dataProviderDaoTestHelper.createDataProviderEntity(DATA_PROVIDER_NAME);
// Override security configuration to disable the security.
Map<String, Object> overrideMap = new HashMap<>();
overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "false");
modifyPropertySourceInEnvironment(overrideMap);
try {
// Invalidate user session if exists.
invalidateApplicationUser(null);
// Call the relative filter to set username to trusted user in the security context.
// This will automatically load all functions defined in the database.
trustedUserAuthenticationFilter.init(new MockFilterConfig());
trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
// Create a business object definition.
// This indirectly requires the "FN_BUSINESS_OBJECT_DEFINITIONS_POST" function point to be present in the authenticated user.
BusinessObjectDefinitionCreateRequest request = new BusinessObjectDefinitionCreateRequest(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, NO_ATTRIBUTES);
BusinessObjectDefinition businessObjectDefinition = businessObjectDefinitionService.createBusinessObjectDefinition(request);
// Retrieve the newly created business object definition and validate the created by field.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
// Validate the newly created entity.
assertEquals(Integer.valueOf(businessObjectDefinition.getId()), businessObjectDefinitionEntity.getId());
String expectedUsername = TrustedApplicationUserBuilder.TRUSTED_USER_ID;
assertEquals(expectedUsername, businessObjectDefinitionEntity.getCreatedBy());
assertEquals(expectedUsername, businessObjectDefinitionEntity.getUpdatedBy());
} finally {
// Restore the property sources so we don't affect other tests.
restorePropertySourceInEnvironment();
}
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionRestControllerIndexTest method testIndexSearchBusinessObjectDefinitions.
@Test
public void testIndexSearchBusinessObjectDefinitions() {
// Create a new tag key with a tag type and a tag code
TagKey tagKey = new TagKey(TAG_TYPE, TAG_CODE);
// Create a new business object definition search key for use in the business object definition search key list
BusinessObjectDefinitionSearchKey businessObjectDefinitionSearchKey = new BusinessObjectDefinitionSearchKey(tagKey, INCLUDE_TAG_HIERARCHY);
// Create a new business object definition search key list with the tag key and the include tag hierarchy boolean flag
List<BusinessObjectDefinitionSearchKey> businessObjectDefinitionSearchKeyList = new ArrayList<>();
businessObjectDefinitionSearchKeyList.add(businessObjectDefinitionSearchKey);
// Create a new business object definition search filter list with the new business object definition search key list
List<BusinessObjectDefinitionSearchFilter> businessObjectDefinitionSearchFilterList = new ArrayList<>();
businessObjectDefinitionSearchFilterList.add(new BusinessObjectDefinitionSearchFilter(false, businessObjectDefinitionSearchKeyList));
// Create a list of facet fields
List<String> facetFields = new ArrayList<>();
facetFields.add("Invalid");
// Create a new business object definition search request that will be used when testing the index search business object definitions method
BusinessObjectDefinitionIndexSearchRequest businessObjectDefinitionSearchRequest = new BusinessObjectDefinitionIndexSearchRequest(businessObjectDefinitionSearchFilterList, facetFields);
// Create a new fields set that will be used when testing the index search business object definitions method
Set<String> fields = Sets.newHashSet(FIELD_DATA_PROVIDER_NAME, FIELD_DISPLAY_NAME, FIELD_SHORT_DESCRIPTION);
// Create a business object definition entity list to return from the search business object definitions by tags function
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()));
// Create a list to hold the business object definitions that will be returned as part of the search response
List<BusinessObjectDefinition> businessObjectDefinitions = new ArrayList<>();
// Retrieve all unique business object definition entities and construct a list of business object definitions based on the requested fields.
for (BusinessObjectDefinitionEntity businessObjectDefinitionEntity : ImmutableSet.copyOf(businessObjectDefinitionEntityList)) {
// Convert the business object definition entity to a business object definition and add it to the list of business object definitions that will be
// returned as a part of the search response
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition();
// Populate the business object definition
businessObjectDefinition.setNamespace(businessObjectDefinitionEntity.getNamespace().getCode());
businessObjectDefinition.setBusinessObjectDefinitionName(businessObjectDefinitionEntity.getName());
businessObjectDefinition.setDataProviderName(businessObjectDefinitionEntity.getDataProvider().getName());
businessObjectDefinition.setShortDescription(StringUtils.left(businessObjectDefinitionEntity.getDescription(), SHORT_DESCRIPTION_LENGTH));
businessObjectDefinition.setDisplayName(businessObjectDefinitionEntity.getDisplayName());
businessObjectDefinitions.add(businessObjectDefinition);
}
List<TagTypeIndexSearchResponseDto> tagTypeIndexSearchResponseDtos = new ArrayList<>();
List<TagIndexSearchResponseDto> tagIndexSearchResponseDtos = new ArrayList<>();
tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_DISPLAY_NAME));
tagIndexSearchResponseDtos.add(new TagIndexSearchResponseDto(TAG_CODE_2, TAG_COUNT, TAG_DISPLAY_NAME_2));
TagTypeIndexSearchResponseDto tagTypeIndexSearchResponseDto = new TagTypeIndexSearchResponseDto(TAG_TYPE, tagIndexSearchResponseDtos, TAG_TYPE_DISPLAY_NAME);
tagTypeIndexSearchResponseDtos.add(tagTypeIndexSearchResponseDto);
List<Facet> tagTypeFacets = new ArrayList<>();
for (TagTypeIndexSearchResponseDto tagTypeIndexSearchResponse : ImmutableSet.copyOf(tagTypeIndexSearchResponseDtos)) {
List<Facet> tagFacets = new ArrayList<>();
for (TagIndexSearchResponseDto tagIndexSearchResponseDto : tagTypeIndexSearchResponse.getTagIndexSearchResponseDtos()) {
Facet tagFacet = new Facet(tagIndexSearchResponseDto.getTagDisplayName(), tagIndexSearchResponseDto.getCount(), FacetTypeEnum.TAG.value(), tagIndexSearchResponseDto.getTagCode(), null);
tagFacets.add(tagFacet);
}
tagTypeFacets.add(new Facet(tagTypeIndexSearchResponse.getDisplayName(), null, FacetTypeEnum.TAG_TYPE.value(), tagTypeIndexSearchResponse.getCode(), tagFacets));
}
// Construct business object search response.
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponse = new BusinessObjectDefinitionIndexSearchResponse();
businessObjectDefinitionSearchResponse.setBusinessObjectDefinitions(businessObjectDefinitions);
businessObjectDefinitionSearchResponse.setFacets(tagTypeFacets);
// Mock the call to the business object definition service
when(businessObjectDefinitionService.indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields)).thenReturn(businessObjectDefinitionSearchResponse);
// Create a business object definition.
BusinessObjectDefinitionIndexSearchResponse businessObjectDefinitionSearchResponseFromRestCall = businessObjectDefinitionRestController.indexSearchBusinessObjectDefinitions(fields, businessObjectDefinitionSearchRequest);
// Verify the method call to businessObjectDefinitionService.indexAllBusinessObjectDefinitions()
verify(businessObjectDefinitionService, times(1)).indexSearchBusinessObjectDefinitions(businessObjectDefinitionSearchRequest, fields);
// Validate the returned object.
assertThat("Business object definition index search response was null.", businessObjectDefinitionSearchResponseFromRestCall, not(nullValue()));
assertThat("Business object definition index search response was not correct.", businessObjectDefinitionSearchResponseFromRestCall, is(businessObjectDefinitionSearchResponse));
assertThat("Business object definition index search response was not an instance of BusinessObjectDefinitionSearchResponse.class.", businessObjectDefinitionSearchResponseFromRestCall, instanceOf(BusinessObjectDefinitionIndexSearchResponse.class));
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionRestControllerTest method testGetBusinessObjectDefinitionNotIncludeUpdateHistory.
@Test
public void testGetBusinessObjectDefinitionNotIncludeUpdateHistory() {
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Create a business object definition.
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition(ID, BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, SHORT_DESCRIPTION, BDEF_DISPLAY_NAME, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)), new DescriptiveBusinessObjectFormat(FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), Arrays.asList(new SampleDataFile(DIRECTORY_PATH, FILE_NAME)), CREATED_BY, UPDATED_BY, UPDATED_ON, NO_BUSINESS_OBJECT_DEFINITION_CHANGE_EVENTS);
// Mock the external calls.
when(businessObjectDefinitionService.getBusinessObjectDefinition(businessObjectDefinitionKey, NOT_INCLUDE_BUSINESS_OBJECT_DEFINITION_UPDATE_HISTORY)).thenReturn(businessObjectDefinition);
// Call the method under test.
BusinessObjectDefinition result = businessObjectDefinitionRestController.getBusinessObjectDefinition(BDEF_NAMESPACE, BDEF_NAME, NOT_INCLUDE_BUSINESS_OBJECT_DEFINITION_UPDATE_HISTORY);
// Verify the external calls.
verify(businessObjectDefinitionService).getBusinessObjectDefinition(businessObjectDefinitionKey, NOT_INCLUDE_BUSINESS_OBJECT_DEFINITION_UPDATE_HISTORY);
verifyNoMoreInteractions(businessObjectDefinitionService);
// Validate the results.
assertEquals(businessObjectDefinition, result);
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionRestControllerTest method testGetBusinessObjectDefinitionIncludeUpdateHistory.
@Test
public void testGetBusinessObjectDefinitionIncludeUpdateHistory() {
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Create business object definition change event
List<BusinessObjectDefinitionChangeEvent> businessObjectDefinitionChangeEvents = new ArrayList<>();
businessObjectDefinitionChangeEvents.add(new BusinessObjectDefinitionChangeEvent(BDEF_DISPLAY_NAME, BDEF_DESCRIPTION, new DescriptiveBusinessObjectFormatUpdateRequest(FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE), CREATED_ON, CREATED_BY));
// Create a business object definition.
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition(ID, BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, SHORT_DESCRIPTION, BDEF_DISPLAY_NAME, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)), new DescriptiveBusinessObjectFormat(FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), Arrays.asList(new SampleDataFile(DIRECTORY_PATH, FILE_NAME)), CREATED_BY, UPDATED_BY, UPDATED_ON, businessObjectDefinitionChangeEvents);
// Mock the external calls.
when(businessObjectDefinitionService.getBusinessObjectDefinition(businessObjectDefinitionKey, INCLUDE_BUSINESS_OBJECT_DEFINITION_UPDATE_HISTORY)).thenReturn(businessObjectDefinition);
// Call the method under test.
BusinessObjectDefinition result = businessObjectDefinitionRestController.getBusinessObjectDefinition(BDEF_NAMESPACE, BDEF_NAME, INCLUDE_BUSINESS_OBJECT_DEFINITION_UPDATE_HISTORY);
// Verify the external calls.
verify(businessObjectDefinitionService).getBusinessObjectDefinition(businessObjectDefinitionKey, INCLUDE_BUSINESS_OBJECT_DEFINITION_UPDATE_HISTORY);
verifyNoMoreInteractions(businessObjectDefinitionService);
// Validate the results.
assertEquals(businessObjectDefinition, result);
}
use of org.finra.herd.model.api.xml.BusinessObjectDefinition in project herd by FINRAOS.
the class BusinessObjectDefinitionRestControllerTest method testCreateBusinessObjectDefinition.
@Test
public void testCreateBusinessObjectDefinition() {
// Create a business object definition.
BusinessObjectDefinitionCreateRequest request = new BusinessObjectDefinitionCreateRequest(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)));
// Create a business object definition.
BusinessObjectDefinition businessObjectDefinition = new BusinessObjectDefinition(ID, BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, SHORT_DESCRIPTION, BDEF_DISPLAY_NAME, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)), new DescriptiveBusinessObjectFormat(FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), Arrays.asList(new SampleDataFile(DIRECTORY_PATH, FILE_NAME)), CREATED_BY, UPDATED_BY, UPDATED_ON, NO_BUSINESS_OBJECT_DEFINITION_CHANGE_EVENTS);
// Mock the external calls.
when(businessObjectDefinitionService.createBusinessObjectDefinition(request)).thenReturn(businessObjectDefinition);
// Call the method under test.
BusinessObjectDefinition result = businessObjectDefinitionRestController.createBusinessObjectDefinition(request);
// Verify the external calls.
verify(businessObjectDefinitionService).createBusinessObjectDefinition(request);
verifyNoMoreInteractions(businessObjectDefinitionService);
// Validate the returned object.
assertEquals(businessObjectDefinition, result);
}
Aggregations