-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add abstract to address entity * #80 fix update car * fix and complete registration test * fix Registration IT * fix and complete registration test * fix Registration IT
- Loading branch information
1 parent
afa88cc
commit 99b98d1
Showing
7 changed files
with
76 additions
and
15 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
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 |
---|---|---|
|
@@ -22,4 +22,6 @@ public User getLoggedInUser() { | |
} | ||
|
||
|
||
|
||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,25 +4,35 @@ | |
import com.amigoscode.chohort2.carRental.authority.Authority; | ||
import com.amigoscode.chohort2.carRental.authority.AuthorityConstants; | ||
import com.amigoscode.chohort2.carRental.authority.AuthorityService; | ||
import com.amigoscode.chohort2.carRental.carProvider.CarProvider; | ||
import com.amigoscode.chohort2.carRental.carProvider.CarProviderService; | ||
import com.amigoscode.chohort2.carRental.carProvider.VM.CarProviderVM; | ||
import com.amigoscode.chohort2.carRental.carProviderUser.CarProviderUser; | ||
import com.amigoscode.chohort2.carRental.carProviderUser.CarProviderUserService; | ||
import com.amigoscode.chohort2.carRental.driverLicense.DriverLicense; | ||
import com.amigoscode.chohort2.carRental.driverLicense.DriverLicenseService; | ||
import com.amigoscode.chohort2.carRental.driverLicense.VM.DriverLicenseVM; | ||
import com.amigoscode.chohort2.carRental.registration.VM.CarProviderRegistrationVM; | ||
import com.amigoscode.chohort2.carRental.registration.VM.ClientRegistrationVM; | ||
import com.amigoscode.chohort2.carRental.user.User; | ||
import com.amigoscode.chohort2.carRental.user.UserService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
|
||
|
||
import java.time.LocalDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class RegistrationServiceTest{ | ||
class RegistrationServiceTest { | ||
|
||
@Mock | ||
private UserService userService; | ||
|
@@ -36,6 +46,11 @@ class RegistrationServiceTest{ | |
@Mock | ||
private DriverLicenseService driverLicenseService; | ||
|
||
@Mock | ||
private CarProviderUserService carProviderUserService; | ||
|
||
@Mock | ||
private CarProviderService carProviderService; | ||
|
||
|
||
@InjectMocks | ||
|
@@ -66,13 +81,48 @@ void givenClientRegistration_whenSave_thenCreateNewUser() { | |
.willReturn(new Authority().setName(AuthorityConstants.CLIENT)); | ||
|
||
given(passwordEncoder.encode(clientRegistrationVM.getPassword())) | ||
.willReturn("$2a$10$fi6PMDJmJaxFyoursx7Pw.LdMbpcbvAf0i7g9wO6fG8HrIJ6Kn0jm"); | ||
.willReturn("encoded"); | ||
|
||
|
||
// when - action or the behaviour that we are going test | ||
underTest.clientRegistration(clientRegistrationVM); | ||
underTest.registration(clientRegistrationVM); | ||
|
||
// then verify the output | ||
verify(userService).save(any(User.class)); | ||
verify(driverLicenseService).save(any(DriverLicense.class)); | ||
|
||
} | ||
|
||
|
||
@Test | ||
void givenCarProviderRegistration_whenSave_thenCreateNewUser() { | ||
// given precondition or setup | ||
CarProviderRegistrationVM carProviderRegistrationVM = (CarProviderRegistrationVM) new CarProviderRegistrationVM() | ||
.setUsername("esmaeeil") | ||
.setFirstName("esmaeeil") | ||
.setLastName("enani") | ||
.setEmail("[email protected]") | ||
.setNin("123456789") | ||
.setPassword("123456789"); | ||
|
||
CarProviderVM carProviderVM = new CarProviderVM() | ||
.setCrNumber("1234567890") | ||
.setName("my company"); | ||
carProviderRegistrationVM.setCarProviderVM(carProviderVM); | ||
|
||
given(authorityService.findByName(AuthorityConstants.CAR_PROVIDER)) | ||
.willReturn(new Authority().setName(AuthorityConstants.CAR_PROVIDER)); | ||
|
||
given(passwordEncoder.encode(carProviderRegistrationVM.getPassword())) | ||
.willReturn("encoded"); | ||
// when - action or the behaviour that we are going test | ||
underTest.registration(carProviderRegistrationVM); | ||
|
||
|
||
// then verify the output | ||
verify(userService).save(any(User.class)); | ||
verify(carProviderService).saveCarProvider(any(CarProvider.class)); | ||
verify(carProviderUserService).saveCarProviderUser(any(CarProviderUser.class)); | ||
|
||
} | ||
} |