Skip to content

feat: extract data from repository #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.decathlon.tzatziki.utils.InsertionMode.INSERTION_MODE;
import static com.decathlon.tzatziki.utils.Patterns.THAT;
import static com.decathlon.tzatziki.utils.Patterns.TYPE;
import static com.decathlon.tzatziki.utils.Patterns.VARIABLE;
import static org.assertj.core.api.Assertions.assertThat;

public class SpringJPASteps {
Expand Down Expand Up @@ -104,6 +105,16 @@ public void the_entities_contain_nothing(Guard guard, Type type) {
the_repository_contains_nothing(guard, getRepositoryForEntity(type));
}

@Then(THAT + GUARD + VARIABLE + " is the ([^ ]+) table content$")
public void add_table_content_to_variable(Guard guard, String name, String table) {
add_repository_content_to_variable(guard, name, getRepositoryForTable(table));
}

@Then(THAT + GUARD + VARIABLE + " is the " + TYPE + " entities$")
public void add_entities_to_variable(Guard guard, String name, Type type) {
add_repository_content_to_variable(guard, name, getRepositoryForEntity(type));
}

private void the_repository_contains_nothing(Guard guard, CrudRepository<Object, ?> repositoryOfEntity) {
guard.in(objects, () -> awaitUntilAsserted(() -> assertThat(repositoryOfEntity.count()).isZero()));
}
Expand Down Expand Up @@ -138,6 +149,10 @@ public <E> void the_repository_contains(Guard guard, CrudRepository<E, ?> reposi
});
}

public <E> void add_repository_content_to_variable(Guard guard, String name, CrudRepository<E, ?> repository) {
guard.in(objects, () -> objects.add(name, StreamSupport.stream(repository.findAll().spliterator(), false).toList()));
}

@SuppressWarnings("unchecked")
public <E> CrudRepository<E, ?> getRepositoryForTable(String table) {
return spring.applicationContext().getBeansOfType(CrudRepository.class).values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,23 @@ Feature: to interact with a spring boot service having a persistence layer
Then the groups table contains:
| id | name |
| 1 | Sith |

Scenario: we can get a table content
Given that the users table will contain only:
| id | firstName | lastName |
| 1 | Darth | Vader |
| 2 | Han | Solo |
Then usersTableContent is the users table content
And usersTableContent.size is equal to 2
And usersTableContent[0].id is equal to 1
And usersTableContent[1].id is equal to 2

Scenario: we can get entities
Given that the User entities will contain only:
| id | firstName | lastName |
| 1 | Darth | Vader |
| 2 | Han | Solo |
Then userEntities is the User entities
And userEntities.size is equal to 2
And userEntities[0].id is equal to 1
And userEntities[1].id is equal to 2