-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: Fix mixed wrong spring and hibernate transitive deps to old versions by maven (for IDEA run, just remove them from project)
- Loading branch information
Rene Gielen
authored and
Rene Gielen
committed
Apr 14, 2009
1 parent
b4c7841
commit 71fbde0
Showing
5 changed files
with
115 additions
and
2 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
42 changes: 42 additions & 0 deletions
42
src/main/java/org/aurifa/demo/strutter/service/MessageService.java
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,42 @@ | ||
package org.aurifa.demo.strutter.service; | ||
|
||
import org.aurifa.demo.strutter.model.Message; | ||
import org.aurifa.demo.strutter.model.User; | ||
import org.springframework.util.Assert; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.List; | ||
|
||
@Service | ||
public class MessageService extends GenericEntityService<Message, Long> { | ||
|
||
@Resource | ||
UserService userService; | ||
|
||
protected Class<Message> entityClass() { | ||
return Message.class; | ||
} | ||
|
||
public Message post ( User author, String text ) { | ||
Assert.notNull(author, "User must be provided"); | ||
|
||
if (text!=null) { | ||
Message m = new Message(author, text); | ||
save(m); | ||
author.getMessages().add(0, m); | ||
return m; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public List<Message> getTimeline(User user) { | ||
return null; | ||
} | ||
|
||
public List<Message> getPosts(User user) { | ||
return null; | ||
} | ||
|
||
} |
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
59 changes: 59 additions & 0 deletions
59
src/test/java/org/aurifa/demo/strutter/service/MessageServiceTest.java
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,59 @@ | ||
package org.aurifa.demo.strutter.service; | ||
|
||
import org.aurifa.demo.strutter.AbstractSpringEnabledTest; | ||
import org.aurifa.demo.strutter.model.User; | ||
import org.aurifa.demo.strutter.model.Message; | ||
import org.junit.runner.RunWith; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.transaction.TransactionConfiguration; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.annotation.Resource; | ||
|
||
import static junit.framework.Assert.assertTrue; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@TransactionConfiguration(defaultRollback=true) | ||
@Transactional | ||
public class MessageServiceTest extends AbstractSpringEnabledTest { | ||
|
||
@Resource | ||
MessageService messageService; | ||
|
||
@Test | ||
public void testInjection() { | ||
assertNotNull(messageService); | ||
} | ||
|
||
@Test | ||
public void testPost() { | ||
User u = new User("palim", null, null); | ||
messageService.userService.save(u); | ||
messageService.getCurrentSession().flush(); | ||
|
||
try { | ||
messageService.post(null, "huhu"); | ||
fail("Exception expected"); | ||
} catch (Exception e) { | ||
//expected | ||
} | ||
|
||
Message m = messageService.post(u, "huhu"); | ||
messageService.getCurrentSession().flush(); | ||
|
||
assertSame(u, m.getAuthor()); | ||
assertTrue(u.getMessages().contains(m)); | ||
} | ||
|
||
@Test | ||
public void testGetTimeline() { | ||
// Add your code here | ||
} | ||
|
||
@Test | ||
public void testGetPosts() { | ||
// Add your code here | ||
} | ||
} |