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 #8 from button/merchant-library-traffic-shaping-up…
…date Add Application ID to all API requests
- Loading branch information
Showing
7 changed files
with
193 additions
and
26 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
47 changes: 47 additions & 0 deletions
47
button-merchant/src/main/java/com/usebutton/merchant/ButtonUtil.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,47 @@ | ||
/* | ||
* ButtonUtil.java | ||
* | ||
* Copyright (c) 2019 Button, Inc. (https://usebutton.com) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.usebutton.merchant; | ||
|
||
/** | ||
* Utility Class | ||
*/ | ||
class ButtonUtil { | ||
/** | ||
* Valid App Id Regex | ||
*/ | ||
private static final String APP_ID_REGEX = "^app-[0-9a-zA-Z-]+$"; | ||
|
||
/** | ||
* Validates the string against the {@link ButtonUtil#APP_ID_REGEX} to verify if it is a valid | ||
* Application ID | ||
* | ||
* @param appId String to be validated. | ||
* @return True if string is not empty and is a valid application id, otherwise false. | ||
*/ | ||
static boolean isApplicationIdValid(String appId) { | ||
return appId.matches(APP_ID_REGEX); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
button-merchant/src/test/java/com/usebutton/merchant/ButtonUtilTest.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,54 @@ | ||
/* | ||
* ButtonUtilTest.java | ||
* | ||
* Copyright (c) 2019 Button, Inc. (https://usebutton.com) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*/ | ||
|
||
package com.usebutton.merchant; | ||
|
||
import org.junit.Test; | ||
|
||
import static com.usebutton.merchant.TestHelper.APPLICATION_ID; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ButtonUtilTest { | ||
@Test | ||
public void isApplicationIdValid_ShouldReturnTrueWithValidAppId() { | ||
assertTrue(ButtonUtil.isApplicationIdValid(APPLICATION_ID)); | ||
} | ||
|
||
@Test | ||
public void isApplicationIdValid_ShouldReturnFalseWithInvalidAppId_EmptyString() { | ||
assertFalse(ButtonUtil.isApplicationIdValid("")); | ||
} | ||
|
||
@Test | ||
public void isApplicationIdValid_ShouldReturnFalseWithInvalidAppId_NoAppPrefix() { | ||
assertFalse(ButtonUtil.isApplicationIdValid("-1111111111111111")); | ||
} | ||
|
||
@Test | ||
public void isApplicationIdValid_ShouldReturnFalseWithInvalidAppId_InvalidCharacter() { | ||
assertFalse(ButtonUtil.isApplicationIdValid("app-992&&&&3 ")); | ||
} | ||
} |
Oops, something went wrong.