Search in sources :

Example 1 with AccountAwareResource

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");
}
Also used : ResourceBasicView(com.sequenceiq.cloudbreak.common.dal.ResourceBasicView) HashMap(java.util.HashMap) AccountAwareResource(com.sequenceiq.cloudbreak.common.dal.model.AccountAwareResource) Test(org.junit.jupiter.api.Test)

Example 2 with AccountAwareResource

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");
}
Also used : ResourceBasicView(com.sequenceiq.cloudbreak.common.dal.ResourceBasicView) HashMap(java.util.HashMap) AccountAwareResource(com.sequenceiq.cloudbreak.common.dal.model.AccountAwareResource) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceBasicView (com.sequenceiq.cloudbreak.common.dal.ResourceBasicView)2 AccountAwareResource (com.sequenceiq.cloudbreak.common.dal.model.AccountAwareResource)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2