-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Showing
15 changed files
with
489 additions
and
96 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
43 changes: 43 additions & 0 deletions
43
vividus-engine/src/main/java/org/vividus/condition/AbstractBooleanPropertyCondition.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,43 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.vividus.condition; | ||
|
||
import java.util.Objects; | ||
import java.util.Properties; | ||
import java.util.stream.Stream; | ||
|
||
import org.springframework.context.annotation.Condition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
public abstract class AbstractBooleanPropertyCondition implements Condition | ||
{ | ||
private final String[] propertyNames; | ||
|
||
protected AbstractBooleanPropertyCondition(String... propertyNames) | ||
{ | ||
this.propertyNames = propertyNames; | ||
} | ||
|
||
@Override | ||
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) | ||
{ | ||
Properties properties = Objects.requireNonNull(context.getBeanFactory()) | ||
.getBean("properties", Properties.class); | ||
return Stream.of(propertyNames).allMatch(p -> Boolean.parseBoolean(properties.getProperty(p))); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...dus-engine/src/test/java/org/vividus/condition/AbstractBooleanPropertyConditionTests.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,81 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.vividus.condition; | ||
|
||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Properties; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
class AbstractBooleanPropertyConditionTests | ||
{ | ||
private static final String TRUE = "true"; | ||
private static final String FALSE = "false"; | ||
private static final String FIRST_PROP = "prop1"; | ||
private static final String SECOND_PROP = "prop2"; | ||
|
||
static Stream<Arguments> propertyValues() | ||
{ | ||
return Stream.of( | ||
arguments(TRUE, TRUE, true), | ||
arguments(FALSE, FALSE, false), | ||
arguments(FALSE, TRUE, false), | ||
arguments(TRUE, FALSE, false), | ||
arguments(null, TRUE, false), | ||
arguments(EMPTY, TRUE, false) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("propertyValues") | ||
void testCondition(String firstPropValue, String secondPropValue, Boolean expected) | ||
{ | ||
var beanFactory = mock(ConfigurableListableBeanFactory.class); | ||
var metadata = mock(AnnotatedTypeMetadata.class); | ||
var context = mock(ConditionContext.class); | ||
var properties = mock(Properties.class); | ||
|
||
when(context.getBeanFactory()).thenReturn(beanFactory); | ||
when(beanFactory.getBean("properties", Properties.class)).thenReturn(properties); | ||
when(properties.getProperty(FIRST_PROP)).thenReturn(firstPropValue); | ||
when(properties.getProperty(SECOND_PROP)).thenReturn(secondPropValue); | ||
|
||
var condition = new BooleanPropertyCondition(); | ||
Assertions.assertEquals(expected, condition.matches(context, metadata)); | ||
verifyNoInteractions(metadata); | ||
} | ||
|
||
static class BooleanPropertyCondition extends AbstractBooleanPropertyCondition | ||
{ | ||
BooleanPropertyCondition() | ||
{ | ||
super(FIRST_PROP, SECOND_PROP); | ||
} | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
...ion-selenium/src/main/java/org/vividus/ui/listener/AttachSourceCodePropertyCondition.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,29 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.vividus.ui.listener; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.vividus.condition.AbstractBooleanPropertyCondition; | ||
|
||
@Component | ||
public class AttachSourceCodePropertyCondition extends AbstractBooleanPropertyCondition | ||
{ | ||
public AttachSourceCodePropertyCondition() | ||
{ | ||
super("ui.publish-source-on-failure"); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...elenium/src/test/java/org/vividus/ui/listener/AttachSourceCodePropertyConditionTests.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,65 @@ | ||
/* | ||
* Copyright 2019-2024 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* https://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.vividus.ui.listener; | ||
|
||
import static org.apache.commons.lang3.StringUtils.EMPTY; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Properties; | ||
import java.util.stream.Stream; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
class AttachSourceCodePropertyConditionTests | ||
{ | ||
static Stream<Arguments> propertyValues() | ||
{ | ||
return Stream.of( | ||
arguments("true", true), | ||
arguments("false", false), | ||
arguments(null, false), | ||
arguments(EMPTY, false) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("propertyValues") | ||
void testCondition(String publishSource, Boolean expected) | ||
{ | ||
var beanFactory = mock(ConfigurableListableBeanFactory.class); | ||
var metadata = mock(AnnotatedTypeMetadata.class); | ||
var context = mock(ConditionContext.class); | ||
var properties = mock(Properties.class); | ||
|
||
when(context.getBeanFactory()).thenReturn(beanFactory); | ||
when(beanFactory.getBean("properties", Properties.class)).thenReturn(properties); | ||
when(properties.getProperty("ui.publish-source-on-failure")).thenReturn(publishSource); | ||
|
||
var condition = new AttachSourceCodePropertyCondition(); | ||
Assertions.assertEquals(expected, condition.matches(context, metadata)); | ||
verifyNoInteractions(metadata); | ||
} | ||
} |
Oops, something went wrong.