From 87ca427a91e476e288b2cb8203c86e255111c649 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 26 Dec 2019 19:21:12 +0800 Subject: [PATCH] test: add test for count app --- _fixtures/count/call.json | 614 ++++++++++++++++++++++++++++ core/domain/count/count_app_test.go | 24 ++ 2 files changed, 638 insertions(+) create mode 100644 _fixtures/count/call.json create mode 100644 core/domain/count/count_app_test.go diff --git a/_fixtures/count/call.json b/_fixtures/count/call.json new file mode 100644 index 0000000..395b89c --- /dev/null +++ b/_fixtures/count/call.json @@ -0,0 +1,614 @@ +[ + { + "Package": "com.phodal.pholedge.book", + "Class": "BookController", + "Type": "Class", + "Path": "examples/api/BookController.java", + "Fields": [ + { + "Type": "BookService", + "Value": "applicationService" + } + ], + "Methods": [ + { + "Name": "BookController", + "Type": "", + "StartLine": 20, + "StartLinePosition": 11, + "StopLine": 22, + "StopLinePosition": 4, + "Parameters": [ + { + "Name": "applicationService", + "Type": "BookService" + } + ], + "MethodCalls": null, + "Override": false, + "Annotations": null, + "IsConstructor": true + }, + { + "Name": "createBook", + "Type": "Map\u003cString,String\u003e", + "StartLine": 26, + "StartLinePosition": 31, + "StopLine": 28, + "StopLinePosition": 41, + "Parameters": [ + { + "Name": "command", + "Type": "CreateBookCommand" + } + ], + "MethodCalls": [ + { + "Package": "com.google.common.collect.ImmutableSortedMap.of", + "Type": "", + "Class": "", + "MethodName": "of", + "StartLine": 27, + "StartLinePosition": 15, + "StopLine": 27, + "StopLinePosition": 17 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "createBook", + "StartLine": 27, + "StartLinePosition": 43, + "StopLine": 27, + "StopLinePosition": 53 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "updateBook", + "Type": "BookRepresentaion", + "StartLine": 32, + "StartLinePosition": 29, + "StopLine": 34, + "StopLinePosition": 39, + "Parameters": [ + { + "Name": "id", + "Type": "String" + }, + { + "Name": "command", + "Type": "UpdateBookCommand" + } + ], + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "updateBook", + "StartLine": 33, + "StartLinePosition": 34, + "StopLine": 33, + "StopLinePosition": 44 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "getBookList", + "Type": "List\u003cBookRepresentaion\u003e", + "StartLine": 37, + "StartLinePosition": 35, + "StopLine": 39, + "StopLinePosition": 46, + "Parameters": null, + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "getBooksLists", + "StartLine": 38, + "StartLinePosition": 34, + "StopLine": 38, + "StopLinePosition": 47 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "getBookById", + "Type": "BookRepresentaion", + "StartLine": 42, + "StartLinePosition": 29, + "StopLine": 44, + "StopLinePosition": 40, + "Parameters": [ + { + "Name": "id", + "Type": "String" + } + ], + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "getBookById", + "StartLine": 43, + "StartLinePosition": 34, + "StopLine": 43, + "StopLinePosition": 45 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + } + ], + "MethodCalls": [ + { + "Package": "com.google.common.collect.ImmutableSortedMap.of", + "Type": "", + "Class": "", + "MethodName": "of", + "StartLine": 27, + "StartLinePosition": 15, + "StopLine": 27, + "StopLinePosition": 17 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "createBook", + "StartLine": 27, + "StartLinePosition": 43, + "StopLine": 27, + "StopLinePosition": 53 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "updateBook", + "StartLine": 33, + "StartLinePosition": 34, + "StopLine": 33, + "StopLinePosition": 44 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "getBooksLists", + "StartLine": 38, + "StartLinePosition": 34, + "StopLine": 38, + "StopLinePosition": 47 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookService", + "MethodName": "getBookById", + "StartLine": 43, + "StartLinePosition": 34, + "StopLine": 43, + "StopLinePosition": 45 + } + ], + "Extend": "", + "Implements": null + }, + { + "Package": "com.phodal.pholedge.book", + "Class": "BookService", + "Type": "Class", + "Path": "examples/api/BookService.java", + "Fields": [ + { + "Type": "BookFactory", + "Value": "bookFactory" + }, + { + "Type": "BookRepository", + "Value": "bookRepository" + } + ], + "Methods": [ + { + "Name": "createBook", + "Type": "String", + "StartLine": 25, + "StartLinePosition": 18, + "StopLine": 29, + "StopLinePosition": 28, + "Parameters": [ + { + "Name": "command", + "Type": "CreateBookCommand" + } + ], + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "Book", + "MethodName": "create", + "StartLine": 26, + "StartLinePosition": 32, + "StopLine": 26, + "StopLinePosition": 38 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "CreateBookCommand", + "MethodName": "getIsbn", + "StartLine": 26, + "StartLinePosition": 47, + "StopLine": 26, + "StopLinePosition": 54 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "CreateBookCommand", + "MethodName": "getName", + "StartLine": 26, + "StartLinePosition": 66, + "StopLine": 26, + "StopLinePosition": 73 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookRepository", + "MethodName": "save", + "StartLine": 27, + "StartLinePosition": 23, + "StopLine": 27, + "StopLinePosition": 27 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "getId", + "StartLine": 28, + "StartLinePosition": 20, + "StopLine": 28, + "StopLinePosition": 25 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "getBooksLists", + "Type": "List\u003cBookRepresentaion\u003e", + "StartLine": 31, + "StartLinePosition": 35, + "StopLine": 33, + "StopLinePosition": 48, + "Parameters": null, + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookRepository", + "MethodName": "list", + "StartLine": 32, + "StartLinePosition": 30, + "StopLine": 32, + "StopLinePosition": 34 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "getBookById", + "Type": "BookRepresentaion", + "StartLine": 35, + "StartLinePosition": 29, + "StopLine": 38, + "StopLinePosition": 40, + "Parameters": [ + { + "Name": "id", + "Type": "String" + } + ], + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "Book", + "MethodName": "byId", + "StartLine": 36, + "StartLinePosition": 35, + "StopLine": 36, + "StopLinePosition": 39 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "toRepresentation", + "StartLine": 37, + "StartLinePosition": 20, + "StopLine": 37, + "StopLinePosition": 36 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "updateBook", + "Type": "BookRepresentaion", + "StartLine": 40, + "StartLinePosition": 29, + "StopLine": 45, + "StopLinePosition": 39, + "Parameters": [ + { + "Name": "id", + "Type": "String" + }, + { + "Name": "command", + "Type": "UpdateBookCommand" + } + ], + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "Book", + "MethodName": "byId", + "StartLine": 41, + "StartLinePosition": 35, + "StopLine": 41, + "StopLinePosition": 39 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "save", + "StartLine": 42, + "StartLinePosition": 13, + "StopLine": 42, + "StopLinePosition": 17 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "UpdateBookCommand", + "MethodName": "getIsbn", + "StartLine": 42, + "StartLinePosition": 26, + "StopLine": 42, + "StopLinePosition": 33 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "UpdateBookCommand", + "MethodName": "getName", + "StartLine": 42, + "StartLinePosition": 45, + "StopLine": 42, + "StopLinePosition": 52 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookRepository", + "MethodName": "save", + "StartLine": 43, + "StartLinePosition": 23, + "StopLine": 43, + "StopLinePosition": 27 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "toRepresentation", + "StartLine": 44, + "StartLinePosition": 20, + "StopLine": 44, + "StopLinePosition": 36 + } + ], + "Override": false, + "Annotations": null, + "IsConstructor": false + }, + { + "Name": "BookService", + "Type": "", + "StartLine": 19, + "StartLinePosition": 11, + "StopLine": 22, + "StopLinePosition": 4, + "Parameters": [ + { + "Name": "bookFactory", + "Type": "BookFactory" + }, + { + "Name": "bookRepository", + "Type": "BookRepository" + } + ], + "MethodCalls": null, + "Override": false, + "Annotations": null, + "IsConstructor": true + } + ], + "MethodCalls": [ + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "Book", + "MethodName": "create", + "StartLine": 26, + "StartLinePosition": 32, + "StopLine": 26, + "StopLinePosition": 38 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "CreateBookCommand", + "MethodName": "getIsbn", + "StartLine": 26, + "StartLinePosition": 47, + "StopLine": 26, + "StopLinePosition": 54 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "CreateBookCommand", + "MethodName": "getName", + "StartLine": 26, + "StartLinePosition": 66, + "StopLine": 26, + "StopLinePosition": 73 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookRepository", + "MethodName": "save", + "StartLine": 27, + "StartLinePosition": 23, + "StopLine": 27, + "StopLinePosition": 27 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "getId", + "StartLine": 28, + "StartLinePosition": 20, + "StopLine": 28, + "StopLinePosition": 25 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookRepository", + "MethodName": "list", + "StartLine": 32, + "StartLinePosition": 30, + "StopLine": 32, + "StopLinePosition": 34 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "Book", + "MethodName": "byId", + "StartLine": 36, + "StartLinePosition": 35, + "StopLine": 36, + "StopLinePosition": 39 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "toRepresentation", + "StartLine": 37, + "StartLinePosition": 20, + "StopLine": 37, + "StopLinePosition": 36 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "Book", + "MethodName": "byId", + "StartLine": 41, + "StartLinePosition": 35, + "StopLine": 41, + "StopLinePosition": 39 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "save", + "StartLine": 42, + "StartLinePosition": 13, + "StopLine": 42, + "StopLinePosition": 17 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "UpdateBookCommand", + "MethodName": "getIsbn", + "StartLine": 42, + "StartLinePosition": 26, + "StopLine": 42, + "StopLinePosition": 33 + }, + { + "Package": "com.phodal.pholedge.book.model.command", + "Type": "chain", + "Class": "UpdateBookCommand", + "MethodName": "getName", + "StartLine": 42, + "StartLinePosition": 45, + "StopLine": 42, + "StopLinePosition": 52 + }, + { + "Package": "com.phodal.pholedge.book", + "Type": "", + "Class": "BookRepository", + "MethodName": "save", + "StartLine": 43, + "StartLinePosition": 23, + "StopLine": 43, + "StopLinePosition": 27 + }, + { + "Package": "com.phodal.pholedge.book.model", + "Type": "chain", + "Class": "Book", + "MethodName": "toRepresentation", + "StartLine": 44, + "StartLinePosition": 20, + "StopLine": 44, + "StopLinePosition": 36 + } + ], + "Extend": "", + "Implements": [ + "com.phodal.pholedge.core.domain.Service" + ] + } +] \ No newline at end of file diff --git a/core/domain/count/count_app_test.go b/core/domain/count/count_app_test.go new file mode 100644 index 0000000..c01ed57 --- /dev/null +++ b/core/domain/count/count_app_test.go @@ -0,0 +1,24 @@ +package count + +import ( + "encoding/json" + . "github.com/onsi/gomega" + "github.com/phodal/coca/core/models" + "github.com/phodal/coca/core/support" + "testing" +) + +func TestBuildCallMap(t *testing.T) { + g := NewGomegaWithT(t) + + var parsedDeps []models.JClassNode + file := support.ReadFile("../../../_fixtures/count/call.json") + _ = json.Unmarshal(file, &parsedDeps) + + callMap := BuildCallMap(parsedDeps) + + g.Expect(len(callMap)).To(Equal(4)) + g.Expect(callMap["com.phodal.pholedge.book.BookService.createBook"]).To(Equal(1)) + g.Expect(callMap["com.phodal.pholedge.book.BookService.getBookById"]).To(Equal(1)) + g.Expect(callMap["com.phodal.pholedge.book.BookService.getBooksLists"]).To(Equal(1)) +} -- GitLab