This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Pozzi
committed
Mar 16, 2021
1 parent
1af4927
commit 2c9ebda
Showing
4 changed files
with
184 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/de/bonndan/nivio/input/ItemRelationProcessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package de.bonndan.nivio.input; | ||
|
||
import de.bonndan.nivio.input.dto.ItemDescription; | ||
import de.bonndan.nivio.input.dto.LandscapeDescription; | ||
import de.bonndan.nivio.input.dto.RelationDescription; | ||
import de.bonndan.nivio.model.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
||
class ItemRelationProcessorTest { | ||
|
||
private LandscapeDescription input; | ||
private Landscape landscape; | ||
private ItemRelationProcessor processor; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
input = new LandscapeDescription("test"); | ||
Set<Item> items = new HashSet<>(); | ||
Item foo = ItemFactory.getTestItem("a", "foo"); | ||
items.add(foo); | ||
Item bar = ItemFactory.getTestItem("a", "bar"); | ||
items.add(bar); | ||
Item baz = ItemFactory.getTestItem("a", "baz"); | ||
items.add(baz); | ||
|
||
foo.getRelations().add(new Relation(foo, bar)); | ||
bar.getRelations().add(new Relation(foo, bar)); | ||
|
||
foo.getRelations().add(new Relation(foo, baz)); | ||
baz.getRelations().add(new Relation(foo, baz)); | ||
|
||
landscape = LandscapeFactory.createForTesting("test", "test").withItems(items).build(); | ||
|
||
processor = new ItemRelationProcessor(new ProcessLog(LoggerFactory.getLogger(ItemRelationProcessorTest.class))); | ||
} | ||
|
||
@Test | ||
void processAddsRelation() { | ||
|
||
ItemDescription description = new ItemDescription("foo"); | ||
description.setGroup("a"); | ||
description.addRelation(new RelationDescription("foo", "bar")); | ||
description.addRelation(new RelationDescription("foo", "baz")); | ||
input.addItems(List.of(description)); | ||
//new | ||
ItemDescription bar = new ItemDescription("bar"); | ||
bar.setGroup("a"); | ||
description.addRelation(new RelationDescription("bar", "baz")); | ||
input.addItems(List.of(bar)); | ||
|
||
//when | ||
ProcessingChangelog process = processor.process(input, landscape); | ||
|
||
//then | ||
assertThat(process.changes).hasSize(3); //two updates, one created | ||
} | ||
|
||
@Test | ||
void processRemovesRelation() { | ||
|
||
ItemDescription description = new ItemDescription("foo"); | ||
description.setGroup("a"); | ||
description.addRelation(new RelationDescription("foo", "bar")); | ||
input.addItems(List.of(description)); | ||
|
||
//when | ||
ProcessingChangelog process = processor.process(input, landscape); | ||
|
||
//then | ||
assertThat(process.changes).hasSize(2); //one update, one delete | ||
assertThat(process.changes).containsKey("test/a/foo;test/a/baz"); | ||
assertThat(process.changes.get("test/a/foo;test/a/baz").getChangeType()).isEqualTo(ProcessingChangelog.ChangeType.DELETED.name()); | ||
} | ||
} |