-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jpa tests with h2 + tested postgres profile local #3634
- Loading branch information
1 parent
c564f62
commit 1e583e8
Showing
7 changed files
with
60 additions
and
9 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
7 changes: 0 additions & 7 deletions
7
sechub-web-server/src/main/resources/db/migration/V1__initial_version.sql
This file was deleted.
Oops, something went wrong.
File renamed without changes.
8 changes: 8 additions & 0 deletions
8
sechub-web-server/src/main/resources/db/migration/common/V1__Initial_version.sql
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,8 @@ | ||
-- SPDX-License-Identifier: MIT | ||
CREATE TABLE adm_user | ||
( | ||
user_id varchar(60) not null, | ||
user_email_address varchar(255) not null, | ||
user_roles VARCHAR(50) NOT NULL, | ||
PRIMARY KEY (user_id) | ||
); |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@DataJpaTest | ||
@ActiveProfiles("h2") | ||
|
@@ -25,4 +26,48 @@ void assert_flyway_test_user_is_in_h2_database() { | |
assert (users.get(0).getEmailAddress().equals("[email protected]")); | ||
assert (users.get(0).getRoles().equals("USER")); | ||
} | ||
|
||
@Test | ||
void save_user_to_database() { | ||
/* prepare */ | ||
User user = new User(); | ||
user.setName("testuser2"); | ||
user.setEmailAddress("[email protected]"); | ||
user.setRoles("USER"); | ||
|
||
/* execute */ | ||
userRepository.save(user); | ||
|
||
/* test */ | ||
List<User> users = userRepository.findAll(); | ||
assert (users.size() == 2); | ||
} | ||
|
||
@Test | ||
void find_user_from_database() { | ||
/* execute */ | ||
Optional<User> optUser = userRepository.findById("testuser"); | ||
|
||
/* test */ | ||
assert (optUser.isPresent()); | ||
User user = optUser.get(); | ||
assert (user.getName().equals("testuser")); | ||
assert (user.getEmailAddress().equals("[email protected]")); | ||
assert (user.getRoles().equals("USER")); | ||
} | ||
|
||
@Test | ||
void save_and_delete_user_from_database() { | ||
/* prepare */ | ||
Optional<User> optUser = userRepository.findById("testuser"); | ||
assert (optUser.isPresent()); | ||
User user = optUser.get(); | ||
|
||
/* execute */ | ||
userRepository.delete(user); | ||
|
||
/* test */ | ||
List<User> users = userRepository.findAll(); | ||
assert (users.isEmpty()); | ||
} | ||
} |