BusinessObjectFormatExternalInterfaceServiceImpl implements BusinessObjectFormatExternalInterfaceService { @Override public BusinessObjectFormatExternalInterface createBusinessObjectFormatExternalInterface( BusinessObjectFormatExternalInterfaceCreateRequest businessObjectFormatExternalInterfaceCreateRequest) { businessObjectFormatExternalInterfaceHelper .validateAndTrimBusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceCreateRequest); BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getNamespace(), businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectDefinitionName(), businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatUsage(), businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getBusinessObjectFormatFileType(), null); String externalInterfaceName = businessObjectFormatExternalInterfaceCreateRequest.getBusinessObjectFormatExternalInterfaceKey().getExternalInterfaceName(); BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey); ExternalInterfaceEntity externalInterfaceEntity = externalInterfaceDaoHelper.getExternalInterfaceEntity(externalInterfaceName); BusinessObjectFormatExternalInterfaceEntity businessObjectFormatExternalInterfaceEntity = businessObjectFormatExternalInterfaceDao .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity); if (businessObjectFormatExternalInterfaceEntity != null) { throw new AlreadyExistsException(String.format("Unable to create business object format to external interface mapping for \"%s\" namespace, " + "\"%s\" business object definition name, \"%s\" business object format usage, \"%s\" business object format file type, and " + "\"%s\" external interface name because it already exists.", businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(), businessObjectFormatKey.getBusinessObjectFormatUsage(), businessObjectFormatKey.getBusinessObjectFormatFileType(), externalInterfaceName)); } businessObjectFormatExternalInterfaceEntity = new BusinessObjectFormatExternalInterfaceEntity(); businessObjectFormatExternalInterfaceEntity.setBusinessObjectFormat(businessObjectFormatEntity); businessObjectFormatExternalInterfaceEntity.setExternalInterface(externalInterfaceEntity); businessObjectFormatExternalInterfaceDao.saveAndRefresh(businessObjectFormatExternalInterfaceEntity); return businessObjectFormatExternalInterfaceHelper.createBusinessObjectFormatExternalInterfaceFromEntity(businessObjectFormatExternalInterfaceEntity); }  @Override BusinessObjectFormatExternalInterface createBusinessObjectFormatExternalInterface(
        BusinessObjectFormatExternalInterfaceCreateRequest businessObjectFormatExternalInterfaceCreateRequest); @Override BusinessObjectFormatExternalInterface deleteBusinessObjectFormatExternalInterface(
        BusinessObjectFormatExternalInterfaceKey businessObjectFormatExternalInterfaceKey); @Override BusinessObjectFormatExternalInterface getBusinessObjectFormatExternalInterface(
        BusinessObjectFormatExternalInterfaceKey businessObjectFormatExternalInterfaceKey);  }
@Test public void testCreateBusinessObjectFormatExternalInterface() { BusinessObjectFormatExternalInterfaceKey businessObjectFormatExternalInterfaceKey = new BusinessObjectFormatExternalInterfaceKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, EXTERNAL_INTERFACE); BusinessObjectFormatExternalInterfaceCreateRequest businessObjectFormatExternalInterfaceCreateRequest = new BusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceKey); BusinessObjectFormatExternalInterface businessObjectFormatExternalInterface = new BusinessObjectFormatExternalInterface(ID, businessObjectFormatExternalInterfaceKey); BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity(); ExternalInterfaceEntity externalInterfaceEntity = new ExternalInterfaceEntity(); when(businessObjectFormatDaoHelper .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null))) .thenReturn(businessObjectFormatEntity); when(externalInterfaceDaoHelper.getExternalInterfaceEntity(EXTERNAL_INTERFACE)).thenReturn(externalInterfaceEntity); when(businessObjectFormatExternalInterfaceDao .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity)) .thenReturn(null); when(businessObjectFormatExternalInterfaceHelper .createBusinessObjectFormatExternalInterfaceFromEntity(any(BusinessObjectFormatExternalInterfaceEntity.class))) .thenReturn(businessObjectFormatExternalInterface); BusinessObjectFormatExternalInterface result = businessObjectFormatExternalInterfaceService.createBusinessObjectFormatExternalInterface(businessObjectFormatExternalInterfaceCreateRequest); assertEquals(businessObjectFormatExternalInterface, result); verify(businessObjectFormatExternalInterfaceHelper) .validateAndTrimBusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceCreateRequest); verify(businessObjectFormatDaoHelper) .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null)); verify(externalInterfaceDaoHelper).getExternalInterfaceEntity(EXTERNAL_INTERFACE); verify(businessObjectFormatExternalInterfaceDao) .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity); verify(businessObjectFormatExternalInterfaceDao).saveAndRefresh(any(BusinessObjectFormatExternalInterfaceEntity.class)); verify(businessObjectFormatExternalInterfaceHelper) .createBusinessObjectFormatExternalInterfaceFromEntity(any(BusinessObjectFormatExternalInterfaceEntity.class)); verifyNoMoreInteractionsHelper(); }
@Test public void testCreateBusinessObjectFormatExternalInterfaceAlreadyExists() { BusinessObjectFormatExternalInterfaceKey businessObjectFormatExternalInterfaceKey = new BusinessObjectFormatExternalInterfaceKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, EXTERNAL_INTERFACE); BusinessObjectFormatExternalInterfaceCreateRequest businessObjectFormatExternalInterfaceCreateRequest = new BusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceKey); BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity(); ExternalInterfaceEntity externalInterfaceEntity = new ExternalInterfaceEntity(); when(businessObjectFormatDaoHelper .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null))) .thenReturn(businessObjectFormatEntity); when(externalInterfaceDaoHelper.getExternalInterfaceEntity(EXTERNAL_INTERFACE)).thenReturn(externalInterfaceEntity); when(businessObjectFormatExternalInterfaceDao .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity)) .thenReturn(new BusinessObjectFormatExternalInterfaceEntity()); expectedException.expect(AlreadyExistsException.class); expectedException.expectMessage(String.format("Unable to create business object format to external interface mapping for \"%s\" namespace, " + "\"%s\" business object definition name, \"%s\" business object format usage, \"%s\" business object format file type, and " + "\"%s\" external interface name because it already exists.", NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, EXTERNAL_INTERFACE)); businessObjectFormatExternalInterfaceService.createBusinessObjectFormatExternalInterface(businessObjectFormatExternalInterfaceCreateRequest); verify(businessObjectFormatExternalInterfaceHelper) .validateAndTrimBusinessObjectFormatExternalInterfaceCreateRequest(businessObjectFormatExternalInterfaceCreateRequest); verify(businessObjectFormatDaoHelper) .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null)); verify(externalInterfaceDaoHelper).getExternalInterfaceEntity(EXTERNAL_INTERFACE); verify(businessObjectFormatExternalInterfaceDao) .getBusinessObjectFormatExternalInterfaceByBusinessObjectFormatAndExternalInterface(businessObjectFormatEntity, externalInterfaceEntity); verifyNoMoreInteractionsHelper(); }