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

test: add basic test for call

上级 3025c083
package com.phodal.pholedge.book;
import com.phodal.pholedge.book.model.BookRepresentaion;
import com.phodal.pholedge.book.model.command.CreateBookCommand;
import com.phodal.pholedge.book.model.command.UpdateBookCommand;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import static com.google.common.collect.ImmutableSortedMap.of;
@RestController
@RequestMapping(value = "/books")
public class BookController {
private final BookService applicationService;
public BookController(BookService applicationService) {
this.applicationService = applicationService;
}
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public Map<String, String> createBook(@RequestBody @Valid CreateBookCommand command) {
return of("id", applicationService.createBook(command));
}
@PutMapping("/{id}")
@ResponseStatus(HttpStatus.OK)
public BookRepresentaion updateBook(@PathVariable(name = "id") String id, @RequestBody @Valid UpdateBookCommand command) {
return applicationService.updateBook(id, command);
}
@GetMapping("/")
public List<BookRepresentaion> getBookList() {
return applicationService.getBooksLists();
}
@GetMapping("/{id}")
public BookRepresentaion getBookById(@PathVariable(name = "id") String id) {
return applicationService.getBookById(id);
}
}
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"coca/core/models" "coca/core/models"
. "coca/core/support" . "coca/core/support"
"encoding/json" "encoding/json"
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"log" "log"
) )
...@@ -28,7 +29,12 @@ var conceptCmd = &cobra.Command{ ...@@ -28,7 +29,12 @@ var conceptCmd = &cobra.Command{
_ = json.Unmarshal(file, &parsedDeps) _ = json.Unmarshal(file, &parsedDeps)
analyser.Analysis(&parsedDeps) wordCounts := analyser.Analysis(&parsedDeps)
for _, word := range wordCounts {
if word.Value > 0 {
fmt.Println(word.Key, word.Value)
}
}
} }
}, },
} }
......
package call package call
import ( import (
"coca/core/adapter/identifier"
"fmt"
. "github.com/onsi/gomega"
"testing" "testing"
) )
func TestJavaCallApp_AnalysisPath(t *testing.T) { func TestJavaCallApp_AnalysisPath(t *testing.T) {
g := NewGomegaWithT(t)
codePath := "../../../_fixtures/call"
identifierApp := new(identifier.JavaIdentifierApp)
iNodes := identifierApp.AnalysisPath(codePath)
var classes []string = nil
for _, node := range iNodes {
classes = append(classes, node.Package+"."+node.ClassName)
}
callApp := new(JavaCallApp)
callNodes := callApp.AnalysisPath(codePath, classes, iNodes)
g.Expect(len(callNodes)).To(Equal(1))
} }
\ No newline at end of file
...@@ -9,9 +9,11 @@ func TestJavaIdentifierApp_AnalysisPath(t *testing.T) { ...@@ -9,9 +9,11 @@ func TestJavaIdentifierApp_AnalysisPath(t *testing.T) {
g := NewGomegaWithT(t) g := NewGomegaWithT(t)
identApp := new(JavaIdentifierApp) identApp := new(JavaIdentifierApp)
identifiers := identApp.AnalysisPath("../../../examples/method-call") identifiers := identApp.AnalysisPath("../../../_fixtures/call")
g.Expect(len(identifiers)).To(Equal(1)) g.Expect(len(identifiers)).To(Equal(1))
g.Expect(identifiers[0].ClassName).To(Equal("BlogRepositoryImpl")) g.Expect(identifiers[0].ClassName).To(Equal("BookController"))
g.Expect(identifiers[0].Methods[0].Name).To(Equal("save")) g.Expect(identifiers[0].Methods[0].Name).To(Equal("createBook"))
g.Expect(identifiers[0].Annotations[0].QualifiedName).To(Equal("RestController"))
} }
\ No newline at end of file
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
languages2 "coca/core/domain/call_graph/stop_words/languages" languages2 "coca/core/domain/call_graph/stop_words/languages"
"coca/core/models" "coca/core/models"
"coca/core/support" "coca/core/support"
"fmt"
) )
type ConceptAnalyser struct { type ConceptAnalyser struct {
...@@ -18,11 +17,11 @@ func (c ConceptAnalyser) run() { ...@@ -18,11 +17,11 @@ func (c ConceptAnalyser) run() {
} }
func (c ConceptAnalyser) Analysis(clzs *[]models.JClassNode) { func (c ConceptAnalyser) Analysis(clzs *[]models.JClassNode) support.PairList {
buildMethodsFromDeps(*clzs) return buildMethodsFromDeps(*clzs)
} }
func buildMethodsFromDeps(clzs []models.JClassNode) { func buildMethodsFromDeps(clzs []models.JClassNode) support.PairList {
var methodsName []string var methodsName []string
var methodStr string var methodStr string
for _, clz := range clzs { for _, clz := range clzs {
...@@ -38,11 +37,7 @@ func buildMethodsFromDeps(clzs []models.JClassNode) { ...@@ -38,11 +37,7 @@ func buildMethodsFromDeps(clzs []models.JClassNode) {
words = removeNormalWords(words) words = removeNormalWords(words)
wordCounts := support.RankByWordCount(words) wordCounts := support.RankByWordCount(words)
for _, word := range wordCounts { return wordCounts
if word.Value > 0 {
fmt.Println(word.Key, word.Value)
}
}
} }
var itStopWords = []string{ var itStopWords = []string{
......
package concept
import (
"coca/core/models"
"coca/core/support"
"encoding/json"
"log"
"testing"
. "github.com/onsi/gomega"
)
func TestConceptAnalyser_Analysis(t *testing.T) {
g := NewGomegaWithT(t)
var parsedDeps []models.JClassNode
analyser := NewConceptAnalyser()
file := support.ReadFile("../../../_fixtures/call_api_test.json")
if file == nil {
log.Fatal("lost file")
}
_ = json.Unmarshal(file, &parsedDeps)
counts := analyser.Analysis(&parsedDeps)
g.Expect(counts.Len()).To(Equal(4))
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册