|
1 | 1 | package dev.mhh.cloner; |
2 | 2 |
|
| 3 | +import dev.mhh.cloner.api.CloneConfiguration; |
| 4 | +import dev.mhh.cloner.api.CloneError; |
3 | 5 | import dev.mhh.cloner.api.CloneException; |
4 | 6 | import dev.mhh.cloner.api.Cloner; |
5 | 7 | import dev.mhh.cloner.impl.ClonerImpl; |
|
13 | 15 | import java.util.List; |
14 | 16 |
|
15 | 17 | import static dev.mhh.cloner.TestDatabase.*; |
16 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
17 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 18 | +import static org.junit.jupiter.api.Assertions.*; |
18 | 19 |
|
19 | 20 | class RecloneTest { |
20 | 21 | Cloner<Long> cloner = new ClonerImpl<>(); |
@@ -125,4 +126,28 @@ int count(final Connection conn, final String sql) throws SQLException { |
125 | 126 | return rs.getInt(1); |
126 | 127 | } |
127 | 128 | } |
| 129 | + |
| 130 | + @Test |
| 131 | + void recloneWithADifferentConfigurationFails() throws SQLException, IOException, CloneException { |
| 132 | + runTestWithScripts( |
| 133 | + List.of("V1__schema.sql", "V2__data.sql"), |
| 134 | + List.of("V1__schema.sql"), |
| 135 | + this::recloneWithADifferentConfigurationFails |
| 136 | + ); |
| 137 | + } |
| 138 | + |
| 139 | + void recloneWithADifferentConfigurationFails(final Connection exportConn, final Connection importConn) throws IOException, CloneException, SQLException { |
| 140 | + final byte[] zipBytes; |
| 141 | + try (final var out = new ByteArrayOutputStream()) { |
| 142 | + cloner.exportClone(out, exportConn, CLONE_CONFIGURATION, List.of(1L)); |
| 143 | + zipBytes = out.toByteArray(); |
| 144 | + } |
| 145 | + |
| 146 | + // First import |
| 147 | + try (final var in = new ByteArrayInputStream(zipBytes)) { |
| 148 | + final var differentConfiguration = CloneConfiguration.builder("wrong", "wrong", Long.class).build(); |
| 149 | + final var cloneException = assertThrows(CloneException.class, () -> cloner.importClone(in, importConn, differentConfiguration)); |
| 150 | + assertEquals(CloneError.CONFIG_FINGERPRINT_MISMATCH, cloneException.error()); |
| 151 | + } |
| 152 | + } |
128 | 153 | } |
0 commit comments