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

feat: add tst for api

上级 2250ad6b
......@@ -48,9 +48,17 @@ var apiCmd = &cobra.Command{
identifiersMap := adapter.BuildIdentifierMap(identifiers)
diMap := adapter.BuildDIMap(identifiers, identifiersMap)
parsedDeps = nil
depFile := ReadFile(depPath)
if depFile == nil {
log.Fatal("lost deps")
}
_ = json.Unmarshal(depFile, &parsedDeps)
if *&apiCmdConfig.ForceUpdate {
app := new(JavaApiApp)
restApis = app.AnalysisPath(path, depPath, identifiersMap, diMap)
restApis = app.AnalysisPath(path, parsedDeps, identifiersMap, diMap)
cModel, _ := json.MarshalIndent(restApis, "", "\t")
WriteToCocaFile("apis.json", string(cModel))
} else {
......
......@@ -3,26 +3,17 @@ package api
import (
"coca/core/models"
"coca/core/support"
"encoding/json"
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr"
"path/filepath"
)
var parsedDeps []models.JClassNode
var allApis []RestApi
type JavaApiApp struct {
}
func (j *JavaApiApp) AnalysisPath(codeDir string, depPath string, identifiersMap map[string]models.JIdentifier, diMap map[string]string) []RestApi {
parsedDeps = nil
file := support.ReadFile(depPath)
if file == nil {
return nil
}
_ = json.Unmarshal(file, &parsedDeps)
func (j *JavaApiApp) AnalysisPath(codeDir string, parsedDeps []models.JClassNode, identifiersMap map[string]models.JIdentifier, diMap map[string]string) []RestApi {
files := support.GetJavaFiles(codeDir)
for index := range files {
......
package api
import (
"coca/core/adapter"
"coca/core/adapter/call"
"coca/core/adapter/identifier"
. "github.com/onsi/gomega"
"testing"
)
func TestJavaCallApp_AnalysisPath(t *testing.T) {
g := NewGomegaWithT(t)
codePath := "../../../_fixtures/call"
identifierApp := new(identifier.JavaIdentifierApp)
identifiers := identifierApp.AnalysisPath(codePath)
var classes []string = nil
for _, node := range identifiers {
classes = append(classes, node.Package+"."+node.ClassName)
}
callApp := new(call.JavaCallApp)
callNodes := callApp.AnalysisPath(codePath, classes, identifiers)
identifiersMap := adapter.BuildIdentifierMap(identifiers)
diMap := adapter.BuildDIMap(identifiers, identifiersMap)
app := new(JavaApiApp)
restApis := app.AnalysisPath(codePath, callNodes, identifiersMap, diMap)
g.Expect(len(restApis)).To(Equal(4))
g.Expect(restApis[0].HttpMethod).To(Equal("POST"))
g.Expect(restApis[0].Uri).To(Equal("/books"))
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package call
import (
"coca/core/adapter/identifier"
"fmt"
. "github.com/onsi/gomega"
"testing"
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册