Search in sources :

Example 11 with DataProviderKey

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

the class DataProviderTest method testGetDataProviderByKey.

@Test
public void testGetDataProviderByKey() {
    // Create a data provider entity.
    DataProviderEntity dataProviderEntity = dataProviderDaoTestHelper.createDataProviderEntity(DATA_PROVIDER_NAME);
    // Retrieve the data provider entity.
    assertEquals(dataProviderEntity, dataProviderDao.getDataProviderByKey(new DataProviderKey(DATA_PROVIDER_NAME)));
    // Test case insensitivity of data provider key.
    assertEquals(dataProviderEntity, dataProviderDao.getDataProviderByKey(new DataProviderKey(DATA_PROVIDER_NAME.toUpperCase())));
    assertEquals(dataProviderEntity, dataProviderDao.getDataProviderByKey(new DataProviderKey(DATA_PROVIDER_NAME.toLowerCase())));
}
Also used : DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey) Test(org.junit.Test)

Example 12 with DataProviderKey

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

the class DataProviderDaoImpl method getDataProviders.

@Override
public List<DataProviderKey> getDataProviders() {
    // 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 data provider.
    Root<DataProviderEntity> dataProviderEntity = criteria.from(DataProviderEntity.class);
    // Get the columns.
    Path<String> dataProviderNameColumn = dataProviderEntity.get(DataProviderEntity_.name);
    // Add the select clause.
    criteria.select(dataProviderNameColumn);
    // Add the order by clause.
    criteria.orderBy(builder.asc(dataProviderNameColumn));
    // Run the query to get a list of data provider names back.
    List<String> dataProviderNames = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned data provider names.
    List<DataProviderKey> dataProviderKeys = new ArrayList<>();
    for (String dataProviderName : dataProviderNames) {
        dataProviderKeys.add(new DataProviderKey(dataProviderName));
    }
    return dataProviderKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) ArrayList(java.util.ArrayList) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey)

Example 13 with DataProviderKey

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

the class DataProviderRestControllerTest method testDeleteDataProvider.

@Test
public void testDeleteDataProvider() throws Exception {
    // Create a data provider key.
    DataProviderKey dataProviderKey = new DataProviderKey(DATA_PROVIDER_NAME);
    DataProvider dataProvider = new DataProvider(DATA_PROVIDER_NAME);
    when(dataProviderService.deleteDataProvider(dataProviderKey)).thenReturn(dataProvider);
    DataProvider deletedDataProvider = dataProviderRestController.deleteDataProvider(DATA_PROVIDER_NAME);
    // Verify the external calls.
    verify(dataProviderService).deleteDataProvider(dataProviderKey);
    verifyNoMoreInteractions(dataProviderService);
    // Validate the returned object.
    assertEquals(dataProvider, deletedDataProvider);
}
Also used : DataProvider(org.finra.herd.model.api.xml.DataProvider) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey) Test(org.junit.Test)

Example 14 with DataProviderKey

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

the class DataProviderServiceTest method testGetDataProviderMissingRequiredParameters.

@Test
public void testGetDataProviderMissingRequiredParameters() {
    // Try to get a data provider when data provider name is not specified.
    try {
        dataProviderService.getDataProvider(new DataProviderKey(BLANK_TEXT));
        fail("Should throw an IllegalArgumentException when data provider name is not specified.");
    } catch (IllegalArgumentException e) {
        assertEquals("A data provider name must be specified.", e.getMessage());
    }
}
Also used : DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey) Test(org.junit.Test)

Example 15 with DataProviderKey

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

the class DataProviderServiceTest method testDeleteDataProviderLowerCaseParameters.

@Test
public void testDeleteDataProviderLowerCaseParameters() {
    // Create a data provider key.
    DataProviderKey dataProviderKey = new DataProviderKey(DATA_PROVIDER_NAME);
    // Create and persist a data provider entity.
    dataProviderDaoTestHelper.createDataProviderEntity(DATA_PROVIDER_NAME);
    // Validate that this data provider exists.
    assertNotNull(dataProviderDao.getDataProviderByKey(dataProviderKey));
    // Delete the data provider using lower case input parameters.
    DataProvider deletedDataProvider = dataProviderService.deleteDataProvider(new DataProviderKey(DATA_PROVIDER_NAME.toLowerCase()));
    // Validate the returned object.
    assertEquals(new DataProvider(DATA_PROVIDER_NAME), deletedDataProvider);
    // Ensure that this data provider is no longer there.
    assertNull(dataProviderDao.getDataProviderByKey(dataProviderKey));
}
Also used : DataProvider(org.finra.herd.model.api.xml.DataProvider) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey) Test(org.junit.Test)

Aggregations

DataProviderKey (org.finra.herd.model.api.xml.DataProviderKey)19 Test (org.junit.Test)17 DataProvider (org.finra.herd.model.api.xml.DataProvider)10 DataProviderEntity (org.finra.herd.model.jpa.DataProviderEntity)3 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 DataProviderKeys (org.finra.herd.model.api.xml.DataProviderKeys)2 ArrayList (java.util.ArrayList)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1