Skip to content

Commit

Permalink
Unable to save email send to WebWolf WebGoat#419
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaars committed Jan 10, 2018
1 parent ae92ac6 commit e801b09
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
7 changes: 7 additions & 0 deletions webwolf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
<artifactId>hsqldb</artifactId>
<version>${hsqldb.version}</version>
</dependency>

<!-- ************* START: Dependencies for Unit and Integration Testing ************** -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
5 changes: 4 additions & 1 deletion webwolf/src/main/java/org/owasp/webwolf/mailbox/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.time.LocalDateTime;
Expand All @@ -23,7 +25,8 @@
public class Email implements Serializable {

@Id
private String id;
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private LocalDateTime time;
private String contents;
private String sender;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.owasp.webwolf.mailbox;

import org.hamcrest.CoreMatchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDateTime;
import java.util.List;

import static org.junit.Assert.*;

@DataJpaTest
@RunWith(SpringRunner.class)
public class MailboxRepositoryTest {


@Autowired
private MailboxRepository mailboxRepository;

@Test
public void emailShouldBeSaved() {
Email email = new Email();
email.setTime(LocalDateTime.now());
email.setTitle("test");
email.setSender("[email protected]");
email.setContents("test");
email.setRecipient("[email protected]");
mailboxRepository.save(email);
}

@Test
public void savedEmailShouldBeFoundByReceipient() {
Email email = new Email();
email.setTime(LocalDateTime.now());
email.setTitle("test");
email.setSender("[email protected]");
email.setContents("test");
email.setRecipient("[email protected]");
mailboxRepository.saveAndFlush(email);

List<Email> emails = mailboxRepository.findByRecipientOrderByTimeDesc("[email protected]");

assertThat(emails.size(), CoreMatchers.is(1));
}

}

0 comments on commit e801b09

Please sign in to comment.