![JAR search and dependency download from the Maven repository](/logo.png)
com.consol.citrus.yaml.YamlTestCase Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2021 the original author or authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.consol.citrus.yaml;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Optional;
import com.consol.citrus.DefaultTestCase;
import com.consol.citrus.TestCase;
import com.consol.citrus.TestCaseMetaInfo;
import com.consol.citrus.exceptions.CitrusRuntimeException;
import com.consol.citrus.util.FileUtils;
import com.consol.citrus.variable.VariableUtils;
import com.consol.citrus.yaml.actions.script.ScriptDefinitionType;
/**
* @author Christoph Deppisch
*/
public class YamlTestCase {
private final DefaultTestCase delegate = new DefaultTestCase();
/**
* Gets the test case.
* @return
*/
public TestCase getTestCase() {
return delegate;
}
public void setName(String name) {
delegate.setName(name);
}
public void setDescription(String description) {
delegate.setDescription(description);
}
public void setAuthor(String author) {
delegate.getMetaInfo().setAuthor(author);
}
public void setStatus(TestCaseMetaInfo.Status status) {
delegate.getMetaInfo().setStatus(status);
}
public void setVariables(List variables) {
variables.forEach(variable -> {
if (variable.script != null) {
if (variable.script.getFile() != null) {
try {
delegate.getVariableDefinitions().put(variable.name, VariableUtils.getValueFromScript(variable.script.getType(),
FileUtils.readToString(FileUtils.getFileResource(variable.script.getFile()),
Optional.ofNullable(variable.script.getCharset()).map(Charset::forName).orElse(FileUtils.getDefaultCharset()))));
} catch (IOException e) {
throw new CitrusRuntimeException("Failed to read script file resource", e);
}
} else {
delegate.getVariableDefinitions().put(variable.name, VariableUtils.getValueFromScript(variable.script.getType(), variable.script.getValue()));
}
} else {
delegate.getVariableDefinitions().put(variable.name, variable.value);
}
});
}
public void setActions(List actions) {
actions.forEach(action -> delegate.addTestAction(action.get()));
}
public void setFinally(List actions) {
actions.forEach(action -> delegate.addTestAction(action.get()));
}
public static class Variable {
protected ScriptDefinitionType script;
protected String name;
protected String value;
public ScriptDefinitionType getScript() {
return script;
}
public void setScript(ScriptDefinitionType value) {
this.script = value;
}
public String getName() {
return name;
}
public void setName(String value) {
this.name = value;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy