Skip to content

Commit

Permalink
Upgrade all dependencies and do some non-functional refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
lnhrdt committed Apr 3, 2018
1 parent 7abe116 commit 5e24fc3
Show file tree
Hide file tree
Showing 27 changed files with 146 additions and 178 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
buildscript {
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}

dependencies {
Expand All @@ -18,8 +16,6 @@ allprojects {

repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url "https://jitpack.io" }
maven { url "https://dl.bintray.com/kotlin/exposed" }
}
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jvmTarget=1.8
kotlinVersion=1.1.51
springBootVersion=2.0.0.M5
mockitoKotlinVersion=1.5.0
resultsVersion=e8c7c86ae8
exposedVersion=0.8.7
kotlinVersion=1.2.31
springBootVersion=2.0.0.RELEASE
mockitoKotlinVersion=2.0.0-alpha03
resultsVersion=be4fa24ab2
exposedVersion=0.10.1
4 changes: 3 additions & 1 deletion gradle/scripts/kotlin.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}")
compile("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
compile('com.fasterxml.jackson.module:jackson-module-kotlin')
testCompile("com.nhaarman:mockito-kotlin-kt1.1:${mockitoKotlinVersion}")
testCompile("com.nhaarman.mockitokotlin2:mockito-kotlin:$mockitoKotlinVersion") {
exclude group: "org.jetbrains.kotlin"
}
}
1 change: 0 additions & 1 deletion gradle/scripts/persistence.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dependencies {
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile("org.jetbrains.exposed:exposed:$exposedVersion")
compile("org.jetbrains.exposed:spring-transaction:$exposedVersion")
compile('org.flywaydb:flyway-core')
runtime('mysql:mysql-connector-java')
}
6 changes: 5 additions & 1 deletion gradle/scripts/springBoot.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
runtime('org.springframework.boot:spring-boot-devtools')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.boot:spring-boot-starter-test'){
exclude group: 'junit'
}
testCompile('org.junit.jupiter:junit-jupiter-api')
testRuntime('org.junit.jupiter:junit-jupiter-engine')
}
2 changes: 1 addition & 1 deletion kaapi/src/friends/components/FriendListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Coffee from './coffee.svg'
export default ({friend, recordCoffee}) => (
<div className={styles.friend}>
<div className={styles.name}>{friend.name}</div>
<div className={styles.lastCoffee}>{friend.coffees.length ? moment(friend.coffees[0].dateTime, 'X').fromNow() : 'never'}</div>
<div className={styles.lastCoffee}>{friend.coffees.length ? moment(friend.coffees[0].dateTime, 'YYYY-MM-DDTHH:mm:ss.SSSZ').fromNow() : 'never'}</div>
<div className={styles.action}><Button clickHandler={() => recordCoffee(friend)}><Coffee className={styles.icon}/></Button></div>
</div>
)
2 changes: 1 addition & 1 deletion kaapi/src/friends/components/FriendListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('FriendListItem', () => {
})

