|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.hop.core.database; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 24 | + |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +class DriverDownloadTest { |
| 28 | + |
| 29 | + @Test |
| 30 | + void coordinateUsesDefaultVersionAndHonoursOverride() { |
| 31 | + DriverDownload download = |
| 32 | + DriverDownload.builder() |
| 33 | + .mavenCoordinate("com.oracle.database.jdbc:ojdbc11") |
| 34 | + .defaultVersion("23.5.0.24.07") |
| 35 | + .licenseCategory("X") |
| 36 | + .build(); |
| 37 | + |
| 38 | + assertEquals("com.oracle.database.jdbc:ojdbc11:23.5.0.24.07", download.toCoordinate(null)); |
| 39 | + assertEquals("com.oracle.database.jdbc:ojdbc11:21.0.0", download.toCoordinate("21.0.0")); |
| 40 | + assertEquals("ojdbc11", download.getArtifactId()); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void coordinateKeepsAnExplicitClassifier() { |
| 45 | + // Some drivers ship a self-contained classified artifact, e.g. ClickHouse's "all" jar. The |
| 46 | + // version is appended after the group:artifact:packaging:classifier, and the artifactId is |
| 47 | + // still the second segment. |
| 48 | + DriverDownload download = |
| 49 | + DriverDownload.builder() |
| 50 | + .mavenCoordinate("com.clickhouse:clickhouse-jdbc:jar:all") |
| 51 | + .defaultVersion("0.9.8") |
| 52 | + .licenseCategory("A") |
| 53 | + .build(); |
| 54 | + |
| 55 | + assertEquals("com.clickhouse:clickhouse-jdbc:jar:all:0.9.8", download.toCoordinate(null)); |
| 56 | + assertEquals("clickhouse-jdbc", download.getArtifactId()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void coordinateUsesDefaultVersionWhenOverrideIsBlank() { |
| 61 | + DriverDownload download = |
| 62 | + DriverDownload.builder() |
| 63 | + .mavenCoordinate("org.postgresql:postgresql") |
| 64 | + .defaultVersion("42.7.4") |
| 65 | + .build(); |
| 66 | + |
| 67 | + assertEquals("org.postgresql:postgresql:42.7.4", download.toCoordinate(" ")); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + void artifactIdIsNullForAnIncompleteCoordinate() { |
| 72 | + assertNull(DriverDownload.builder().build().getArtifactId()); |
| 73 | + assertNull(DriverDownload.builder().mavenCoordinate("single-segment").build().getArtifactId()); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void restrictedIsBasedOnCategoryX() { |
| 78 | + assertTrue(DriverDownload.builder().licenseCategory("X").build().isRestricted()); |
| 79 | + assertTrue(DriverDownload.builder().licenseCategory("x").build().isRestricted()); |
| 80 | + assertFalse(DriverDownload.builder().licenseCategory("A").build().isRestricted()); |
| 81 | + assertFalse(DriverDownload.builder().build().isRestricted()); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void databaseWithoutDownloadReturnsNullByDefault() { |
| 86 | + IDatabase database = new NoneDatabaseMeta(); |
| 87 | + assertNull(database.getDriverDownload()); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + void excludesDefaultToEmptyAndCarryValues() { |
| 92 | + assertTrue(DriverDownload.builder().build().getExcludes().isEmpty()); |
| 93 | + assertEquals( |
| 94 | + java.util.List.of("com.google.protobuf:protobuf-java"), |
| 95 | + DriverDownload.builder() |
| 96 | + .excludes(java.util.List.of("com.google.protobuf:protobuf-java")) |
| 97 | + .build() |
| 98 | + .getExcludes()); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + void repositoryUrlDefaultsToNullAndCarriesValue() { |
| 103 | + org.junit.jupiter.api.Assertions.assertNull( |
| 104 | + DriverDownload.builder().build().getRepositoryUrl()); |
| 105 | + assertEquals( |
| 106 | + "https://clojars.org/repo/", |
| 107 | + DriverDownload.builder() |
| 108 | + .repositoryUrl("https://clojars.org/repo/") |
| 109 | + .build() |
| 110 | + .getRepositoryUrl()); |
| 111 | + } |
| 112 | +} |
0 commit comments