diff --git a/allure-generator/build.gradle b/allure-generator/build.gradle index da3527b27..314e4763d 100644 --- a/allure-generator/build.gradle +++ b/allure-generator/build.gradle @@ -58,6 +58,7 @@ dependencies { compile('org.apache.tika:tika-core') compile('commons-io:commons-io') compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml') + compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml' compile('org.apache.httpcomponents:httpclient') compileOnly('org.projectlombok:lombok') diff --git a/allure-generator/src/main/java/io/qameta/allure/allure1/Allure1Plugin.java b/allure-generator/src/main/java/io/qameta/allure/allure1/Allure1Plugin.java index 609f346cd..283f6df7e 100644 --- a/allure-generator/src/main/java/io/qameta/allure/allure1/Allure1Plugin.java +++ b/allure-generator/src/main/java/io/qameta/allure/allure1/Allure1Plugin.java @@ -1,6 +1,10 @@ package io.qameta.allure.allure1; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.type.TypeFactory; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; import io.qameta.allure.Reader; import io.qameta.allure.context.RandomUidContext; import io.qameta.allure.core.Configuration; @@ -26,7 +30,6 @@ import ru.yandex.qatools.allure.model.TestCaseResult; import ru.yandex.qatools.allure.model.TestSuiteResult; -import javax.xml.bind.JAXB; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; @@ -51,6 +54,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static com.fasterxml.jackson.databind.MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME; import static io.qameta.allure.entity.LabelName.ISSUE; import static io.qameta.allure.entity.LabelName.PACKAGE; import static io.qameta.allure.entity.LabelName.PARENT_SUITE; @@ -68,7 +72,6 @@ import static java.util.Comparator.naturalOrder; import static java.util.Comparator.nullsFirst; import static java.util.stream.Collectors.toList; -import static org.allurefw.allure1.AllureUtils.unmarshalTestSuite; /** * Plugin that reads results from Allure1 data format. @@ -90,7 +93,17 @@ public class Allure1Plugin implements Reader { public static final String ENVIRONMENT_BLOCK_NAME = "environment"; public static final String ALLURE1_RESULTS_FORMAT = "allure1"; - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper jsonMapper = new ObjectMapper(); + private final ObjectMapper xmlMapper; + + public Allure1Plugin() { + final SimpleModule module = new SimpleModule() + .addDeserializer(ru.yandex.qatools.allure.model.Status.class, new StatusDeserializer()); + xmlMapper = new XmlMapper() + .configure(USE_WRAPPER_NAME_AS_PROPERTY_NAME, true) + .setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())) + .registerModule(module); + } @Override public void readResults(final Configuration configuration, @@ -415,8 +428,8 @@ private Stream jsonFiles(final Path source) { } private Optional readXmlTestSuiteFile(final Path source) { - try { - return Optional.of(unmarshalTestSuite(source)); + try (InputStream is = Files.newInputStream(source)) { + return Optional.of(xmlMapper.readValue(is, TestSuiteResult.class)); } catch (IOException e) { LOGGER.debug("Could not read result {}: {}", source, e); } @@ -425,7 +438,7 @@ private Optional readXmlTestSuiteFile(final Path source) { private Optional readJsonTestSuiteFile(final Path source) { try (InputStream is = Files.newInputStream(source)) { - return Optional.of(mapper.readValue(is, TestSuiteResult.class)); + return Optional.of(jsonMapper.readValue(is, TestSuiteResult.class)); } catch (IOException e) { LOGGER.debug("Could not read result {}: {}", source, e); return Optional.empty(); @@ -489,7 +502,7 @@ private Map processEnvironmentXml(final Path directory) { final Map items = new HashMap<>(); if (Files.exists(envXmlFile)) { try (InputStream fis = Files.newInputStream(envXmlFile)) { - JAXB.unmarshal(fis, ru.yandex.qatools.commons.model.Environment.class).getParameter().forEach(p -> + xmlMapper.readValue(fis, ru.yandex.qatools.commons.model.Environment.class).getParameter().forEach(p -> items.put(p.getKey(), p.getValue()) ); } catch (Exception e) { diff --git a/allure-generator/src/main/java/io/qameta/allure/allure1/StatusDeserializer.java b/allure-generator/src/main/java/io/qameta/allure/allure1/StatusDeserializer.java new file mode 100644 index 000000000..ad2ec0f23 --- /dev/null +++ b/allure-generator/src/main/java/io/qameta/allure/allure1/StatusDeserializer.java @@ -0,0 +1,28 @@ +package io.qameta.allure.allure1; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import ru.yandex.qatools.allure.model.Status; + +import java.io.IOException; +import java.util.stream.Stream; + +/** + * @author charlie (Dmitry Baev). + */ +public class StatusDeserializer extends StdDeserializer { + + protected StatusDeserializer() { + super(io.qameta.allure.model.Status.class); + } + + @Override + public Status deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException { + String value = p.readValueAs(String.class); + return Stream.of(Status.values()) + .filter(status -> status.value().equalsIgnoreCase(value)) + .findAny() + .orElse(null); + } +} diff --git a/allure-plugin-api/build.gradle b/allure-plugin-api/build.gradle index 3bd8d4c7b..1d65e65c2 100644 --- a/allure-plugin-api/build.gradle +++ b/allure-plugin-api/build.gradle @@ -5,6 +5,7 @@ apply from: "${gradleScriptDir}/bintray.gradle" apply plugin: 'maven' dependencies { + compile('javax.xml.bind:jaxb-api') compile('com.fasterxml.jackson.core:jackson-databind') compile('com.fasterxml.jackson.module:jackson-module-jaxb-annotations') compile('com.vladsch.flexmark:flexmark') diff --git a/build.gradle b/build.gradle index 19f43997c..fa8baac2e 100644 --- a/build.gradle +++ b/build.gradle @@ -90,6 +90,7 @@ allprojects { dependency 'commons-io:commons-io:2.5' dependency 'io.qameta.allure:allure-java-commons:2.0-BETA18' dependency 'io.qameta.allure:allure2-model-api:1.0-BETA4' + dependency 'javax.xml.bind:jaxb-api:2.3.0' dependency 'junit:junit:4.12' dependency 'org.allurefw:allure1-model:1.0' dependency 'org.apache.commons:commons-lang3:3.6'