From 672ca631ba4432c38f01da578eec062dc05e79f0 Mon Sep 17 00:00:00 2001 From: Jeroen Benckhuijsen Date: Mon, 25 Mar 2024 11:20:01 +0100 Subject: [PATCH 1/6] Prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2e048ea..0774784 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ nl.group9 firestore-unit - 0.0.1 + 0.0.2 jar firestore-unit From a4c98ba3a5b1f81f4d8703d5c85476225a4fc2de Mon Sep 17 00:00:00 2001 From: Jeroen Benckhuijsen Date: Mon, 25 Mar 2024 11:23:12 +0100 Subject: [PATCH 2/6] Deploy step only for main branch --- bitbucket-pipelines.yml | 54 ++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml index a23b013..6ba583a 100644 --- a/bitbucket-pipelines.yml +++ b/bitbucket-pipelines.yml @@ -7,30 +7,40 @@ image: maven:3.6.3 +build-test: &build-test + step: + name: Build and Test + caches: + - maven + script: + - mvn -B verify --file pom.xml + after-script: + # Collect checkstyle results, if any, and convert to Bitbucket Code Insights. + - pipe: atlassian/checkstyle-report:0.3.0 +security-scan: &security-scan + step: + name: Security Scan + script: + # Run a security scan for sensitive data. + # See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security + - pipe: atlassian/git-secrets-scan:0.5.1 + pipelines: - default: - - parallel: + branches: + main: + - parallel: + - <<: *build-test + - <<: *security-scan - step: - name: Build and Test + name: Deploy to repository + deployment: Production + trigger: manual caches: - maven script: - - mvn -B verify --file pom.xml - after-script: - # Collect checkstyle results, if any, and convert to Bitbucket Code Insights. - - pipe: atlassian/checkstyle-report:0.3.0 - - step: - name: Security Scan - script: - # Run a security scan for sensitive data. - # See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security - - pipe: atlassian/git-secrets-scan:0.5.1 - - step: - name: Deploy to repository - deployment: Production - trigger: manual - caches: - - maven - script: - - bash configure-maven.sh - - mvn -B deploy --file pom.xml \ No newline at end of file + - bash configure-maven.sh + - mvn -B deploy --file pom.xml + default: + - parallel: + - <<: *build-test + - <<: *security-scan From 68587c72c0b20eb5aa752c617eead5b297364a64 Mon Sep 17 00:00:00 2001 From: Jeroen Benckhuijsen Date: Thu, 4 Apr 2024 22:02:35 +0200 Subject: [PATCH 3/6] Added specifying optional intermediate documents --- README.md | 23 +++++++++++++++++-- .../firestore/unit/FirestoreTester.java | 16 ++++++++++--- .../firestore/unit/FirestoreUnitTest.java | 15 ++++++++++++ src/test/resources/json/missing_subdoc.json | 11 +++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/json/missing_subdoc.json diff --git a/README.md b/README.md index 755551a..019002e 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,10 @@ You can choose to either define the validation files as JSON or as YAML. Both fo offer equal features. **Example in JSON:** + ```json { - "_testcollection" : { + "_testcollection": { "testdoc1": { "testArray": [ false, @@ -56,11 +57,18 @@ offer equal features. "testDateTime": "2024-03-22T12:13:14.123Z", "testReference": "testcollection/ref1", "testText": "Hello world", - "_subcollection" : { + "_subcollection": { "testdoc2": { "testText": "Hello Firestore" } } + }, + "_testdoc3": { + "_subcollection": { + "testdoc4": { + "testText": "Hello Firestore" + } + } } } } @@ -86,12 +94,19 @@ _testcollection: _subcollection: testdoc2: testText: "Hello Firestore" + _testdoc3: + _subcollection: + testdoc3: + testText: "Hello Firestore" ``` Note that in this example: * Collections always need to be prefixed with an underscore "_". This is to let the library differentiate between the Map datatype and collections. * Date/time values need to be defined in ISO 8601 format +* In case a document should be skipped for checking (both for existance and the fields), prefix it with an underscore + "_". In this case the document "testcollection/testdoc3" is optional. Firestore allows you to skip definition of all + intermediate documents in a path. ### Use the library in your test ### @@ -128,3 +143,7 @@ These will be reviewed and if appropriate merged into the main release. ### Who do I talk to? ### For contact, see the developers section in the `pom.xml` file. + +### Releasing a new version ### + +Run: `mvn clean deploy -P release` \ No newline at end of file diff --git a/src/main/java/nl/group9/firestore/unit/FirestoreTester.java b/src/main/java/nl/group9/firestore/unit/FirestoreTester.java index d1ab7c7..3de74f2 100644 --- a/src/main/java/nl/group9/firestore/unit/FirestoreTester.java +++ b/src/main/java/nl/group9/firestore/unit/FirestoreTester.java @@ -59,14 +59,24 @@ private ApiFuture validateCollection(CollectionReference collectionReference, for (Iterator> it = node.fields(); it.hasNext(); ) { Map.Entry fieldEntry = it.next(); - DocumentReference doc = collectionReference.document(fieldEntry.getKey()); - futures.add(validateDocument(doc, fieldEntry.getValue())); + String documentName = fieldEntry.getKey(); + boolean skipCurrent = false; + if (documentName.startsWith("_")) { + documentName = documentName.substring(1); + skipCurrent = true; + } + + DocumentReference doc = collectionReference.document(documentName); + futures.add(validateDocument(doc, fieldEntry.getValue(), skipCurrent)); } return ApiFutures.allAsList(futures); } - private ApiFuture validateDocument(DocumentReference docRef, JsonNode node) { + private ApiFuture validateDocument(DocumentReference docRef, JsonNode node, boolean skipCurrent) { ApiFuture childFuture = traverseCollections(docRef::collection, node); + if (skipCurrent) { + return childFuture; + } ApiFuture docFuture = docRef.get(); ApiFuture result = ApiFutures.transform( diff --git a/src/test/java/nl/group9/firestore/unit/FirestoreUnitTest.java b/src/test/java/nl/group9/firestore/unit/FirestoreUnitTest.java index b2687c0..2ce1b03 100644 --- a/src/test/java/nl/group9/firestore/unit/FirestoreUnitTest.java +++ b/src/test/java/nl/group9/firestore/unit/FirestoreUnitTest.java @@ -66,6 +66,14 @@ public static void fillFirestore() throws Exception { Map testdoc2Fields = new HashMap<>(); testdoc2Fields.put("testText", "Hello Firestore"); testdoc2.set(testdoc2Fields).get(); + + // Document with a missing intermediate Document node as parent + DocumentReference testdoc3 = testcollection.document("testdoc3"); + CollectionReference subsubcollection = testdoc3.collection("subcollection"); + DocumentReference testdoc4 = subsubcollection.document("testdoc4"); + Map testdoc4Fields = new HashMap<>(); + testdoc4Fields.put("testText", "Hello Firestore"); + testdoc4.set(testdoc4Fields).get(); } } @@ -139,6 +147,13 @@ void testYamlInputStream() throws Exception { } } + @Test + void emptySubDocument() throws Exception { + try (Firestore firestore = connection()) { + assertFirestoreJson(firestore, asInputStream("json/missing_subdoc.json")); + } + } + @Test void testArrayDifferentElements() { testInvalidFile("json/array_diff_element.json", "Field does not have the expected value at testcollection/testdoc1/testArray[0] ==> expected: but was: "); diff --git a/src/test/resources/json/missing_subdoc.json b/src/test/resources/json/missing_subdoc.json new file mode 100644 index 0000000..d515b69 --- /dev/null +++ b/src/test/resources/json/missing_subdoc.json @@ -0,0 +1,11 @@ +{ + "_testcollection" : { + "_testdoc3": { + "_subcollection" : { + "testdoc4": { + "testText": "Hello Firestore" + } + } + } + } +} From 8f46cce465f1dce206d67788ad2c2c5a325c3085 Mon Sep 17 00:00:00 2001 From: Jeroen Benckhuijsen Date: Thu, 4 Apr 2024 22:10:36 +0200 Subject: [PATCH 4/6] Moved to github --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0774784..03c05f5 100644 --- a/pom.xml +++ b/pom.xml @@ -29,9 +29,9 @@ - scm:git:git://bitbucket.org:group9nl/firestore-unit.git - scm:git:ssh://bitbucket.org:group9nl/firestore-unit.git - https://bitbucket.org/group9nl/firestore-unit/src/main/ + scm:git:https://github.com/alfa1-group/firestore-unit.git + scm:git:https://github.com/alfa1-group/firestore-unit.git + https://github.com/alfa1-group/firestore-unit/ From 9a2bddc2f210376c85430d35434b9aae68a037bd Mon Sep 17 00:00:00 2001 From: jfbenckhuijsen Date: Thu, 4 Apr 2024 22:25:07 +0200 Subject: [PATCH 5/6] Create maven.yml --- .github/workflows/maven.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..fbe029e --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "main", "develop" ] + pull_request: + branches: [ "main", "develop" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 2307b374f77dab432e3a16ea5236013e7e449cac Mon Sep 17 00:00:00 2001 From: jfbenckhuijsen Date: Thu, 4 Apr 2024 22:30:05 +0200 Subject: [PATCH 6/6] Update maven.yml Removed dependency graph --- .github/workflows/maven.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fbe029e..253c70f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,3 @@ jobs: cache: maven - name: Build with Maven run: mvn -B package --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6