Skip to content

Commit

Permalink
feat: add generic adapter (#405)
Browse files Browse the repository at this point in the history
* feat: add generic executions

* feat: add generic cartography

* test: add generic cartography

* doc: add generic adapter documentation

* chore: update api to 8.1.0

* chore: update web-ui to 8.1.0

* fix: remove timed annotation

* fix: sonar lombok analysis

Co-authored-by: Thomas GRUSON <thomas.gruson@protonmail.com>
  • Loading branch information
omar-chahbouni-decathlon and Thomas GRUSON authored Mar 23, 2021
1 parent a7152b7 commit 342d987
Show file tree
Hide file tree
Showing 33 changed files with 2,079 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
with:
java-version: '14'
- name: Analyze with SonarCloud
run: mvn -B -f code/api/pom.xml verify
run: mvn -B -f code/api/pom.xml clean install dependency:copy-dependencies
- name: Setup sonar-scanner
uses: warchant/setup-sonar-scanner@v3
- name: SonarCloud Scan
Expand Down
2 changes: 1 addition & 1 deletion code/api/database/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>com.decathlon.ara</groupId>
<artifactId>ara-database</artifactId>
<version>8.0.3</version>
<version>8.1.0</version>

<name>ARA Database</name>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
public enum Technology {

GENERIC,

/**
* Cucumber job (no matter if it runs Selenium or other technologies like RestAssured or Karate): index its
* report.json result.
Expand Down
2 changes: 1 addition & 1 deletion code/api/generated-cucumber-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<groupId>com.decathlon.ara</groupId>
<artifactId>ara-generated-cucumber-report</artifactId>
<version>8.0.3</version>
<version>8.1.0</version>

<name>ARA Cucumber</name>
<description>
Expand Down
2 changes: 1 addition & 1 deletion code/api/jacoco-aggregation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>ara-parent</artifactId>
<groupId>com.decathlon.ara</groupId>
<version>8.0.3</version>
<version>8.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion code/api/lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<groupId>com.decathlon.ara</groupId>
<artifactId>ara-lib</artifactId>
<version>8.0.3</version>
<version>8.1.0</version>

<properties>
<java.version>14</java.version>
Expand Down
2 changes: 1 addition & 1 deletion code/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<groupId>com.decathlon.ara</groupId>
<artifactId>ara-parent</artifactId>
<packaging>pom</packaging>
<version>8.0.3</version>
<version>8.1.0</version>

<name>ARA API</name>
<description>
Expand Down
2 changes: 1 addition & 1 deletion code/api/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>com.decathlon.ara</groupId>
<artifactId>ara-server</artifactId>
<version>8.0.3</version>
<version>8.1.0</version>

<name>ARA Server</name>
<description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.decathlon.ara.domain.enumeration.Technology;
import com.decathlon.ara.scenario.cucumber.indexer.CucumberScenariosIndexer;
import com.decathlon.ara.scenario.cypress.indexer.CypressScenariosIndexer;
import com.decathlon.ara.scenario.generic.indexer.GenericScenariosIndexer;
import com.decathlon.ara.scenario.postman.indexer.PostmanScenariosIndexer;
import com.decathlon.ara.scenario.common.indexer.ScenariosIndexer;
import lombok.NonNull;
Expand All @@ -18,6 +19,9 @@
@Slf4j
public class ScenariosIndexerStrategy {

@NonNull
private final GenericScenariosIndexer genericScenariosIndexer;

@NonNull
private final PostmanScenariosIndexer postmanScenariosIndexerService;

Expand All @@ -38,6 +42,8 @@ public Optional<ScenariosIndexer> getScenariosIndexer(Technology technology) {
return Optional.empty();
}
switch (technology) {
case GENERIC:
return Optional.of(genericScenariosIndexer);
case CUCUMBER:
return Optional.of(cucumberScenariosIndexerService);
case POSTMAN:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/******************************************************************************
* 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.generic.bean;

import com.decathlon.ara.scenario.generic.bean.description.GenericExecutedScenarioDescription;
import com.decathlon.ara.scenario.generic.bean.display.GenericExecutedScenarioResultsDisplay;
import com.decathlon.ara.scenario.generic.bean.error.GenericExecutedScenarioError;
import com.decathlon.ara.scenario.generic.bean.feature.GenericExecutedScenarioFeature;
import com.decathlon.ara.scenario.generic.bean.log.GenericExecutedScenarioLogs;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
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;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class GenericExecutedScenarioReport {

private String code;

private String name;

private GenericExecutedScenarioFeature feature;

private GenericExecutedScenarioDescription description;

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

private boolean ignored;

private List<GenericExecutedScenarioError> errors;

private List<Long> cartography;

private GenericExecutedScenarioResultsDisplay display;

private GenericExecutedScenarioLogs 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()
.collect(Collectors.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()
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/******************************************************************************
* 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.generic.bean.description;

import com.decathlon.ara.scenario.generic.bean.description.step.GenericExecutedScenarioStep;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import org.springframework.util.CollectionUtils;

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

@Data
@With
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class GenericExecutedScenarioDescription {

private List<GenericExecutedScenarioStep> 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(GenericExecutedScenarioStep::getStepLine)
.collect(Collectors.joining("\n"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/******************************************************************************
* 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.generic.bean.description.step;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;

import java.util.Optional;

@Data
@With
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class GenericExecutedScenarioStep {

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);
}
}
Loading

0 comments on commit 342d987

Please sign in to comment.