/** * Gets the file type entity and ensure it exists. * * @param fileType the file type (case insensitive) * * @return the file type entity * @throws ObjectNotFoundException if the file type entity doesn't exist */ public FileTypeEntity getFileTypeEntity(String fileType) throws ObjectNotFoundException { FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileType); if (fileTypeEntity == null) { throw new ObjectNotFoundException(String.format("File type with code \"%s\" doesn't exist.", fileType)); } return fileTypeEntity; } }
/** * Gets the file type entity and ensure it exists. * * @param fileType the file type (case insensitive) * * @return the file type entity * @throws ObjectNotFoundException if the file type entity doesn't exist */ public FileTypeEntity getFileTypeEntity(String fileType) throws ObjectNotFoundException { FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileType); if (fileTypeEntity == null) { throw new ObjectNotFoundException(String.format("File type with code \"%s\" doesn't exist.", fileType)); } return fileTypeEntity; } }
if (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatFileType())) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectDataSearchKey.getBusinessObjectFormatFileType());
if (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatFileType())) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectDataSearchKey.getBusinessObjectFormatFileType());
if (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatFileType())) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectDataSearchKey.getBusinessObjectFormatFileType());
if (StringUtils.isNotBlank(businessObjectDataSearchKey.getBusinessObjectFormatFileType())) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectDataSearchKey.getBusinessObjectFormatFileType());
if (StringUtils.isNotBlank(businessObjectFormatFileType)) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType);
if (StringUtils.isNotBlank(businessObjectFormatFileType)) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType);
@Test public void testCreateFileType() { when(fileTypeMockDao.getFileTypeByCode(FORMAT_FILE_TYPE_CODE)).thenReturn(null); when(alternateKeyHelper.validateStringParameter(anyString(), anyString())).thenReturn(FORMAT_FILE_TYPE_CODE); when(fileTypeMockDao.saveAndRefresh(any(FileTypeEntity.class))).thenReturn(FILE_TYPE_ENTITY); FileType fileType = fileTypeMockService.createFileType(FILE_TYPE_CREATE_REQUEST); assertEquals(FORMAT_FILE_TYPE_CODE, fileType.getFileTypeCode()); verify(alternateKeyHelper).validateStringParameter("file type code", FORMAT_FILE_TYPE_CODE); verify(fileTypeMockDao).getFileTypeByCode(FORMAT_FILE_TYPE_CODE); verify(fileTypeMockDao).saveAndRefresh(any(FileTypeEntity.class)); verifyNoMoreInteractionsHelper(); }
@Test public void testCreateFileTypeAlreadyExists() { expectedException.expect(AlreadyExistsException.class); expectedException.expectMessage(String.format("Unable to create file type \"%s\" because it already exists.", FORMAT_FILE_TYPE_CODE)); when(fileTypeMockDao.getFileTypeByCode(FORMAT_FILE_TYPE_CODE)).thenReturn(FILE_TYPE_ENTITY); when(alternateKeyHelper.validateStringParameter(anyString(), anyString())).thenReturn(FORMAT_FILE_TYPE_CODE); fileTypeMockService.createFileType(FILE_TYPE_CREATE_REQUEST); }
@Test public void testGetFileTypeByCodeInLowerCase() { // Create relative database entities. fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toUpperCase(), "Description of " + FORMAT_FILE_TYPE_CODE.toUpperCase()); // Retrieve file type entity. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(FORMAT_FILE_TYPE_CODE.toLowerCase()); // Validate the results. assertNotNull(fileTypeEntity); assertTrue(fileTypeEntity.getCode().equals(FORMAT_FILE_TYPE_CODE.toUpperCase())); assertTrue(fileTypeEntity.getDescription().equals("Description of " + FORMAT_FILE_TYPE_CODE.toUpperCase())); }
@Test public void testGetFileTypeByCodeInUpperCase() { // Create relative database entities. fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toLowerCase(), "Description of " + FORMAT_FILE_TYPE_CODE.toLowerCase()); // Retrieve file type entity. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(FORMAT_FILE_TYPE_CODE.toUpperCase()); // Validate the results. assertNotNull(fileTypeEntity); assertTrue(fileTypeEntity.getCode().equals(FORMAT_FILE_TYPE_CODE.toLowerCase())); assertTrue(fileTypeEntity.getDescription().equals("Description of " + FORMAT_FILE_TYPE_CODE.toLowerCase())); }
@Test public void testGetFileTypeByCodeMultipleRecordsFound() { // Create relative database entities. fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toUpperCase(), "Description of " + FORMAT_FILE_TYPE_CODE.toUpperCase()); fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toLowerCase(), "Description of " + FORMAT_FILE_TYPE_CODE.toLowerCase()); try { // Try retrieve file type entity. fileTypeDao.getFileTypeByCode(FORMAT_FILE_TYPE_CODE); fail("Should throw an IllegalArgumentException if finds more than one file type entities with the same code."); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().startsWith("Found more than one file type")); } }
@Override public FileType createFileType(FileTypeCreateRequest fileTypeCreateRequest) { // Perform the validation. validateFileTypeCreateRequest(fileTypeCreateRequest); // Ensure a file type with the specified file type code doesn't already exist. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileTypeCreateRequest.getFileTypeCode()); if (fileTypeEntity != null) { throw new AlreadyExistsException( String.format("Unable to create file type \"%s\" because it already exists.", fileTypeCreateRequest.getFileTypeCode())); } // Create a file type entity from the request information. fileTypeEntity = createFileTypeEntity(fileTypeCreateRequest); // Persist the new entity. fileTypeEntity = fileTypeDao.saveAndRefresh(fileTypeEntity); // Create and return the file type object from the persisted entity. return createFileTypeFromEntity(fileTypeEntity); }
@Override public FileType createFileType(FileTypeCreateRequest fileTypeCreateRequest) { // Perform the validation. validateFileTypeCreateRequest(fileTypeCreateRequest); // Ensure a file type with the specified file type code doesn't already exist. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileTypeCreateRequest.getFileTypeCode()); if (fileTypeEntity != null) { throw new AlreadyExistsException( String.format("Unable to create file type \"%s\" because it already exists.", fileTypeCreateRequest.getFileTypeCode())); } // Create a file type entity from the request information. fileTypeEntity = createFileTypeEntity(fileTypeCreateRequest); // Persist the new entity. fileTypeEntity = fileTypeDao.saveAndRefresh(fileTypeEntity); // Create and return the file type object from the persisted entity. return createFileTypeFromEntity(fileTypeEntity); }
@Test public void testGetFileTypeByCodeInvalidCode() { // Create relative database entities. fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, "Description of " + FORMAT_FILE_TYPE_CODE); // Try to retrieve file type entity using an invalid code value. assertNull(fileTypeDao.getFileTypeByCode("I_DO_NOT_EXIST")); }
@Test public void testGetFileTypeByCode() { // Create relative database entities. fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, "Description of " + FORMAT_FILE_TYPE_CODE); // Retrieve file type entity. FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(FORMAT_FILE_TYPE_CODE); // Validate the results. assertNotNull(fileTypeEntity); assertTrue(fileTypeEntity.getCode().equals(FORMAT_FILE_TYPE_CODE)); assertTrue(fileTypeEntity.getDescription().equals("Description of " + FORMAT_FILE_TYPE_CODE)); }
FileTypeEntity fileTypeEntity = fileTypeDao.getFileTypeByCode(fileType); if (fileTypeEntity == null)
if (StringUtils.isNotBlank(businessObjectFormatFileType)) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType); if (fileTypeEntity == null)
if (StringUtils.isNotBlank(businessObjectFormatFileType)) fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType); if (fileTypeEntity == null)