forked from UdL-EPS-SoftArch/spring-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Content&report test #9
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
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c67410b
Cucumber Tests for Content and Report
mariaazcona c18c28a
Fix cucumber test errors
mariaazcona 40ad878
Fix error in ReportRepositorySetpsDefs Test
EricksonHR adf235b
2nd try to fix Maven Build Errors
EricksonHR cc2fb97
API connection in When step
EricksonHR 5241e4d
Changes in Report Steps
EricksonHR ced9c1a
Content&Report Create Features
EricksonHR 4a7c987
Added login in features
neusfdez 4bfd676
Fix errors
neusfdez b6ed4a2
fix changes 2
neusfdez dddab17
fix 3
neusfdez 2528554
Fix authentication errors
neusfdez a083f81
still trying to fix
neusfdez a81abc1
fixing...
neusfdez 3341442
Fix Report Tests
mariaazcona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
43 changes: 43 additions & 0 deletions
43
src/test/java/cat/udl/eps/softarch/demo/steps/ContentRepositoryStepsDefs.java
This file contains hidden or 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,43 @@ | ||
| package cat.udl.eps.softarch.demo.steps; | ||
|
|
||
| import cat.udl.eps.softarch.demo.domain.Content; | ||
| import cat.udl.eps.softarch.demo.repository.ContentRepository; | ||
| import io.cucumber.java.en.*; | ||
| import org.junit.jupiter.api.Assertions; | ||
|
|
||
| public class ContentRepositoryStepsDefs { | ||
|
|
||
| private final ContentRepository contentRepository; | ||
| private boolean existsResult; | ||
| private Long createdContentId; | ||
|
|
||
| public ContentRepositoryStepsDefs(ContentRepository contentRepository) { | ||
| this.contentRepository = contentRepository; | ||
| } | ||
|
|
||
| @Given("there are no Contents in the system") | ||
| public void there_are_no_Contents_in_the_system() { | ||
| contentRepository.deleteAll(); | ||
| Assertions.assertEquals(0, contentRepository.count()); | ||
| } | ||
|
|
||
| @When("I create a Content with name {string} and description {string}") | ||
| public void iCreateAContentWithNameAndDescription(String name, String description) { | ||
| if (!contentRepository.existsByName(name)) { | ||
| Content content = new Content(); | ||
| content.setName(name); | ||
| content.setDescription(description); | ||
|
|
||
| Content saved = contentRepository.save(content); | ||
| createdContentId = saved.getContentId(); | ||
| existsResult = contentRepository.existsById(createdContentId); | ||
| } else { | ||
| existsResult = true; | ||
| } | ||
| } | ||
|
|
||
| @Then("Content existsById should return true") | ||
| public void exists_by_id_should_return_true() { | ||
| Assertions.assertTrue(existsResult); | ||
| } | ||
| } | ||
This file contains hidden or 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
52 changes: 52 additions & 0 deletions
52
src/test/java/cat/udl/eps/softarch/demo/steps/ReportRepositoryStepsDefs.java
This file contains hidden or 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,52 @@ | ||
| package cat.udl.eps.softarch.demo.steps; | ||
|
|
||
| import cat.udl.eps.softarch.demo.domain.Report; | ||
| import cat.udl.eps.softarch.demo.domain.Content; | ||
| import cat.udl.eps.softarch.demo.repository.ReportRepository; | ||
| import cat.udl.eps.softarch.demo.repository.ContentRepository; | ||
| import io.cucumber.java.ParameterType; | ||
| import io.cucumber.java.en.*; | ||
| import org.junit.jupiter.api.Assertions; | ||
|
|
||
| public class ReportRepositoryStepsDefs { | ||
|
|
||
| private final ReportRepository reportRepository; | ||
| private boolean existsResult; | ||
| private Long createdReportId; | ||
| private final ContentRepository contentRepository; | ||
|
|
||
| @ParameterType(".*") public Content content(String name) { | ||
| return this.contentRepository.findByName(name).orElseThrow(() -> new RuntimeException("Content not found")); | ||
| } | ||
|
|
||
| @ParameterType("\\d+") public Long Long(String value) { | ||
| return Long.valueOf(value); | ||
| } | ||
|
|
||
| public ReportRepositoryStepsDefs(ReportRepository reportRepository, ContentRepository contentRepository) { | ||
| this.reportRepository = reportRepository; | ||
| this.contentRepository = contentRepository; | ||
| } | ||
|
|
||
| @Given("there are no Reports in the system") | ||
| public void there_are_no_Reports_in_the_system() { | ||
| reportRepository.deleteAll(); | ||
| Assertions.assertEquals(0, reportRepository.count()); | ||
| } | ||
|
|
||
| @When("I create a Report with reportId {Long}, content {content} and reason {string}") | ||
| public void iCreateAReportWithNameAndDescription(Long reportId, Content content, String reason) { | ||
| Report report = new Report(); | ||
| report.setContent(content); | ||
| report.setReason(reason); | ||
|
|
||
| Report saved = reportRepository.save(report); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the When steps, as you are testing the API to check if it can create reports, you should be using the API instead of directly creating the intance into de database. |
||
| createdReportId = saved.getReportId(); | ||
| existsResult = reportRepository.existsById(createdReportId); | ||
| } | ||
|
|
||
| @Then("Report existsById should return true") | ||
| public void exists_by_id_should_return_true() { | ||
| Assertions.assertTrue(existsResult); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the When steps, as you are testing the API to check if it can create Contents, you should be using the API instead of directly creating the intance into de database.
For an example: https://github.com/UdL-EPS-SoftArch/spring-template/blob/c846b30f32b9e1a5d9477616de14edf84e7ae737/src/test/java/cat/udl/eps/softarch/demo/steps/ManageRecordStepDefs.java#L33