Skip to content
Merged
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
26 changes: 23 additions & 3 deletions cmd/testcase-extractor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ func compileTest(tckTestCase *tck.TestCase, dmnDecisionsMap map[string]*dmn.Deci
for _, tckResult := range tckTestCase.ResultNodes {
dmnDecision := dmnDecisionsMap[tckResult.NameAttr]

context := compileContext(dmnDecision.Context)
expectedResult := compileExpectedResult(tckResult.Expected)
tests = append(
tests,
testconfig.Test{
Context: &context,
FeelExpression: dmnDecision.LiteralExpression,
ExpectedResult: expectedResult,
},
Expand All @@ -221,6 +223,25 @@ func compileTest(tckTestCase *tck.TestCase, dmnDecisionsMap map[string]*dmn.Deci
return tests
}

func compileContext(dmnContext *dmn.Context) []testconfig.ContextEntry {
if dmnContext == nil {
return nil
}

var contextEntries = make([]testconfig.ContextEntry, 0)
for _, dmnCe := range dmnContext.ContextEntries {
contextEntries = append(
contextEntries,
testconfig.ContextEntry{
Variable: dmnCe.Variable.Name,
FeelExpression: dmnCe.LiteralExpression,
},
)
}

return contextEntries
}

// Strip namespace prefix from `valueType`, if not `nil`.
// Otherwise, return `nil`.
func stripNamespacePrefix(valueType *string) *string {
Expand All @@ -244,7 +265,6 @@ func mapDmnDecisionsByName(tckDecisions []*dmn.Decision) map[string]*dmn.Decisio
func saveTestConfigs(testConfigs []tcktestconfig.TestConfig, outputDir string) {

for _, testConfig := range testConfigs {

testConfigFilename := strings.TrimSuffix(
testConfig.Model.Name,
filepath.Ext(testConfig.Model.Name),
Expand All @@ -263,12 +283,12 @@ func saveTestConfigs(testConfigs []tcktestconfig.TestConfig, outputDir string) {
os.Exit(1)
}

defer func(outputFile *os.File) {
defer func() {
err := outputFile.Close()
if err != nil {
printError("Error closing output file: %v\n", err)
}
}(outputFile)
}()

_, err = outputFile.Write(yamlData)
if err != nil {
Expand Down
18 changes: 16 additions & 2 deletions cmd/testcase-extractor/model/dmn/dmn_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ type Definitions struct {
}

type Decision struct {
Name string `xml:"name,attr"`
Context *Context `xml:"context"`
Variable *Variable `xml:"variable,omitempty"`
LiteralExpression *string `xml:"literalExpression>text,omitempty"`
}

type Context struct {
ContextEntries []ContextEntry `xml:"contextEntry"`
}

type ContextEntry struct {
Variable Variable `xml:"variable"`
LiteralExpression string `xml:"literalExpression>text"`
}

type Variable struct {
Name string `xml:"name,attr"`
// TODO[JSot]: Add support for "contextEntry>literalExpression>text"
LiteralExpression string `xml:"literalExpression>text"`
}
18 changes: 16 additions & 2 deletions cmd/testcase-extractor/model/testconfig/testconfig_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@ import (

type TestCase struct {
Id string `yaml:"id"`
Description string `yaml:"description"`
Description string `yaml:"description,omitempty"`
Tests []Test `yaml:"tests"`
}

type Test struct {
FeelExpression string `yaml:"feel-expression"`
Context *[]ContextEntry `yaml:"context,omitempty"`
FeelExpression *string `yaml:"feel-expression,omitempty"`
ExpectedResult `yaml:"expected"`
}

type ContextEntry struct {
Variable string `xml:"variable"`
FeelExpression string `yaml:"feel-expression"`
}

func (ce ContextEntry) String() string {
return fmt.Sprintf(
"%s: %s",
ce.Variable,
ce.FeelExpression,
)
}

type ExpectedResult struct {
Components *[]Component `yaml:"components,omitempty"`
Value *ExpectedValue `yaml:"result,omitempty"`
Expand Down
Loading