Skip to content

Commit

Permalink
refine testing
Browse files Browse the repository at this point in the history
  • Loading branch information
deemount committed Mar 21, 2024
1 parent 2fa1a1f commit 5eacd09
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
7 changes: 7 additions & 0 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import (
"testing"
)

var (
// Defaults
DefaultFiletestPath = "temp"
DefaultFiletestNameBPMN = "test.bpmn"
DefaultFiletestNameJSON = "test.json"
)

// TestReflectQuantities ...
func TestReflectQuantities(t *testing.T) {

Expand Down
11 changes: 6 additions & 5 deletions tobpmn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,34 @@ import (

func TestToBPMN(t *testing.T) {
var err error

// create a new repository
repo := core.NewDefinitions()
repo.SetDefaultAttributes()
repo.SetID("definitions", "1234")
repo.SetMainElements(1)
proc := repo.GetProcess(0)
t.Logf("result of proc is %v", proc)

// marshal xml to byte slice
b, err := xml.MarshalIndent(&repo, " ", " ")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
// path to temporary bpmn files
path := "temp"

// create .bpmn file
f, err := os.Create(path + "/test.bpmn")
f, err := os.Create(DefaultFiletestPath + "/test.bpmn")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
defer f.Close()

// add xml header
w := []byte(fmt.Sprintf("%v", xml.Header+string(b)))
// write bytes to file
_, err = f.Write(w)
if err != nil {
t.Errorf("expected nil, got %v", err)
}

err = f.Sync()
if err != nil {
t.Errorf("expected nil, got %v", err)
Expand Down
43 changes: 43 additions & 0 deletions tojson_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package gobpmn_builder_test

import (
"encoding/json"
"os"
"testing"

"github.com/deemount/gobpmnModels/pkg/core"
)

func TestToJSON(t *testing.T) {
var err error

// create a new repository
repo := core.NewDefinitions()
repo.SetDefaultAttributes()
repo.SetID("definitions", "1234")
repo.SetMainElements(1)

// marshal xml to byte slice
b, err := json.MarshalIndent(&repo, " ", " ")
if err != nil {
t.Errorf("expected nil, got %v", err)
}

// create .bpmn file
f, err := os.Create(DefaultFiletestPath + "/test.json")
if err != nil {
t.Errorf("expected nil, got %v", err)
}
defer f.Close()

// write bytes to file
_, err = f.Write(b)
if err != nil {
t.Errorf("expected nil, got %v", err)
}
err = f.Sync()
if err != nil {
t.Errorf("expected nil, got %v", err)
}

}

0 comments on commit 5eacd09

Please sign in to comment.