diff --git a/build.gradle.kts b/build.gradle.kts index 55eee2f..5bf9652 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.springframework.boot.gradle.tasks.bundling.BootJar plugins { id("java") @@ -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("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")) @@ -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")) } \ No newline at end of file diff --git a/src/it/java/cloud/cosmin/checklister/BaseIT.java b/src/integrationTest/java/cloud/cosmin/checklister/BaseIT.java similarity index 90% rename from src/it/java/cloud/cosmin/checklister/BaseIT.java rename to src/integrationTest/java/cloud/cosmin/checklister/BaseIT.java index 19c0141..7e8a111 100644 --- a/src/it/java/cloud/cosmin/checklister/BaseIT.java +++ b/src/integrationTest/java/cloud/cosmin/checklister/BaseIT.java @@ -38,9 +38,7 @@ 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); @@ -48,10 +46,7 @@ protected ListGetDto createList(String title) { } 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); @@ -59,9 +54,7 @@ protected ListGetDto createList(UUID uuid, String title) { } 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); diff --git a/src/integrationTest/java/cloud/cosmin/checklister/ItemUpdateIT.java b/src/integrationTest/java/cloud/cosmin/checklister/ItemUpdateIT.java new file mode 100644 index 0000000..a5d473a --- /dev/null +++ b/src/integrationTest/java/cloud/cosmin/checklister/ItemUpdateIT.java @@ -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()); + } + } +} diff --git a/src/it/java/cloud/cosmin/checklister/ListCreationIT.java b/src/integrationTest/java/cloud/cosmin/checklister/ListCreationIT.java similarity index 74% rename from src/it/java/cloud/cosmin/checklister/ListCreationIT.java rename to src/integrationTest/java/cloud/cosmin/checklister/ListCreationIT.java index d38d283..599ae89 100644 --- a/src/it/java/cloud/cosmin/checklister/ListCreationIT.java +++ b/src/integrationTest/java/cloud/cosmin/checklister/ListCreationIT.java @@ -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()); } } diff --git a/src/it/java/cloud/cosmin/checklister/ListUpdateIT.java b/src/integrationTest/java/cloud/cosmin/checklister/ListUpdateIT.java similarity index 69% rename from src/it/java/cloud/cosmin/checklister/ListUpdateIT.java rename to src/integrationTest/java/cloud/cosmin/checklister/ListUpdateIT.java index 2505bea..fe9da50 100644 --- a/src/it/java/cloud/cosmin/checklister/ListUpdateIT.java +++ b/src/integrationTest/java/cloud/cosmin/checklister/ListUpdateIT.java @@ -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()); } } diff --git a/src/it/java/cloud/cosmin/checklister/LoginTest.java b/src/integrationTest/java/cloud/cosmin/checklister/LoginTest.java similarity index 100% rename from src/it/java/cloud/cosmin/checklister/LoginTest.java rename to src/integrationTest/java/cloud/cosmin/checklister/LoginTest.java diff --git a/src/it/java/cloud/cosmin/checklister/discovery/Service.java b/src/integrationTest/java/cloud/cosmin/checklister/discovery/Service.java similarity index 100% rename from src/it/java/cloud/cosmin/checklister/discovery/Service.java rename to src/integrationTest/java/cloud/cosmin/checklister/discovery/Service.java diff --git a/src/it/java/cloud/cosmin/checklister/discovery/ServiceDiscovery.java b/src/integrationTest/java/cloud/cosmin/checklister/discovery/ServiceDiscovery.java similarity index 100% rename from src/it/java/cloud/cosmin/checklister/discovery/ServiceDiscovery.java rename to src/integrationTest/java/cloud/cosmin/checklister/discovery/ServiceDiscovery.java diff --git a/src/it/java/cloud/cosmin/checklister/ItemUpdateIT.java b/src/it/java/cloud/cosmin/checklister/ItemUpdateIT.java deleted file mode 100644 index 38ecb02..0000000 --- a/src/it/java/cloud/cosmin/checklister/ItemUpdateIT.java +++ /dev/null @@ -1,42 +0,0 @@ -package cloud.cosmin.checklister; - -import cloud.cosmin.checklister.dto.ItemPostDto; -import org.junit.Test; - -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(); - itemPost.content = "content"; - itemPost.contentType = "text/plain"; - - UUID itemId; - { - var itemAdded = addItem(newList.id, itemPost); - assertNotNull(itemAdded); - assertEquals("content", itemAdded.content); - assertEquals("text/plain", itemAdded.contentType); - assertEquals(0, itemAdded.rank); - itemId = itemAdded.id; - }{ - itemPost.content = "content1"; - itemPost.contentType = "application/json"; - var itemAdded = addItem(newList.id, itemPost); - assertNotNull(itemAdded); - assertEquals("content1", itemAdded.content); - assertEquals("application/json", itemAdded.contentType); - assertEquals(1, itemAdded.rank); - }{ - var item = getItem(itemId); - assertEquals("content", item.content); - assertEquals("text/plain", item.contentType); - assertEquals(0, item.rank); - } - } -} diff --git a/src/main/java/cloud/cosmin/checklister/dto/Dtos.kt b/src/main/java/cloud/cosmin/checklister/dto/Dtos.kt index ae7f412..2c9df26 100644 --- a/src/main/java/cloud/cosmin/checklister/dto/Dtos.kt +++ b/src/main/java/cloud/cosmin/checklister/dto/Dtos.kt @@ -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( @@ -21,7 +21,7 @@ data class ListGetDto( ) data class ListPostDto( - @JsonProperty var uuid: UUID, + @JsonProperty var uuid: UUID?, @JsonProperty var title: String )