-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from ClareChu/pool
support es
- Loading branch information
Showing
21 changed files
with
659 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# config file for testing | ||
|
||
server: | ||
port: 8080 | ||
|
||
logging: | ||
level: info | ||
|
||
es: | ||
host: 10.10.13.5 | ||
port: 9200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# config file for testing | ||
# filename should be application.yml | ||
|
||
app: | ||
project: examples | ||
name: es-demo | ||
profiles: | ||
include: | ||
- actuator | ||
- locale | ||
- logging | ||
- es | ||
|
||
logging: | ||
level: info | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
success = Success | ||
failed = Failed | ||
hello = Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
success = 成功 | ||
failed = 失败 | ||
hello = 您好 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http:#www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
mkdir -p ssl | ||
|
||
openssl genrsa -out ssl/app.rsa 1024 | ||
openssl rsa -in ssl/app.rsa -pubout > ssl/app.rsa.pub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIICXQIBAAKBgQDBaFochwjb/PFXA9EOmynT+SQr54wh9HMx5VFj0bNUKegMS02W | ||
4DSsneRVaY5Bo+8sDoNPx2Luzp7pPRNbukP4pjgVWAASVWnGeBaGRaYbo/d9SV/R | ||
OdKwmV1DJM3PtOo82oNnI26FJeJ/oTl+5UJ4sd7J8UbR0DCu40venKLlOwIDAQAB | ||
AoGAOFuJDpEGstvlE38INyJdsOgDc0u4mNhbjOmOqvCbOeYwOQzkYheZIceslnr4 | ||
ugXkFslv2Bp4qK/KvJpQfsUrMtGNr1FKfwLzD09++GU89ltufgn8Z6iYJ+app0qa | ||
hYKAoGQkvPP4ks+k3nBYRESL01y9mKZ/JSvWfKj8wHOu1pkCQQD/Pdom+5r2q150 | ||
QUkw4huDthHBB96LMJiVLSNkPoHXPwXqSoa8CXNquCQA43F1gjtCz37rZDEyFYWH | ||
IYT4TcG1AkEAwft3WsON1ND0p8Z+iUCe/+ySajBvH4ICJ6Muj8D4FdydRvBhNJT0 | ||
qmZYZI19Bjk8qYHV7UoUhQQcfBB8TVQhLwJBAOE10CEJbEguGR9243+wYhqrMasi | ||
qGgkLt2hgFLZHHOx9iQuMggERsRpSctG5DuM94ER2KkWNJo+hx0epFb7NOkCQEnq | ||
1c9LRyd6PFAWTi9k5XGmJyC5tg5ujv2lq99xa9eAypm2jYPo4tZvy2z9kU+mzdvV | ||
srwKB4msSGJqMcORtFcCQQDJ1nXPTCgptvny+FhkFGAy3UNLdGXKeAM9UHhJW+/Z | ||
RJvfo1hEyCPZZbPrMrPzqkJ8pBd2VRwoevlJreZDekvd | ||
-----END RSA PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-----BEGIN PUBLIC KEY----- | ||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBaFochwjb/PFXA9EOmynT+SQr | ||
54wh9HMx5VFj0bNUKegMS02W4DSsneRVaY5Bo+8sDoNPx2Luzp7pPRNbukP4pjgV | ||
WAASVWnGeBaGRaYbo/d9SV/ROdKwmV1DJM3PtOo82oNnI26FJeJ/oTl+5UJ4sd7J | ||
8UbR0DCu40venKLlOwIDAQAB | ||
-----END PUBLIC KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package controller | ||
|
||
import ( | ||
"hidevops.io/hiboot-data/examples/es/entity" | ||
"hidevops.io/hiboot-data/examples/es/service" | ||
"hidevops.io/hiboot/pkg/app" | ||
"hidevops.io/hiboot/pkg/at" | ||
"hidevops.io/hiboot/pkg/model" | ||
"net/http" | ||
) | ||
|
||
// RestController | ||
type userController struct { | ||
at.RestController | ||
|
||
userService service.UserService | ||
} | ||
|
||
func init() { | ||
app.Register(newUserController) | ||
} | ||
|
||
// newUserController inject userService automatically | ||
func newUserController(userService service.UserService) *userController { | ||
return &userController{ | ||
userService: userService, | ||
} | ||
} | ||
|
||
// Post POST /user | ||
func (c *userController) Post(request *entity.User) (model.Response, error) { | ||
user, err := c.userService.AddUser(request) | ||
response := new(model.BaseResponse) | ||
response.SetData(user) | ||
return response, err | ||
} | ||
|
||
// GetById GET /id/{id} | ||
func (c *userController) GetById(id string) (response model.Response, err error) { | ||
user, err := c.userService.GetUser(id) | ||
response = new(model.BaseResponse) | ||
if err != nil { | ||
response.SetCode(http.StatusNotFound) | ||
} else { | ||
response.SetData(user) | ||
} | ||
return | ||
} | ||
|
||
// GetById GET /id/{id} | ||
func (c *userController) GetAll() (response model.Response, err error) { | ||
users, err := c.userService.GetAll() | ||
response = new(model.BaseResponse) | ||
response.SetData(users) | ||
return | ||
} | ||
|
||
// DeleteById DELETE /id/{id} | ||
func (c *userController) DeleteById(id string) (response model.Response, err error) { | ||
err = c.userService.DeleteUser(id) | ||
response = new(model.BaseResponse) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package controller | ||
|
||
import ( | ||
"errors" | ||
"github.com/stretchr/testify/assert" | ||
"hidevops.io/hiboot-data/examples/es/entity" | ||
"hidevops.io/hiboot-data/examples/es/service/mocks" | ||
"hidevops.io/hiboot/pkg/app/web" | ||
"hidevops.io/hiboot/pkg/log" | ||
"hidevops.io/hiboot/pkg/utils/idgen" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
log.SetLevel(log.DebugLevel) | ||
} | ||
|
||
func TestCrdRequest(t *testing.T) { | ||
|
||
mockUserService := new(mocks.UserService) | ||
userController := newUserController(mockUserService) | ||
testApp := web.NewTestApp(userController).Run(t) | ||
|
||
id, err := idgen.NextString() | ||
assert.Equal(t, nil, err) | ||
|
||
testUser := &entity.User{ | ||
Id: id, | ||
Name: "Bill Gates", | ||
Username: "billg", | ||
Password: "3948tdaD", | ||
Email: "bill.gates@microsoft.com", | ||
Age: 60, | ||
Gender: 1, | ||
} | ||
|
||
// first, call mocks.UserService.AddUser | ||
mockUserService.On("AddUser", testUser).Return(testUser, nil) | ||
// then run the test that will call UserService.AddUser | ||
t.Run("should add user with POST request", func(t *testing.T) { | ||
// First, let's Post User | ||
testApp.Post("/user"). | ||
WithJSON(testUser). | ||
Expect().Status(http.StatusOK) | ||
}) | ||
|
||
mockUserService.On("GetUser", id).Return(testUser, nil) | ||
t.Run("should get user with GET request", func(t *testing.T) { | ||
// Then Get User | ||
// e.g. GET /user/id/123456 | ||
testApp.Get("/user/id/{id}"). | ||
WithPath("id", id). | ||
Expect().Status(http.StatusOK) | ||
}) | ||
|
||
mockUserService.On("GetAll").Return(&[]entity.User{*testUser}, nil) | ||
t.Run("should get user with GET request", func(t *testing.T) { | ||
// Then Get User | ||
// e.g. GET /user/id/123456 | ||
testApp.Get("/user/all"). | ||
Expect().Status(http.StatusOK) | ||
}) | ||
|
||
// assert that the expectations were met | ||
mockUserService.AssertExpectations(t) | ||
|
||
unknownId, err := idgen.NextString() | ||
assert.Equal(t, nil, err) | ||
mockUserService.On("GetUser", unknownId).Return((*entity.User)(nil), errors.New("not found")) | ||
|
||
t.Run("should return 404 if trying to find a record that does not exist", func(t *testing.T) { | ||
// Then Get User | ||
testApp.Get("/user/id/{id}"). | ||
WithPath("id", unknownId). | ||
Expect().Status(http.StatusNotFound) | ||
}) | ||
|
||
// assert that the expectations were met | ||
mockUserService.AssertExpectations(t) | ||
|
||
mockUserService.On("DeleteUser", id).Return(nil) | ||
t.Run("should delete the record with DELETE request", func(t *testing.T) { | ||
// Finally Delete User | ||
testApp.Delete("/user/id/{id}"). | ||
WithPath("id", id). | ||
Expect().Status(http.StatusOK) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package entity | ||
|
||
import "hidevops.io/hiboot/pkg/model" | ||
|
||
type User struct { | ||
model.RequestBody | ||
Id string `json:"id"` | ||
Name string `json:"name"` | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
Email string `json:"email"` | ||
Age uint `json:"age"` | ||
Gender uint `json:"gender"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package entity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
_ "hidevops.io/hiboot-data/examples/es/controller" | ||
"hidevops.io/hiboot/pkg/app" | ||
"hidevops.io/hiboot/pkg/app/web" | ||
"hidevops.io/hiboot/pkg/starter/actuator" | ||
"hidevops.io/hiboot/pkg/starter/locale" | ||
"hidevops.io/hiboot/pkg/starter/logging" | ||
) | ||
|
||
func main() { | ||
web.NewApplication(). | ||
SetProperty(app.ProfilesInclude, | ||
actuator.Profile, | ||
locale.Profile, | ||
logging.Profile). | ||
Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2018 John Deng (hi.devops.io@gmail.com). | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import "testing" | ||
|
||
func TestRunMain(t *testing.T) { | ||
go main() | ||
} |
Oops, something went wrong.