-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension-selenium] Add context source code dynamic variable (#4719)
Co-authored-by: draker94 <noreply@github.com>
- Loading branch information
Showing
18 changed files
with
262 additions
and
102 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
26 changes: 26 additions & 0 deletions
26
vividus-extension-selenium/src/main/java/org/vividus/ui/ContextSourceCodeProvider.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,26 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Map; | ||
|
||
public interface ContextSourceCodeProvider | ||
{ | ||
String APPLICATION_SOURCE_CODE = "Application source code"; | ||
|
||
Map<String, String> getSourceCode(); | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...sion-selenium/src/main/java/org/vividus/ui/variable/ContextSourceCodeDynamicVariable.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,42 @@ | ||
/* | ||
* 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.variable; | ||
|
||
import static org.vividus.ui.ContextSourceCodeProvider.APPLICATION_SOURCE_CODE; | ||
|
||
import org.vividus.ui.ContextSourceCodeProvider; | ||
import org.vividus.variable.DynamicVariable; | ||
import org.vividus.variable.DynamicVariableCalculationResult; | ||
|
||
public class ContextSourceCodeDynamicVariable implements DynamicVariable | ||
{ | ||
private final ContextSourceCodeProvider contextSourceCodeProvider; | ||
|
||
public ContextSourceCodeDynamicVariable(ContextSourceCodeProvider contextSourceCodeProvider) | ||
{ | ||
this.contextSourceCodeProvider = contextSourceCodeProvider; | ||
} | ||
|
||
@Override | ||
public DynamicVariableCalculationResult calculateValue() | ||
{ | ||
String contextSourceCode = contextSourceCodeProvider.getSourceCode().get(APPLICATION_SOURCE_CODE); | ||
return contextSourceCode != null | ||
? DynamicVariableCalculationResult.withValue(contextSourceCode) | ||
: DynamicVariableCalculationResult.withError("application is not started"); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
...selenium/src/test/java/org/vividus/ui/variable/ContextSourceCodeDynamicVariableTests.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.variable; | ||
|
||
import static com.github.valfirst.slf4jtest.LoggingEvent.error; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
import static org.vividus.ui.ContextSourceCodeProvider.APPLICATION_SOURCE_CODE; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.github.valfirst.slf4jtest.TestLogger; | ||
import com.github.valfirst.slf4jtest.TestLoggerFactory; | ||
import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.vividus.ui.ContextSourceCodeProvider; | ||
import org.vividus.variable.DynamicVariableCalculationResult; | ||
|
||
@ExtendWith({ TestLoggerFactoryExtension.class, MockitoExtension.class }) | ||
class ContextSourceCodeDynamicVariableTests | ||
{ | ||
private static final String SOURCES = "<html/>"; | ||
|
||
private final TestLogger logger = TestLoggerFactory.getTestLogger(ContextSourceCodeDynamicVariable.class); | ||
|
||
@Mock private ContextSourceCodeProvider contextSourceCodeProvider; | ||
@InjectMocks private ContextSourceCodeDynamicVariable dynamicVariable; | ||
|
||
@Test | ||
void shouldReturnSourceCodeAsResultIfApplicationStarted() | ||
{ | ||
when(contextSourceCodeProvider.getSourceCode()).thenReturn(Map.of(APPLICATION_SOURCE_CODE, SOURCES)); | ||
DynamicVariableCalculationResult actualResult = dynamicVariable.calculateValue(); | ||
assertEquals(SOURCES, actualResult.getValueOrHandleError(null).get()); | ||
} | ||
|
||
@Test | ||
void shouldReturnErrorAsResultIfApplicationNotStarted() | ||
{ | ||
when(contextSourceCodeProvider.getSourceCode()).thenReturn(Map.of()); | ||
DynamicVariableCalculationResult actualResult = dynamicVariable.calculateValue(); | ||
actualResult.getValueOrHandleError(logger::error); | ||
assertEquals(List.of(error("application is not started")), logger.getLoggingEvents()); | ||
} | ||
} |
Oops, something went wrong.