Search in sources :

Example 1 with FileTypeKey

use of org.finra.herd.model.api.xml.FileTypeKey in project herd by FINRAOS.

the class FileTypeRestControllerTest method testGetFileTypes.

@Test
public void testGetFileTypes() throws Exception {
    // Get a list of test file type keys.
    List<FileTypeKey> testFileTypeKeys = Arrays.asList(new FileTypeKey(FORMAT_FILE_TYPE_CODE), new FileTypeKey(FORMAT_FILE_TYPE_CODE_2));
    FileTypeKeys fileTypeKeys = new FileTypeKeys(testFileTypeKeys);
    // Create and persist file type entities.
    when(fileTypeService.getFileTypes()).thenReturn(fileTypeKeys);
    // Retrieve a list of file type keys.
    FileTypeKeys resultFileTypeKeys = fileTypeRestController.getFileTypes();
    // Verify the external calls.
    verify(fileTypeService).getFileTypes();
    verifyNoMoreInteractions(fileTypeService);
    // Validate the returned object.
    assertEquals(fileTypeKeys, resultFileTypeKeys);
}
Also used : FileTypeKey(org.finra.herd.model.api.xml.FileTypeKey) FileTypeKeys(org.finra.herd.model.api.xml.FileTypeKeys) Test(org.junit.Test)

Example 2 with FileTypeKey

use of org.finra.herd.model.api.xml.FileTypeKey in project herd by FINRAOS.

the class FileTypeDaoTest method testGetFileTypes.

@Test
public void testGetFileTypes() throws Exception {
    // Create and persist file type entities.
    for (FileTypeKey key : fileTypeDaoTestHelper.getTestFileTypeKeys()) {
        fileTypeDaoTestHelper.createFileTypeEntity(key.getFileTypeCode());
    }
    // Retrieve a list of file type keys.
    List<FileTypeKey> resultFileTypeKeys = fileTypeDao.getFileTypes();
    // Validate the returned object.
    assertNotNull(resultFileTypeKeys);
    assertTrue(resultFileTypeKeys.containsAll(fileTypeDaoTestHelper.getTestFileTypeKeys()));
}
Also used : FileTypeKey(org.finra.herd.model.api.xml.FileTypeKey) Test(org.junit.Test)

Example 3 with FileTypeKey

use of org.finra.herd.model.api.xml.FileTypeKey in project herd by FINRAOS.

the class FileTypeDaoImpl method getFileTypes.

@Override
public List<FileTypeKey> getFileTypes() {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<String> criteria = builder.createQuery(String.class);
    // The criteria root is the file type.
    Root<FileTypeEntity> fileTypeEntity = criteria.from(FileTypeEntity.class);
    // Get the columns.
    Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
    // Add the select clause.
    criteria.select(fileTypeCodeColumn);
    // Add the order by clause.
    criteria.orderBy(builder.asc(fileTypeCodeColumn));
    // Run the query to get a list of file type codes back.
    List<String> fileTypeCodes = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned file type codes.
    List<FileTypeKey> fileTypeKeys = new ArrayList<>();
    for (String fileTypeCode : fileTypeCodes) {
        fileTypeKeys.add(new FileTypeKey(fileTypeCode));
    }
    return fileTypeKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) FileTypeKey(org.finra.herd.model.api.xml.FileTypeKey) ArrayList(java.util.ArrayList)

Example 4 with FileTypeKey

use of org.finra.herd.model.api.xml.FileTypeKey in project herd by FINRAOS.

the class FileTypeServiceTest method testGetFileTypes.

@Test
public void testGetFileTypes() throws Exception {
    // Create and persist file type entities.
    for (FileTypeKey key : fileTypeDaoTestHelper.getTestFileTypeKeys()) {
        fileTypeDaoTestHelper.createFileTypeEntity(key.getFileTypeCode());
    }
    // Retrieve a list of file type keys.
    FileTypeKeys resultFileTypeKeys = fileTypeService.getFileTypes();
    // Validate the returned object.
    assertNotNull(resultFileTypeKeys);
    assertTrue(resultFileTypeKeys.getFileTypeKeys().containsAll(fileTypeDaoTestHelper.getTestFileTypeKeys()));
}
Also used : FileTypeKey(org.finra.herd.model.api.xml.FileTypeKey) FileTypeKeys(org.finra.herd.model.api.xml.FileTypeKeys) Test(org.junit.Test)

Aggregations

FileTypeKey (org.finra.herd.model.api.xml.FileTypeKey)4 Test (org.junit.Test)3 FileTypeKeys (org.finra.herd.model.api.xml.FileTypeKeys)2 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)1