Skip to content
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

fix: all CoJ PM IDs are UUIDs now #992

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tcs-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.transformuk.hee.tis</groupId>
<artifactId>tcs-service</artifactId>
<version>6.36.0</version>
<version>6.36.1</version>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
public class ConditionsOfJoiningSignedEvent {

@JsonProperty("programmeMembershipTisId")
private final Object id; //this may be a long or a UUID
private final String id;
private final ConditionsOfJoiningDto conditionsOfJoining;

public ConditionsOfJoiningSignedEvent(Object id,
public ConditionsOfJoiningSignedEvent(String id,
ConditionsOfJoiningDto conditionsOfJoining) {
this.id = id;
this.conditionsOfJoining = conditionsOfJoining;
}

public Object getId() {
public String getId() {
return id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
public interface ConditionsOfJoiningService {

/**
* Save a Conditions of Joining from its DTO and related programme membership ID/UUID.
* Save a Conditions of Joining from its DTO and related programme membership UUID.
*
* @param id the programme membership ID or UUID
* @param id the programme membership UUID as a string
* @param dto the Conditions Of Joining DTO
* @return the saved Conditions of Joining DTO
*/
ConditionsOfJoiningDto save(Object id, ConditionsOfJoiningDto dto);
ConditionsOfJoiningDto save(String id, ConditionsOfJoiningDto dto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ public ConditionsOfJoiningServiceImpl(ConditionsOfJoiningRepository repository,
}

@Override
public ConditionsOfJoiningDto save(Object id, ConditionsOfJoiningDto dto) {
public ConditionsOfJoiningDto save(String id, ConditionsOfJoiningDto dto) {
ProgrammeMembershipDTO programmeMembership;
LOG.info("Request received to save Conditions of Joining for id {}.", id);
try {
programmeMembership = programmeMembershipService.findOne(Long.parseLong(id.toString()));
} catch (NumberFormatException e) {
programmeMembership = programmeMembershipService.findOne(UUID.fromString(id.toString()));
}
LOG.info("Request received to save Conditions of Joining for UUID {}.", id);
programmeMembership = programmeMembershipService.findOne(UUID.fromString(id));

if (programmeMembership == null) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

class TraineeMessageListenerTest {

private static final Long CURRICULUM_MEMBERSHIP_ID = 40L;
private static final UUID PROGRAMME_MEMBERSHIP_ID = UUID.randomUUID();
private static final String PROGRAMME_MEMBERSHIP_ID = UUID.randomUUID().toString();
private static final Instant SIGNED_AT = Instant.now();

private TraineeMessageListener listener;
Expand All @@ -34,16 +33,6 @@ void setUp() {
dto.setVersion(GoldGuideVersion.GG9);
}

@Test
void shouldSaveSignedCojWhenEventValidWithCmId() {
ConditionsOfJoiningSignedEvent event = new ConditionsOfJoiningSignedEvent(
CURRICULUM_MEMBERSHIP_ID, dto);

listener.receiveMessage(event);

verify(service).save(CURRICULUM_MEMBERSHIP_ID, dto);
}

@Test
void shouldSaveSignedCojWhenEventValidWithPmId() {
ConditionsOfJoiningSignedEvent event = new ConditionsOfJoiningSignedEvent(
Expand All @@ -57,9 +46,9 @@ void shouldSaveSignedCojWhenEventValidWithPmId() {
@Test
void shouldNotRequeueMessageWhenEventArgumentsInvalid() {
ConditionsOfJoiningSignedEvent event = new ConditionsOfJoiningSignedEvent(
CURRICULUM_MEMBERSHIP_ID, dto);
PROGRAMME_MEMBERSHIP_ID, dto);

when(service.save(CURRICULUM_MEMBERSHIP_ID, dto)).thenThrow(IllegalArgumentException.class);
when(service.save(PROGRAMME_MEMBERSHIP_ID, dto)).thenThrow(IllegalArgumentException.class);

assertThrows(AmqpRejectAndDontRequeueException.class, () -> listener.receiveMessage(event));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

class ConditionsOfJoiningServiceImplTest {

private static final Long CURRICULUM_MEMBERSHIP_ID = 40L;
private static final UUID PROGRAMME_MEMBERSHIP_UUID = UUID.randomUUID();
private static final Instant SIGNED_AT = Instant.now();

Expand All @@ -46,51 +45,15 @@ void setUp() {
coj.setVersion(GoldGuideVersion.GG9);
}

@Test
void saveShouldThrowExceptionWhenCurriculumMembershipIdNotFound() {
when(programmeMembershipService.findOne(CURRICULUM_MEMBERSHIP_ID)).thenReturn(null);

assertThrows(IllegalArgumentException.class,
() -> conditionsOfJoiningService.save(CURRICULUM_MEMBERSHIP_ID, coj));
verify(repository, never()).save(any());
}

@Test
void saveShouldThrowExceptionWhenProgrammeMembershipIdNotFound() {
when(programmeMembershipService.findOne(PROGRAMME_MEMBERSHIP_UUID)).thenReturn(null);

assertThrows(IllegalArgumentException.class,
() -> conditionsOfJoiningService.save(PROGRAMME_MEMBERSHIP_UUID, coj));
verify(repository, never()).save(any());
}

@Test
void saveShouldThrowExceptionWhenInvalidIdProvided() {
assertThrows(IllegalArgumentException.class,
() -> conditionsOfJoiningService.save("not a long or a uuid", coj));
() -> conditionsOfJoiningService.save(PROGRAMME_MEMBERSHIP_UUID.toString(), coj));
verify(repository, never()).save(any());
}

@Test
void saveShouldSaveTheConditionsOfJoiningAgainstTheProgrammeMembershipFromCmId() {
ProgrammeMembershipDTO programmeMembershipDto = new ProgrammeMembershipDTO();
programmeMembershipDto.setUuid(PROGRAMME_MEMBERSHIP_UUID);

when(programmeMembershipService.findOne(CURRICULUM_MEMBERSHIP_ID)).thenReturn(
programmeMembershipDto);
when(repository.save(any())).thenAnswer(invocation -> invocation.getArguments()[0]);

ConditionsOfJoiningDto savedCoj = conditionsOfJoiningService.save(CURRICULUM_MEMBERSHIP_ID,
coj);

assertThat("Unexpected programme membership uuid.", savedCoj.getProgrammeMembershipUuid(),
is(PROGRAMME_MEMBERSHIP_UUID));
assertThat("Unexpected programme membership signed at.", savedCoj.getSignedAt(),
is(SIGNED_AT));
assertThat("Unexpected programme membership version.", savedCoj.getVersion(),
is(GoldGuideVersion.GG9));
}

@Test
void saveShouldSaveTheConditionsOfJoiningAgainstTheProgrammeMembershipFromPmId() {
ProgrammeMembershipDTO programmeMembershipDto = new ProgrammeMembershipDTO();
Expand All @@ -100,8 +63,8 @@ void saveShouldSaveTheConditionsOfJoiningAgainstTheProgrammeMembershipFromPmId()
programmeMembershipDto);
when(repository.save(any())).thenAnswer(invocation -> invocation.getArguments()[0]);

ConditionsOfJoiningDto savedCoj = conditionsOfJoiningService.save(PROGRAMME_MEMBERSHIP_UUID,
coj);
ConditionsOfJoiningDto savedCoj
= conditionsOfJoiningService.save(PROGRAMME_MEMBERSHIP_UUID.toString(), coj);

assertThat("Unexpected programme membership uuid.", savedCoj.getProgrammeMembershipUuid(),
is(PROGRAMME_MEMBERSHIP_UUID));
Expand All @@ -110,22 +73,4 @@ void saveShouldSaveTheConditionsOfJoiningAgainstTheProgrammeMembershipFromPmId()
assertThat("Unexpected programme membership version.", savedCoj.getVersion(),
is(GoldGuideVersion.GG9));
}

@Test
void saveShouldReplaceAnyProvidedProgrammeMembershipUuid() {
coj.setProgrammeMembershipUuid(UUID.randomUUID());

ProgrammeMembershipDTO programmeMembershipDto = new ProgrammeMembershipDTO();
programmeMembershipDto.setUuid(PROGRAMME_MEMBERSHIP_UUID);

when(programmeMembershipService.findOne(CURRICULUM_MEMBERSHIP_ID)).thenReturn(
programmeMembershipDto);
when(repository.save(any())).thenAnswer(invocation -> invocation.getArguments()[0]);

ConditionsOfJoiningDto savedCoj = conditionsOfJoiningService.save(CURRICULUM_MEMBERSHIP_ID,
coj);

assertThat("Unexpected programme membership uuid.", savedCoj.getProgrammeMembershipUuid(),
is(PROGRAMME_MEMBERSHIP_UUID));
}
}
Loading