Skip to content

Commit

Permalink
[vividus] Unify naming of properties declaring variables (#3429)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikalinin1 authored Dec 8, 2022
1 parent e6931a8 commit 7222acf
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 103 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:

- name: VIVIDUS tasks validation
run: |
./gradlew validateKnownIssues printSteps countSteps -x testVividusInitialization -p vividus-tests --project-prop 'vividus.bdd.variables.global.iterationLimit=3' --project-prop 'vividus.bdd.variables.global.target-platform=ios'
./gradlew validateKnownIssues printSteps countSteps -x testVividusInitialization -p vividus-tests --project-prop 'vividus.variables.iterationLimit=3' --project-prop 'vividus.variables.target-platform=ios'
- name: Integration tests
Expand Down Expand Up @@ -312,7 +312,7 @@ jobs:
-Pvividus.allure.executor.build-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="SauceLabs iOS System tests report (Downscaled)" \
-Pvividus.bdd.variables.global.app-url=sauce-storage:vividus-test-app-ios-$TEST_APP_VERSION.zip
-Pvividus.variables.app-url=sauce-storage:vividus-test-app-ios-$TEST_APP_VERSION.zip
else
echo No SAUCELABS_USER and/or SAUCELABS_KEY variables, System tests will be skipped
fi
Expand Down Expand Up @@ -347,7 +347,7 @@ jobs:
-Pvividus.allure.executor.build-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="SauceLabs iOS System tests report (Original)" \
-Pvividus.bdd.variables.global.app-url=sauce-storage:vividus-test-app-ios-$TEST_APP_VERSION.zip \
-Pvividus.variables.app-url=sauce-storage:vividus-test-app-ios-$TEST_APP_VERSION.zip \
-Pvividus.statistics.print-failures=true \
-Pvividus.ui.visual.baseline-storage.filesystem.folder=./baselines/original \
-Pvividus.ui.context.self-healing=true
Expand Down Expand Up @@ -388,7 +388,7 @@ jobs:
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="SauceLabs iOS Proxy tests report" \
-Pvividus.saucelabs.sauce-connect.command-line-arguments="--proxy-localhost --no-ssl-bump-domains example.com" \
-Pvividus.bdd.variables.global.app-url=sauce-storage:vividus-test-app-ios-$TEST_APP_VERSION.zip
-Pvividus.variables.app-url=sauce-storage:vividus-test-app-ios-$TEST_APP_VERSION.zip
else
echo No SAUCELABS_USER and/or SAUCELABS_KEY variables, System tests will be skipped
fi
Expand Down Expand Up @@ -424,7 +424,7 @@ jobs:
-Pvividus.allure.executor.build-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="SauceLabs Android System tests report (Downscaled)" \
-Pvividus.bdd.variables.global.app-url=sauce-storage:vividus-test-app-android-$TEST_APP_VERSION.zip
-Pvividus.variables.app-url=sauce-storage:vividus-test-app-android-$TEST_APP_VERSION.zip
else
echo No SAUCELABS_USER and/or SAUCELABS_KEY variables, System tests will be skipped
fi
Expand Down Expand Up @@ -459,7 +459,7 @@ jobs:
-Pvividus.allure.executor.build-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="SauceLabs Android System tests report (Original)" \
-Pvividus.bdd.variables.global.app-url=sauce-storage:vividus-test-app-android-$TEST_APP_VERSION.zip \
-Pvividus.variables.app-url=sauce-storage:vividus-test-app-android-$TEST_APP_VERSION.zip \
-Pvividus.statistics.print-failures=true \
-Pvividus.batch-1.resource-include-patterns=VisualTesting.story \
-Pvividus.ui.visual.baseline-storage.filesystem.folder=./baselines/original
Expand Down Expand Up @@ -500,7 +500,7 @@ jobs:
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="SauceLabs Android Proxy tests report" \
-Pvividus.saucelabs.sauce-connect.command-line-arguments="--proxy-localhost --no-ssl-bump-domains example.com" \
-Pvividus.bdd.variables.global.app-url=sauce-storage:vividus-test-app-android-$TEST_APP_VERSION.zip
-Pvividus.variables.app-url=sauce-storage:vividus-test-app-android-$TEST_APP_VERSION.zip
else
echo No SAUCELABS_USER and/or SAUCELABS_KEY variables, System tests will be skipped
fi
Expand Down Expand Up @@ -557,7 +557,7 @@ jobs:
-Pvividus.allure.executor.build-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="BrowserStack iOS System tests report" \
-Pvividus.bdd.variables.global.app-url=bs://444bd0308813ae0dc236f8cd461c02d3afa7901d \
-Pvividus.variables.app-url=bs://444bd0308813ae0dc236f8cd461c02d3afa7901d \
-Pvividus.notifications.base.comment="VIVIDUS CI - BrowserStack iOS System Tests" \
-Pvividus.notifications.base.report-link=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.notifications.base.project=vividus-tests \
Expand Down Expand Up @@ -602,7 +602,7 @@ jobs:
-Pvividus.allure.executor.build-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-url=https://github.com/vividus-framework/vividus/actions/runs/${GITHUB_RUN_ID} \
-Pvividus.allure.executor.report-name="BrowserStack Android System tests report" \
-Pvividus.bdd.variables.global.app-url=bs://c700ce60cf13ae8ed97705a55b8e022f13c5827c
-Pvividus.variables.app-url=bs://c700ce60cf13ae8ed97705a55b8e022f13c5827c
else
echo No BROWSERSTACK_USER and/or BROWSERSTACK_KEY variables, System tests will be skipped
fi
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/tests-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ export EXTERNAL_CONFIG_VALUE=value
+
[source,properties]
----
bdd.variables.global.some-key=${EXTERNAL_CONFIG_VALUE}
variables.some-key=${EXTERNAL_CONFIG_VALUE}
----
+

Expand All @@ -597,7 +597,7 @@ The prefix only plays role during test start-up phase and cut off during the act
+
[source,shell]
----
./gradlew runStories -Pvividus.bdd.variables.global.some-key-1=value1 -Pvividus.bdd.variables.global.some-key-2=value2
./gradlew runStories -Pvividus.variables.some-key-1=value1 -Pvividus.variables.some-key-2=value2
----
+
This approach can be used only when tests are run via Gradle.
Expand All @@ -609,8 +609,8 @@ The following script assumes that we are in the root of the test project folder.
[source,shell]
----
cat > src/main/resources/overriding.properties << EOD
bdd.variables.global.some-key-1=value1
bdd.variables.global.some-key-2=value2
variables.some-key-1=value1
variables.some-key-2=value2
EOD
----
+
Expand Down
12 changes: 6 additions & 6 deletions docs/modules/commons/pages/variables.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ NOTE: The scopes names are case-insensitive.
|Variables are available in the next batches. `next_batches`-scoped variable is not available in batch it's declared within.

|`batch`
a|Such variables are declared only with `bdd.variables.batch-<batch-number>.` prefix and available throughout the execution of the batch in the suite. An attempt to create the batch-scoped variables during test execution leads to an error.
a|Such variables are declared only with `batch-<batch-number>.variables.` prefix and available throughout the execution of the batch in the suite. An attempt to create the batch-scoped variables during test execution leads to an error.

.Declaring batch variable `locale`
[source,properties]
----
bdd.variables.batch-1.locale=/us/en/
bdd.variables.batch-2.locale=/uk/en/
batch-1.variables.locale=/us/en/
batch-2.variables.locale=/uk/en/
----

.Using batch variable `locale`
Expand All @@ -82,12 +82,12 @@ When I go to the relative URL '${locale}'
----

|`global`
a|Such variables are declared only via properties with `bdd.variables.global.` prefix and available throughout the entire execution. An attempt to create the globally scoped variables during test execution leads to an error.
a|Such variables are declared only via properties with `variables.` prefix and available throughout the entire execution. An attempt to create the globally scoped variables during test execution leads to an error.

.Declaring global variable `login-endpoint`
[source,properties]
----
bdd.variables.global.login-endpoint=https://my-auth-server.com/api/login
variables.login-endpoint=https://my-auth-server.com/api/login
----

.Using global variable `login-endpoint`
Expand All @@ -114,7 +114,7 @@ may produce different results per usage.
.Declaring global variable with expression `random-user`
[source,properties]
----
bdd.variables.global.random-user=#{anyOf(superadmin,admin)}
variables.random-user=#{anyOf(superadmin,admin)}
----

.Using global variable `random-user`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -36,6 +37,7 @@ public class BatchConfiguration
private Boolean failFast;
private ScenarioExecutionConfiguration scenario;
private StoryExecutionConfiguration story;
private Map<String, String> variables = Map.of();

public String getResourceLocation()
{
Expand Down Expand Up @@ -142,6 +144,16 @@ public void setStory(StoryExecutionConfiguration story)
this.story = story;
}

public void setVariables(Map<String, String> variables)
{
this.variables = variables;
}

public Map<String, String> getVariables()
{
return variables;
}

private List<String> convertToList(String list)
{
if (list == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 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.
Expand All @@ -16,46 +16,41 @@

package org.vividus.variable;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.vividus.batch.BatchStorage;
import org.vividus.context.RunContext;
import org.vividus.util.property.IPropertyMapper;
import org.vividus.util.property.IPropertyParser;

public class VariablesFactory implements IVariablesFactory
{
private static final String VARIABLES_PREFIX = "bdd.variables.";
private static final String BATCH_PREFIX = "batch-";
private static final String VARIABLES_PROPERTY_PREFIX = VARIABLES_PREFIX + "global.";
private static final String VARIABLES_PROPERTY_PREFIX = "variables.";

private final IPropertyParser propertyParser;
private final IPropertyMapper propertyMapper;
private final BatchStorage batchStorage;
private final RunContext runContext;

private Map<String, String> globalVariables;
private Map<String, Map<String, String>> batchVariables;
private final Map<String, Object> nextBatchesVariables = new ConcurrentHashMap<>();

public VariablesFactory(IPropertyParser propertyParser, IPropertyMapper propertyMapper,
RunContext runContext)
public VariablesFactory(IPropertyParser propertyParser, RunContext runContext, BatchStorage batchStorage)
{
this.propertyParser = propertyParser;
this.propertyMapper = propertyMapper;
this.runContext = runContext;
this.batchStorage = batchStorage;
}

@SuppressWarnings({ "unchecked", "rawtypes" })
public void init() throws IOException
public void init()
{
globalVariables = propertyParser.getPropertyValuesByPrefix(VARIABLES_PROPERTY_PREFIX);
batchVariables = propertyMapper.readValues(VARIABLES_PREFIX + BATCH_PREFIX, BATCH_PREFIX::concat, Map.class)
.getData().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
batchVariables = batchStorage.getBatchConfigurations().entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey, e -> e.getValue().getVariables()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class BatchStorageTests
private static final int BATCH_2_THREADS = 5;
private static final Duration BATCH_2_TIMEOUT = Duration.ofHours(1);
private static final String BATCH_2_META_FILTERS = "grooyv: !ignored";
private static final String VALUE_1 = "value1";
private static final String VALUE_2 = "value2";

private BatchStorage batchStorage;

Expand Down Expand Up @@ -96,6 +98,8 @@ private void createBatchStorage(Map<String, String> batchConfigurations) throws
batchConfigurations.put("batch-2.story-execution-timeout", BATCH_2_TIMEOUT.toString());
batchConfigurations.put("batch-2.meta-filters", BATCH_2_META_FILTERS);
batchConfigurations.put("batch-2.fail-fast", TRUE);
batchConfigurations.put("batch-2.variables.key1", VALUE_1);
batchConfigurations.put("batch-2.variables.key2", VALUE_2);
var propertyParser = mock(PropertyParser.class);
when(propertyParser.getPropertiesByPrefix(BATCH)).thenReturn(batchConfigurations);

Expand Down Expand Up @@ -138,7 +142,8 @@ void shouldGetBatchConfigurationInitializedWithNonDefaultValues()
() -> assertEquals(List.of(BATCH_2_META_FILTERS), config.getMetaFilters()),
() -> assertTrue(config.isFailFast()),
() -> assertTrue(config.isFailStoryFast()),
() -> assertTrue(config.isFailScenarioFast())
() -> assertTrue(config.isFailScenarioFast()),
() -> assertEquals(Map.of("key1", VALUE_1, "key2", VALUE_2), config.getVariables())
);
}

Expand All @@ -158,7 +163,8 @@ private void assertDefaultBatchConfiguration(String batchKey)
() -> assertEquals(DEFAULT_META_FILTERS, config.getMetaFilters()),
() -> assertFalse(config.isFailFast()),
() -> assertNull(config.isFailStoryFast()),
() -> assertNull(config.isFailScenarioFast())
() -> assertNull(config.isFailScenarioFast()),
() -> assertEquals(Map.of(), config.getVariables())
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 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.
Expand All @@ -21,32 +21,29 @@

import java.io.IOException;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.vividus.batch.BatchConfiguration;
import org.vividus.batch.BatchStorage;
import org.vividus.context.RunContext;
import org.vividus.util.property.IPropertyMapper;
import org.vividus.util.property.PropertyMapper;
import org.vividus.util.property.PropertyParser;

@ExtendWith(MockitoExtension.class)
class VariablesFactoryTests
{
private static final String GLOBAL_PROPERTY_PREFIX = "bdd.variables.global.";
private static final String BATCH_PROPERTY_FAMILY = "bdd.variables.batch-";
private static final String GLOBAL_PROPERTY_PREFIX = "variables.";
private static final String KEY1 = "key1";
private static final String KEY2 = "key2";
private static final String KEY3 = "key3";

private static final String GLOBAL = "global";
private static final String BATCH = "batch";
private static final String NEXT_BATCHES = "next-batches";
private static final String BATCH_1 = "batch-1";

private static final Map<String, String> GLOBAL_VARIABLES = Map.of(
KEY1, GLOBAL,
Expand All @@ -56,29 +53,24 @@ class VariablesFactoryTests

@Mock private PropertyParser propertyParser;
@Mock private RunContext runContext;
@Mock private BatchStorage batchStorage;
private VariablesFactory variablesFactory;

@BeforeEach
void beforeEach()
{
IPropertyMapper propertyMapper = new PropertyMapper(".", PropertyNamingStrategies.KEBAB_CASE, propertyParser,
Set.of());
variablesFactory = new VariablesFactory(propertyParser, propertyMapper, runContext);

String batch1PropertyPrefix = BATCH_PROPERTY_FAMILY + "1.";

variablesFactory = new VariablesFactory(propertyParser, runContext, batchStorage);
when(propertyParser.getPropertyValuesByPrefix(GLOBAL_PROPERTY_PREFIX)).thenReturn(GLOBAL_VARIABLES);
when(propertyParser.getPropertiesByPrefix(BATCH_PROPERTY_FAMILY)).thenReturn(Map.of(
batch1PropertyPrefix + KEY1, BATCH,
batch1PropertyPrefix + KEY2, BATCH
));
var configuration = new BatchConfiguration();
configuration.setVariables(Map.of(KEY1, BATCH, KEY2, BATCH));
when(batchStorage.getBatchConfigurations()).thenReturn(Map.of(BATCH_1, configuration));
}

@Test
void shouldCreateVariables() throws IOException
{
variablesFactory.init();
when(runContext.getRunningBatchKey()).thenReturn("batch-1");
when(runContext.getRunningBatchKey()).thenReturn(BATCH_1);
variablesFactory.addNextBatchesVariable(KEY1, NEXT_BATCHES);
Variables variables = variablesFactory.createVariables();

Expand Down
Loading

0 comments on commit 7222acf

Please sign in to comment.