Added some basic sanity tests

This commit is contained in:
neviyn 2021-04-04 14:59:09 +01:00
parent 1d95b6fb00
commit b11e273d7e
4 changed files with 130 additions and 46 deletions

72
pom.xml
View File

@ -13,10 +13,40 @@
<version>0.0.1-SNAPSHOT</version>
<name>Project Planner</name>
<description>Application for planning project time</description>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.4.31</kotlin.version>
</properties>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@ -103,34 +133,10 @@
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.4.31</kotlin.version>
<junit-jupiter.version>5.6.0</junit-jupiter.version>
</properties>
</project>

View File

@ -0,0 +1,52 @@
package uk.co.neviyn.projectplanner
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
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.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@SpringBootTest
@AutoConfigureMockMvc
class HtmlControllerTest(@Autowired val mockMvc: MockMvc) {
val textHtmlWithCharset = MediaType.parseMediaType("text/html;charset=UTF-8")
@Test
fun getLandingPage() {
mockMvc.perform(get("/"))
.andExpect(status().isOk)
.andExpect(content().contentType(textHtmlWithCharset))
}
@Test
fun getLoginPage() {
mockMvc.perform(get("/login"))
.andExpect(status().isOk)
.andExpect(content().contentType(textHtmlWithCharset))
}
@Test
fun getRegistrationPage() {
mockMvc.perform(get("/register"))
.andExpect(status().isOk)
.andExpect(content().contentType(textHtmlWithCharset))
}
@Test
fun getProfileNotLoggedInt() {
mockMvc.perform(get("/profile"))
.andExpect(status().isUnauthorized)
}
@Test
fun getProjectsNotLoggedIn() {
mockMvc.perform(get("/projects"))
.andExpect(status().isUnauthorized)
}
}

View File

@ -0,0 +1,39 @@
package uk.co.neviyn.projectplanner
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class ProjectPlannerApplicationTest {
@Autowired
private var controller: HtmlController? = null
@Autowired
private var userRepository: UserRepository? = null
@Autowired
private var projectRepository: ProjectRepository? = null
@Autowired
private var eventRepository: EventRepository? = null
@Autowired
private var tagRepository: TagRepository? = null
@Autowired
private var commentRepository: CommentRepository? = null
@Test
fun contextLoads() {
assertNotNull(controller)
assertNotNull(userRepository)
assertNotNull(projectRepository)
assertNotNull(eventRepository)
assertNotNull(tagRepository)
assertNotNull(commentRepository)
}
}

View File

@ -1,13 +0,0 @@
package uk.co.neviyn.projectplanner
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class ProjectPlannerApplicationTests {
@Test
fun contextLoads() {
}
}