|
22 | 22 | import tools.dynamia.modules.saas.migration.api.AccountImportOptions; |
23 | 23 | import tools.dynamia.modules.saas.migration.api.IdentityMapper; |
24 | 24 | import tools.dynamia.modules.saas.migration.api.IdentityStrategy; |
25 | | -import tools.dynamia.modules.saas.migration.api.MigrationException; |
26 | 25 | import tools.dynamia.modules.saas.migration.config.AccountMigrationProperties; |
27 | 26 | import tools.dynamia.modules.saas.migration.identity.KeepIdsIdentityMapper; |
| 27 | +import tools.dynamia.modules.saas.migration.identity.Uuid7IdentityMapper; |
28 | 28 |
|
29 | 29 | import java.io.ByteArrayInputStream; |
30 | 30 | import java.io.ByteArrayOutputStream; |
|
40 | 40 | /** |
41 | 41 | * Verifies that {@link ImportPipeline} correctly resolves the identity mapper: |
42 | 42 | * <ul> |
43 | | - * <li>UUID7 throws {@link MigrationException} immediately.</li> |
| 43 | + * <li>UUID7 completes without error (uses {@link tools.dynamia.modules.saas.migration.identity.Uuid7IdentityMapper}).</li> |
44 | 44 | * <li>A custom Spring bean mapper is preferred over built-in defaults.</li> |
45 | 45 | * <li>KEEP_IDS falls back to {@link tools.dynamia.modules.saas.migration.identity.KeepIdsIdentityMapper} |
46 | 46 | * when no custom bean is present.</li> |
@@ -71,20 +71,41 @@ public void setUp() { |
71 | 71 | } |
72 | 72 |
|
73 | 73 | @Test |
74 | | - public void uuid7StrategyThrowsMigrationException() { |
| 74 | + public void uuid7StrategyCompletesWithoutException() { |
75 | 75 | ImportPipeline pipeline = new ImportPipeline(emf, properties, objectMapper); |
76 | 76 |
|
77 | 77 | AccountImportOptions opts = new AccountImportOptions() |
78 | 78 | .targetAccountId(1L) |
79 | 79 | .identityStrategy(IdentityStrategy.UUID7); |
80 | 80 |
|
81 | | - try { |
82 | | - pipeline.importTenant(emptyExportStream(), opts, null, null); |
83 | | - Assert.fail("Expected MigrationException for UUID7"); |
84 | | - } catch (MigrationException e) { |
85 | | - Assert.assertTrue("Message should mention UUID7", |
86 | | - e.getMessage().contains("UUID7")); |
87 | | - } |
| 81 | + // Empty entity stream — should complete cleanly using Uuid7IdentityMapper |
| 82 | + pipeline.importTenant(emptyExportStream(), opts, null, null); |
| 83 | + } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void uuid7StrategyUsesUuid7IdentityMapper() { |
| 87 | + // Verify the built-in UUID7 mapper is selected when no custom bean overrides it |
| 88 | + ImportPipeline pipeline = new ImportPipeline(emf, properties, objectMapper); |
| 89 | + |
| 90 | + IdentityMapper[] captured = {null}; |
| 91 | + IdentityMapper spy = new Uuid7IdentityMapper() { |
| 92 | + @Override |
| 93 | + public Object mapId(Object originalId, Class<?> entityClass) { |
| 94 | + captured[0] = this; |
| 95 | + return super.mapId(originalId, entityClass); |
| 96 | + } |
| 97 | + }; |
| 98 | + injectCustomMappers(pipeline, List.of(spy)); |
| 99 | + |
| 100 | + // spy handles UUID7 → it should be selected |
| 101 | + AccountImportOptions opts = new AccountImportOptions() |
| 102 | + .targetAccountId(1L) |
| 103 | + .identityStrategy(IdentityStrategy.UUID7); |
| 104 | + |
| 105 | + pipeline.importTenant(emptyExportStream(), opts, null, null); |
| 106 | + // No entities → mapId is never called, but resolveIdentityMapper must pick |
| 107 | + // our spy (strategy == UUID7) rather than throwing. |
| 108 | + // The import completes: that alone proves UUID7 is no longer rejected. |
88 | 109 | } |
89 | 110 |
|
90 | 111 | @Test |
|
0 commit comments