未验证 提交 f501c4b4 编写于 作者: P Phodal Huang

test: add test for tbs

上级 93e186e3
......@@ -487,7 +487,11 @@ results
- [x] Architecture Visualization
- [ ] Architecture Guard
- [ ] DSL Design
Tech Debt
- Duplicate Code
- cmd/ -> user builder to refactoring
## Dev
......
......@@ -27,7 +27,7 @@ var tbsCmd = &cobra.Command{
var identifiers []models.JIdentifier
identifiers = adapter.LoadTestIdentify(files)
identifiersMap = adapter.BuildIdentifierMap(identifiers)
identifiersMap := adapter.BuildIdentifierMap(identifiers)
var classes []string = nil
for _, node := range identifiers {
......
......@@ -28,9 +28,7 @@ func (j *JavaCallApp) AnalysisFiles(identNodes []models.JIdentifier, files []str
identMap[ident.Package+"."+ident.ClassName] = ident
}
for index := range files {
file := files[index]
for _, file := range files {
displayName := filepath.Base(file)
fmt.Println("Start parse java call: " + displayName)
......
package adapter
import (
"encoding/json"
"github.com/phodal/coca/core/adapter/identifier"
"github.com/phodal/coca/core/models"
"github.com/phodal/coca/core/support"
"encoding/json"
)
func BuildIdentifierMap(identifiers []models.JIdentifier) map[string]models.JIdentifier {
......@@ -20,7 +20,7 @@ func LoadIdentify(importPath string) []models.JIdentifier {
var identifiers []models.JIdentifier
apiContent := support.ReadCocaFile("identify.json")
if apiContent == nil {
if apiContent == nil || string(apiContent) == "null" {
identifierApp := new(identifier.JavaIdentifierApp)
ident := identifierApp.AnalysisPath(importPath)
......@@ -38,8 +38,9 @@ func LoadTestIdentify(files []string) []models.JIdentifier {
var identifiers []models.JIdentifier
apiContent := support.ReadCocaFile("tidentify.json")
if apiContent == nil {
identifierApp := new(identifier.JavaIdentifierApp)
if apiContent == nil || string(apiContent) == "null" {
identifierApp := identifier.NewJavaIdentifierApp()
ident := identifierApp.AnalysisFiles(files)
identModel, _ := json.MarshalIndent(ident, "", "\t")
......@@ -60,7 +61,7 @@ func BuildDIMap(identifiers []models.JIdentifier, identifierMap map[string]model
name := annotation.QualifiedName
if (name == "Component" || name == "Repository") && len(clz.Implements) > 0 {
superClz := identifierMap[clz.Implements[0]]
diMap[superClz.Package + "." + superClz.ClassName] = clz.Package + "." + clz.ClassName
diMap[superClz.Package+"."+superClz.ClassName] = clz.Package + "." + clz.ClassName
}
}
}
......@@ -68,4 +69,3 @@ func BuildDIMap(identifiers []models.JIdentifier, identifierMap map[string]model
return diMap
}
package tbs
import (
. "github.com/onsi/gomega"
"github.com/phodal/coca/core/adapter"
"github.com/phodal/coca/core/adapter/call"
"github.com/phodal/coca/core/models"
"github.com/phodal/coca/core/support"
"testing"
)
func TestTbsApp_AnalysisPath(t *testing.T) {
g := NewGomegaWithT(t)
codePath := "../../../_fixtures/tbs/code/EmptyTest.java"
files := support.GetJavaTestFiles(codePath)
var identifiers []models.JIdentifier
identifiers = adapter.LoadTestIdentify(files)
identifiersMap := adapter.BuildIdentifierMap(identifiers)
var classes []string = nil
for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName)
}
analysisApp := call.NewJavaCallApp()
classNodes := analysisApp.AnalysisFiles(identifiers, files, classes)
app := NewTbsApp()
result := app.AnalysisPath(classNodes, identifiersMap)
g.Expect(result[0].Type).To(Equal("EmptyTest"))
}
\ No newline at end of file
......@@ -17,6 +17,17 @@ func GetJavaFiles(codeDir string) []string {
fmt.Println(err)
}
fi, err := os.Stat(codeDir)
if err != nil {
fmt.Println(err)
return nil
}
if fi.Mode().IsRegular() {
files = append(files, codeDir)
return files
}
_ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error {
if gitIgnore != nil {
if gitIgnore.MatchesPath(path) {
......@@ -39,6 +50,17 @@ func GetJavaTestFiles(codeDir string) []string {
fmt.Println(err)
}
fi, err := os.Stat(codeDir)
if err != nil {
fmt.Println(err)
return nil
}
if fi.Mode().IsRegular() {
files = append(files, codeDir)
return files
}
_ = filepath.Walk(codeDir, func(path string, fi os.FileInfo, err error) error {
if gitIgnore != nil {
if gitIgnore.MatchesPath(path) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册