Search in sources :

Example 1 with DataProviderKey

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

the class DataProviderServiceImpl method createDataProvider.

@Override
public DataProvider createDataProvider(DataProviderCreateRequest request) {
    // Perform the validation.
    validateDataProviderCreateRequest(request);
    // Get the data provider key.
    DataProviderKey dataProviderKey = new DataProviderKey(request.getDataProviderName());
    // Ensure a data provider with the specified data provider key doesn't already exist.
    DataProviderEntity dataProviderEntity = dataProviderDao.getDataProviderByKey(dataProviderKey);
    if (dataProviderEntity != null) {
        throw new AlreadyExistsException(String.format("Unable to create data provider \"%s\" because it already exists.", dataProviderKey.getDataProviderName()));
    }
    // Create a data provider entity from the request information.
    dataProviderEntity = createDataProviderEntity(request);
    // Persist the new entity.
    dataProviderEntity = dataProviderDao.saveAndRefresh(dataProviderEntity);
    // Create and return the data provider object from the persisted entity.
    return createDataProviderFromEntity(dataProviderEntity);
}
Also used : DataProviderEntity(org.finra.herd.model.jpa.DataProviderEntity) AlreadyExistsException(org.finra.herd.model.AlreadyExistsException) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey)

Example 2 with DataProviderKey

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

the class DataProviderRestControllerTest method testGetDataProvider.

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

Example 3 with DataProviderKey

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

the class DataProviderRestControllerTest method testGetDataProviders.

@Test
public void testGetDataProviders() throws Exception {
    DataProviderKeys dataProviderKeys = new DataProviderKeys(Arrays.asList(new DataProviderKey(DATA_PROVIDER_NAME), new DataProviderKey(DATA_PROVIDER_NAME_2)));
    when(dataProviderService.getDataProviders()).thenReturn(dataProviderKeys);
    // Retrieve a list of data provider keys.
    DataProviderKeys resultDataProviderKeys = dataProviderRestController.getDataProviders();
    // Verify the external calls.
    verify(dataProviderService).getDataProviders();
    verifyNoMoreInteractions(dataProviderService);
    // Validate the returned object.
    assertEquals(dataProviderKeys, resultDataProviderKeys);
}
Also used : DataProviderKeys(org.finra.herd.model.api.xml.DataProviderKeys) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey) Test(org.junit.Test)

Example 4 with DataProviderKey

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

the class DataProviderServiceTest method testDeleteDataProviderNoExists.

@Test
public void testDeleteDataProviderNoExists() throws Exception {
    // Try to delete a non-existing data provider.
    try {
        dataProviderService.deleteDataProvider(new DataProviderKey(DATA_PROVIDER_NAME));
        fail("Should throw an ObjectNotFoundException when data provider doesn't exist.");
    } catch (ObjectNotFoundException e) {
        assertEquals(String.format("Data provider with name \"%s\" doesn't exist.", DATA_PROVIDER_NAME), e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) DataProviderKey(org.finra.herd.model.api.xml.DataProviderKey) Test(org.junit.Test)

Example 5 with DataProviderKey

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

the class DataProviderServiceTest method testGetDataProviderLowerCaseParameters.

@Test
public void testGetDataProviderLowerCaseParameters() {
    // Create and persist a data provider entity.
    dataProviderDaoTestHelper.createDataProviderEntity(DATA_PROVIDER_NAME);
    // Retrieve the data provider using lower case input parameters.
    DataProvider resultDataProvider = dataProviderService.getDataProvider(new DataProviderKey(DATA_PROVIDER_NAME.toLowerCase()));
    // Validate the returned object.
    assertEquals(new DataProvider(DATA_PROVIDER_NAME), resultDataProvider);
}
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