Search in sources :

Example 1 with StackCrnView

use of com.sequenceiq.cloudbreak.domain.projection.StackCrnView in project cloudbreak by hortonworks.

the class StackOperationsTest method testGetWithEnvironmentCrnsByResourceCrns.

@Test
public void testGetWithEnvironmentCrnsByResourceCrns() {
    StackCrnView stack1 = mock(StackCrnView.class);
    when(stack1.getResourceCrn()).thenReturn("crn1");
    when(stack1.getEnvironmentCrn()).thenReturn("envcrn1");
    StackCrnView stack2 = mock(StackCrnView.class);
    when(stack2.getResourceCrn()).thenReturn("crn2");
    when(stack2.getEnvironmentCrn()).thenReturn("envcrn2");
    StackCrnView stackWithoutEnv = mock(StackCrnView.class);
    when(stackWithoutEnv.getResourceCrn()).thenReturn("crn3");
    when(stackService.findAllByCrn(anySet())).thenReturn(List.of(stack1, stack2, stackWithoutEnv));
    Map<String, Optional<String>> result = ThreadBasedUserCrnProvider.doAs("crn:altus:iam:us-west-1:123:user:456", () -> underTest.getEnvironmentCrnsByResourceCrns(List.of("crn1", "crn2", "crn3")));
    Map<String, Optional<String>> expected = new LinkedHashMap<>();
    expected.put("crn1", Optional.of("envcrn1"));
    expected.put("crn2", Optional.of("envcrn2"));
    expected.put("crn3", Optional.empty());
    assertEquals(expected, result);
}
Also used : Optional(java.util.Optional) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackCrnView(com.sequenceiq.cloudbreak.domain.projection.StackCrnView) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

StackCrnView (com.sequenceiq.cloudbreak.domain.projection.StackCrnView)1 LinkedHashMap (java.util.LinkedHashMap)1 Optional (java.util.Optional)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1