|
| 1 | +package io.javaoperatorsdk.operator.processing.dependent.workflow; |
| 2 | + |
| 3 | +import java.util.Map; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +import io.fabric8.kubernetes.api.model.HasMetadata; |
| 8 | +import io.javaoperatorsdk.operator.AggregatedOperatorException; |
| 9 | +import io.javaoperatorsdk.operator.api.reconciler.Context; |
| 10 | +import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; |
| 11 | +import io.javaoperatorsdk.operator.api.reconciler.dependent.ReconcileResult; |
| 12 | + |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; |
| 14 | + |
| 15 | +class WorkflowResultTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + void throwsExceptionWithoutNumberingIfAllDifferentClass() { |
| 19 | + var res = new WorkflowResult(Map.of(new DependentA(), new RuntimeException(), |
| 20 | + new DependentB(), new RuntimeException())); |
| 21 | + try { |
| 22 | + res.throwAggregateExceptionIfErrorsPresent(); |
| 23 | + } catch (AggregatedOperatorException e) { |
| 24 | + assertThat(e.getAggregatedExceptions()).containsOnlyKeys(DependentA.class.getName(), |
| 25 | + DependentB.class.getName()); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + void numbersDependentClassNamesIfMoreOfSameType() { |
| 31 | + var res = new WorkflowResult(Map.of(new DependentA(), new RuntimeException(), |
| 32 | + new DependentA(), new RuntimeException())); |
| 33 | + try { |
| 34 | + res.throwAggregateExceptionIfErrorsPresent(); |
| 35 | + } catch (AggregatedOperatorException e) { |
| 36 | + assertThat(e.getAggregatedExceptions()).hasSize(2); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + @SuppressWarnings("rawtypes") |
| 41 | + static class DependentA implements DependentResource { |
| 42 | + @Override |
| 43 | + public ReconcileResult reconcile(HasMetadata primary, Context context) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Class resourceType() { |
| 49 | + return null; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + @SuppressWarnings("rawtypes") |
| 54 | + static class DependentB implements DependentResource { |
| 55 | + @Override |
| 56 | + public ReconcileResult reconcile(HasMetadata primary, Context context) { |
| 57 | + return null; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public Class resourceType() { |
| 62 | + return null; |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments