Skip to content

Commit

Permalink
Added test cases for expectedDocumentCount precondition
Browse files Browse the repository at this point in the history
  • Loading branch information
a13221236 authored and alexandru-slobodcicov committed Jan 16, 2021
1 parent bb11f0a commit 79606e3
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/test/java/liquibase/ext/MongoLiquibaseIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,17 @@ void testPreconditions() {
liquibase.update("");

List<MongoRanChangeSet> changeSets = findAllRanChangeSets.queryForList(connection).stream().map(converter::fromDocument).collect(Collectors.toList());
assertThat(changeSets).hasSize(6)
assertThat(changeSets).hasSize(8)
.extracting(MongoRanChangeSet::getId, MongoRanChangeSet::getOrderExecuted, MongoRanChangeSet::getExecType)
.containsExactly(
tuple("1", 1, SKIPPED),
tuple("2", 2, EXECUTED),
tuple("3", 3, EXECUTED),
tuple("4", 4, SKIPPED),
tuple("5", 5, EXECUTED),
tuple("6", 6, EXECUTED)
tuple("6", 6, EXECUTED),
tuple("7", 7, SKIPPED),
tuple("8", 8, EXECUTED)
);

assertThat(getCollections(connection))
Expand All @@ -265,8 +267,8 @@ void testPreconditions() {

final FindAllStatement findAllResults = new FindAllStatement("results");
assertThat(findAllResults.queryForList(connection))
.hasSize(3).extracting(d -> d.get("info"))
.containsExactlyInAnyOrder("existsAnyDocumentInCollection1", "filterMatchedInCollection1", "changeSetExecutedMatch");
.hasSize(4).extracting(d -> d.get("info"))
.containsExactlyInAnyOrder("existsAnyDocumentInCollection1", "filterMatchedInCollection1", "changeSetExecutedMatch", "expectedDocumentCountfilterMatchedInCollection1");

}

Expand Down
10 changes: 6 additions & 4 deletions src/test/java/liquibase/ext/MongoLiquibaseJsonIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,17 @@ void testPreconditions() {
liquibase.update("");

List<MongoRanChangeSet> changeSets = findAllRanChangeSets.queryForList(connection).stream().map(converter::fromDocument).collect(Collectors.toList());
assertThat(changeSets).hasSize(6)
assertThat(changeSets).hasSize(8)
.extracting(MongoRanChangeSet::getId, MongoRanChangeSet::getOrderExecuted, MongoRanChangeSet::getExecType)
.containsExactly(
tuple("1", 1, SKIPPED),
tuple("2", 2, EXECUTED),
tuple("3", 3, EXECUTED),
tuple("4", 4, SKIPPED),
tuple("5", 5, EXECUTED),
tuple("6", 6, EXECUTED)
tuple("6", 6, EXECUTED),
tuple("7", 7, SKIPPED),
tuple("8", 8, EXECUTED)
);

assertThat(getCollections(connection))
Expand All @@ -201,8 +203,8 @@ void testPreconditions() {

final FindAllStatement findAllResults = new FindAllStatement("results");
assertThat(findAllResults.queryForList(connection))
.hasSize(3).extracting(d -> d.get("info"))
.containsExactlyInAnyOrder("existsAnyDocumentInCollection1", "filterMatchedInCollection1", "changeSetExecutedMatch");
.hasSize(4).extracting(d -> d.get("info"))
.containsExactlyInAnyOrder("existsAnyDocumentInCollection1", "filterMatchedInCollection1", "changeSetExecutedMatch", "expectedDocumentCountFilterMatchedInCollection1");

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,68 @@
</ext:insertOne>

</changeSet>

<changeSet id="7" author="alex">
<preConditions onFail="CONTINUE" onError="HALT">
<ext:expectedDocumentCount collectionName="collection1">
<ext:filter>
<!--@formatter:off-->
{
"$or" :
[
{"id": 100}, {"id": {"$lt": 10}}
]
}
<!--@formatter:on-->
</ext:filter>
<ext:expectedCount>0</ext:expectedCount>
</ext:expectedDocumentCount>
</preConditions>
<comment>Will not be inserted as filter not matches</comment>

<ext:insertOne collectionName="results">

<ext:document>
<!--@formatter:off-->
{
info: "expectedDocumentCountfilterNotMatchedInCollection1"
}
<!--@formatter:on-->
</ext:document>

</ext:insertOne>

</changeSet>

<changeSet id="8" author="alex">
<preConditions onFail="CONTINUE" onError="HALT">
<ext:expectedDocumentCount collectionName="collection1">
<ext:filter>
<!--@formatter:off-->
{
"$or" :
[
{"id": 100}, {"id": {"$lt": 10}}
]
}
<!--@formatter:on-->
</ext:filter>
<ext:expectedCount>1</ext:expectedCount>
</ext:expectedDocumentCount>
</preConditions>
<comment>Will be inserted as filter matches</comment>

<ext:insertOne collectionName="results">

<ext:document>
<!--@formatter:off-->
{
info: "expectedDocumentCountfilterMatchedInCollection1"
}
<!--@formatter:on-->
</ext:document>

</ext:insertOne>

</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,94 @@
}
]
}
},
{
"changeSet": {
"id": "7",
"author": "alex",
"preConditions": [
{
"onFail": "CONTINUE"
},
{
"expectedDocumentCount": {
"collectionName": "collection1",
"filter": {
"$rawJson": {
"$or": [
{
"id": 100
},
{
"id": {
"$lt": 10
}
}
]
}
},
"expectedCount":0
}
}
],
"comment": "Will not be inserted as filter not matches",
"changes": [
{
"insertOne": {
"collectionName": "results",
"document": {
"$rawJson": {
"info": "expectedDocumentCountFilterNotMatchedInCollection1"
}
}
}
}
]
}
},
{
"changeSet": {
"id": "8",
"author": "alex",
"preConditions": [
{
"onFail": "CONTINUE"
},
{
"expectedDocumentCount": {
"collectionName": "collection1",
"filter": {
"$rawJson": {
"$or": [
{
"id": 100
},
{
"id": {
"$lt": 10
}
}
]
}
},
"expectedCount":1
}
}
],
"comment": "Will be inserted as filter matches",
"changes": [
{
"insertOne": {
"collectionName": "results",
"document": {
"$rawJson": {
"info": "expectedDocumentCountFilterMatchedInCollection1"
}
}
}
}
]
}
}
]
}

0 comments on commit 79606e3

Please sign in to comment.