From de300c14f7535e0b26d11dd96df55fc2eba262e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Mon, 15 Jun 2020 14:11:49 +0200 Subject: [PATCH 1/5] Prepare for v0.1.0 release --- CHANGELOG.md | 21 +++++++++++++++++++++ pom.xml | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5f2af25 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,21 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.1.0] + +Initial version for simple list of FAIR Data Points. + +### Added + +- Endpoint for "call home" ping and storing entries in MongoDB +- REST API to retrieve entries list (both all and paged) documented using Swagger/OpenAPI +- Simple webpage with table to browse entries including sorting and pagination + +[Unreleased]: /../../compare/v0.1.0...develop +[0.1.0]: /../../tree/v0.1.0 diff --git a/pom.xml b/pom.xml index 788b2fe..e8326c6 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ solutions.fairdata fairdatapoint-index - 0.1.0-SNAPSHOT + 0.1.0 2020 From cc3d50f707f9163f9b839e113ae1e4238240f794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Mon, 15 Jun 2020 18:03:45 +0200 Subject: [PATCH 2/5] Simplify getting sort order for view Co-authored-by: kburger <6997485+kburger@users.noreply.github.com> --- .../fairdata/fdp/index/web/controller/HomeController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/solutions/fairdata/fdp/index/web/controller/HomeController.java b/src/main/java/solutions/fairdata/fdp/index/web/controller/HomeController.java index 074247f..0bb5151 100644 --- a/src/main/java/solutions/fairdata/fdp/index/web/controller/HomeController.java +++ b/src/main/java/solutions/fairdata/fdp/index/web/controller/HomeController.java @@ -42,8 +42,10 @@ public class HomeController { @GetMapping public String home(Model model, @SortDefault(sort = "modificationTime", direction = Sort.Direction.DESC) Pageable pageable) { - Optional order = pageable.getSort().stream().findFirst(); - String sort = order.map(o -> o.getProperty() + "," + o.getDirection().name().toLowerCase()).orElse(""); + var sort = pageable.getSort().stream() + .findFirst() + .map(o -> o.getProperty() + "," + o.getDirection().name().toLowerCase()) + .orElse(""); model.addAttribute("entries", service.getEntriesPage(pageable)); model.addAttribute("sort", sort); From ed9157d66f947ef17de4eae26e56a03df4dd783d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Mon, 15 Jun 2020 21:27:50 +0200 Subject: [PATCH 3/5] Add CORS config --- .../solutions/fairdata/fdp/index/config/WebConfig.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/solutions/fairdata/fdp/index/config/WebConfig.java b/src/main/java/solutions/fairdata/fdp/index/config/WebConfig.java index 0405dde..5f4c086 100644 --- a/src/main/java/solutions/fairdata/fdp/index/config/WebConfig.java +++ b/src/main/java/solutions/fairdata/fdp/index/config/WebConfig.java @@ -23,8 +23,16 @@ package solutions.fairdata.fdp.index.config; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration +@EnableWebMvc public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**"); + } } From b74fc0ccbc6a711666c0b0965502c52bc0f1720f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Mon, 15 Jun 2020 21:29:05 +0200 Subject: [PATCH 4/5] Update+simplify Spring and tests --- pom.xml | 2 +- .../index/FairDataPointIndexApplication.java | 2 +- src/main/resources/templates/home.html | 6 +++--- .../fairdata/fdp/index/WebIntegrationTest.java | 1 + ...iesAll_GET.java => EntriesAll_GET_Test.java} | 11 ++++------- ...sPage_GET.java => EntriesPage_GET_Test.java} | 17 +++++------------ ...ing_POST.java => ReceivePing_POST_Test.java} | 15 ++++----------- .../home/{Home_GET.java => Home_GET_Test.java} | 3 ++- 8 files changed, 21 insertions(+), 36 deletions(-) rename src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/{EntriesAll_GET.java => EntriesAll_GET_Test.java} (92%) rename src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/{EntriesPage_GET.java => EntriesPage_GET_Test.java} (93%) rename src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/{ReceivePing_POST.java => ReceivePing_POST_Test.java} (91%) rename src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/{Home_GET.java => Home_GET_Test.java} (99%) diff --git a/pom.xml b/pom.xml index e8326c6..f9356c7 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ org.springframework.boot spring-boot-starter-parent - 2.2.5.RELEASE + 2.2.7.RELEASE diff --git a/src/main/java/solutions/fairdata/fdp/index/FairDataPointIndexApplication.java b/src/main/java/solutions/fairdata/fdp/index/FairDataPointIndexApplication.java index 760ed04..e518374 100644 --- a/src/main/java/solutions/fairdata/fdp/index/FairDataPointIndexApplication.java +++ b/src/main/java/solutions/fairdata/fdp/index/FairDataPointIndexApplication.java @@ -25,7 +25,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -@SpringBootApplication(scanBasePackages = {"solutions.fairdata.fdp.index"}) +@SpringBootApplication public class FairDataPointIndexApplication { public static void main(String[] args) { SpringApplication.run(FairDataPointIndexApplication.class, args); diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 2df03aa..3d36838 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -78,7 +78,7 @@
- +
@@ -86,14 +86,14 @@
- +
- +
diff --git a/src/test/java/solutions/fairdata/fdp/index/WebIntegrationTest.java b/src/test/java/solutions/fairdata/fdp/index/WebIntegrationTest.java index 0fbc071..fadbb65 100644 --- a/src/test/java/solutions/fairdata/fdp/index/WebIntegrationTest.java +++ b/src/test/java/solutions/fairdata/fdp/index/WebIntegrationTest.java @@ -23,6 +23,7 @@ package solutions.fairdata.fdp.index; import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; diff --git a/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesAll_GET.java b/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesAll_GET_Test.java similarity index 92% rename from src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesAll_GET.java rename to src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesAll_GET_Test.java index e4ef9e9..ee4ac2b 100644 --- a/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesAll_GET.java +++ b/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesAll_GET_Test.java @@ -45,13 +45,16 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; -public class EntriesAll_GET extends WebIntegrationTest { +@DisplayName("GET /entries/all") +public class EntriesAll_GET_Test extends WebIntegrationTest { @Autowired private EntryRepository entryRepository; @Autowired private MongoTemplate mongoTemplate; + private final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() {}; + private URI url() { return URI.create("/entries/all"); } @@ -67,8 +70,6 @@ public void res200_listEmpty() { .get(url()) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); @@ -92,8 +93,6 @@ public void res200_listFew() { .get(url()) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); @@ -120,8 +119,6 @@ public void res200_listMany() { .get(url()) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); diff --git a/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesPage_GET.java b/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesPage_GET_Test.java similarity index 93% rename from src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesPage_GET.java rename to src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesPage_GET_Test.java index bae581b..0331579 100644 --- a/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesPage_GET.java +++ b/src/test/java/solutions/fairdata/fdp/index/acceptance/api/entries/EntriesPage_GET_Test.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -46,12 +47,14 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; - -public class EntriesPage_GET extends WebIntegrationTest { +@DisplayName("GET /entries") +public class EntriesPage_GET_Test extends WebIntegrationTest { @Autowired private EntryRepository entryRepository; + private final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() {}; + private URI url() { return URI.create("/entries"); } @@ -80,8 +83,6 @@ public void res200_pageEmpty() { .get(url()) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); @@ -108,8 +109,6 @@ public void res200_outOfBoundsPage() { .get(urlWithPage(7)) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); @@ -138,8 +137,6 @@ public void res200_pageFew() { .get(url()) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); @@ -174,8 +171,6 @@ public void res200_pageManyMiddle() { .get(urlWithPageSize(page, size)) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); @@ -208,8 +203,6 @@ public void res200_pageManyLast() { .get(urlWithPageSize(page, size)) .accept(MediaType.APPLICATION_JSON) .build(); - ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity> result = client.exchange(request, responseType); diff --git a/src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/ReceivePing_POST.java b/src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/ReceivePing_POST_Test.java similarity index 91% rename from src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/ReceivePing_POST.java rename to src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/ReceivePing_POST_Test.java index dce70f0..c46fa80 100644 --- a/src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/ReceivePing_POST.java +++ b/src/test/java/solutions/fairdata/fdp/index/acceptance/api/ping/ReceivePing_POST_Test.java @@ -44,13 +44,16 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; -public class ReceivePing_POST extends WebIntegrationTest { +@DisplayName("POST /ping") +public class ReceivePing_POST_Test extends WebIntegrationTest { @Autowired private EntryRepository entryRepository; @Autowired private MongoTemplate mongoTemplate; + private final ParameterizedTypeReference responseType = new ParameterizedTypeReference<>() {}; + private URI url() { return URI.create("/"); } @@ -74,8 +77,6 @@ public void res204_newEnty() { .post(url()) .accept(MediaType.APPLICATION_JSON) .body(reqDto); - ParameterizedTypeReference responseType = new ParameterizedTypeReference<>() { - }; // WHEN assertThat("Entry does not exist before the ping", entryRepository.findByClientUrl(clientUrl).isPresent(), is(Boolean.FALSE)); @@ -100,8 +101,6 @@ public void res204_existingEnty() { .post(url()) .accept(MediaType.APPLICATION_JSON) .body(reqDto); - ParameterizedTypeReference responseType = new ParameterizedTypeReference<>() { - }; // WHEN entryRepository.save(indexEntry); @@ -124,8 +123,6 @@ public void res400_nullClientUrl() { .post(url()) .accept(MediaType.APPLICATION_JSON) .body(reqDto); - ParameterizedTypeReference responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity result = client.exchange(request, responseType); @@ -145,8 +142,6 @@ public void res400_nonUrlClientUrl() { .post(url()) .accept(MediaType.APPLICATION_JSON) .body(reqDto); - ParameterizedTypeReference responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity result = client.exchange(request, responseType); @@ -167,8 +162,6 @@ public void res400_differentBody() { .post(url()) .accept(MediaType.APPLICATION_JSON) .body(dummyData); - ParameterizedTypeReference responseType = new ParameterizedTypeReference<>() { - }; // WHEN ResponseEntity result = client.exchange(request, responseType); diff --git a/src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/Home_GET.java b/src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/Home_GET_Test.java similarity index 99% rename from src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/Home_GET.java rename to src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/Home_GET_Test.java index e7de234..c5db9c6 100644 --- a/src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/Home_GET.java +++ b/src/test/java/solutions/fairdata/fdp/index/acceptance/web/home/Home_GET_Test.java @@ -40,7 +40,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -public class Home_GET extends WebIntegrationTest { +@DisplayName("Browse /") +public class Home_GET_Test extends WebIntegrationTest { @Autowired private EntryRepository entryRepository; From e494a68194e7a2ae90584f870954e2c96dfa5e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Mon, 15 Jun 2020 21:33:18 +0200 Subject: [PATCH 5/5] Use Zulu JDK in CI --- .github/workflows/main.yml | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 76714f8..53e0b2d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,8 +15,6 @@ jobs: TAG_DEVELOP: develop TAG_LATEST: latest JDK_VERSION: 11 - JDK_FILE: openjdk-11.0.2_linux-x64_bin.tar.gz - JDK_URL: https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz services: mongo: @@ -37,25 +35,13 @@ jobs: path: ~/.m2 key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - - name: Cache JDK folder - uses: actions/cache@v1 - with: - path: ~/jdk - key: ${{ env.JDK_FILE }} - # (2) -> Prepare Java - - name: Download Oracle JDK - run: | - if [ ! -f ~/jdk/$JDK_FILE ]; then - wget --quiet $JDK_URL -O ~/jdk/$JDK_FILE - fi - cp ~/jdk/$JDK_FILE . - - name: Setup Java - uses: actions/setup-java@master + uses: actions/setup-java@v1 with: - version: ${{ env.JDK_VERSION }} - jdkFile: ${{ env.JDK_FILE }} + java-version: ${{ env.JDK_VERSION }} + java-package: jdk + architecture: x64 - name: Verify Maven and Java run: | @@ -64,11 +50,11 @@ jobs: # (3) -> Test and build - name: Run tests run: | - mvn --quiet -U -B org.jacoco:jacoco-maven-plugin:prepare-agent test + mvn -U -B org.jacoco:jacoco-maven-plugin:prepare-agent test - name: Build package and verify run: | - mvn --quiet -B -U --fail-fast -DskipTests tidy:check com.github.spotbugs:spotbugs-maven-plugin:check license:check verify + mvn -U -B --fail-fast -DskipTests tidy:check com.github.spotbugs:spotbugs-maven-plugin:check license:check verify # (4) -> Build Docker image - name: Docker build