describe('when the friend has coffees', () => {
beforeEach(() => mockProps.friend.coffees = [{dateTime: moment().subtract(9, 'days').unix()}])
beforeEach(() => mockProps.friend.coffees = [{dateTime: moment().subtract(9, 'days').format('YYYY-MM-DDTHH:mm:ss.SSSZ')}])

it('should render how long since the last coffee', () => {
const subject = shallow(<FriendListItem {...mockProps}/>)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.leonhardt.coffee.latte

import org.jetbrains.exposed.sql.Database
import org.springframework.context.event.ContextRefreshedEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component
import javax.sql.DataSource

@Component
class ExposedDatabaseConnector(val dataSource: DataSource) {

@EventListener
fun connectExposedToDatabase(event: ContextRefreshedEvent) {
Database.connect(dataSource)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@ import io.github.codebandits.results.map
import io.github.codebandits.results.mapError
import io.leonhardt.coffee.latte.Errors
import io.leonhardt.coffee.latte.friends.FriendEntity
import org.jetbrains.exposed.sql.transactions.transaction
import org.joda.time.DateTime
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.Instant

@Service
class CoffeeCreateService {

@Transactional
fun create(coffeeNew: CoffeeNew): Result<Errors, Coffee> {
fun create(coffeeNew: CoffeeNew): Result<Errors, Coffee> = transaction {
val friendId = coffeeNew.friendId.toString()
return FriendEntity.findById(friendId)
.presenceAsResult()
.mapError { mapOf("friendId" to "friendId $friendId not found") }
.map { friendEntity ->
CoffeeEntity.new {
friend = friendEntity
dateTime = DateTime(Instant.now().toEpochMilli())
}
FriendEntity.findById(friendId)
.presenceAsResult()
.mapError { mapOf("friendId" to "friendId $friendId not found") }
.map { friendEntity ->
CoffeeEntity.new {
friend = friendEntity
dateTime = DateTime(Instant.now().toEpochMilli())
}
.map { it.toCoffee() }
}
.map { it.toCoffee() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ import io.github.codebandits.results.map
import io.github.codebandits.results.mapError
import io.leonhardt.coffee.latte.Errors
import io.leonhardt.coffee.latte.groups.GroupEntity
import org.jetbrains.exposed.sql.transactions.transaction
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class FriendCreateService(val friendCreateRequestValidator: FriendCreateRequestValidator) {

@Transactional
fun create(friendNew: FriendNew): Result<Errors, Friend> {
fun create(friendNew: FriendNew): Result<Errors, Friend> = transaction {
val groupId = friendNew.groupId.toString()
return GroupEntity.findById(groupId)
.presenceAsResult()
.mapError { mapOf("groupId" to "groupId $groupId not found") }
.flatMap { groupEntity ->
friendCreateRequestValidator.validate(friendNew)
.map { validFriendNew ->
FriendEntity.new {
name = validFriendNew.name
group = groupEntity
}
}
}
.map { it.toFriend() }
GroupEntity.findById(groupId)
.presenceAsResult()
.mapError { mapOf("groupId" to "groupId $groupId not found") }
.flatMap { groupEntity ->
friendCreateRequestValidator.validate(friendNew)
.map { validFriendNew ->
FriendEntity.new {
name = validFriendNew.name
group = groupEntity
}
}
}
.map { it.toFriend() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package io.leonhardt.coffee.latte.friends
import io.github.codebandits.results.Result
import io.github.codebandits.results.Success
import io.leonhardt.coffee.latte.Errors
import org.jetbrains.exposed.sql.transactions.transaction
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.util.*

@Service
class FriendFindAllByGroupService {

@Transactional
fun findAllByGroup(groupId: UUID): Result<Errors, List<Friend>> {
val friends = FriendEntity.find { FriendTable.group eq groupId.toString() }.map { it.toFriend() }
return Success(friends)
fun findAllByGroup(groupId: UUID): Result<Errors, List<Friend>> = transaction {
FriendEntity.find { FriendTable.group eq groupId.toString() }.map { it.toFriend() }.let { Success(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ package io.leonhardt.coffee.latte.groups
import io.github.codebandits.results.Result
import io.github.codebandits.results.Success
import io.leonhardt.coffee.latte.Errors
import org.jetbrains.exposed.sql.transactions.transaction
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class GroupCreateService {

@Transactional
fun create(groupNew: GroupNew): Result<Errors, Group> {
return Success(GroupEntity.new {
name = groupNew.name
}.toGroup())
fun create(groupNew: GroupNew): Result<Errors, Group> = transaction {
Success(GroupEntity.new { name = groupNew.name }.toGroup())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package io.leonhardt.coffee.latte.groups
import io.github.codebandits.results.Result
import io.github.codebandits.results.Success
import io.leonhardt.coffee.latte.Errors
import org.jetbrains.exposed.sql.transactions.transaction
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
class GroupGetAllService {

@Transactional
fun getAll(): Result<Errors, List<Group>> {
val groups = GroupEntity.all().map { it.toGroup() }
return Success(groups)
fun getAll(): Result<Errors, List<Group>> = transaction {
GroupEntity.all().map { it.toGroup() }.let { Success(it) }
}
}
23 changes: 23 additions & 0 deletions latte/src/test/kotlin/io/leonhardt/coffee/latte/DatabaseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.leonhardt.coffee.latte

import io.leonhardt.coffee.latte.groups.GroupTable
import org.jetbrains.exposed.sql.deleteAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.junit.jupiter.SpringExtension

@ExtendWith(SpringExtension::class)
@SpringBootTest
@ActiveProfiles("test")
abstract class DatabaseTest {

@BeforeEach
@AfterEach
fun cleanup() {
transaction { GroupTable.deleteAll() }
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package io.leonhardt.coffee.latte

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.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

@RunWith(SpringRunner::class)
@ExtendWith(SpringExtension::class)
@SpringBootTest
@ActiveProfiles("test")
class LatteApplicationTests {

@Test
fun contextLoads() {
fun `context loads`() {
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.leonhardt.coffee.latte.coffee

import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.whenever
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import io.github.codebandits.results.Failure
import io.github.codebandits.results.Success
import io.leonhardt.coffee.latte.support.asJson
import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,21 @@ package io.leonhardt.coffee.latte.coffee

import io.github.codebandits.results.succeeds
import io.github.codebandits.results.succeedsAnd
import io.github.codebandits.results.traverse
import io.leonhardt.coffee.latte.DatabaseTest
import io.leonhardt.coffee.latte.friends.FriendCreateService
import io.leonhardt.coffee.latte.friends.FriendNew
import io.leonhardt.coffee.latte.groups.GroupCreateService
import io.leonhardt.coffee.latte.groups.GroupNew
import io.leonhardt.coffee.latte.support.closeToNow
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.Test
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.transaction.annotation.Transactional
import java.util.*

@RunWith(SpringRunner::class)
@SpringBootTest
@ActiveProfiles("test")
@Transactional
class CoffeeCreateServiceTest {

@Autowired
lateinit var friendCreateService: FriendCreateService

@Autowired
lateinit var groupCreateService: GroupCreateService
class CoffeeCreateServiceTest(
@Autowired private val friendCreateService: FriendCreateService,
@Autowired private val groupCreateService: GroupCreateService
) : DatabaseTest() {

val subject: CoffeeCreateService = CoffeeCreateService()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.leonhardt.coffee.latte.friends

import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.whenever
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.whenever
import io.github.codebandits.results.Failure
import io.github.codebandits.results.Success
import io.leonhardt.coffee.latte.support.asJson
import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.jupiter.api.Test
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.github.codebandits.results.failsAnd
import io.github.codebandits.results.succeedsWith
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.hasEntry
import org.junit.Test
import org.junit.jupiter.api.Test
import java.util.*

class FriendCreateRequestValidatorTest {
Expand Down
Loading

0 comments on commit 5e24fc3

Please sign in to comment.