-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe7f56d
commit 4dbbbc7
Showing
5 changed files
with
195 additions
and
1 deletion.
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
31 changes: 31 additions & 0 deletions
31
src/test/java/com/dabsquared/gitlabjenkins/trigger/filter/AllBranchesFilterTest.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,31 @@ | ||
package com.dabsquared.gitlabjenkins.trigger.filter; | ||
|
||
import org.apache.commons.lang.RandomStringUtils; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Robin Müller | ||
*/ | ||
public class AllBranchesFilterTest { | ||
|
||
@Test | ||
public void isRandomBranchNameAllowed() { | ||
String randomBranchName = RandomStringUtils.random(10, true, false); | ||
|
||
assertThat(new AllBranchesFilter().isBranchAllowed(randomBranchName), is(true)); | ||
} | ||
|
||
@Test | ||
public void getConfig() { | ||
BranchFilterConfig config = new AllBranchesFilter().getConfig(); | ||
|
||
assertThat(config.getType(), is(BranchFilterType.All)); | ||
assertThat(config.getExcludeBranchesSpec(), nullValue()); | ||
assertThat(config.getIncludeBranchesSpec(), nullValue()); | ||
assertThat(config.getTargetBranchRegex(), nullValue()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/com/dabsquared/gitlabjenkins/trigger/filter/BranchFilterFactoryTest.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,60 @@ | ||
package com.dabsquared.gitlabjenkins.trigger.filter; | ||
|
||
import org.junit.Test; | ||
|
||
import static com.dabsquared.gitlabjenkins.trigger.filter.BranchFilterConfig.BranchFilterConfigBuilder.branchFilterConfig; | ||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Robin Müller | ||
*/ | ||
public class BranchFilterFactoryTest { | ||
|
||
@Test | ||
public void getAllBranchesFilter() { | ||
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig() | ||
.withIncludeBranchesSpec("master") | ||
.withExcludeBranchesSpec("develop") | ||
.withTargetBranchRegex(".*") | ||
.build(BranchFilterType.All)); | ||
|
||
assertThat(branchFilter, instanceOf(AllBranchesFilter.class)); | ||
assertThat(branchFilter.getConfig().getIncludeBranchesSpec(), nullValue()); | ||
assertThat(branchFilter.getConfig().getExcludeBranchesSpec(), nullValue()); | ||
assertThat(branchFilter.getConfig().getTargetBranchRegex(), nullValue()); | ||
} | ||
|
||
@Test | ||
public void getNameBasedFilterFilter() { | ||
String includeBranchesSpec = "master"; | ||
String excludeBranchesSpec = "develop"; | ||
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig() | ||
.withIncludeBranchesSpec(includeBranchesSpec) | ||
.withExcludeBranchesSpec(excludeBranchesSpec) | ||
.withTargetBranchRegex(".*") | ||
.build(BranchFilterType.NameBasedFilter)); | ||
|
||
assertThat(branchFilter, instanceOf(NameBasedFilter.class)); | ||
assertThat(branchFilter.getConfig().getIncludeBranchesSpec(), is(includeBranchesSpec)); | ||
assertThat(branchFilter.getConfig().getExcludeBranchesSpec(), is(excludeBranchesSpec)); | ||
assertThat(branchFilter.getConfig().getTargetBranchRegex(), nullValue()); | ||
} | ||
|
||
@Test | ||
public void getRegexBasedFilterFilter() { | ||
String regex = ".*"; | ||
BranchFilter branchFilter = BranchFilterFactory.newBranchFilter(branchFilterConfig() | ||
.withIncludeBranchesSpec("master") | ||
.withExcludeBranchesSpec("develop") | ||
.withTargetBranchRegex(regex) | ||
.build(BranchFilterType.RegexBasedFilter)); | ||
|
||
assertThat(branchFilter, instanceOf(RegexBasedFilter.class)); | ||
assertThat(branchFilter.getConfig().getIncludeBranchesSpec(), nullValue()); | ||
assertThat(branchFilter.getConfig().getExcludeBranchesSpec(), nullValue()); | ||
assertThat(branchFilter.getConfig().getTargetBranchRegex(), is(regex)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/com/dabsquared/gitlabjenkins/trigger/filter/NameBasedFilterTest.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,52 @@ | ||
package com.dabsquared.gitlabjenkins.trigger.filter; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Robin Müller | ||
*/ | ||
public class NameBasedFilterTest { | ||
|
||
@Test | ||
public void includeBranches() { | ||
NameBasedFilter nameBasedFilter = new NameBasedFilter("master, develop", ""); | ||
|
||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true)); | ||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(true)); | ||
} | ||
|
||
@Test | ||
public void excludeBranches() { | ||
NameBasedFilter nameBasedFilter = new NameBasedFilter("", "master, develop"); | ||
|
||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(false)); | ||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false)); | ||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-branch"), is(true)); | ||
} | ||
|
||
@Test | ||
public void includeAndExcludeBranches() { | ||
NameBasedFilter nameBasedFilter = new NameBasedFilter("master", "develop"); | ||
|
||
assertThat(nameBasedFilter.isBranchAllowed("master"), is(true)); | ||
assertThat(nameBasedFilter.isBranchAllowed("develop"), is(false)); | ||
assertThat(nameBasedFilter.isBranchAllowed("not-excluded-and-not-included-branch"), is(false)); | ||
} | ||
|
||
@Test | ||
public void getConfig() { | ||
String includedBranches = "master, develop"; | ||
String excludedBranches = "hotfix/test"; | ||
|
||
BranchFilterConfig config = new NameBasedFilter(includedBranches, excludedBranches).getConfig(); | ||
|
||
assertThat(config.getType(), is(BranchFilterType.NameBasedFilter)); | ||
assertThat(config.getIncludeBranchesSpec(), is(includedBranches)); | ||
assertThat(config.getExcludeBranchesSpec(), is(excludedBranches)); | ||
assertThat(config.getTargetBranchRegex(), nullValue()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/com/dabsquared/gitlabjenkins/trigger/filter/RegexBasedFilterTest.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,51 @@ | ||
package com.dabsquared.gitlabjenkins.trigger.filter; | ||
|
||
import org.junit.Test; | ||
import org.junit.experimental.theories.DataPoints; | ||
import org.junit.experimental.theories.FromDataPoints; | ||
import org.junit.experimental.theories.Theories; | ||
import org.junit.experimental.theories.Theory; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* @author Robin Müller | ||
*/ | ||
@RunWith(Theories.class) | ||
public class RegexBasedFilterTest { | ||
|
||
@DataPoints("matching-branches") | ||
public static String[] matchingBranchNames = {"feature/test", "feature/awesome-feature"}; | ||
|
||
@DataPoints("not-matching-branches") | ||
public static String[] notMatchingBranchNames = {"hotfix/test", "hotfix/awesome-feature", "master", "develop"}; | ||
|
||
@Theory | ||
public void isRegexBranchAllowed(@FromDataPoints("matching-branches") String branchName) { | ||
RegexBasedFilter featureBranches = new RegexBasedFilter("feature/.*"); | ||
|
||
assertThat(featureBranches.isBranchAllowed(branchName), is(true)); | ||
} | ||
|
||
@Theory | ||
public void isRegexBranchNotAllowed(@FromDataPoints("not-matching-branches") String branchName) { | ||
RegexBasedFilter featureBranches = new RegexBasedFilter("feature/.*"); | ||
|
||
assertThat(featureBranches.isBranchAllowed(branchName), is(false)); | ||
} | ||
|
||
@Test | ||
public void getConfig() { | ||
String regex = "test.*"; | ||
|
||
BranchFilterConfig config = new RegexBasedFilter(regex).getConfig(); | ||
|
||
assertThat(config.getType(), is(BranchFilterType.RegexBasedFilter)); | ||
assertThat(config.getIncludeBranchesSpec(), nullValue()); | ||
assertThat(config.getExcludeBranchesSpec(), nullValue()); | ||
assertThat(config.getTargetBranchRegex(), is(regex)); | ||
} | ||
} |