-
Notifications
You must be signed in to change notification settings - Fork 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
[TACKLE-268]-Request failed with status 500 on importing invalid csv file #107
Conversation
Codecov Report
@@ Coverage Diff @@
## main #107 +/- ##
============================================
+ Coverage 97.27% 97.32% +0.04%
- Complexity 219 220 +1
============================================
Files 25 25
Lines 441 448 +7
Branches 22 23 +1
============================================
+ Hits 429 436 +7
Misses 9 9
Partials 3 3
Continue to review full report at Codecov.
|
* TACKLE-271: case insensitive headers now allowed in import csv file (migtools#82) * TACKLE-290 importer native image tests (migtools#88) * TACKLE-290 importer native image tests * TACKLE-290: removed userTransactions in tests * TACKLE-290: convert to use endpoints * TACKLE-290: convert to use endpoints so NativeImageTests don't fail * TACKLE-290:inititialise mocks * TACKLE-290: initialise mocks * TACKLE-290: add wiremock http server to enable native image tests to call out to remote rest api * TACKLE-290: tidy up importer test code * TACKLE-290: increase test coverage for importer * TACKLE-290: added extra test * TACKLE-290: test coverage * TACKLE-290: fix problem with controls services query parameters not being picked up * TACKLE-290: remove status field from ApplicationImport * Tackle 290 - Fix native tests (migtools#6) * Comment tests * Restart changes * comment test * comment test * comment test * Working tests * build tests inside own gh account * fix ImportServiceTest * Remove comments * restore gh workflow * restore gh workflow * TACKLE-290: fix merged test to be native-compliant * TACKLE-290 Removed 'baseUri' and changed 'mp-rest/uri' props (migtools#7) * TACKLE-290: alter order of ImportServiceTest methods * TACKLE-290: alter test method ordering * TACKLE-290 Refactored some tests and WireMock (migtools#8) Co-authored-by: Carlos E. Feria Vila <[email protected]> Co-authored-by: Marco Rizzi <[email protected]> * Maven pom.xml(deps-dev): Bump mockito-core from 3.8.0 to 3.12.0 (migtools#117) Bumps [mockito-core](https://github.com/mockito/mockito) from 3.8.0 to 3.12.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](mockito/mockito@v3.8.0...v3.12.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Maven pom.xml(deps-dev): Bump wiremock-jre8 from 2.29.0 to 2.30.1 (migtools#120) Bumps [wiremock-jre8](https://github.com/tomakehurst/wiremock) from 2.29.0 to 2.30.1. - [Release notes](https://github.com/tomakehurst/wiremock/releases) - [Commits](wiremock/wiremock@2.29.0...2.30.1) --- updated-dependencies: - dependency-name: com.github.tomakehurst:wiremock-jre8 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Maven pom.xml(deps-dev): Bump assertj-core from 2.6.0 to 3.20.2 (migtools#76) Bumps [assertj-core](https://github.com/assertj/assertj-core) from 2.6.0 to 3.20.2. - [Release notes](https://github.com/assertj/assertj-core/releases) - [Commits](assertj/assertj@assertj-core-2.6.0...assertj-core-3.20.2) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Maven pom.xml(deps-dev): Bump postgresql from 1.15.2 to 1.16.0 (migtools#96) Bumps [postgresql](https://github.com/testcontainers/testcontainers-java) from 1.15.2 to 1.16.0. - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/master/CHANGELOG.md) - [Commits](testcontainers/testcontainers-java@1.15.2...1.16.0) --- updated-dependencies: - dependency-name: org.testcontainers:postgresql dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Maven pom.xml(deps-dev): Bump mockito-core from 3.12.0 to 3.12.1 (migtools#121) Bumps [mockito-core](https://github.com/mockito/mockito) from 3.12.0 to 3.12.1. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](mockito/mockito@v3.12.0...v3.12.1) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * TACKLE-268 Properly clean data inserted during test execution ('Import-app-8') Co-authored-by: Mark Brophy <[email protected]> Co-authored-by: Carlos E. Feria Vila <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
# Conflicts: # src/test/java/io/tackle/applicationimporter/ImportServiceTest.java
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.
The validation approach has been widely discussed on some meetings and the implementation has been done accordingly so no need to further discuss the validation approach in this PR.
I've reviewed the test class in order to enhance where possible.
I'm aware of the need for quickly get this PR merged so I'll provide a PR to this PR to fix all the comments I raised and also for adding the native test once only HTTP endpoints are used in the test.
src/test/java/io/tackle/applicationinventory/services/issues/Issue268Test.java
Outdated
Show resolved
Hide resolved
@ResourceArg(name = KeycloakTestResource.REALM_NAME, value = "quarkus") | ||
} | ||
) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
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.
There's just one test method so no need to use @Order(X)
annotation.
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
} | ||
) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class Issue268Test extends SecuredResourceTest { |
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.
Better keep the naming consistent with the other issue-related test class IssueTACKLE282Test and add the link to the issue for a quick reference in case of need.
public class Issue268Test extends SecuredResourceTest { | |
// https://issues.redhat.com/browse/TACKLE-268 | |
public class IssueTACKLE268Test extends SecuredResourceTest { |
@InjectMock | ||
@RestClient | ||
TagService mockTagService; | ||
|
||
@InjectMock | ||
@RestClient | ||
BusinessServiceService mockBusinessServiceService; |
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.
Here we can leverage and be consistent with the usage of the WireMockControlsServices
recently added that allows for removing this code.
@Inject | ||
UserTransaction userTransaction; |
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.
Relying only on REST endpoints makes it easier for using the test also in native mode.
Mockito.when(mockTagService.getListOfTags(0, 1000)).thenReturn(Collections.emptySet()); | ||
Mockito.when(mockBusinessServiceService.getListOfBusinessServices(0, 1000)).thenReturn(Collections.emptySet()); |
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.
From above, we can leverage and be consistent with the usage of the WireMockControlsServices
recently added that allows for removing this code.
given() | ||
.accept("application/json") | ||
.when() | ||
.get("/import-summary") |
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.
It's a call to the same /import-summary
tested in the call straight above so all the tests can be done with just one call.
"[0].'invalidCount'", is(2) | ||
); | ||
|
||
ImportSummary summary = ImportSummary.findAll().firstResult(); |
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.
The summary ID can be retrieve from the above test call to the /import-summary
endpoint avoiding the need for executing this query.
given() | ||
.accept("text/csv") | ||
.when() | ||
.get("/csv-export?importSummaryId=" + summary.id); |
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.
importSummaryId
should be managed properly as a query parameter
userTransaction.begin(); | ||
ApplicationImport.deleteAll(); | ||
ImportSummary.deleteAll(); | ||
userTransaction.commit(); |
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.
using the summary ID retrieve in a call above, this transaction can be replaced with a REST delete
call.
.log().all() | ||
.statusCode(200).extract().response(); | ||
|
||
assertEquals(200, response.getStatusCode()); |
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.
This is tested in the above RESTAssured call.
assertEquals(200, response.getStatusCode()); |
TACKLE-268 Enhancements after the review
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.
As already reported, validation process already discussed outside of this PR.
The test part of the PR has been reviewed so I think we're fine to merge this.
The PR has been also manually tested in a live Tackle instance (thanks @PhilipCattanach)
I approve even if I've been a contributor but we need this to let #92 build successfully.
Thanks @carlosthe19916 for having done this enhancement 👍
https://issues.redhat.com/browse/TACKLE-268
About creating SQL scripts to change the column sizes
The current definition of the table
application_import
is something like:In our last meeting, it was suggested to create a new SQL script to alter the
application_import
table and align the column sizes to the UI; it means, to reduce some column's size. For instance,applicationname varchar(255)
will becomeapplicationname varchar(120)
. This change will work in an empty database but it will cause problems if for any reason the DB is not empty and the tableapplication_import
containsapplicationname
column values longer than120
.