|
| 1 | +package io.javaoperatorsdk.operator.api.reconciler; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | + |
| 5 | +import io.fabric8.kubernetes.api.model.ConfigMap; |
| 6 | +import io.fabric8.kubernetes.api.model.Secret; |
| 7 | +import io.javaoperatorsdk.operator.processing.Controller; |
| 8 | +import io.javaoperatorsdk.operator.processing.event.EventSourceManager; |
| 9 | +import io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException; |
| 10 | + |
| 11 | +import static org.assertj.core.api.Assertions.assertThat; |
| 12 | +import static org.junit.jupiter.api.Assertions.*; |
| 13 | +import static org.mockito.ArgumentMatchers.any; |
| 14 | +import static org.mockito.Mockito.mock; |
| 15 | +import static org.mockito.Mockito.when; |
| 16 | + |
| 17 | +class DefaultContextTest { |
| 18 | + |
| 19 | + Secret primary = new Secret(); |
| 20 | + Controller<Secret> mockController = mock(Controller.class); |
| 21 | + |
| 22 | + DefaultContext<?> context = new DefaultContext<>(null, mockController, primary); |
| 23 | + |
| 24 | + @Test |
| 25 | + void getSecondaryResourceReturnsEmptyOptionalOnNonActivatedDRType() { |
| 26 | + var mockManager = mock(EventSourceManager.class); |
| 27 | + when(mockController.getEventSourceManager()).thenReturn(mockManager); |
| 28 | + when(mockController.workflowContainsDependentForType(ConfigMap.class)).thenReturn(true); |
| 29 | + when(mockManager.getEventSourceFor(any(), any())) |
| 30 | + .thenThrow(new NoEventSourceForClassException(ConfigMap.class)); |
| 31 | + |
| 32 | + var res = context.getSecondaryResource(ConfigMap.class); |
| 33 | + |
| 34 | + assertThat(res).isEmpty(); |
| 35 | + } |
| 36 | + |
| 37 | +} |
0 commit comments