|
| 1 | +/* |
| 2 | + * Copyright 2025 Flamingock (https://www.flamingock.io) |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.flamingock.core.e2e; |
| 17 | + |
| 18 | +import io.flamingock.common.test.pipeline.CodeChangeTestDefinition; |
| 19 | +import io.flamingock.common.test.pipeline.PipelineTestHelper; |
| 20 | +import io.flamingock.core.e2e.changes._008__TargetSystemManagerInjectionChange; |
| 21 | +import io.flamingock.core.e2e.helpers.Counter; |
| 22 | +import io.flamingock.core.kit.audit.AuditTestHelper; |
| 23 | +import io.flamingock.core.kit.inmemory.InMemoryTestKit; |
| 24 | +import io.flamingock.internal.common.core.util.Deserializer; |
| 25 | +import io.flamingock.internal.core.targets.TargetSystemManager; |
| 26 | +import io.flamingock.targetsystem.nontransactional.NonTransactionalTargetSystem; |
| 27 | +import org.junit.jupiter.api.DisplayName; |
| 28 | +import org.junit.jupiter.api.Test; |
| 29 | +import org.mockito.MockedStatic; |
| 30 | +import org.mockito.Mockito; |
| 31 | + |
| 32 | +import java.util.Arrays; |
| 33 | + |
| 34 | +import static io.flamingock.core.kit.audit.AuditEntryExpectation.APPLIED; |
| 35 | +import static io.flamingock.core.kit.audit.AuditEntryExpectation.STARTED; |
| 36 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 37 | + |
| 38 | + |
| 39 | +class BuilderE2ETest { |
| 40 | + |
| 41 | + @Test |
| 42 | + @DisplayName("Should inject TargetSystemManager as dependency in change") |
| 43 | + void shouldInjectTargetSystemManagerInChange() { |
| 44 | + // Given - Create isolated test kit with domain-separated helpers |
| 45 | + InMemoryTestKit testKit = InMemoryTestKit.create(); |
| 46 | + AuditTestHelper auditHelper = testKit.getAuditHelper(); |
| 47 | + |
| 48 | + Counter counter = new Counter(); |
| 49 | + |
| 50 | + NonTransactionalTargetSystem targetSystem = new NonTransactionalTargetSystem("kafka") |
| 51 | + .addDependency(counter); |
| 52 | + |
| 53 | + try (MockedStatic<Deserializer> mocked = Mockito.mockStatic(Deserializer.class)) { |
| 54 | + mocked.when(Deserializer::readPreviewPipelineFromFile).thenReturn( |
| 55 | + PipelineTestHelper.getPreviewPipeline( |
| 56 | + new CodeChangeTestDefinition( |
| 57 | + _008__TargetSystemManagerInjectionChange.class, |
| 58 | + Arrays.asList(TargetSystemManager.class, Counter.class) |
| 59 | + ) |
| 60 | + ) |
| 61 | + ); |
| 62 | + |
| 63 | + // When - Execute using test builder |
| 64 | + testKit.createBuilder() |
| 65 | + .addTargetSystem(targetSystem) |
| 66 | + .build() |
| 67 | + .run(); |
| 68 | + } |
| 69 | + |
| 70 | + // Then - Verify that TargetSystemManager was successfully injected |
| 71 | + assertTrue(counter.isExecuted(), "Counter.executed should be true, indicating TargetSystemManager was injected"); |
| 72 | + |
| 73 | + // Verify complete audit flow |
| 74 | + auditHelper.verifyAuditSequenceStrict( |
| 75 | + STARTED("test8-target-system-manager-injection"), |
| 76 | + APPLIED("test8-target-system-manager-injection") |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments