
website.automate.waml.io.reader.WamlReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of waml-io Show documentation
Show all versions of waml-io Show documentation
(De)Serializer of the web automation markup language (WAML) for Java
The newest version!
package website.automate.waml.io.reader;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import website.automate.waml.io.model.main.Scenario;
import website.automate.waml.io.model.main.action.Action;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;
import static java.text.MessageFormat.format;
public class WamlReader {
private ObjectMapper objectMapper;
public WamlReader(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
public Scenario read(File file) {
String path = file.getPath();
String name = file.getName();
try {
List steps = readSteps(new FileInputStream(file));
return createScenario(name, path, steps);
} catch (Exception e) {
throw new WamlDeserializationException(format("Failed to open file {0}.", path), e);
}
}
private Scenario createScenario(String name, String path, List steps) {
Scenario scenario = new Scenario();
scenario.setPath(path);
scenario.setName(name);
scenario.setSteps(steps);
return scenario;
}
private List readSteps(InputStream inputStream) {
try {
return objectMapper.readValue(
inputStream,
objectMapper
.getTypeFactory()
.constructType(new TypeReference>() {
})
);
} catch (Exception e) {
if (e instanceof WamlDeserializationException) {
throw (WamlDeserializationException) e;
} else {
throw new WamlDeserializationException(
"Failed to deserialize from stream.", e);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy