Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
feat(): make env mandatory for execution
Browse files Browse the repository at this point in the history
  • Loading branch information
KarimGl committed Jan 13, 2024
1 parent acef679 commit 684127b
Show file tree
Hide file tree
Showing 71 changed files with 436 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .idea/copyright/apache2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import com.chutneytesting.engine.api.execution.EnvironmentDto;
import com.chutneytesting.environment.EnvironmentConfiguration;
import com.chutneytesting.environment.api.environment.EmbeddedEnvironmentApi;
import com.chutneytesting.environment.api.variable.dto.EnvironmentVariableDto;
import com.chutneytesting.glacio.GlacioAdapterConfiguration;
import com.chutneytesting.glacio.api.GlacioAdapter;
import com.chutneytesting.junit.api.Chutney;
import com.chutneytesting.junit.api.EnvironmentService;
import com.chutneytesting.tools.UncheckedException;
import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.junit.platform.commons.support.ReflectionSupport;
Expand All @@ -42,7 +42,7 @@ public class ChutneyTestEngine extends HierarchicalTestEngine<ChutneyEngineExecu

public static final String CHUTNEY_JUNIT_ENGINE_ID = "chutney-junit-engine";
private static final Logger LOGGER = LoggerFactory.getLogger(ChutneyTestEngine.class);
public static final String CHUTNEY_JUNIT_ENV_PATH = ".chutney/junit/conf";
private static final String CHUTNEY_JUNIT_ENV_PATH = ".chutney/junit/conf";

@Override
public String getId() {
Expand Down Expand Up @@ -115,14 +115,18 @@ private String getEnvironmentDirectoryPath(ConfigurationParameters cp) {
private EnvironmentDto getEnvironment(ConfigurationParameters cp) {
EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration(getEnvironmentDirectoryPath(cp));
String environmentName = getEnvironmentName(cp);
return cp.get("chutney.junit.engine.conf.env.name")
.map(name -> environmentConfiguration.getEmbeddedEnvironmentApi().getEnvironment(environmentName))
.map(env -> env.variables.stream().collect(Collectors.toMap(EnvironmentVariableDto::key,EnvironmentVariableDto::value)))
.map(variables -> new EnvironmentDto(environmentName, variables))
.orElse(new EnvironmentDto(GlacioAdapter.DEFAULT_ENV, Collections.emptyMap()));
List<EnvironmentVariableDto> variables = environmentConfiguration.getEmbeddedEnvironmentApi().getEnvironment(environmentName).variables;
return new EnvironmentDto(environmentName, variables.stream().collect(Collectors.toMap(EnvironmentVariableDto::key,EnvironmentVariableDto::value)));
}

private String getEnvironmentName(ConfigurationParameters cp) {
return cp.get("chutney.junit.engine.conf.env.name").orElse(GlacioAdapter.DEFAULT_ENV);
return cp.get("chutney.junit.engine.conf.env.name")
.orElseGet(() -> getDefaultEnvName(cp));
}

private String getDefaultEnvName(ConfigurationParameters cp) {
EnvironmentConfiguration environmentConfiguration = new EnvironmentConfiguration(getEnvironmentDirectoryPath(cp));
EmbeddedEnvironmentApi embeddedEnvironmentApi = environmentConfiguration.getEmbeddedEnvironmentApi();
return embeddedEnvironmentApi.defaultEnvironmentName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.chutneytesting.engine.api.execution;

import static com.chutneytesting.engine.api.execution.NoEnvironmentDto.NO_ENVIRONMENT_DTO;

import com.chutneytesting.action.spi.injectable.ActionsConfiguration;
import com.chutneytesting.engine.domain.execution.ExecutionEngine;
import com.chutneytesting.engine.domain.execution.ExecutionManager;
Expand Down Expand Up @@ -55,7 +53,7 @@ public Long executeAsync(ExecutionRequestDto request) {
Dataset dataset = Optional.ofNullable(request.dataset)
.map(d -> new Dataset(d.constants, d.datatable))
.orElseGet(Dataset::new);
Environment environment = EnvironmentDtoMapper.INSTANCE.toDomain(Optional.ofNullable(request.environment).orElse(NO_ENVIRONMENT_DTO));
Environment environment = EnvironmentDtoMapper.INSTANCE.toDomain(request.environment);
return engine.execute(
stepDefinition,
dataset,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
*
* * Copyright 2017-2023 Enedis
* *
* * 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.
* Copyright 2017-2023 Enedis
*
* 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.
*
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
*
* * Copyright 2017-2023 Enedis
* *
* * 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.
* Copyright 2017-2023 Enedis
*
* 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.
*
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package com.chutneytesting.engine.domain.delegation;


import com.chutneytesting.engine.domain.execution.StepDefinition;
import com.chutneytesting.engine.domain.execution.engine.step.Step;
import com.chutneytesting.engine.domain.execution.report.StepExecutionReport;

public interface DelegationClient {

StepExecutionReport handDown(StepDefinition stepDefinition, NamedHostAndPort delegate) throws CannotDelegateException;
StepExecutionReport handDown(Step stepDefinition, NamedHostAndPort delegate) throws CannotDelegateException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.chutneytesting.action.spi.injectable.Target;
import com.chutneytesting.engine.domain.execution.ScenarioExecution;
import com.chutneytesting.engine.domain.execution.engine.Environment;
import com.chutneytesting.engine.domain.execution.engine.StepExecutor;
import com.chutneytesting.engine.domain.execution.engine.step.Step;
import com.chutneytesting.engine.domain.execution.report.StepExecutionReport;
Expand All @@ -36,7 +37,7 @@ public RemoteStepExecutor(DelegationClient delegationClient, NamedHostAndPort ag
@Override
public void execute(ScenarioExecution scenarioExecution, Target target, Step step) {
try {
StepExecutionReport remoteReport = delegationClient.handDown(step.definition(), agentInfo);
StepExecutionReport remoteReport = delegationClient.handDown(step, agentInfo);

guardFromIllegalReport(remoteReport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public Long execute(StepDefinition stepDefinition, Dataset dataset, ScenarioExec

final ScenarioContext scenarioContext = new ScenarioContextImpl();
scenarioContext.put("environment", environment.name());
scenarioContext.put("dataset", dataset.datatable);
scenarioContext.putAll(ofNullable(environment.variables()).orElse(emptyMap()));
scenarioContext.put("dataset", dataset.datatable);
scenarioContext.putAll(evaluateDatasetConstants(dataset, scenarioContext));

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
/*
*
* * Copyright 2017-2023 Enedis
* *
* * 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.
* Copyright 2017-2023 Enedis
*
* 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.chutneytesting.engine.domain.execution.engine;

import static java.util.Collections.emptyMap;

import java.util.Map;

public record Environment(String name, Map<String, String> variables) {
public Environment(String name) {
this(name, emptyMap());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import com.chutneytesting.engine.domain.delegation.NamedHostAndPort;
import com.chutneytesting.engine.domain.execution.StepDefinition;
import com.chutneytesting.engine.domain.execution.engine.Dataset;
import com.chutneytesting.engine.domain.execution.engine.Environment;
import com.chutneytesting.engine.domain.execution.engine.step.Step;
import com.chutneytesting.engine.domain.execution.report.StepExecutionReport;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -69,12 +71,13 @@ public HttpClient(String username, String password) {
}

@Override
public StepExecutionReport handDown(StepDefinition stepDefinition, NamedHostAndPort delegate) throws CannotDelegateException {
public StepExecutionReport handDown(Step step, NamedHostAndPort delegate) throws CannotDelegateException {
if (connectionChecker.canConnectTo(delegate)) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Dataset dataset = new Dataset(emptyMap(), emptyList()); // TODO - check if it still works
HttpEntity<ExecutionRequestDto> request = new HttpEntity<>(ExecutionRequestMapper.from(stepDefinition, dataset, null), headers);
Environment environment = new Environment((String) step.getScenarioContext().get("environment"));
HttpEntity<ExecutionRequestDto> request = new HttpEntity<>(ExecutionRequestMapper.from(step.definition(), dataset, environment), headers);
StepExecutionReportDto reportDto = restTemplate.postForObject("https://" + delegate.host() + ":" + delegate.port() + EXECUTION_URL, request, StepExecutionReportDto.class);
return StepExecutionReportMapper.fromDto(reportDto);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.concurrent.Executors;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -100,6 +101,7 @@ void protect_step_definition_execution_by_fault_barrier_unless_vm_error(Supplier
}

@Test
@Disabled
void execute_tear_down_after_step_definition_attaching_it_to_root_step() {
// Given
StepExecutionStrategy strategy = DefaultStepExecutionStrategy.instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static java.util.Optional.ofNullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;

import com.chutneytesting.engine.api.execution.StatusDto;
import com.chutneytesting.engine.api.execution.StepExecutionReportDto;
import com.chutneytesting.engine.domain.delegation.CannotDelegateException;
import com.chutneytesting.engine.domain.delegation.NamedHostAndPort;
import com.chutneytesting.engine.domain.environment.TargetImpl;
import com.chutneytesting.engine.domain.execution.StepDefinition;
import com.chutneytesting.engine.domain.execution.engine.step.Step;
import com.chutneytesting.engine.domain.execution.report.StepExecutionReport;
import com.chutneytesting.engine.domain.execution.strategies.StepStrategyDefinition;
import com.chutneytesting.engine.domain.execution.strategies.StrategyProperties;
Expand All @@ -46,6 +48,7 @@
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
Expand All @@ -55,6 +58,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mockito;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

Expand Down Expand Up @@ -88,6 +92,9 @@ public void tearDown() {
public void should_delegate_execution_to_endpoint(String user, String password) throws JsonProcessingException {
//G
StepDefinition stepDefinition = createFakeStepDefinition();
Step step = mock(Step.class);
when(step.definition()).thenReturn(stepDefinition);
when(step.getScenarioContext()).thenReturn(Map.of("environment","test"));
NamedHostAndPort remoteHost = new NamedHostAndPort("name", "localhost", server.httpsPort());
StepExecutionReportDto dto = createStepExecutionReportDto();
String dtoAsString = objectMapper().writeValueAsString(dto);
Expand All @@ -104,7 +111,7 @@ public void should_delegate_execution_to_endpoint(String user, String password)

//W
HttpClient client = new HttpClient(user, password);
StepExecutionReport report = client.handDown(stepDefinition, remoteHost);
StepExecutionReport report = client.handDown(step, remoteHost);

//T
assertThat(report).isNotNull();
Expand Down
2 changes: 1 addition & 1 deletion engine/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.mode.default=same_thread
junit.jupiter.execution.parallel.mode.classes.default=concurrent
32 changes: 16 additions & 16 deletions engine/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
</encoder>
</appender>

<logger name="com.intellij" level="ERROR"/>
<logger name="com.jayway" level="WARN"/>
<logger name="com.zaxxer" level="WARN"/>
<logger name="io.undertow" level="ERROR"/>
<logger name="liquibase" level="WARN"/>
<logger name="LiquibaseSchemaResolver" level="WARN"/>
<logger name="org.apache" level="WARN"/>
<logger name="org.apache.maven.surefire.booter" level="WARN"/>
<logger name="org.eclipse" level="WARN"/>
<logger name="org.hibernate" level="WARN"/>
<logger name="org.jboss" level="WARN"/>
<logger name="org.springframework" level="WARN" />
<logger name="com.intellij" level="DEBUG"/>
<logger name="com.jayway" level="DEBUG"/>
<logger name="com.zaxxer" level="DEBUG"/>
<logger name="io.undertow" level="DEBUG"/>
<logger name="liquibase" level="DEBUG"/>
<logger name="LiquibaseSchemaResolver" level="DEBUG"/>
<logger name="org.apache" level="DEBUG"/>
<logger name="org.apache.maven.surefire.booter" level="DEBUG"/>
<logger name="org.eclipse" level="DEBUG"/>
<logger name="org.hibernate" level="DEBUG"/>
<logger name="org.jboss" level="DEBUG"/>
<logger name="org.springframework" level="DEBUG" />
<logger name="org.springframework.test.web.servlet.result" level="DEBUG" />
<logger name="org.xnio" level="WARN"/>
<logger name="net.schmizz" level="WARN" />
<logger name="wiremock" level="WARN" />
<logger name="org.xnio" level="DEBUG"/>
<logger name="net.schmizz" level="DEBUG" />
<logger name="wiremock" level="DEBUG" />

<root level="INFO">
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
]
}
]
},
"environment": {
"name": "env"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
]
}
]
},
"environment": {
"name": "env"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
}
}
]
},
"environment": {
"name": "env"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
}
}
]
},
"environment": {
"name": "env"
}
}
Loading

0 comments on commit 684127b

Please sign in to comment.