-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JC-2409 Error 500 when saving PM with invalid "To" field
- Fixed hibernate lazy initialization exception by moving userService.getCurrentUser() to service layer.
- Loading branch information
1 parent
cdf589c
commit 8566f46
Showing
10 changed files
with
160 additions
and
13 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
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
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
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
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 |
---|---|---|
|
@@ -181,12 +181,13 @@ public void testGetDraftsForCurrentUser() { | |
} | ||
|
||
@Test | ||
public void testSaveDraft() throws NotFoundException { | ||
public void testSaveDraft() { | ||
JCUser recipient = new JCUser("name", "[email protected]", "pwd"); | ||
|
||
when(securityService.<User>createAclBuilder()).thenReturn(aclBuilder); | ||
when(userService.getCurrentUser()).thenReturn(JC_USER); | ||
|
||
pmService.saveDraft(PM_ID, recipient, "title", "body", JC_USER); | ||
pmService.saveDraft(PM_ID, recipient, "title", "body"); | ||
|
||
verify(pmDao).saveOrUpdate(any(PrivateMessage.class)); | ||
verify(aclBuilder).grant(GeneralPermission.WRITE); | ||
|
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
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
72 changes: 72 additions & 0 deletions
72
...mmune-web-view/src/test/java/org/jtalks/jcommune/test/PrivateMessageControllerTest.groovy
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,72 @@ | ||
/** | ||
* Copyright (C) 2011 JTalks.org Team | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
package org.jtalks.jcommune.test | ||
|
||
import org.jtalks.common.model.permissions.ProfilePermission | ||
import org.jtalks.jcommune.service.security.AdministrationGroup | ||
import org.jtalks.jcommune.test.model.User | ||
import org.jtalks.jcommune.test.service.GroupsService | ||
import org.jtalks.jcommune.test.utils.PrivateMessages | ||
import org.jtalks.jcommune.test.utils.Users | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.mock.web.MockHttpSession | ||
import org.springframework.test.context.ContextConfiguration | ||
import org.springframework.test.context.transaction.TransactionConfiguration | ||
import org.springframework.test.context.web.WebAppConfiguration | ||
import org.springframework.test.web.servlet.MockMvc | ||
import org.springframework.transaction.annotation.Transactional | ||
import spock.lang.Specification | ||
|
||
import static org.jtalks.jcommune.test.utils.assertions.Assert.assertView | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post | ||
|
||
/** | ||
* @author Evgeniy Cheban | ||
*/ | ||
@WebAppConfiguration | ||
@ContextConfiguration(locations = 'classpath:/org/jtalks/jcommune/web/view/test-configuration.xml') | ||
@TransactionConfiguration(transactionManager = 'transactionManager', defaultRollback = true) | ||
@Transactional | ||
class PrivateMessageControllerTest extends Specification { | ||
@Autowired | ||
Users users | ||
@Autowired | ||
GroupsService groupsService | ||
@Autowired | ||
MockMvc mockMvc | ||
|
||
def setup() { | ||
groupsService.createPredefinedGroups() | ||
} | ||
|
||
def 'should save draft private message when "to" invalid'() { | ||
given: 'User logged in' | ||
def user = User.newInstance() | ||
def group = groupsService.getGroupByName(AdministrationGroup.USER.name) | ||
users.created(user).withPermissionOn(group, ProfilePermission.SEND_PRIVATE_MESSAGES) | ||
|
||
def session = users.signIn(user) | ||
when: 'User save draft private message with invalid "to"' | ||
def pmDto = PrivateMessages.randomDto() | ||
def mvcResult = mockMvc.perform(post('/pm/save') | ||
.session(session as MockHttpSession) | ||
.param('title', pmDto.title) | ||
.param('body', pmDto.body) | ||
.param('recipient', pmDto.recipient) | ||
).andReturn() | ||
then: | ||
assertView(mvcResult, 'redirect:/drafts') | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...w/jcommune-web-view/src/test/java/org/jtalks/jcommune/test/model/PrivateMessageDto.groovy
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,24 @@ | ||
/** | ||
* Copyright (C) 2011 JTalks.org Team | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
package org.jtalks.jcommune.test.model | ||
|
||
/** | ||
* @author Evgeniy Cheban | ||
*/ | ||
class PrivateMessageDto { | ||
String title | ||
String body | ||
String recipient | ||
} |
37 changes: 37 additions & 0 deletions
37
...iew/jcommune-web-view/src/test/java/org/jtalks/jcommune/test/utils/PrivateMessages.groovy
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,37 @@ | ||
/** | ||
* Copyright (C) 2011 JTalks.org Team | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
package org.jtalks.jcommune.test.utils | ||
|
||
import org.jtalks.common.model.entity.User | ||
import org.jtalks.jcommune.model.entity.PrivateMessage | ||
import org.jtalks.jcommune.test.model.PrivateMessageDto | ||
|
||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic | ||
|
||
/** | ||
* @author Evgeniy Cheban | ||
*/ | ||
class PrivateMessages { | ||
|
||
static PrivateMessageDto randomDto(Map<String, Object> overrideDefaults = [:]) { | ||
Map<String, Object> defaults = [ | ||
'title': randomAlphabetic(PrivateMessage.MAX_TITLE_LENGTH).toString(), | ||
'body': randomAlphabetic(PrivateMessage.MAX_MESSAGE_LENGTH).toString(), | ||
'recipient': randomAlphabetic(User.USERNAME_MAX_LENGTH).toString() | ||
] | ||
defaults.putAll(overrideDefaults) | ||
return new PrivateMessageDto(defaults) | ||
} | ||
} |