-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from xsalefter/platform_157-fix_extra_slash
fix extra slash
- Loading branch information
Showing
7 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ndles/kpm/src/main/java/org/killbill/billing/osgi/bundles/kpm/KpmPropertiesValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2020-2024 Equinix, Inc | ||
* Copyright 2014-2024 The Billing Project, LLC | ||
* | ||
* The Billing Project licenses this file to you under the Apache License, version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.killbill.billing.osgi.bundles.kpm; | ||
|
||
import org.killbill.commons.utils.annotation.VisibleForTesting; | ||
|
||
public final class KpmPropertiesValidator { | ||
|
||
private final KpmProperties kpmProperties; | ||
|
||
public KpmPropertiesValidator(final KpmProperties kpmProperties) { | ||
this.kpmProperties = kpmProperties; | ||
} | ||
|
||
public void validate() throws KPMPluginException { | ||
this.validateNexusUrl(); | ||
this.validateNexusRepository(); | ||
} | ||
|
||
@VisibleForTesting | ||
void validateNexusUrl() throws KPMPluginException { | ||
if (kpmProperties.getNexusUrl().endsWith("/")) { | ||
throw new KPMPluginException("nexusUrl should not end with a trailing slash"); | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
void validateNexusRepository() throws KPMPluginException { | ||
final String toValidate = kpmProperties.getNexusRepository(); | ||
if (!toValidate.startsWith("/") || toValidate.endsWith("/")) { | ||
throw new KPMPluginException("nexusRepository should start with a slash and not end with a trailing slash"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...s/kpm/src/test/java/org/killbill/billing/osgi/bundles/kpm/TestKpmPropertiesValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2020-2024 Equinix, Inc | ||
* Copyright 2014-2024 The Billing Project, LLC | ||
* | ||
* The Billing Project licenses this file to you under the Apache License, version 2.0 | ||
* (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.killbill.billing.osgi.bundles.kpm; | ||
|
||
import org.mockito.Mockito; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestKpmPropertiesValidator { | ||
|
||
@Test(groups = "fast") | ||
public void testValidateNexusUrl_noTrailingSlash() throws KPMPluginException { | ||
// Valid | ||
final KpmProperties kpmProperties = Mockito.mock(KpmProperties.class); | ||
Mockito.when(kpmProperties.getNexusUrl()).thenReturn("http://example.com"); | ||
KpmPropertiesValidator validator = new KpmPropertiesValidator(kpmProperties); | ||
validator.validateNexusUrl(); | ||
|
||
// Invalid: end with "/" | ||
Mockito.when(kpmProperties.getNexusUrl()).thenReturn("http://example.com/"); | ||
validator = new KpmPropertiesValidator(kpmProperties); | ||
try { | ||
validator.validateNexusUrl(); | ||
} catch (final KPMPluginException e) { | ||
Assert.assertEquals(e.getMessage(), "nexusUrl should not end with a trailing slash"); | ||
} | ||
} | ||
|
||
@Test(groups = "fast") | ||
public void testValidateNexusRepository() throws KPMPluginException { | ||
final KpmProperties kpmProperties = Mockito.mock(KpmProperties.class); | ||
|
||
// Valid | ||
Mockito.when(kpmProperties.getNexusRepository()).thenReturn("/valid/nexus/repository/location"); | ||
KpmPropertiesValidator validator = new KpmPropertiesValidator(kpmProperties); | ||
validator.validateNexusRepository(); | ||
|
||
// Should start with "/" | ||
Mockito.when(kpmProperties.getNexusRepository()).thenReturn("some/invalid/repository"); | ||
validator = new KpmPropertiesValidator(kpmProperties); | ||
try { | ||
validator.validateNexusRepository(); | ||
} catch (final KPMPluginException e) { | ||
Assert.assertEquals(e.getMessage(), "nexusRepository should start with a slash and not end with a trailing slash"); | ||
} | ||
|
||
// Should never end with "/" | ||
Mockito.when(kpmProperties.getNexusRepository()).thenReturn("/some/other/invalid/"); | ||
validator = new KpmPropertiesValidator(kpmProperties); | ||
try { | ||
validator.validateNexusRepository(); | ||
} catch (final KPMPluginException e) { | ||
Assert.assertEquals(e.getMessage(), "nexusRepository should start with a slash and not end with a trailing slash"); | ||
} | ||
} | ||
} |