-
Notifications
You must be signed in to change notification settings - Fork 218
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 #2271 from zebrunner/develop
1.2.9
- Loading branch information
Showing
15 changed files
with
215 additions
and
20 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
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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/zebrunner/carina/core/filter/v2/CountryFilter.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,39 @@ | ||
package com.zebrunner.carina.core.filter.v2; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.concurrent.ConcurrentException; | ||
import org.apache.commons.lang3.concurrent.LazyInitializer; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.testng.ITestNGMethod; | ||
|
||
import com.zebrunner.carina.webdriver.config.WebDriverConfiguration; | ||
|
||
public class CountryFilter implements ITestFilter { | ||
|
||
private static final LazyInitializer<String> COUNTRY = new LazyInitializer<>() { | ||
@Override | ||
protected String initialize() throws ConcurrentException { | ||
return WebDriverConfiguration.getLocale() | ||
.getCountry(); | ||
} | ||
}; | ||
|
||
@Override | ||
public String key() { | ||
return "country"; | ||
} | ||
|
||
@Override | ||
public boolean isPerform(ITestNGMethod testMethod) { | ||
try { | ||
String country = COUNTRY.get(); | ||
return testMethod != null && testMethod.getGroups().length > 0 && | ||
Arrays.stream(testMethod.getGroups()) | ||
.anyMatch(group -> StringUtils.equals(country, group)); | ||
} catch (ConcurrentException e) { | ||
return ExceptionUtils.rethrow(e); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/zebrunner/carina/core/filter/v2/ITestFilter.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,15 @@ | ||
package com.zebrunner.carina.core.filter.v2; | ||
|
||
import org.testng.ITestNGMethod; | ||
|
||
import com.zebrunner.carina.utils.exception.InvalidConfigurationException; | ||
|
||
public interface ITestFilter { | ||
|
||
boolean isPerform(ITestNGMethod testMethod); | ||
|
||
default String key() { | ||
throw new InvalidConfigurationException("Filter should have key."); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/zebrunner/carina/core/filter/v2/MethodsFilter.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,57 @@ | ||
package com.zebrunner.carina.core.filter.v2; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import com.zebrunner.carina.core.config.TestConfiguration; | ||
import org.apache.commons.lang3.concurrent.ConcurrentException; | ||
import org.apache.commons.lang3.concurrent.LazyInitializer; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.testng.ITestNGMethod; | ||
|
||
import com.zebrunner.carina.utils.config.Configuration; | ||
|
||
public class MethodsFilter implements ITestFilter { | ||
|
||
private static final LazyInitializer<Boolean> IS_PERFORM = new LazyInitializer<>() { | ||
@Override | ||
protected Boolean initialize() throws ConcurrentException { | ||
return Configuration.get(TestConfiguration.Parameter.FILTER_METHOD_PATTERN) | ||
.isPresent(); | ||
} | ||
}; | ||
|
||
private static final LazyInitializer<List<Pattern>> PATTERN = new LazyInitializer<>() { | ||
@Override | ||
protected List<Pattern> initialize() throws ConcurrentException { | ||
return Arrays.stream(Configuration.getRequired(TestConfiguration.Parameter.FILTER_METHOD_PATTERN).split(",")) | ||
.map(Pattern::compile) | ||
.collect(Collectors.toList()); | ||
} | ||
}; | ||
|
||
@Override | ||
public String key() { | ||
return "methods"; | ||
} | ||
|
||
@Override | ||
public boolean isPerform(ITestNGMethod testMethod) { | ||
try { | ||
if (!IS_PERFORM.get()) { | ||
return true; | ||
} | ||
for (Pattern pattern : PATTERN.get()) { | ||
if (testMethod != null && pattern.matcher(testMethod.getRealClass().getSimpleName() + "#" + testMethod.getMethodName()) | ||
.find()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} catch (ConcurrentException e) { | ||
return ExceptionUtils.rethrow(e); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/com/zebrunner/carina/core/filter/v2/TestRunFilterListener.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,78 @@ | ||
/******************************************************************************* | ||
* Copyright 2020-2023 Zebrunner Inc (https://www.zebrunner.com). | ||
* | ||
* Licensed 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 com.zebrunner.carina.core.filter.v2; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.commons.lang3.concurrent.ConcurrentException; | ||
import org.apache.commons.lang3.concurrent.LazyInitializer; | ||
import org.apache.commons.lang3.exception.ExceptionUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testng.ISuite; | ||
import org.testng.ISuiteListener; | ||
import org.testng.ITestNGMethod; | ||
|
||
import com.zebrunner.carina.utils.config.Configuration; | ||
|
||
public class TestRunFilterListener implements ISuiteListener { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
private static final LazyInitializer<List<ITestFilter>> FILTERS = new LazyInitializer<>() { | ||
@Override | ||
protected List<ITestFilter> initialize() throws ConcurrentException { | ||
List<ITestFilter> filters = List.of(new CountryFilter(), new MethodsFilter()); | ||
List<String> usedFilters = Configuration.get("test_run_filters") | ||
.map(StringUtils::lowerCase) | ||
.map(p -> StringUtils.split(p, ",")) | ||
.map(Arrays::asList) | ||
.orElse(List.of()); | ||
|
||
if (usedFilters.isEmpty()) { | ||
return List.of(); | ||
} | ||
return filters.stream() | ||
.filter(filter -> usedFilters.contains(filter.key())) | ||
.collect(Collectors.toList()); | ||
} | ||
}; | ||
|
||
@Override | ||
public void onStart(ISuite suite) { | ||
try { | ||
List<ITestFilter> filters = FILTERS.get(); | ||
if (filters.isEmpty()) { | ||
return; | ||
} | ||
|
||
for (ITestNGMethod testMethod : suite.getAllMethods().stream().filter(ITestNGMethod::isTest) | ||
.collect(Collectors.toList())) { | ||
boolean isPerform = filters.stream() | ||
.allMatch(filter -> filter.isPerform(testMethod)); | ||
|
||
if (!isPerform) { | ||
LOGGER.info("Disable test: [{}]", testMethod.getMethodName()); | ||
testMethod.setInvocationCount(0); | ||
} | ||
} | ||
} catch (ConcurrentException e) { | ||
ExceptionUtils.rethrow(e); | ||
} | ||
} | ||
} |
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