Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vorgang-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
vorgang-manager
Commits
de38fcd1
Commit
de38fcd1
authored
3 months ago
by
Felix Reichenbach
Browse files
Options
Downloads
Patches
Plain Diff
OZG-7515 remove main code dependencies from migration test
parent
d15d2051
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!11
Ozg 7515 migrate patch item command
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommandITCase.java
+147
-68
147 additions, 68 deletions
..._AddItemNameBescheidToPatchAttachedItemCommandITCase.java
with
147 additions
and
68 deletions
vorgang-manager-server/src/test/java/de/ozgcloud/vorgang/common/migration/M014_AddItemNameBescheidToPatchAttachedItemCommandITCase.java
+
147
−
68
View file @
de38fcd1
...
@@ -25,24 +25,30 @@ package de.ozgcloud.vorgang.common.migration;
...
@@ -25,24 +25,30 @@ package de.ozgcloud.vorgang.common.migration;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.*;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.UUID
;
import
org.bson.Document
;
import
org.bson.types.ObjectId
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Nested
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.InjectMocks
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.mongodb.core.MongoOperations
;
import
org.springframework.data.mongodb.core.MongoOperations
;
import
de.ozgcloud.command.Command
;
import
com.thedeanda.lorem.LoremIpsum
;
import
de.ozgcloud.common.test.DataITCase
;
import
de.ozgcloud.common.test.DataITCase
;
import
de.ozgcloud.vorgang.command.CommandTestFactory
;
import
de.ozgcloud.vorgang.command.PersistedCommand
;
@DataITCase
@DataITCase
class
M014_AddItemNameBescheidToPatchAttachedItemCommandITCase
{
class
M014_AddItemNameBescheidToPatchAttachedItemCommandITCase
{
private
static
final
String
ID_FIELD
=
"_id"
;
private
static
final
String
BESCHEID_ITEM_NAME
=
"Bescheid"
;
private
static
final
String
BESCHEID_ITEM_NAME
=
"Bescheid"
;
private
static
final
String
ITEM_NAME_FIELD
=
"itemName"
;
private
static
final
String
ITEM_NAME_FIELD
=
"itemName"
;
private
static
final
String
PATCH_ATTACHED_ITEM_ORDER
=
"PATCH_ATTACHED_ITEM"
;
private
static
final
String
PATCH_ATTACHED_ITEM_ORDER
=
"PATCH_ATTACHED_ITEM"
;
...
@@ -56,18 +62,18 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
...
@@ -56,18 +62,18 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
@Autowired
@Autowired
private
MongoOperations
mongoOperations
;
private
MongoOperations
mongoOperations
;
private
List
<
PersistedCommand
>
expectedCommands
;
private
List
<
Document
>
expectedCommands
;
private
PersistedCommand
sendBescheidCommand
;
private
Document
sendBescheidCommand
;
private
PersistedCommand
patchAttachedItemCommand
;
private
Document
patchAttachedItemCommand
;
private
PersistedCommand
otherSubCommand
;
private
Document
otherSubCommand
;
private
PersistedCommand
otherPatchAttachedItemCommand
;
private
Document
otherPatchAttachedItemCommand
;
@BeforeEach
@BeforeEach
void
setUp
()
{
void
setUp
()
{
migrationDbTestUtils
.
dropCommandCollection
();
migrationDbTestUtils
.
dropCommandCollection
();
sendBescheidCommand
=
saveSendBescheidCommand
();
sendBescheidCommand
=
saveSendBescheidCommand
();
patchAttachedItemCommand
=
savePatchAttachedItemSubCommand
(
sendBescheidCommand
.
get
Id
(
));
patchAttachedItemCommand
=
savePatchAttachedItemSubCommand
(
sendBescheidCommand
.
get
ObjectId
(
ID_FIELD
));
otherSubCommand
=
saveOtherSubCommand
(
sendBescheidCommand
.
get
Id
(
));
otherSubCommand
=
saveOtherSubCommand
(
sendBescheidCommand
.
get
ObjectId
(
ID_FIELD
));
otherPatchAttachedItemCommand
=
saveOtherPatchAttachedItemSubCommand
();
otherPatchAttachedItemCommand
=
saveOtherPatchAttachedItemSubCommand
();
expectedCommands
=
List
.
of
(
sendBescheidCommand
,
expectedCommands
=
List
.
of
(
sendBescheidCommand
,
buildExpectedPatchAttachedItemCommand
(
patchAttachedItemCommand
),
buildExpectedPatchAttachedItemCommand
(
patchAttachedItemCommand
),
...
@@ -75,53 +81,68 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
...
@@ -75,53 +81,68 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
otherPatchAttachedItemCommand
);
otherPatchAttachedItemCommand
);
}
}
private
PersistedCommand
saveSendBescheidCommand
()
{
private
Document
saveSendBescheidCommand
()
{
var
command
=
CommandTestFactory
.
create
Builder
().
id
(
null
).
o
rder
(
SEND_BESCHEID_ORDER
)
.
build
()
;
var
command
=
Command
Document
TestFactory
.
create
WithO
rder
(
SEND_BESCHEID_ORDER
);
return
m
ongoOperations
.
save
(
command
);
return
m
igrationDbTestUtils
.
saveCommand
(
command
);
}
}
private
PersistedCommand
savePatchAttachedItemSubCommand
(
String
id
)
{
private
Document
savePatchAttachedItemSubCommand
(
ObjectId
id
)
{
Map
<
String
,
Object
>
itemBody
=
Map
.
of
(
PARENT_ID_FIELD
,
id
);
Map
<
String
,
Object
>
itemBody
=
Map
.
of
(
PARENT_ID_FIELD
,
id
.
toString
());
var
command
=
CommandTestFactory
.
createBuilder
()
var
command
=
CommandDocumentTestFactory
.
createWithOrderAndBody
(
PATCH_ATTACHED_ITEM_ORDER
,
itemBody
);
.
id
(
null
)
return
migrationDbTestUtils
.
saveCommand
(
command
);
.
order
(
PATCH_ATTACHED_ITEM_ORDER
)
.
bodyObject
(
itemBody
)
.
build
();
return
mongoOperations
.
save
(
command
);
}
}
private
PersistedCommand
saveOtherSubCommand
(
String
id
)
{
private
Document
saveOtherSubCommand
(
ObjectId
id
)
{
Map
<
String
,
Object
>
itemBody
=
Map
.
of
(
PARENT_ID_FIELD
,
id
);
Map
<
String
,
Object
>
itemBody
=
Map
.
of
(
PARENT_ID_FIELD
,
id
.
toString
());
var
command
=
CommandTestFactory
.
createBuilder
()
var
command
=
CommandDocumentTestFactory
.
createWithBody
(
itemBody
);
.
id
(
null
)
return
migrationDbTestUtils
.
saveCommand
(
command
);
.
bodyObject
(
itemBody
)
.
build
();
return
mongoOperations
.
save
(
command
);
}
}
private
PersistedCommand
saveOtherPatchAttachedItemSubCommand
()
{
private
Document
saveOtherPatchAttachedItemSubCommand
()
{
var
command
=
CommandTestFactory
.
createBuilder
()
var
command
=
CommandDocumentTestFactory
.
createWithOrder
(
PATCH_ATTACHED_ITEM_ORDER
);
.
id
(
null
)
return
migrationDbTestUtils
.
saveCommand
(
command
);
.
order
(
PATCH_ATTACHED_ITEM_ORDER
)
.
build
();
return
mongoOperations
.
save
(
command
);
}
}
private
PersistedCommand
buildExpectedPatchAttachedItemCommand
(
Command
patchAttachedItemCommand
)
{
@SuppressWarnings
(
"unchecked"
)
var
body
=
new
HashMap
<>(
patchAttachedItemCommand
.
getBodyObject
());
private
Document
buildExpectedPatchAttachedItemCommand
(
Document
patchAttachedItemCommand
)
{
var
body
=
new
HashMap
<>((
Map
<
String
,
Object
>)
patchAttachedItemCommand
.
get
(
CommandDocumentTestFactory
.
BODY_OBJECT_FIELD
));
body
.
put
(
ITEM_NAME_FIELD
,
BESCHEID_ITEM_NAME
);
body
.
put
(
ITEM_NAME_FIELD
,
BESCHEID_ITEM_NAME
);
return
CommandTestFactory
.
createBuilder
()
var
command
=
CommandDocumentTestFactory
.
createWithOrderAndBody
(
PATCH_ATTACHED_ITEM_ORDER
,
body
);
.
id
(
patchAttachedItemCommand
.
getId
())
command
.
put
(
ID_FIELD
,
patchAttachedItemCommand
.
getObjectId
(
ID_FIELD
));
.
order
(
patchAttachedItemCommand
.
getOrder
())
return
command
;
.
bodyObject
(
body
)
}
.
build
();
@Nested
class
TestGetSendBescheidCommandIds
{
@Test
void
shouldReturnSendBescheidCommandId
()
{
var
ids
=
migration
.
getSendBescheidCommandIds
(
mongoOperations
);
assertThat
(
ids
).
containsExactly
(
sendBescheidCommand
.
getObjectId
(
ID_FIELD
).
toString
());
}
}
@Nested
class
TestBuildQuery
{
@Test
void
shouldQueryPatchAttachedItemCommandsWithParentId
()
{
var
query
=
migration
.
buildQuery
(
List
.
of
(
sendBescheidCommand
.
getObjectId
(
ID_FIELD
).
toString
()));
var
comands
=
mongoOperations
.
find
(
query
,
Document
.
class
,
MigrationDbTestUtils
.
COMMAND_COLLECTION
);
assertThat
(
comands
).
usingRecursiveFieldByFieldElementComparator
().
containsExactly
(
patchAttachedItemCommand
);
}
}
}
@Nested
class
TestFullMigration
{
@Test
@Test
void
shouldContainSendBescheidCommand
()
{
void
shouldContainSendBescheidCommand
()
{
migration
.
doMigration
(
mongoOperations
);
migration
.
doMigration
(
mongoOperations
);
var
command
=
m
ongoOperations
.
findById
(
sendBescheidCommand
.
getId
(),
PersistedCommand
.
class
);
var
command
=
m
igrationDbTestUtils
.
getCommand
(
sendBescheidCommand
.
getObjectId
(
ID_FIELD
)
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
sendBescheidCommand
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
sendBescheidCommand
);
}
}
...
@@ -130,7 +151,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
...
@@ -130,7 +151,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
void
shouldModifyPatchAttachedBescheidItem
()
{
void
shouldModifyPatchAttachedBescheidItem
()
{
migration
.
doMigration
(
mongoOperations
);
migration
.
doMigration
(
mongoOperations
);
var
command
=
m
ongoOperations
.
findByI
d
(
patchAttachedItemCommand
.
get
Id
(),
PersistedCommand
.
class
);
var
command
=
m
igrationDbTestUtils
.
getComman
d
(
patchAttachedItemCommand
.
get
ObjectId
(
ID_FIELD
)
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
buildExpectedPatchAttachedItemCommand
(
patchAttachedItemCommand
));
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
buildExpectedPatchAttachedItemCommand
(
patchAttachedItemCommand
));
}
}
...
@@ -139,7 +160,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
...
@@ -139,7 +160,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
void
shouldNotModifyOtherSubcommands
()
{
void
shouldNotModifyOtherSubcommands
()
{
migration
.
doMigration
(
mongoOperations
);
migration
.
doMigration
(
mongoOperations
);
var
command
=
m
ongoOperations
.
findById
(
otherSubCommand
.
getId
(),
PersistedCommand
.
class
);
var
command
=
m
igrationDbTestUtils
.
getCommand
(
otherSubCommand
.
getObjectId
(
ID_FIELD
)
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
otherSubCommand
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
otherSubCommand
);
}
}
...
@@ -148,7 +169,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
...
@@ -148,7 +169,7 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
void
shouldNotModifyOtherPatchAttachedItemCommands
()
{
void
shouldNotModifyOtherPatchAttachedItemCommands
()
{
migration
.
doMigration
(
mongoOperations
);
migration
.
doMigration
(
mongoOperations
);
var
command
=
m
ongoOperations
.
findByI
d
(
otherPatchAttachedItemCommand
.
get
Id
(),
PersistedCommand
.
class
);
var
command
=
m
igrationDbTestUtils
.
getComman
d
(
otherPatchAttachedItemCommand
.
get
ObjectId
(
ID_FIELD
)
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
otherPatchAttachedItemCommand
);
assertThat
(
command
).
usingRecursiveComparison
().
isEqualTo
(
otherPatchAttachedItemCommand
);
}
}
...
@@ -157,8 +178,66 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
...
@@ -157,8 +178,66 @@ class M014_AddItemNameBescheidToPatchAttachedItemCommandITCase {
void
shouldContainExpectedCommands
()
{
void
shouldContainExpectedCommands
()
{
migration
.
doMigration
(
mongoOperations
);
migration
.
doMigration
(
mongoOperations
);
var
commands
=
mongoOperations
.
findAll
(
PersistedCommand
.
class
);
var
commands
=
mongoOperations
.
findAll
(
Document
.
class
,
MigrationDbTestUtils
.
COMMAND_COLLECTION
);
assertThat
(
commands
).
usingRecursiveFieldByFieldElementComparator
().
containsExactlyInAnyOrderElementsOf
(
expectedCommands
);
assertThat
(
commands
).
usingRecursiveFieldByFieldElementComparator
().
containsExactlyInAnyOrderElementsOf
(
expectedCommands
);
}
}
}
}
private
class
CommandDocumentTestFactory
{
public
static
final
String
ORDER_FIELD
=
"order"
;
public
static
final
String
BODY_OBJECT_FIELD
=
"bodyObject"
;
public
static
final
String
VORGANG_ID
=
UUID
.
randomUUID
().
toString
();
public
static
final
String
CREATED_AT_STR
=
"2021-01-10T10:30:00Z"
;
public
static
final
Date
CREATED_AT
=
Date
.
from
(
ZonedDateTime
.
parse
(
CREATED_AT_STR
).
toInstant
());
public
static
final
String
CREATED_BY
=
UUID
.
randomUUID
().
toString
();
public
static
final
String
CREATED_BY_NAME
=
LoremIpsum
.
getInstance
().
getName
();
public
static
final
String
CREATED_BY_CLIENT
=
LoremIpsum
.
getInstance
().
getWords
(
1
);
public
static
final
String
STATUS
=
"PENDING"
;
public
static
final
String
RELATION_ID
=
UUID
.
randomUUID
().
toString
();
public
static
final
Long
RELATION_VERSION
=
1L
;
public
static
final
String
ORDER
=
"VORGANG_ANNEHMEN"
;
public
static
final
Map
<
String
,
Object
>
PREVIOUS_STATE
=
Map
.
of
(
"test"
,
"value"
);
public
static
final
Map
<
String
,
Object
>
BODY
=
Map
.
of
(
"key"
,
"value"
);
public
static
final
String
CREATED_RESOURCE
=
"createdResource"
;
public
static
Document
create
()
{
var
command
=
new
Document
();
command
.
put
(
"vorgangId"
,
VORGANG_ID
);
command
.
put
(
"createdAt"
,
CREATED_AT
);
command
.
put
(
"createdBy"
,
CREATED_BY
);
command
.
put
(
"createdByName"
,
CREATED_BY_NAME
);
command
.
put
(
"createdByClientName"
,
CREATED_BY_CLIENT
);
command
.
put
(
"status"
,
STATUS
);
command
.
put
(
"relationId"
,
RELATION_ID
);
command
.
put
(
"relationVersion"
,
RELATION_VERSION
);
command
.
put
(
"previousState"
,
PREVIOUS_STATE
);
command
.
put
(
ORDER_FIELD
,
ORDER
);
command
.
put
(
BODY_OBJECT_FIELD
,
BODY
);
command
.
put
(
"createdResource"
,
CREATED_RESOURCE
);
return
command
;
}
public
static
Document
createWithOrder
(
String
order
)
{
var
command
=
create
();
command
.
put
(
ORDER_FIELD
,
order
);
return
command
;
}
public
static
Document
createWithBody
(
Map
<
String
,
Object
>
body
)
{
var
command
=
create
();
command
.
put
(
BODY_OBJECT_FIELD
,
body
);
return
command
;
}
public
static
Document
createWithOrderAndBody
(
String
order
,
Map
<
String
,
Object
>
body
)
{
var
command
=
createWithOrder
(
order
);
command
.
put
(
BODY_OBJECT_FIELD
,
body
);
return
command
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment