[#762] add CRUD logic for user, member of userGroup

This commit is contained in:
Minwoo Jung
2015-08-04 16:46:58 +09:00
parent 3ef9be4e75
commit efb057ab37
22 changed files with 608 additions and 48 deletions
+7
View File
@@ -303,6 +303,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -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() {
@@ -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() {
@@ -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<String, String> insertUser(@RequestBody User user) {
if (StringUtils.isEmpty(user.getUserId()) || StringUtils.isEmpty(user.getName())) {
Map<String, String> result = new HashMap<String, String>();
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<String, String> result = new HashMap<String, String>();
result.put("result", "SUCCESS");
return result;
}
@RequestMapping(method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> deletetUser(@RequestBody User user) {
if (StringUtils.isEmpty(user.getUserId())) {
Map<String, String> result = new HashMap<String, String>();
result.put("errorCode", "500");
result.put("errorMessage", "there is not userId in params to delete user");
return result;
}
userService.deleteUser(user);
Map<String, String> result = new HashMap<String, String>();
result.put("result", "SUCCESS");
return result;
}
}
@@ -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<String, String> insertUserGroupMember(@RequestBody Map<String, String> params) {
String userGroupId = params.get(USER_GROUP_ID);
String userGroupMemberId = params.get(USER_GROUP_MEMBER_ID);
if (userGroupId == null || userGroupMemberId == null) {
Map<String, String> result = new HashMap<String, String>();
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<String, String> result = new HashMap<String, String>();
result.put("result", "SUCCESS");
return result;
}
@RequestMapping(value = "/member", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, String> deleteUserGroupMember(@RequestBody Map<String, String> params) {
String userGroupId = params.get(USER_GROUP_ID);
String userGroupMemberId = params.get(USER_GROUP_MEMBER_ID);
if (userGroupId == null || userGroupMemberId == null) {
Map<String, String> result = new HashMap<String, String>();
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<String, String> result = new HashMap<String, String>();
result.put("result", "SUCCESS");
return result;
}
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
}
@@ -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<String> 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);
}
}
@@ -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);
}
@@ -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);
}
}
@@ -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);
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -2,7 +2,6 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.navercorp.pinpoint.web.dao.AlarmResourceDao">
<select id="selectRules" resultType="rule" parameterType="String">
SELECT *
FROM alarm_rule
@@ -10,10 +9,10 @@
</select>
<insert id="insertAppRule" parameterType="java.util.List">
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
<foreach collection="list" item="rule" separator=",">
(#{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})
</foreach>
</insert>
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.navercorp.pinpoint.web.dao.UserGroupDao">
<insert id="insertUserGroup" parameterType="string">
@@ -13,4 +14,15 @@
FROM user_group
WHERE groupId = #{userGroupId}
</delete>
<insert id="insertMember" parameterType="UserGroupMember">
INSERT INTO user_group_member
VALUES (#{userGroupId}, #{memberId})
</insert>
<delete id="deleteMember" parameterType="UserGroupMember">
DELETE
FROM user_group_member
WHERE groupId = #{userGroupId} AND memberId = #{memberId}
</delete>
</mapper>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.navercorp.pinpoint.web.dao.UserDao">
<insert id="insertUser" parameterType="User">
INSERT INTO user
VALUES (#{userId}, #{name}, #{department}, #{phoneNumber}, #{email})
</insert>
<delete id="deleteUser" parameterType="User">
DELETE
FROM user
WHERE userId = #{userId}
</delete>
</mapper>
@@ -22,5 +22,10 @@
<!--undersocre mapping of DB table -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
<typeAliases>
<typeAlias type="com.navercorp.pinpoint.web.vo.UserGroupMember" alias="UserGroupMember"/>
<typeAlias type="com.navercorp.pinpoint.web.vo.User" alias="User"/>
</typeAliases>
</configuration>
@@ -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`)
);
@@ -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();
}
}
@@ -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();
}
}