diff --git a/web/pom.xml b/web/pom.xml index 2d6144151..2cfaa7f96 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -303,6 +303,13 @@ test + + javax.servlet + javax.servlet-api + 3.0.1 + test + + diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/checker/AlarmChecker.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/checker/AlarmChecker.java index 1e0bd1c85..34884e2ad 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/checker/AlarmChecker.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/checker/AlarmChecker.java @@ -60,8 +60,8 @@ public abstract class AlarmChecker { return rule.isEmailSend(); } - public String getEmpGroup() { - return rule.getEmpGroup(); + public String getuserGroupId() { + return rule.getUserGroupId(); } public String getUnit() { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java index 410af44fb..e1e91ce6a 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/vo/Rule.java @@ -28,7 +28,7 @@ public class Rule { private String applicationId; private String CheckerName; private Integer threshold; - private String empGroup; + private String userGroupId; private boolean smsSend; private boolean emailSend; private String notes; @@ -36,11 +36,11 @@ public class Rule { public Rule() { } - public Rule(String applicationId, String checkerName, Integer Threshold, String empGroup, boolean smsSend, boolean emailSend, String notes) { + public Rule(String applicationId, String checkerName, Integer Threshold, String userGroupId, boolean smsSend, boolean emailSend, String notes) { this.applicationId = applicationId; this.CheckerName = checkerName; this.threshold = Threshold; - this.empGroup = empGroup; + this.userGroupId = userGroupId; this.smsSend = smsSend; this.emailSend = emailSend; this.notes = notes; @@ -70,12 +70,12 @@ public class Rule { this.threshold = threshold; } - public String getEmpGroup() { - return empGroup; + public String getUserGroupId() { + return userGroupId; } - public void setEmpGroup(String empGroup) { - this.empGroup = empGroup; + public void setuserGroupId(String userGroupId) { + this.userGroupId = userGroupId; } public boolean isSmsSend() { diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/UserController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/UserController.java new file mode 100644 index 000000000..12a8e1bcc --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/UserController.java @@ -0,0 +1,76 @@ +/* + * Copyright 2014 NAVER Corp. + * + * 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 com.navercorp.pinpoint.web.controller; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.navercorp.pinpoint.web.service.UserService; +import com.navercorp.pinpoint.web.vo.User; + +/** + * @author minwoo.jung + */ +@Controller +@RequestMapping(value = "/user") +public class UserController { + + @Autowired + UserService userService; + + @RequestMapping(method = RequestMethod.POST) + @ResponseBody + public Map insertUser(@RequestBody User user) { + + if (StringUtils.isEmpty(user.getUserId()) || StringUtils.isEmpty(user.getName())) { + Map result = new HashMap(); + result.put("errorCode", "500"); + result.put("errorMessage", "there is not userId or name in params to creating user infomation"); + return result; + } + + userService.insertUser(user); + + Map result = new HashMap(); + result.put("result", "SUCCESS"); + return result; + } + + @RequestMapping(method = RequestMethod.DELETE) + @ResponseBody + public Map deletetUser(@RequestBody User user) { + if (StringUtils.isEmpty(user.getUserId())) { + Map result = new HashMap(); + result.put("errorCode", "500"); + result.put("errorMessage", "there is not userId in params to delete user"); + return result; + } + + userService.deleteUser(user); + + Map result = new HashMap(); + result.put("result", "SUCCESS"); + return result; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/UserGroupController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/UserGroupController.java index 22c790b99..dfaeaf099 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/UserGroupController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/UserGroupController.java @@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.navercorp.pinpoint.web.service.UserGroupService; +import com.navercorp.pinpoint.web.vo.UserGroupMember; /** * @author minwoo.jung @@ -35,6 +36,7 @@ import com.navercorp.pinpoint.web.service.UserGroupService; public class UserGroupController { public static final String USER_GROUP_ID = "userGroupId"; + public static final String USER_GROUP_MEMBER_ID = "userGroupMemberId"; @Autowired UserGroupService userGroupService; @@ -76,4 +78,45 @@ public class UserGroupController { result.put("result", "SUCCESS"); return result; } + + + @RequestMapping(value = "/member", method = RequestMethod.POST) + @ResponseBody + public Map insertUserGroupMember(@RequestBody Map params) { + String userGroupId = params.get(USER_GROUP_ID); + String userGroupMemberId = params.get(USER_GROUP_MEMBER_ID); + + if (userGroupId == null || userGroupMemberId == null) { + Map result = new HashMap(); + result.put("errorCode", "500"); + result.put("errorMessage", "there is not userGroupId or userGroupMemberId in params to deleting user group"); + return result; + } + + userGroupService.insertMember(new UserGroupMember(userGroupId, userGroupMemberId)); + + Map result = new HashMap(); + result.put("result", "SUCCESS"); + return result; + } + + @RequestMapping(value = "/member", method = RequestMethod.DELETE) + @ResponseBody + public Map deleteUserGroupMember(@RequestBody Map params) { + String userGroupId = params.get(USER_GROUP_ID); + String userGroupMemberId = params.get(USER_GROUP_MEMBER_ID); + + if (userGroupId == null || userGroupMemberId == null) { + Map result = new HashMap(); + result.put("errorCode", "500"); + result.put("errorMessage", "there is not userGroupId or userGroupMemberId in params to deleting user group"); + return result; + } + + userGroupService.deleteMember(new UserGroupMember(userGroupId, userGroupMemberId)); + + Map result = new HashMap(); + result.put("result", "SUCCESS"); + return result; + } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/UserDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/UserDao.java new file mode 100644 index 000000000..95105c378 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/UserDao.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 NAVER Corp. + * + * 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 com.navercorp.pinpoint.web.dao; + +import com.navercorp.pinpoint.web.vo.User; + +/** + * @author minwoo.jung + */ +public interface UserDao { + + void insertUser(User user); + + void deleteUser(User user); + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java index a564f317f..16545b77d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java @@ -17,6 +17,8 @@ package com.navercorp.pinpoint.web.dao; import java.util.List; +import com.navercorp.pinpoint.web.vo.UserGroupMember; + /** * @author minwoo.jung */ @@ -28,4 +30,8 @@ public interface UserGroupDao { void updateUserGroup(); void deleteUserGroup(String userGroupId); + + void insertMember(UserGroupMember userGroupMember); + + void deleteMember(UserGroupMember userGroupMember); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserDao.java new file mode 100644 index 000000000..af7f6b151 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserDao.java @@ -0,0 +1,49 @@ +/* + * Copyright 2014 NAVER Corp. + * + * 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 com.navercorp.pinpoint.web.dao.mysql; + +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import com.navercorp.pinpoint.web.dao.UserDao; +import com.navercorp.pinpoint.web.vo.User; + +/** + * @author minwoo.jung + */ +@Repository +public class MysqlUserDao implements UserDao { + + private static final String NAMESPACE = UserDao.class.getPackage().getName() + "." + UserDao.class.getSimpleName() + "."; + + @Autowired + @Qualifier("sqlSessionTemplate") + private SqlSessionTemplate sqlSessionTemplate; + + @Override + public void insertUser(User user) { + sqlSessionTemplate.insert(NAMESPACE + "insertUser", user); + } + + @Override + public void deleteUser(User user) { + sqlSessionTemplate.delete(NAMESPACE + "deleteUser", user); + + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java index f1349e608..c32d2f55e 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java @@ -17,12 +17,15 @@ package com.navercorp.pinpoint.web.dao.mysql; import java.util.List; +import javax.xml.stream.events.Namespace; + import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.navercorp.pinpoint.web.dao.UserGroupDao; +import com.navercorp.pinpoint.web.vo.UserGroupMember; /** * @author minwoo.jung @@ -43,14 +46,11 @@ public class MysqlUserGroupDao implements UserGroupDao { @Override public List selectUserGroupList() { - // TODO Auto-generated method stub return null; } @Override public void updateUserGroup() { - // TODO Auto-generated method stub - } @Override @@ -58,4 +58,14 @@ public class MysqlUserGroupDao implements UserGroupDao { sqlSessionTemplate.delete(NAMESPACE + "deleteUserGroup", userGroupId); } + @Override + public void insertMember(UserGroupMember userGroupMember) { + sqlSessionTemplate.insert(NAMESPACE + "insertMember", userGroupMember); + } + + @Override + public void deleteMember(UserGroupMember userGroupMember) { + sqlSessionTemplate.delete(NAMESPACE + "deleteMember", userGroupMember); + } + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java index 9677c7317..d18f79656 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java @@ -17,6 +17,8 @@ package com.navercorp.pinpoint.web.service; import java.util.List; +import com.navercorp.pinpoint.web.vo.UserGroupMember; + /** * @author minwoo.jung */ @@ -28,4 +30,8 @@ public interface UserGroupService { void updateUserGroup(); void deleteUserGroup(String userGroupId); + + void insertMember(UserGroupMember userGroupMember); + + void deleteMember(UserGroupMember userGroupMember); } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java index 38cceee17..1dde3ed18 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.navercorp.pinpoint.web.dao.UserGroupDao; +import com.navercorp.pinpoint.web.vo.UserGroupMember; /** * @author minwoo.jung @@ -50,4 +51,15 @@ public class UserGroupServiceImpl implements UserGroupService { userGroupDao.deleteUserGroup(userGroupId); } + @Override + public void insertMember(UserGroupMember userGroupMember) { + userGroupDao.insertMember(userGroupMember); + } + + @Override + public void deleteMember(UserGroupMember userGroupMember) { + userGroupDao.deleteMember(userGroupMember); + + } + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/UserService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/UserService.java new file mode 100644 index 000000000..2b705e376 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/UserService.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 NAVER Corp. + * + * 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 com.navercorp.pinpoint.web.service; + +import com.navercorp.pinpoint.web.vo.User; + +/** + * @author minwoo.jung + */ +public interface UserService { + + void insertUser(User user); + + void deleteUser(User user); + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/UserServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/UserServiceImpl.java new file mode 100644 index 000000000..894d7b3e3 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/UserServiceImpl.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014 NAVER Corp. + * + * 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 com.navercorp.pinpoint.web.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.navercorp.pinpoint.web.dao.UserDao; +import com.navercorp.pinpoint.web.vo.User; + +/** + * @author minwoo.jung + */ +@Service +public class UserServiceImpl implements UserService { + + @Autowired + UserDao userDao; + + @Override + public void insertUser(User user) { + userDao.insertUser(user); + } + + @Override + public void deleteUser(User user) { + userDao.deleteUser(user); + } + +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/User.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/User.java new file mode 100644 index 000000000..2a68e8390 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/User.java @@ -0,0 +1,49 @@ +package com.navercorp.pinpoint.web.vo; + +public class User { + private String userId; + private String name; + private String department; + private String phoneNumber; + private String email; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/vo/UserGroupMember.java b/web/src/main/java/com/navercorp/pinpoint/web/vo/UserGroupMember.java new file mode 100644 index 000000000..920724da3 --- /dev/null +++ b/web/src/main/java/com/navercorp/pinpoint/web/vo/UserGroupMember.java @@ -0,0 +1,32 @@ +package com.navercorp.pinpoint.web.vo; + +public class UserGroupMember { + + private String userGroupId; + private String memberId; + + public UserGroupMember() { + } + + public UserGroupMember(String userGroupId, String memberId) { + this.userGroupId = userGroupId; + this.memberId = memberId; + } + + public String getUserGroupId() { + return userGroupId; + } + + public void setUserGroupId(String userGroupId) { + this.userGroupId = userGroupId; + } + + public String getMemberId() { + return memberId; + } + + public void setMemberId(String memberId) { + this.memberId = memberId; + } + +} diff --git a/web/src/main/resources/mapper/AlarmMapper.xml b/web/src/main/resources/mapper/AlarmMapper.xml index 0991fbe2b..4c29fb770 100644 --- a/web/src/main/resources/mapper/AlarmMapper.xml +++ b/web/src/main/resources/mapper/AlarmMapper.xml @@ -2,7 +2,6 @@ - - INSERT INTO alarm_rule(application_id, checker_name, threshold, emp_group, sms_send, email_send, notes) + INSERT INTO alarm_rule(application_id, checker_name, threshold, user_group_id, sms_send, email_send, notes) VALUES - (#{rule.applicationId}, #{rule.checkerName}, #{rule.threshold}, #{rule.empGroup}, #{rule.smsSend}, #{rule.emailSend}, #{rule.notes}) + (#{rule.applicationId}, #{rule.checkerName}, #{rule.threshold}, #{rule.userGroupId}, #{rule.smsSend}, #{rule.emailSend}, #{rule.notes}) diff --git a/web/src/main/resources/mapper/UserGroupMapper.xml b/web/src/main/resources/mapper/UserGroupMapper.xml index edc138f38..d11fe4505 100644 --- a/web/src/main/resources/mapper/UserGroupMapper.xml +++ b/web/src/main/resources/mapper/UserGroupMapper.xml @@ -1,6 +1,7 @@ + @@ -13,4 +14,15 @@ FROM user_group WHERE groupId = #{userGroupId} + + + INSERT INTO user_group_member + VALUES (#{userGroupId}, #{memberId}) + + + + DELETE + FROM user_group_member + WHERE groupId = #{userGroupId} AND memberId = #{memberId} + diff --git a/web/src/main/resources/mapper/UserMapper.xml b/web/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 000000000..a6979422f --- /dev/null +++ b/web/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + INSERT INTO user + VALUES (#{userId}, #{name}, #{department}, #{phoneNumber}, #{email}) + + + + DELETE + FROM user + WHERE userId = #{userId} + + diff --git a/web/src/main/resources/mybatis-config.xml b/web/src/main/resources/mybatis-config.xml index 8186851ac..8fa8bab67 100644 --- a/web/src/main/resources/mybatis-config.xml +++ b/web/src/main/resources/mybatis-config.xml @@ -22,5 +22,10 @@ + + + + + diff --git a/web/src/main/resources/sql/CreateTableStatement.sql b/web/src/main/resources/sql/CreateTableStatement.sql new file mode 100644 index 000000000..81fdf7832 --- /dev/null +++ b/web/src/main/resources/sql/CreateTableStatement.sql @@ -0,0 +1,23 @@ +DROP TABLE user_group; +DROP TABLE user_group_member; +DROP TABLE user; + +CREATE TABLE `user_group` ( + `groupId` VARCHAR(30) NOT NULL, + PRIMARY KEY (`groupId`) +); + +CREATE TABLE `user_group_member` ( + `groupId` VARCHAR(30) NOT NULL, + `memberId` VARCHAR(30) NOT NULL, + PRIMARY KEY (`groupId`, memberId) +); + +CREATE TABLE `user` ( + `userId` VARCHAR(30) NOT NULL, + `name` VARCHAR(30) NOT NULL, + `department` VARCHAR(100) NOT NULL, + `phonenumber` VARCHAR(30) NOT NULL, + `email` VARCHAR(30) NOT NULL, + PRIMARY KEY (`id`) +); \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/controller/UserControllerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/controller/UserControllerTest.java new file mode 100644 index 000000000..0d0a65982 --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/controller/UserControllerTest.java @@ -0,0 +1,96 @@ +/* + * Copyright 2014 NAVER Corp. + * + * 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 com.navercorp.pinpoint.web.controller; + +import static org.hamcrest.Matchers.hasKey; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import com.navercorp.pinpoint.web.dao.UserDao; +import com.navercorp.pinpoint.web.vo.User; + +/** + * @author minwoo.jung + */ +@Ignore +@RunWith(SpringJUnit4ClassRunner.class) +@WebAppConfiguration +@ContextConfiguration(locations = {"classpath:servlet-context.xml", "classpath:applicationContext-web.xml"}) +public class UserControllerTest { + + private final static String USER_ID = "naver00"; + private final static String USER_NAME = "minwoo"; + private final static String USER_DEPARTMENT = "Web platfrom development team"; + private final static String USER_PHONENUMBER = "01012347890"; + private final static String USER_EMAIL = "min@naver.com"; + + @Autowired + private WebApplicationContext wac; + + + @Autowired + private UserDao userDao; + + private MockMvc mockMvc; + + @Before + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); + User user = new User(); + user.setUserId(USER_ID); + userDao.deleteUser(user); + } + + @Test + public void insertAndDeleteUser() throws Exception { + String jsonParm = "{" + + "\"userId\" : \"" + USER_ID + "\"," + + "\"name\" : \"" + USER_NAME + "\"," + + "\"department\" : \"" + USER_DEPARTMENT + "\"," + + "\"phoneNumber\" : \"" + USER_PHONENUMBER + "\"," + + "\"email\" : \"" + USER_EMAIL + "\"" + + "}"; + + this.mockMvc.perform(post("/user.pinpoint").contentType(MediaType.APPLICATION_JSON).content(jsonParm)) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); + + this.mockMvc.perform(delete("/user.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userId\" : \"" + USER_ID + "\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); + } +} diff --git a/web/src/test/java/com/navercorp/pinpoint/web/controller/UserGroupControllerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/controller/UserGroupControllerTest.java index 62b949358..1f6de43d3 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/controller/UserGroupControllerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/controller/UserGroupControllerTest.java @@ -17,6 +17,7 @@ package com.navercorp.pinpoint.web.controller; import static org.hamcrest.Matchers.hasKey; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -36,6 +37,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import com.navercorp.pinpoint.web.dao.UserGroupDao; +import com.navercorp.pinpoint.web.vo.UserGroupMember; /** * @author minwoo.jung @@ -46,11 +48,11 @@ import com.navercorp.pinpoint.web.dao.UserGroupDao; @ContextConfiguration(locations = {"classpath:servlet-context.xml", "classpath:applicationContext-web.xml"}) public class UserGroupControllerTest { - public final static String TEST_USER_GROUP_ID = "testUserGroup"; - + private final static String TEST_USER_GROUP_ID = "testUserGroup"; + private final static String TEST_USER_GROUP_MEMBER_ID = "naver01"; + @Autowired private WebApplicationContext wac; - @Autowired private UserGroupDao userGroupDao; @@ -61,48 +63,63 @@ public class UserGroupControllerTest { public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); userGroupDao.deleteUserGroup(TEST_USER_GROUP_ID); - + userGroupDao.deleteMember(new UserGroupMember(TEST_USER_GROUP_ID, TEST_USER_GROUP_MEMBER_ID)); } @Test public void createAndDeleteUserGroup() throws Exception { - MvcResult result = this.mockMvc.perform(post("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + TEST_USER_GROUP_ID + "\"}")) - .andExpect(status().isOk()) - .andExpect(content().contentType("application/json;charset=UTF-8")) - .andExpect(jsonPath("$", hasKey("result"))) - .andExpect(jsonPath("$.result").value("SUCCESS")) - .andReturn(); - - MvcResult result2 = this.mockMvc.perform(delete("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + TEST_USER_GROUP_ID + "\"}")) - .andExpect(status().isOk()) - .andExpect(content().contentType("application/json;charset=UTF-8")) - .andExpect(jsonPath("$", hasKey("result"))) - .andExpect(jsonPath("$.result").value("SUCCESS")) - .andReturn(); + this.mockMvc.perform(post("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + TEST_USER_GROUP_ID + "\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); + + this.mockMvc.perform(delete("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + TEST_USER_GROUP_ID + "\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); } @Test public void createUserGroupError() throws Exception { - MvcResult result = this.mockMvc.perform(post("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{}")) - .andExpect(status().isOk()) - .andExpect(content().contentType("application/json;charset=UTF-8")) - .andExpect(jsonPath("$", hasKey("errorCode"))) - .andExpect(jsonPath("$.errorCode").value("500")) - .andReturn(); - String content = result.getResponse().getContentAsString(); - System.out.println(content); + this.mockMvc.perform(post("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("errorCode"))) + .andExpect(jsonPath("$.errorCode").value("500")) + .andReturn(); } @Test public void createUserGroup2Error() throws Exception { - MvcResult result = this.mockMvc.perform(delete("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{}")) - .andExpect(status().isOk()) - .andExpect(content().contentType("application/json;charset=UTF-8")) - .andExpect(jsonPath("$", hasKey("errorCode"))) - .andExpect(jsonPath("$.errorCode").value("500")) - .andReturn(); - String content = result.getResponse().getContentAsString(); - System.out.println(content); + this.mockMvc.perform(delete("/userGroup.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("errorCode"))) + .andExpect(jsonPath("$.errorCode").value("500")) + .andReturn(); } + @Test + public void insertAndDeleteMember() throws Exception { + this.mockMvc.perform(post("/userGroup/member.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + TEST_USER_GROUP_ID + "\", \"userGroupMemberId\" : \"" + TEST_USER_GROUP_MEMBER_ID + "\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); + + this.mockMvc.perform(delete("/userGroup/member.pinpoint").contentType(MediaType.APPLICATION_JSON).content("{\"userGroupId\" : \"" + TEST_USER_GROUP_ID + "\", \"userGroupMemberId\" : \"" + TEST_USER_GROUP_MEMBER_ID + "\"}")) + .andExpect(status().isOk()) + .andExpect(content().contentType("application/json;charset=UTF-8")) + .andExpect(jsonPath("$", hasKey("result"))) + .andExpect(jsonPath("$.result").value("SUCCESS")) + .andReturn(); + } + + + }