From 226d2802efd5f310d8cbbb113826c25cbfd732c3 Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Sun, 7 Jun 2020 12:10:21 +0200 Subject: [PATCH] Fix tests and add build pipeline --- .drone.yml | 18 +++++++++++++ .../friedl/fling/model/dto/ArtifactDto.java | 2 ++ .../friedl/fling/FlingApplicationTests.java | 13 ---------- .../controller/ArtifactControllerTest.java | 26 ++++++++++++------- 4 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 .drone.yml delete mode 100644 service/fling/src/test/java/net/friedl/fling/FlingApplicationTests.java diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..f708e46 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,18 @@ +kind: pipeline +type: docker +name: default + +steps: +- name: build-service + image: adoptopenjdk:11-hotspot + commands: + - ls -al + - cd service/fling + - ./mvnw clean package + +- name: build-web + image: node:latest + commands: + - ls -al + - cd web/fling + - npm install && npm run build diff --git a/service/fling/src/main/java/net/friedl/fling/model/dto/ArtifactDto.java b/service/fling/src/main/java/net/friedl/fling/model/dto/ArtifactDto.java index ff45c61..9447680 100644 --- a/service/fling/src/main/java/net/friedl/fling/model/dto/ArtifactDto.java +++ b/service/fling/src/main/java/net/friedl/fling/model/dto/ArtifactDto.java @@ -26,6 +26,8 @@ public class ArtifactDto { @JsonProperty("uploadTime") public Long getJsonUploadTime() { + if(uploadTime == null) return null; + return uploadTime.toEpochMilli(); } } diff --git a/service/fling/src/test/java/net/friedl/fling/FlingApplicationTests.java b/service/fling/src/test/java/net/friedl/fling/FlingApplicationTests.java deleted file mode 100644 index 9d8b41b..0000000 --- a/service/fling/src/test/java/net/friedl/fling/FlingApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.friedl.fling; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class FlingApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/service/fling/src/test/java/net/friedl/fling/controller/ArtifactControllerTest.java b/service/fling/src/test/java/net/friedl/fling/controller/ArtifactControllerTest.java index c65aeb0..36588bc 100644 --- a/service/fling/src/test/java/net/friedl/fling/controller/ArtifactControllerTest.java +++ b/service/fling/src/test/java/net/friedl/fling/controller/ArtifactControllerTest.java @@ -10,16 +10,22 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.FilterType; import org.springframework.test.web.servlet.MockMvc; import net.friedl.fling.model.dto.ArtifactDto; import net.friedl.fling.service.ArtifactService; -@WebMvcTest(ArtifactController.class) +@WebMvcTest(controllers = ArtifactController.class, + // do auto-configure security + excludeAutoConfiguration = SecurityAutoConfiguration.class, + // do not try to create beans in security + excludeFilters = @Filter(type = FilterType.REGEX, pattern = "net.friedl.fling.security.*")) class ArtifactControllerTest { - @Autowired private MockMvc mvc; @@ -27,25 +33,27 @@ class ArtifactControllerTest { private ArtifactService artifactService; @Test - void testGetArtifacts_noArtifacts_empty() throws Exception { - var flingId = 123L; + public void testGetArtifacts_noArtifacts_empty() throws Exception { + Long flingId = 123L; when(artifactService.findAllArtifacts(flingId)).thenReturn(List.of()); - mvc.perform(get("/api/fling/{flingId}/artifact", flingId)).andExpect(jsonPath("$", hasSize(0))); + mvc.perform(get("/api/artifacts").param("flingId", flingId.toString())) + .andExpect(jsonPath("$", hasSize(0))); } @Test - void testGetArtifacts_hasArtifacts_allArtifacts() throws Exception { - var flingId = 123L; - var artifactName = "TEST"; + public void testGetArtifacts_hasArtifacts_allArtifacts() throws Exception { + Long flingId = 123L; + String artifactName = "TEST"; ArtifactDto artifactDto = new ArtifactDto(); artifactDto.setName(artifactName); when(artifactService.findAllArtifacts(flingId)).thenReturn(List.of(artifactDto)); - mvc.perform(get("/api/fling/{flingId}/artifact", flingId)).andExpect(jsonPath("$", hasSize(1))) + mvc.perform(get("/api/artifacts").param("flingId", flingId.toString())) + .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].name", equalTo(artifactName))); } }