-
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.
Merge pull request #252 from Health-Education-England/feat/handleRequ…
…estsForDbcAndHeeUserData feat: DBC and HeeUser requests from TSS
- Loading branch information
Showing
9 changed files
with
253 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package uk.nhs.tis.sync.dto; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* A DTO for transferring HeeUser data to the DMS. | ||
*/ | ||
@Data | ||
public class HeeUserDmsDto { | ||
private final String name; | ||
private final String firstName; | ||
private final String lastName; | ||
private final String gmcId; | ||
private final String phoneNumber; | ||
private final String emailAddress; | ||
private final String active; | ||
} |
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,25 @@ | ||
package uk.nhs.tis.sync.mapper; | ||
|
||
import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.Named; | ||
import uk.nhs.tis.sync.dto.HeeUserDmsDto; | ||
|
||
/** | ||
* A mapper to map between Profile and DMS DTOs for the HeeUser data type. | ||
*/ | ||
@Mapper(componentModel = "spring") | ||
public interface HeeUserMapper extends DmsMapper<HeeUserDTO, HeeUserDmsDto> { | ||
|
||
//note that password, roles, etc. in the HeeUserDTO are excluded from HeeUserDmsDto: we simply | ||
//map the 'base' record fields | ||
@Mapping(target = "active", source = "active", | ||
qualifiedByName = "getBooleanAsZeroOrOne") | ||
HeeUserDmsDto toDmsDto(HeeUserDTO heeUserDto); | ||
|
||
@Named("getBooleanAsZeroOrOne") | ||
default String getBooleanAsZeroOrOne(boolean bool) { | ||
return bool ? "1" : "0"; | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
src/test/java/uk/nhs/tis/sync/mapper/HeeUserMapperTest.java
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,63 @@ | ||
package uk.nhs.tis.sync.mapper; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import com.transformuk.hee.tis.profile.dto.RoleDTO; | ||
import com.transformuk.hee.tis.profile.service.dto.HeeUserDTO; | ||
import com.transformuk.hee.tis.profile.service.dto.UserProgrammeDTO; | ||
import com.transformuk.hee.tis.profile.service.dto.UserTrustDTO; | ||
import java.util.Collections; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import uk.nhs.tis.sync.dto.HeeUserDmsDto; | ||
|
||
class HeeUserMapperTest { | ||
|
||
private HeeUserMapper mapper; | ||
|
||
private HeeUserDTO heeUserDto; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mapper = new HeeUserMapperImpl(); | ||
|
||
heeUserDto = new HeeUserDTO(); | ||
heeUserDto.setActive(true); | ||
heeUserDto.setAssociatedProgrammes(Collections.singleton(new UserProgrammeDTO())); | ||
heeUserDto.setAssociatedTrusts(Collections.singleton(new UserTrustDTO())); | ||
heeUserDto.setFirstName("first name"); | ||
heeUserDto.setName("name"); | ||
heeUserDto.setDesignatedBodyCodes(Collections.singleton("dbc1")); | ||
heeUserDto.setEmailAddress("email"); | ||
heeUserDto.setGmcId("gmc"); | ||
heeUserDto.setLastName("last name"); | ||
heeUserDto.setPassword("password"); | ||
heeUserDto.setPhoneNumber("phone"); | ||
heeUserDto.setRoles(Collections.singleton(new RoleDTO())); | ||
heeUserDto.setTemporaryPassword(true); | ||
} | ||
|
||
@Test | ||
void shouldMapAHeeUserDtoToADataDmsDto() { | ||
HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto); | ||
|
||
assertEquals("1", heeUserDmsDto.getActive()); | ||
assertEquals("name", heeUserDmsDto.getName()); | ||
assertEquals("first name", heeUserDmsDto.getFirstName()); | ||
assertEquals("gmc", heeUserDmsDto.getGmcId()); | ||
assertEquals("last name", heeUserDmsDto.getLastName()); | ||
assertEquals("email", heeUserDmsDto.getEmailAddress()); | ||
assertEquals("phone", heeUserDmsDto.getPhoneNumber()); | ||
//other HeeUserDto properties are ignored | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(booleans = {false, true}) | ||
void shouldMapBooleansToZeroOrOneString(boolean bool) { | ||
heeUserDto.setActive(bool); | ||
HeeUserDmsDto heeUserDmsDto = mapper.toDmsDto(heeUserDto); | ||
assertEquals(bool ? "1" : "0", heeUserDmsDto.getActive()); | ||
} | ||
} |
Oops, something went wrong.