Skip to content

Commit

Permalink
Feature/pipeline spec2 (#697)
Browse files Browse the repository at this point in the history
* add pipeline spec
  • Loading branch information
s2oBCN committed Sep 4, 2021
1 parent 6b7379c commit 87c6579
Show file tree
Hide file tree
Showing 1,128 changed files with 49,631 additions and 96 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
- Add functional test to LevaDoc ([#697](https://github.com/opendevstack/ods-jenkins-shared-library/pull/697))
- Throw controlled exception when testIssue has no component assigned ([#693](https://github.com/opendevstack/ods-jenkins-shared-library/pull/693))
- Fix sort tests steps in TCP and TCR documentsn ([#652](https://github.com/opendevstack/ods-jenkins-shared-library/pull/652))
- Fixed environment value of SonarQube edition ([#618](https://github.com/opendevstack/ods-jenkins-shared-library/issues/618))
Expand Down
19 changes: 17 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ext {
repositories {
if (no_nexus) {
println("using repositories 'jcenter' and 'mavenCentral'")
mavenLocal()
jcenter()
mavenCentral()
maven {
Expand Down Expand Up @@ -72,7 +73,7 @@ dependencies {
implementation "fr.opensagres.xdocreport:fr.opensagres.poi.xwpf.converter.pdf:2.0.2"
implementation "net.lingala.zip4j:zip4j:2.1.1"
implementation "org.apache.ivy:ivy:2.2.0"
implementation "org.apache.pdfbox:pdfbox:2.0.17"
implementation "org.apache.pdfbox:pdfbox:2.0.23"
implementation "org.apache.poi:poi:4.0.1"
implementation "org.yaml:snakeyaml:1.24"
implementation 'com.vladsch.flexmark:flexmark-all:0.60.2' // for markdown to pdf conversion (sonarqube reports)
Expand All @@ -82,12 +83,13 @@ dependencies {
testImplementation ("com.athaydes:spock-reports:1.6.0") { transitive = false }
testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.19.0'
testImplementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
testImplementation "com.lesfurets:jenkins-pipeline-unit:1.3"
testImplementation "com.lesfurets:jenkins-pipeline-unit:1.9"
testImplementation "net.bytebuddy:byte-buddy:1.10.8"
testImplementation "org.objenesis:objenesis:3.1"
testImplementation "cglib:cglib-nodep:3.3.0" // for mocking classes
testImplementation "com.github.stefanbirkner:system-rules:1.19.0" // for managing environment variables
testImplementation "com.github.tomakehurst:wiremock:2.27.0" // for mocking HTTP server reponses
testImplementation "com.github.tomakehurst:wiremock-jre8:2.29.0" // for mocking HTTP server reponses
testImplementation "org.hamcrest:hamcrest:2.1"
testImplementation "org.skyscreamer:jsonassert:1.5.0" // JSON Asserts
}
Expand Down Expand Up @@ -119,6 +121,19 @@ test {
}
systemProperty 'com.athaydes.spockframework.report.projectName', 'ods-jenkins-shared-library'
systemProperty 'com.athaydes.spockframework.report.projectVersion', version
maxHeapSize = "2048m"
jvmArgs "-XX:MaxPermSize=256m"
systemProperty "testRecordMode", project.findProperty('testRecordMode')?: false
systemProperty "generateExpectedPdfFiles", project.findProperty('generateExpectedPdfFiles')?: false
systemProperty "nexusURL", project.findProperty('nexusURL')?: "http://nexus.odsbox.lan:7990"
systemProperty "sonarQuURL", project.findProperty('sonarQuURL')?: "http://sonar.odsbox.lan:7990"
systemProperty "bitbucketURL", project.findProperty('bitbucketURL')?: "http://bitbucket.odsbox.lan:7990"
systemProperty "docGenURL", project.findProperty('docGenURL')?: "http://docgen.odsbox.lan:8080"
systemProperty "jiraURL", project.findProperty('jiraURL')?: "http://jira.odsbox.lan:8080"
systemProperty "domainUser", project.findProperty('domainUser')?: "openshift"
systemProperty "domainPassword", project.findProperty('domainPassword')?: "openshift"
systemProperty "nexusUser", project.findProperty('nexusUser')?: "openshift"
systemProperty "nexusPassword", project.findProperty('nexusPassword')?: "openshift"
}

codenarc {
Expand Down
3 changes: 2 additions & 1 deletion src/org/ods/orchestration/InitStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ class InitStage extends Stage {
registry.get(OpenShiftService),
registry.get(PDFUtil),
registry.get(SonarQubeUseCase),
registry.get(BitbucketTraceabilityUseCase)
registry.get(BitbucketTraceabilityUseCase),
logger
)
)

Expand Down
63 changes: 36 additions & 27 deletions src/org/ods/orchestration/usecase/LeVADocumentUseCase.groovy
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.ods.orchestration.usecase

import com.cloudbees.groovy.cps.NonCPS

import java.time.LocalDateTime
import groovy.xml.XmlUtil
import org.ods.orchestration.scheduler.LeVADocumentScheduler
import org.ods.orchestration.service.DocGenService
import org.ods.orchestration.service.LeVADocumentChaptersFileService
import org.ods.orchestration.util.*
import org.ods.services.GitService
import org.ods.services.JenkinsService
import org.ods.services.NexusService
import org.ods.services.OpenShiftService
import org.ods.orchestration.scheduler.LeVADocumentScheduler
import org.ods.orchestration.service.*
import org.ods.orchestration.util.*
import org.ods.services.ServiceRegistry
import org.ods.util.ILogger
import org.ods.util.IPipelineSteps
import org.ods.util.Logger

import groovy.xml.XmlUtil
import java.time.LocalDateTime

@SuppressWarnings(['IfStatementBraces',
'LineLength',
Expand All @@ -34,7 +33,6 @@ import groovy.xml.XmlUtil
class LeVADocumentUseCase extends DocGenUseCase {

enum DocumentType {

CSD,
DIL,
DTP,
Expand All @@ -53,7 +51,6 @@ class LeVADocumentUseCase extends DocGenUseCase {
OVERALL_DTR,
OVERALL_IVR,
OVERALL_TIR

}

protected static Map DOCUMENT_TYPE_NAMES = [
Expand Down Expand Up @@ -98,15 +95,20 @@ class LeVADocumentUseCase extends DocGenUseCase {
private final OpenShiftService os
private final SonarQubeUseCase sq
private final BitbucketTraceabilityUseCase bbt
private final ILogger logger

LeVADocumentUseCase(Project project, IPipelineSteps steps, MROPipelineUtil util, DocGenService docGen, JenkinsService jenkins, JiraUseCase jiraUseCase, JUnitTestReportsUseCase junit, LeVADocumentChaptersFileService levaFiles, NexusService nexus, OpenShiftService os, PDFUtil pdf, SonarQubeUseCase sq, BitbucketTraceabilityUseCase bbt) {
LeVADocumentUseCase(Project project, IPipelineSteps steps, MROPipelineUtil util, DocGenService docGen,
JenkinsService jenkins, JiraUseCase jiraUseCase, JUnitTestReportsUseCase junit,
LeVADocumentChaptersFileService levaFiles, NexusService nexus, OpenShiftService os,
PDFUtil pdf, SonarQubeUseCase sq, BitbucketTraceabilityUseCase bbt, ILogger logger) {
super(project, steps, util, docGen, nexus, pdf, jenkins)
this.jiraUseCase = jiraUseCase
this.junit = junit
this.levaFiles = levaFiles
this.os = os
this.sq = sq
this.bbt = bbt
this.logger = logger
}

@NonCPS
Expand Down Expand Up @@ -247,8 +249,9 @@ class LeVADocumentUseCase extends DocGenUseCase {
}

String createDTR(Map repo, Map data) {
def documentType = DocumentType.DTR as String
logger.debug("createDTR - repo:${repo}, data:${data}")

def documentType = DocumentType.DTR as String
Map resurrectedDocument = resurrectAndStashDocument(documentType, repo)
this.steps.echo "Resurrected ${documentType} for ${repo.id} -> (${resurrectedDocument.found})"
if (resurrectedDocument.found) {
Expand Down Expand Up @@ -483,9 +486,10 @@ class LeVADocumentUseCase extends DocGenUseCase {
}

@SuppressWarnings('CyclomaticComplexity')
String createCFTR(Map repo, Map data) {
def documentType = DocumentType.CFTR as String
String createCFTR(Map repo = null, Map data) {
logger.debug("createCFTR - data:${data}")

def documentType = DocumentType.CFTR as String
def acceptanceTestData = data.tests.acceptance
def integrationTestData = data.tests.integration

Expand Down Expand Up @@ -706,7 +710,9 @@ class LeVADocumentUseCase extends DocGenUseCase {
.flatten()
}

String createIVR(Map repo, Map data) {
String createIVR(Map repo = null, Map data) {
logger.debug("createIVR - data:${data}")

def documentType = DocumentType.IVR as String

def installationTestData = data.tests.installation
Expand Down Expand Up @@ -772,13 +778,10 @@ class LeVADocumentUseCase extends DocGenUseCase {
return uri
}

@NonCPS
private def computeKeysInDocForTCR(def data) {
return data.collect { it.subMap(['key', 'requirements', 'bugs']).values() }.flatten()
}

@SuppressWarnings('CyclomaticComplexity')
String createTCR(Map repo = null, Map data = null) {
String createTCR(Map repo = null, Map data) {
logger.debug("createTCR - data:${data}")

String documentType = DocumentType.TCR as String

def sections = this.getDocumentSections(documentType)
Expand Down Expand Up @@ -922,9 +925,7 @@ class LeVADocumentUseCase extends DocGenUseCase {
String createSSDS(Map repo = null, Map data = null) {
def documentType = DocumentType.SSDS as String

this.bbt.generateSourceCodeReviewFile()
def bbInfo = this.bbt.readSourceCodeReviewFile(this.bbt.generateSourceCodeReviewFile())

def sections = this.getDocumentSections(documentType)
def watermarkText = this.getWatermarkText(documentType, this.project.hasWipJiraIssues())

Expand Down Expand Up @@ -1022,6 +1023,8 @@ class LeVADocumentUseCase extends DocGenUseCase {

@SuppressWarnings('CyclomaticComplexity')
String createTIR(Map repo, Map data) {
logger.debug("createTIR - repo:${repo}, data:${data}")

def documentType = DocumentType.TIR as String

def installationTestData = data?.tests?.installation
Expand Down Expand Up @@ -1115,6 +1118,8 @@ class LeVADocumentUseCase extends DocGenUseCase {
}

String createTRC(Map repo, Map data) {
logger.debug("createTRC - repo:${repo}, data:${data}")

def documentType = DocumentType.TRC as String

def acceptanceTestData = data.tests.acceptance
Expand Down Expand Up @@ -1397,8 +1402,7 @@ class LeVADocumentUseCase extends DocGenUseCase {
return this.project.components.collectEntries { component ->
def normComponentName = component.name.replaceAll('Technology-', '')

def gitUrl = new GitService(
this.steps, new Logger(this.steps, false)).getOriginUrl()
def gitUrl = new GitService(this.steps, logger).getOriginUrl()
def isReleaseManagerComponent =
gitUrl.endsWith("${this.project.key}-${normComponentName}.git".toLowerCase())
if (isReleaseManagerComponent) {
Expand Down Expand Up @@ -1460,7 +1464,7 @@ class LeVADocumentUseCase extends DocGenUseCase {
this.project.repositories.collect {
[
id: it.id,
description: it.metadata.description,
description: it.metadata?.description,
tests: componentTestMapping[it.id]? componentTestMapping[it.id].join(", "): "None defined"
]
}
Expand Down Expand Up @@ -1600,7 +1604,7 @@ class LeVADocumentUseCase extends DocGenUseCase {
def documentType = LeVADocumentUtil.getTypeFromName(documentName)
def jiraData = this.project.data.jira as Map
def environment = this.computeSavedDocumentEnvironment(documentType)
def docHistory = new DocumentHistory(this.steps, ServiceRegistry.instance.get(Logger), environment, documentName)
def docHistory = new DocumentHistory(this.steps, logger, environment, documentName)
def docChapters = this.project.getDocumentChaptersForDocument(documentType)
def docChapterKeys = docChapters.collect { chapter ->
chapter.key
Expand Down Expand Up @@ -1762,4 +1766,9 @@ class LeVADocumentUseCase extends DocGenUseCase {
}

}

@NonCPS
private def computeKeysInDocForTCR(def data) {
return data.collect { it.subMap(['key', 'requirements', 'bugs']).values() }.flatten()
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package org.ods.core.test

import org.ods.util.ILogger

Expand Down
22 changes: 22 additions & 0 deletions test/groovy/org/ods/core/test/PipelineSpecBase.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.ods.core.test

import com.lesfurets.jenkins.unit.RegressionTest
import com.lesfurets.jenkins.unit.cps.BasePipelineTestCPS
import spock.lang.Specification

/**
* Class base to create component tests
*/
class PipelineSpecBase extends Specification implements RegressionTest {

/**
* Delegate to the junit cps transforming base test
*/
@Delegate
BasePipelineTestCPS baseTest

def setup() {
baseTest = new BasePipelineTestCPS()
baseTest.setUp()
}
}
46 changes: 46 additions & 0 deletions test/groovy/org/ods/core/test/jira/JiraServiceForWireMock.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.ods.core.test.jira

import groovy.util.logging.Slf4j
import org.ods.orchestration.service.JiraService

@Slf4j
class JiraServiceForWireMock extends JiraService {
JiraServiceForWireMock(String baseURL, String username, String password) {
super(baseURL, username, password)
}

@Override
void addLabelsToIssue(String issueIdOrKey, List names) {
log.warn("addLabelsToIssue - issueIdOrKey:$issueIdOrKey")
}

@Override
void appendCommentToIssue(String issueIdOrKey, String comment) {
log.warn("appendCommentToIssue - issueIdOrKey:$issueIdOrKey")
}

@Override
void createIssueLinkTypeBlocks(Map inwardIssue, Map outwardIssue) {
log.warn("createIssueLinkTypeBlocks - inwardIssue:$inwardIssue")
}

@Override
Map createIssueType(String type, String projectKey, String summary, String description, String fixVersion = null) {
log.warn("createIssueType - type:${type}")
}

@Override
void removeLabelsFromIssue(String issueIdOrKey, List names) {
log.warn("removeLabelsFromIssue - issueIdOrKey:$issueIdOrKey")
}

@Override
void updateSelectListFieldsOnIssue(String issueIdOrKey, Map fields) {
log.warn("updateSelectListFieldsOnIssue - issueIdOrKey:$issueIdOrKey")
}

@Override
void updateTextFieldsOnIssue(String issueIdOrKey, Map fields) {
log.warn("updateTextFieldsOnIssue - issueIdOrKey:$issueIdOrKey")
}
}
47 changes: 47 additions & 0 deletions test/groovy/org/ods/core/test/pdf/ImageCompare.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.ods.core.test.pdf

import groovy.util.logging.Slf4j

import javax.imageio.ImageIO
import java.awt.Color
import java.awt.image.BufferedImage

@Slf4j
class ImageCompare {
private static final int colorCode = Color.MAGENTA.getRGB()
private static final String PNG = "png"

boolean compareAndHighlightDiffInNewImage(final BufferedImage img1, final BufferedImage img2, String fileName) throws IOException {
final int width = img1.getWidth()
final int height = img1.getHeight()

final int[] p1 = img1.getRGB(0, 0, width, height, null, 0, width)
final int[] p2 = img2.getRGB(0, 0, width, height, null, 0, width)
if(!(java.util.Arrays.equals(p1, p2))){
log.debug("Compared images - does not match")
saveImage(imageDiff(p1, p2, width, height), fileName)
return false
}
return true
}

private BufferedImage imageDiff(int[] p1, int[] p2, int width, int height) {
for (int i = 0; i < p1.length; i++) {
if (p1[i] != p2[i]) {
p1[i] = colorCode
}
}

final BufferedImage out = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)
out.setRGB(0, 0, width, height, p1, 0, width)
return out
}

private void saveImage(BufferedImage image, String file){
try{
ImageIO.write(image, PNG, new File(file))
} catch(Exception e) {
throw new RuntimeException("Error saving image error", e)
}
}
}
Loading

0 comments on commit 87c6579

Please sign in to comment.