Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add karate plugin in ara #827

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Optional;

import com.decathlon.ara.scenario.karate.indexer.KarateScenariosIndexer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -26,13 +27,16 @@ public class ScenariosIndexerStrategy {

private final CypressScenariosIndexer cypressScenariosIndexer;

private final KarateScenariosIndexer karateScenariosIndexer;

public ScenariosIndexerStrategy(GenericScenariosIndexer genericScenariosIndexer,
PostmanScenariosIndexer postmanScenariosIndexerService,
CucumberScenariosIndexer cucumberScenariosIndexerService, CypressScenariosIndexer cypressScenariosIndexer) {
PostmanScenariosIndexer postmanScenariosIndexerService,
CucumberScenariosIndexer cucumberScenariosIndexerService, CypressScenariosIndexer cypressScenariosIndexer, KarateScenariosIndexer karateScenariosIndexer) {
this.genericScenariosIndexer = genericScenariosIndexer;
this.postmanScenariosIndexerService = postmanScenariosIndexerService;
this.cucumberScenariosIndexerService = cucumberScenariosIndexerService;
this.cypressScenariosIndexer = cypressScenariosIndexer;
this.karateScenariosIndexer = karateScenariosIndexer;
}

/**
Expand All @@ -54,6 +58,8 @@ public Optional<ScenariosIndexer> getScenariosIndexer(Technology technology) {
return Optional.of(postmanScenariosIndexerService);
case CYPRESS:
return Optional.of(cypressScenariosIndexer);
case KARATE:
return Optional.of(karateScenariosIndexer);
default:
LOG.info("The technology {} is not handled yet. It may be a great feature request ;)", technology);
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/******************************************************************************
* Copyright (C) 2020 by the ARA Contributors *
* *
* 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.decathlon.ara.scenario.karate.bean;

import com.decathlon.ara.scenario.karate.bean.description.KarateExecutedScenarioDescription;
import com.decathlon.ara.scenario.karate.bean.display.KarateExecutedScenarioResultsDisplay;
import com.decathlon.ara.scenario.karate.bean.error.KarateExecutedScenarioError;
import com.decathlon.ara.scenario.karate.bean.feature.KarateExecutedScenarioFeature;
import com.decathlon.ara.scenario.karate.bean.log.KarateExecutedScenarioLogs;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@JsonIgnoreProperties(ignoreUnknown = true)
public class KarateExecutedScenarioReport {

private String code;

private String name;

private KarateExecutedScenarioFeature feature;

private KarateExecutedScenarioDescription description;

@JsonProperty("start")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss")
private Date startDate;

private boolean ignored;

private List<KarateExecutedScenarioError> errors;

private List<Long> cartography;

private KarateExecutedScenarioResultsDisplay display;

private KarateExecutedScenarioLogs logs;

private List<String> tags;

private String severity;

@JsonProperty("server")
private String serverName;

private String comment;

/**
* Get functionalities name
* @return the functionalities name
*/
public String getFunctionalitiesName() {
String cartographyAsString = "";
if (!CollectionUtils.isEmpty(cartography)) {
String cartographyIdsAsString = cartography
.stream()
.map(String::valueOf)
.collect(Collectors.joining(", "));
cartographyAsString = String.format("Functionality %s", cartographyIdsAsString);
}
String separator = "";
if (StringUtils.isNotBlank(cartographyAsString) && StringUtils.isNotBlank(name)) {
separator = ": ";
}
return String.format("%s%s%s", cartographyAsString, separator, StringUtils.isBlank(name) ? "" : name);
}

/**
* Convert tags into a string. If no tags, then return an empty string
* @param tags the tags to convert
* @return the string representation of the tags
*/
public static String convertTagsToString(List<String> tags) {
if (CollectionUtils.isEmpty(tags)) {
return "";
}
return tags
.stream()
.map(tag -> String.format("@%s", tag))
.collect(Collectors.joining(" "));
}

/**
* Get tags representation as string
* @return tags representation as string
*/
public String getTagsAsString() {
return convertTagsToString(tags);
}

/**
* Get country codes as string from tags and feature tags
* @return country codes as string
*/
public String getCountryCodesAsString() {
List<String> countryCodes = getCountryCodes();
if (CollectionUtils.isEmpty(countryCodes)) {
return "all";
}
return countryCodes.stream().collect(Collectors.joining(","));
}

/**
* Get country codes from tags and feature tags
* @return country codes
*/
public List<String> getCountryCodes() {
List<String> countryCodesFromTags = getCountryCodesFromTags(tags);
List<String> countryCodesFromFeatureTags = feature != null ? getCountryCodesFromTags(feature.getTags()) : new ArrayList<>();
return Stream.of(countryCodesFromTags, countryCodesFromFeatureTags)
.flatMap(Collection::stream)
.distinct()
.toList();
}

/**
* Get country codes from tags
* @param tags the tags to get the country codes from
* @return country codes
*/
private static List<String> getCountryCodesFromTags(List<String> tags) {
if (CollectionUtils.isEmpty(tags)) {
return new ArrayList<>();
}
return tags.stream()
.filter(tag -> tag.startsWith("country-"))
.map(tag -> tag.substring("country-".length()))
.distinct()
.toList();
}

public String getCode() {
return code;
}

public String getName() {
return name;
}

public KarateExecutedScenarioFeature getFeature() {
return feature;
}

public KarateExecutedScenarioDescription getDescription() {
return description;
}

public Date getStartDate() {
return startDate;
}

public boolean isIgnored() {
return ignored;
}

public List<KarateExecutedScenarioError> getErrors() {
return errors;
}

public List<Long> getCartography() {
return cartography;
}

public KarateExecutedScenarioResultsDisplay getDisplay() {
return display;
}

public KarateExecutedScenarioLogs getLogs() {
return logs;
}

public List<String> getTags() {
return tags;
}

public String getSeverity() {
return severity;
}

public String getServerName() {
return serverName;
}

public String getComment() {
return comment;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/******************************************************************************
* Copyright (C) 2020 by the ARA Contributors *
* *
* 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.decathlon.ara.scenario.karate.bean.description;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@JsonIgnoreProperties(ignoreUnknown = true)
public class KarateExecutedScenarioDescription {

private List<KarateExecutedScenarioStep> steps;

@JsonProperty("start_line")
private Integer startLineNumber;

/**
* Get a string displaying all the steps content
* @return the steps content
*/
public String getStepsContent() {
if (CollectionUtils.isEmpty(steps)) {
return "";
}
return steps.stream()
.map(KarateExecutedScenarioStep::getStepLine)
.collect(Collectors.joining("\n"));
}

public List<KarateExecutedScenarioStep> getSteps() {
return steps;
}

public Integer getStartLineNumber() {
return startLineNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/******************************************************************************
* Copyright (C) 2020 by the ARA Contributors *
* *
* 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.decathlon.ara.scenario.karate.bean.description.step;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.Optional;

@JsonIgnoreProperties(ignoreUnknown = true)
public class KarateExecutedScenarioStep {

private Long line;

private String status;

private Long value;

private String content;

public Optional<Long> getOptionalValue() {
return Optional.ofNullable(value);
}

/**
* Get step line as string
* @return get step line
*/
public String getStepLine() {
String valueAsString = getOptionalValue()
.map(String::valueOf)
.map(v -> ":" + v)
.orElse("");
return String.format("%d:%s%s:%s", line, status, valueAsString, content);
}

public Long getLine() {
return line;
}

public String getStatus() {
return status;
}

public Long getValue() {
return value;
}

public String getContent() {
return content;
}
}
Loading
Loading