Skip to content

Commit

Permalink
Merge pull request #1 from alfa1-group/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jfbenckhuijsen authored Apr 4, 2024
2 parents dfe94a9 + b8f9931 commit a626ed2
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 31 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
}
}
}
}
}
Expand All @@ -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 ###
Expand Down Expand Up @@ -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`
54 changes: 32 additions & 22 deletions bitbucket-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- bash configure-maven.sh
- mvn -B deploy --file pom.xml
default:
- parallel:
- <<: *build-test
- <<: *security-scan
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>nl.group9</groupId>
<artifactId>firestore-unit</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<packaging>jar</packaging>

<name>firestore-unit</name>
Expand All @@ -29,9 +29,9 @@
</developers>

<scm>
<connection>scm:git:git://bitbucket.org:group9nl/firestore-unit.git</connection>
<developerConnection>scm:git:ssh://bitbucket.org:group9nl/firestore-unit.git</developerConnection>
<url>https://bitbucket.org/group9nl/firestore-unit/src/main/</url>
<connection>scm:git:https://github.com/alfa1-group/firestore-unit.git</connection>
<developerConnection>scm:git:https://github.com/alfa1-group/firestore-unit.git</developerConnection>
<url>https://github.com/alfa1-group/firestore-unit/</url>
</scm>

<properties>
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/nl/group9/firestore/unit/FirestoreTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@ private ApiFuture<?> validateCollection(CollectionReference collectionReference,
for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext(); ) {
Map.Entry<String, JsonNode> 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<DocumentSnapshot> docFuture = docRef.get();
ApiFuture<DocumentSnapshot> result = ApiFutures.transform(
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/nl/group9/firestore/unit/FirestoreUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ public static void fillFirestore() throws Exception {
Map<String, Object> 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<String, Object> testdoc4Fields = new HashMap<>();
testdoc4Fields.put("testText", "Hello Firestore");
testdoc4.set(testdoc4Fields).get();
}
}

Expand Down Expand Up @@ -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: <true> but was: <false>");
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/json/missing_subdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"_testcollection" : {
"_testdoc3": {
"_subcollection" : {
"testdoc4": {
"testText": "Hello Firestore"
}
}
}
}
}

0 comments on commit a626ed2

Please sign in to comment.