|
| 1 | +/* |
| 2 | +======================================================================== |
| 3 | +SchemaCrawler |
| 4 | +http://www.schemacrawler.com |
| 5 | +Copyright (c) 2000-2021, Sualeh Fatehi <sualeh@hotmail.com>. |
| 6 | +All rights reserved. |
| 7 | +------------------------------------------------------------------------ |
| 8 | +
|
| 9 | +SchemaCrawler is distributed in the hope that it will be useful, but |
| 10 | +WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | +
|
| 13 | +SchemaCrawler and the accompanying materials are made available under |
| 14 | +the terms of the Eclipse Public License v1.0, GNU General Public License |
| 15 | +v3 or GNU Lesser General Public License v3. |
| 16 | +
|
| 17 | +You may elect to redistribute this code under any of these licenses. |
| 18 | +
|
| 19 | +The Eclipse Public License is available at: |
| 20 | +http://www.eclipse.org/legal/epl-v10.html |
| 21 | +
|
| 22 | +The GNU General Public License v3 and the GNU Lesser General Public |
| 23 | +License v3 are available at: |
| 24 | +http://www.gnu.org/licenses/ |
| 25 | +
|
| 26 | +======================================================================== |
| 27 | +*/ |
| 28 | +package schemacrawler.integration.test; |
| 29 | + |
| 30 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | +import static org.hamcrest.Matchers.equalTo; |
| 32 | +import static org.hamcrest.Matchers.hasSize; |
| 33 | + |
| 34 | +import java.sql.SQLException; |
| 35 | + |
| 36 | +import org.apache.commons.lang3.SerializationUtils; |
| 37 | +import org.junit.jupiter.api.BeforeEach; |
| 38 | +import org.junit.jupiter.api.Test; |
| 39 | +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
| 40 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 41 | +import org.testcontainers.containers.JdbcDatabaseContainer; |
| 42 | +import org.testcontainers.containers.MSSQLServerContainer; |
| 43 | +import org.testcontainers.junit.jupiter.Container; |
| 44 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 45 | +import org.testcontainers.utility.DockerImageName; |
| 46 | + |
| 47 | +import schemacrawler.inclusionrule.RegularExpressionInclusionRule; |
| 48 | +import schemacrawler.schema.Catalog; |
| 49 | +import schemacrawler.schemacrawler.LimitOptionsBuilder; |
| 50 | +import schemacrawler.schemacrawler.LoadOptionsBuilder; |
| 51 | +import schemacrawler.schemacrawler.SchemaCrawlerException; |
| 52 | +import schemacrawler.schemacrawler.SchemaCrawlerOptions; |
| 53 | +import schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder; |
| 54 | +import schemacrawler.schemacrawler.SchemaInfoLevelBuilder; |
| 55 | +import schemacrawler.test.utility.BaseAdditionalDatabaseTest; |
| 56 | +import schemacrawler.test.utility.TestContext; |
| 57 | +import schemacrawler.test.utility.TestContextParameterResolver; |
| 58 | +import schemacrawler.test.utility.TestLoggingExtension; |
| 59 | +import schemacrawler.tools.utility.SchemaCrawlerUtility; |
| 60 | + |
| 61 | +@ExtendWith(TestLoggingExtension.class) |
| 62 | +@ExtendWith(TestContextParameterResolver.class) |
| 63 | +@Testcontainers(disabledWithoutDocker = true) |
| 64 | +@EnabledIfSystemProperty(named = "heavydb", matches = "^((?!(false|no)).)*$") |
| 65 | +public class Issue482Test extends BaseAdditionalDatabaseTest { |
| 66 | + |
| 67 | + @Container |
| 68 | + private final JdbcDatabaseContainer<?> dbContainer = |
| 69 | + new MSSQLServerContainer<>( |
| 70 | + DockerImageName.parse("mcr.microsoft.com/mssql/server") |
| 71 | + .withTag("2017-CU22-ubuntu-16.04")) |
| 72 | + .acceptLicense(); |
| 73 | + |
| 74 | + @BeforeEach |
| 75 | + public void createDatabase() throws SQLException, SchemaCrawlerException { |
| 76 | + createDataSource( |
| 77 | + dbContainer.getJdbcUrl(), dbContainer.getUsername(), dbContainer.getPassword()); |
| 78 | + |
| 79 | + createDatabase("/sqlserver.scripts.txt"); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void serializeUnknownObjectSynonym(final TestContext testContext) throws Exception { |
| 84 | + |
| 85 | + final LimitOptionsBuilder limitOptionsBuilder = |
| 86 | + LimitOptionsBuilder.builder() |
| 87 | + .includeSchemas(new RegularExpressionInclusionRule("BOOKS\\.dbo")) |
| 88 | + .includeAllSynonyms(); |
| 89 | + final LoadOptionsBuilder loadOptionsBuilder = |
| 90 | + LoadOptionsBuilder.builder().withSchemaInfoLevel(SchemaInfoLevelBuilder.maximum()); |
| 91 | + final SchemaCrawlerOptions schemaCrawlerOptions = |
| 92 | + SchemaCrawlerOptionsBuilder.newSchemaCrawlerOptions() |
| 93 | + .withLimitOptions(limitOptionsBuilder.toOptions()) |
| 94 | + .withLoadOptions(loadOptionsBuilder.toOptions()); |
| 95 | + |
| 96 | + final Catalog catalog = SchemaCrawlerUtility.getCatalog(getConnection(), schemaCrawlerOptions); |
| 97 | + |
| 98 | + assertThat(catalog.getTables(), hasSize(10)); |
| 99 | + assertThat(catalog.getSynonyms(), hasSize(2)); |
| 100 | + |
| 101 | + final Catalog clonedCatalog = SerializationUtils.clone(catalog); |
| 102 | + |
| 103 | + assertThat(catalog, equalTo(clonedCatalog)); |
| 104 | + assertThat(clonedCatalog.getTables(), hasSize(10)); |
| 105 | + assertThat(clonedCatalog.getSynonyms(), hasSize(2)); |
| 106 | + } |
| 107 | +} |
0 commit comments