Skip to content

Commit

Permalink
Merge pull request #34 from gessnerfl/feature/33_version_in_ui
Browse files Browse the repository at this point in the history
closes #33: version added to UI. All dependencies updated
  • Loading branch information
gessnerfl authored Nov 13, 2020
2 parents 688f728 + 3e6e3e2 commit 5783291
Show file tree
Hide file tree
Showing 27 changed files with 363 additions and 339 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM adoptopenjdk/openjdk11:x86_64-alpine-jdk-11.0.8_10
FROM adoptopenjdk/openjdk11:x86_64-alpine-jdk-11.0.9_11

VOLUME /tmp

Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "com.cinnober.gradle.semver-git" version "3.0.0"
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'org.springframework.boot' version '2.4.0'
id "org.sonarqube" version "3.0"
}

Expand Down Expand Up @@ -45,6 +45,10 @@ dependencies {
testImplementation('org.hamcrest:hamcrest-core:2.2')
}

springBoot {
buildInfo()
}

sonarqube {
properties {
property "sonar.projectName", "Fake SMTP Server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
Expand All @@ -16,17 +17,20 @@
public class EmailController {
private static final Sort DEFAULT_SORT = Sort.by(Sort.Direction.DESC, "receivedOn");
private static final int DEFAULT_PAGE_SIZE = 10;
static final String APP_VERSION_MODEL_NAME = "appVersion";
static final String EMAIL_LIST_VIEW = "email-list";
static final String EMAIL_LIST_MODEL_NAME = "mails";
static final String SINGLE_EMAIL_VIEW = "email";
static final String SINGLE_EMAIL_MODEL_NAME = "mail";
static final String REDIRECT_EMAIL_LIST_VIEW = "redirect:/email";

private final EmailRepository emailRepository;
private final BuildProperties buildProperties;

@Autowired
public EmailController(EmailRepository emailRepository) {
public EmailController(EmailRepository emailRepository, BuildProperties buildProperties) {
this.emailRepository = emailRepository;
this.buildProperties = buildProperties;
}

@GetMapping({"/", "/email"})
Expand All @@ -43,6 +47,7 @@ private String getAllEmailsPaged(int page, int size, Model model) {
return REDIRECT_EMAIL_LIST_VIEW;
}
model.addAttribute(EMAIL_LIST_MODEL_NAME, result);
addApplicationVersion(model);
return EMAIL_LIST_VIEW;
}

Expand All @@ -53,6 +58,7 @@ public String getEmailById(@PathVariable Long id, Model model) {

private String appendToModelAndReturnView(Model model, Email email) {
model.addAttribute(SINGLE_EMAIL_MODEL_NAME, email);
addApplicationVersion(model);
return SINGLE_EMAIL_VIEW;
}

Expand All @@ -63,4 +69,8 @@ public String deleteEmailById(@PathVariable Long id) {
return REDIRECT_EMAIL_LIST_VIEW;
}

private void addApplicationVersion(Model model){
model.addAttribute(APP_VERSION_MODEL_NAME, buildProperties.getVersion());
}

}
5 changes: 4 additions & 1 deletion src/main/resources/templates/fragments/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

<body>
<div class="navbar-fixed" th:fragment="navbar" >
<nav class="light-blue darken-4" style="padding-left:10px">
<nav class="light-blue darken-4" style="padding-left:10px; padding-right:10px;">
<div class="nav-wrapper">
<a class="brand-logo" href="/"><i class="material-icons" style="font-size: 2rem">email</i>Fake SMTP Server</a>
<ul class="right">
<li th:text="${'Version: ' + appVersion}"></li>
</ul>
</div>
</nav>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/de/gessnerfl/fakesmtp/TestResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class TestResourceUtil {
private static final String TEST_DATA_FOLDER = "/test-data/";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package de.gessnerfl.fakesmtp.config;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.net.InetAddress;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

@ActiveProfiles({"integrationtest","config_integrationtest"})
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class FakeSmtpConfigurationPropertiesIntegrationTest {
class FakeSmtpConfigurationPropertiesIntegrationTest {

@Autowired
private FakeSmtpConfigurationProperties sut;

@Test
public void shouldLoadConfigurationParameters() throws Exception {
void shouldLoadConfigurationParameters() throws Exception {
assertEquals(1234, sut.getPort().intValue());
assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
assertNull(sut.getAuthentication());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package de.gessnerfl.fakesmtp.config;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.net.InetAddress;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

@ActiveProfiles({"integrationtest", "config_with_auth_integrationtest"})
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest {
class FakeSmtpConfigurationPropertiesWithAuthenticationIntegrationTest {

@Autowired
private FakeSmtpConfigurationProperties sut;

@Test
public void shouldLoadConfigurationParameters() throws Exception {
assertEquals(1234, sut.getPort().intValue());
assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
assertNotNull(sut.getAuthentication());
assertEquals("user", sut.getAuthentication().getUsername());
assertEquals("password", sut.getAuthentication().getPassword());
assertNotNull(sut.getPersistence());
assertEquals(FakeSmtpConfigurationProperties.Persistence.DEFAULT_MAX_NUMBER_EMAILS, sut.getPersistence().getMaxNumberEmails().intValue());
void shouldLoadConfigurationParameters() throws Exception {
Assertions.assertEquals(1234, sut.getPort().intValue());
Assertions.assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
Assertions.assertNotNull(sut.getAuthentication());
Assertions.assertEquals("user", sut.getAuthentication().getUsername());
Assertions.assertEquals("password", sut.getAuthentication().getPassword());
Assertions.assertNotNull(sut.getPersistence());
Assertions.assertEquals(FakeSmtpConfigurationProperties.Persistence.DEFAULT_MAX_NUMBER_EMAILS, sut.getPersistence().getMaxNumberEmails().intValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
package de.gessnerfl.fakesmtp.config;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.net.InetAddress;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

@ActiveProfiles({"integrationtest","config_with_persistence_integrationtest"})
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest {
class FakeSmtpConfigurationPropertiesWithPersistenceIntegrationTest {

@Autowired
private FakeSmtpConfigurationProperties sut;

@Test
public void shouldLoadConfigurationParameters() throws Exception {
assertEquals(1234, sut.getPort().intValue());
assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
assertNull(sut.getAuthentication());
assertNotNull(sut.getPersistence());
assertEquals(5, sut.getPersistence().getMaxNumberEmails().intValue());
void shouldLoadConfigurationParameters() throws Exception {
Assertions.assertEquals(1234, sut.getPort().intValue());
Assertions.assertEquals(InetAddress.getByName("127.0.0.1"), sut.getBindAddress());
Assertions.assertNull(sut.getAuthentication());
Assertions.assertNotNull(sut.getPersistence());
Assertions.assertEquals(5, sut.getPersistence().getMaxNumberEmails().intValue());
}
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,50 @@
package de.gessnerfl.fakesmtp.controller;

import de.gessnerfl.fakesmtp.model.ContentType;
import de.gessnerfl.fakesmtp.model.Email;
import de.gessnerfl.fakesmtp.model.EmailAttachment;
import de.gessnerfl.fakesmtp.model.EmailContent;
import de.gessnerfl.fakesmtp.repository.EmailRepository;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@ActiveProfiles("integrationtest")
@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
public class EmailControllerMVCIntegrationTest {
class EmailControllerMVCIntegrationTest {

@Autowired
private EmailRepository emailRepository;
@Autowired
private MockMvc mockMvc;

@Before
public void init(){
@BeforeEach
void init(){
emailRepository.deleteAll();
}

@Test
public void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
void shouldReturnEmptyListWhenNoEmailsAreAvailable() throws Exception {
this.mockMvc.perform(get("/email?page"))
.andExpect(status().isOk())
.andExpect(model().attribute("mails", emptyIterableOf(Email.class)))
.andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email-list"));
}

@Test
public void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Exception {
void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Exception {
var email1 = createRandomEmail(5);
var email2 = createRandomEmail(2);
var email3 = createRandomEmail(1);
Expand All @@ -63,17 +53,19 @@ public void shouldReturnListOfEmailsPagedWhenEmailsAreAvailable() throws Excepti
.andExpect(status().isOk())
.andExpect(model().attribute("mails", iterableWithSize(2)))
.andExpect(model().attribute("mails", contains(equalTo(email3), equalTo(email2))))
.andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email-list"));

this.mockMvc.perform(get("/email?page=1&size=2"))
.andExpect(status().isOk())
.andExpect(model().attribute("mails", iterableWithSize(1)))
.andExpect(model().attribute("mails", contains(equalTo(email1))))
.andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email-list"));
}

@Test
public void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception {
void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception {
createRandomEmail(1);

this.mockMvc.perform(get("/email?page=1&size=2"))
Expand All @@ -83,25 +75,26 @@ public void shouldReturnFirstPageWhenGivenPageIsOutOfRange() throws Exception {
}

@Test
public void shouldReturnMailById() throws Exception {
void shouldReturnMailById() throws Exception {
var email = createRandomEmail(1);

this.mockMvc.perform(get("/email/"+email.getId()))
.andExpect(status().isOk())
.andExpect(model().attribute("mail", equalTo(email)))
.andExpect(model().attribute("appVersion", any(String.class)))
.andExpect(view().name("email"));
}

@Test
public void shouldReturnErrorWhenMailIdIsNotValid() throws Exception {
void shouldReturnErrorWhenMailIdIsNotValid() throws Exception {
this.mockMvc.perform(get("/email/123"))
.andExpect(redirectedUrl("/email"))
.andExpect(model().attributeDoesNotExist("mails", "mail"))
.andExpect(status().isFound());
}

@Test
public void shouldDeleteEmail() throws Exception {
void shouldDeleteEmail() throws Exception {
var email = createRandomEmail(1);

this.mockMvc.perform(delete("/email/"+email.getId()))
Expand Down
Loading

0 comments on commit 5783291

Please sign in to comment.