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

Enriching export #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions gradle-test-export-plugin.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't have to commit this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted

<module external.linked.project.id="gradle-test-export-plugin" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.ullink.gradle" external.system.module.version="0.2" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
66 changes: 31 additions & 35 deletions src/main/groovy/com/ullink/testtools/elastic/TestExportTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.TestResult

import java.nio.file.Paths
import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

Expand Down Expand Up @@ -51,6 +49,10 @@ class TestExportTask extends Exec {
@Optional
def enrichment

@Input
@Optional
def featureExport
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add another task instead of export using a closure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in a new FeatureExportTask class inside the project that just prompts the ullink plugin to export the feature?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a new task depends on this task, exporting the feature is ok


@Input
@Optional
def type = "testcase"
Expand All @@ -63,21 +65,25 @@ class TestExportTask extends Exec {
@Optional
String indexTimestampPattern = "yyyy-MM"

@Input
@Optional
String buildTime = LocalDateTime.now().toString()

@Internal
BulkProcessor processor
@Internal
TransportClient client

def overrideDefaultProperties(Properties properties) {
if (getHost() != null) {
log.error "setting host " + getHost()
properties.setProperty('host', getHost())
static def overrideDefaultProperties(TestExportTask task, Properties properties) {
if (task.host != null) {
log.info "setting host ${task.host}" +
properties.setProperty('host', task.host)
}
if (getClusterName() != null) {
properties.setProperty('clusterName', getClusterName())
if (task.clusterName != null) {
properties.setProperty('clusterName', task.clusterName)
}
if (getPort() != null) {
properties.setProperty('port', getPort())
if (task.port != null) {
properties.setProperty('port', task.port)
}

return properties
Expand All @@ -86,7 +92,7 @@ class TestExportTask extends Exec {
@Override
void exec() {
ElasticSearchProcessor elasticSearchProcessor = new ElasticSearchProcessor()
Properties parameters = overrideDefaultProperties(elasticSearchProcessor.getParameters())
Properties parameters = overrideDefaultProperties(this, elasticSearchProcessor.getParameters())

def bulkProcessorListener = elasticSearchProcessor.buildBulkProcessorListener()
client = elasticSearchProcessor.buildTransportClient(parameters)
Expand Down Expand Up @@ -114,7 +120,7 @@ class TestExportTask extends Exec {
def list = parseTestFiles(files)
list.each {
def output = JsonOutput.toJson(it)
output= new JsonSlurper().parseText(output)
output = new JsonSlurper().parseText(output)
assert output instanceof Map
output.remove("timestamp")

Expand Down Expand Up @@ -143,17 +149,9 @@ class TestExportTask extends Exec {
}
}

def InputJSONFile = getEnrichment().featureJsonParser('getFeatureJsonFile')
def InputJSON = getEnrichment().featureJsonParser('getFeatureJsonParseText')

def indexFeature = "feature-" + indexPrefix + new SimpleDateFormat(indexTimestampPattern).format(InputJSONFile.lastModified())
String typeFinal = "feature"

for (object in InputJSON) {
String id = sha1Hashed(object.toString())
IndexRequest indexObjFeature = new IndexRequest(indexFeature, typeFinal, id)
object.productName= getProperties().product.name
processor.add(indexObjFeature.source(object, XContentType.JSON))
if (featureExport) {
featureExport.exportFeature(this)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part should not be done in here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the internal one


processor.close()
Expand All @@ -170,26 +168,26 @@ class TestExportTask extends Exec {
files.each {
def xmlDoc = new XmlSlurper().parse(it)
def fileName = (xmlDoc.@name)
String timestamp = xmlDoc.@timestamp
def solutions = getEnrichment().testCaseJsonParser(fileName)

def filePath = Paths.get("src", "test", "groovy", fileName.toString().replace(".", File.separator) + ".groovy")

xmlDoc.children().each {
if (it.name() == "testcase") {
Result result = parseTestCase(it,solutions)
result.timestamp = timestamp
result.filePath = filePath
Result result = parseTestCase(it)

if (enrichment) {
result = enrichment.enrichJson(result, it, fileName)
}

list << result
}
}
}
list
}

def parseTestCase(def p, def solution) {
String testname = p.@name
Result result = new Result(name: testname)
def parseTestCase(def p) {
String testName = p.@name
Result result = new Result(name: testName)
result.timestamp = buildTime
def time = Float.parseFloat([email protected]()) * 1000
result.with {
classname = p.@classname
Expand All @@ -209,10 +207,8 @@ class TestExportTask extends Exec {
result.resultType = TestResult.ResultType.SKIPPED
}
}
result.feature = getEnrichment().resolveFeature(p, solution)
result.steps = getEnrichment().resolveSteps(p,solution)
result.properties = resolveProperties(p)
result.projectName= project.getName()
result.projectName = project.getName()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, it should be done in enrichment
I can work with you to see how it can be done

result
}
Expand Down
10 changes: 0 additions & 10 deletions src/main/groovy/com/ullink/testtools/elastic/models/Result.groovy
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package com.ullink.testtools.elastic.models

import groovy.json.JsonSlurper
import org.gradle.api.tasks.testing.TestResult
import org.gradle.internal.impldep.com.fasterxml.jackson.databind.util.JSONPObject
import org.gradle.internal.impldep.com.google.gson.JsonObject
import java.nio.file.Path
import java.nio.file.Paths

import java.lang.reflect.Array

class Result {
String name
Expand All @@ -17,9 +10,6 @@ class Result {
String failureType
TestResult.ResultType resultType
String timestamp
String feature
String filePath
String projectName
Map<String, ?> properties
ArrayList steps
}