Skip to content

Commit

Permalink
Update more files to Kotlin.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstroe committed Dec 7, 2018
1 parent b3999b6 commit 1ea823d
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 77 deletions.
62 changes: 50 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
id("java")
Expand All @@ -14,6 +15,44 @@ repositories {
group = "cloud.cosmin.checklister"
version = "0.0.6-SNAPSHOT"

val compileKotlin: KotlinCompile by tasks

compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}

val compileTestKotlin: KotlinCompile by tasks

compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}

val bootJar: BootJar by tasks

bootJar.archiveName = "app.jar"

sourceSets {
create("integrationTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}

val integrationTestImplementation by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}

configurations["integrationTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())

val integrationTest = task<Test>("integrationTest") {
description = "Runs integration tests."
group = "verification"

testClassesDirs = sourceSets["integrationTest"].output.classesDirs
classpath = sourceSets["integrationTest"].runtimeClasspath
shouldRunAfter("test")
}

dependencies {
// Spring Boot
implementation(enforcedPlatform("org.springframework.boot:spring-boot-dependencies:2.1.1.RELEASE"))
Expand Down Expand Up @@ -47,19 +86,18 @@ dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-test-autoconfigure")

// integrationTestCompile("org.seleniumhq.selenium:selenium-java:3.13.0")
// integrationTestCompile("org.seleniumhq.selenium:selenium-remote-driver:3.13.0")
compile(kotlin("stdlib-jdk8"))
}

val compileKotlin: KotlinCompile by tasks
// JUnit 5
testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.2")

compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
// Support running JUnit 4 tests using JUnit 5
testCompileOnly("junit:junit:4.12")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.3.2")

val compileTestKotlin: KotlinCompile by tasks
// H2 in-memory database
testImplementation("com.h2database:h2:1.4.197")

compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
// integrationTestCompile("org.seleniumhq.selenium:selenium-java:3.13.0")
// integrationTestCompile("org.seleniumhq.selenium:selenium-remote-driver:3.13.0")
compile(kotlin("stdlib-jdk8"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,23 @@ public void setUp() throws IOException {
}

protected ListGetDto createList(String title) {
ListPostDto post = new ListPostDto();
post.title = title;

ListPostDto post = new ListPostDto(null, title);
URI newListUri = template.postForLocation(getListUrl(service), post, ListGetDto.class);
assertNotNull(newListUri);

return template.getForObject(service.http + newListUri.toString(), ListGetDto.class);
}

protected ListGetDto createList(UUID uuid, String title) {
ListPostDto post = new ListPostDto();
post.uuid = uuid;
post.title = title;

ListPostDto post = new ListPostDto(uuid, title);
URI newListUri = template.postForLocation(getListUrl(service), post, ListGetDto.class);
assertNotNull(newListUri);

return template.getForObject(service.http + newListUri.toString(), ListGetDto.class);
}

protected ListGetDto updateList(UUID id, String title) {
ListPostDto post = new ListPostDto();
post.title = title;

ListPostDto post = new ListPostDto(null, title);
String listUri = getListUrl(service) + "/" + id.toString();
template.put(listUri, post);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cloud.cosmin.checklister;

import cloud.cosmin.checklister.dto.ItemPostDto;
import org.junit.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.UUID;

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

public class ItemUpdateIT extends BaseIT {
@Test
public void itemUpdate() {
var newList = createList("testlist");
var itemPost = new ItemPostDto("content", "text/plain", null);
UUID itemId;
{
var itemAdded = addItem(newList.getId(), itemPost);
assertNotNull(itemAdded);
assertEquals("content", itemAdded.getContent());
assertEquals("text/plain", itemAdded.getContentType());
assertEquals(0, itemAdded.getRank());
itemId = itemAdded.getId();
}{
itemPost.setContent("content1");
itemPost.setContentType("application/json");
var itemAdded = addItem(newList.getId(), itemPost);
assertNotNull(itemAdded);
assertEquals("content1", itemAdded.getContent());
assertEquals("application/json", itemAdded.getContentType());
assertEquals(1, itemAdded.getRank());
}{
var item = getItem(itemId);
assertEquals("content", item.getContent());
assertEquals("text/plain", item.getContentType());
assertEquals(0, item.getRank());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,29 @@ public class ListCreationIT extends BaseIT {
@Test
public void listCreation() {
ListGetDto newList = createList("testlist");
assertEquals("testlist", newList.title);
assertEquals("testlist", newList.getTitle());
}

@Test
public void itemCreation() {
ListGetDto newList = createList("testtitle");
String itemPostUrl = service.http + "/api/v1/list/" + newList.id.toString() + "/item";
ItemPostDto item = new ItemPostDto();
item.content = "testcontent";
String itemPostUrl = service.http + "/api/v1/list/" + newList.getId().toString() + "/item";
ItemPostDto item = new ItemPostDto("testcontnet", null, null);

URI newItemUri = template.postForLocation(itemPostUrl, item);
assertNotNull(newItemUri);

String newItemUriString = service.http + newItemUri.toString();
ItemGetDto newItem = template.getForObject(newItemUriString, ItemGetDto.class);
assertEquals("testcontent", newItem.content);
assertEquals("text/plain", newItem.contentType);
assertEquals(0, newItem.rank);
assertEquals("testcontent", newItem.getContent());
assertEquals("text/plain", newItem.getContentType());
assertEquals(0, newItem.getRank());
}

@Test
public void listCreationWithId() {
UUID uuid = UUID.randomUUID();
ListGetDto newList = createList(uuid, "title");
assertEquals(uuid, newList.id);
assertEquals(uuid, newList.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ListUpdateIT extends BaseIT {
@Test
public void listUpdate() {
ListGetDto newList = createList("testlist");
ListGetDto updatedList = updateList(newList.id, "newtitle");
assertEquals("newtitle", updatedList.title);
ListGetDto updatedList = updateList(newList.getId(), "newtitle");
assertEquals("newtitle", updatedList.getTitle());
}
}
42 changes: 0 additions & 42 deletions src/it/java/cloud/cosmin/checklister/ItemUpdateIT.java

This file was deleted.

6 changes: 3 additions & 3 deletions src/main/java/cloud/cosmin/checklister/dto/Dtos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ data class ItemGetDto(var id: UUID,

data class ItemPostDto(
@JsonProperty var content: String,
@JsonProperty var contentType: String,
@JsonProperty var rank: Int
@JsonProperty var contentType: String?,
@JsonProperty var rank: Int?
)

data class ListGetDto(
Expand All @@ -21,7 +21,7 @@ data class ListGetDto(
)

data class ListPostDto(
@JsonProperty var uuid: UUID,
@JsonProperty var uuid: UUID?,
@JsonProperty var title: String
)

Expand Down

0 comments on commit 1ea823d

Please sign in to comment.