use of com.sequenceiq.cloudbreak.common.dal.model.AccountAwareResource in project cloudbreak by hortonworks.
the class DataCollectorComponentTest method testFetchDataFromDbIfNeedWhenCrnNotNullAndNameIsNullAndFound.
@Test
public void testFetchDataFromDbIfNeedWhenCrnNotNullAndNameIsNullAndFound() {
AccountAwareResourceRepository<AccountAwareResource, Long> repo = mock(AccountAwareResourceRepository.class);
ResourceBasicView resource = mock(ResourceBasicView.class);
Optional<ResourceBasicView> entityOpt = Optional.of(resource);
pathRepositoryMap.put("key", repo);
Map<String, String> params = new HashMap<>();
params.put(RESOURCE_CRN, "crn");
params.put(RESOURCE_NAME, null);
when(resource.getName()).thenReturn("name-ret");
when(resource.getId()).thenReturn(342L);
when(repo.findResourceBasicViewByResourceCrn("crn")).thenReturn(entityOpt);
ThreadBasedUserCrnProvider.doAs(userCrn, () -> underTest.fetchDataFromDbIfNeed(params));
Assertions.assertEquals("name-ret", params.get(RESOURCE_NAME));
Assertions.assertEquals("crn", params.get(RESOURCE_CRN));
Assertions.assertEquals("342", params.get(RESOURCE_ID));
verify(repo).findResourceBasicViewByResourceCrn("crn");
}
use of com.sequenceiq.cloudbreak.common.dal.model.AccountAwareResource in project cloudbreak by hortonworks.
the class DataCollectorComponentTest method testFetchDataFromDbIfNeedWhenNameNotNullAndCrnIsNullAndFound.
@Test
public void testFetchDataFromDbIfNeedWhenNameNotNullAndCrnIsNullAndFound() {
AccountAwareResourceRepository<AccountAwareResource, Long> repo = mock(AccountAwareResourceRepository.class);
ResourceBasicView resource = mock(ResourceBasicView.class);
pathRepositoryMap.put("key", repo);
Map<String, String> params = new HashMap<>();
params.put(RESOURCE_CRN, null);
params.put(RESOURCE_NAME, "name");
Optional<ResourceBasicView> entityOpt = Optional.of(resource);
when(resource.getResourceCrn()).thenReturn("crn-ret");
when(resource.getId()).thenReturn(342L);
when(repo.findResourceBasicViewByNameAndAccountId("name", "acc")).thenReturn(entityOpt);
ThreadBasedUserCrnProvider.doAs(userCrn, () -> underTest.fetchDataFromDbIfNeed(params));
Assertions.assertEquals("name", params.get(RESOURCE_NAME));
Assertions.assertEquals("crn-ret", params.get(RESOURCE_CRN));
Assertions.assertEquals("342", params.get(RESOURCE_ID));
verify(repo).findResourceBasicViewByNameAndAccountId("name", "acc");
}
Aggregations