Skip to content

Commit

Permalink
Try to improve the coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rmiccoli committed Jul 3, 2024
1 parent 9c0d7e0 commit c62a196
Showing 1 changed file with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import java.text.ParseException;
import java.time.Clock;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.validation.ConstraintViolationException;

Expand Down Expand Up @@ -105,7 +107,7 @@ public void testPagedClientLookup() {

Sort sort = Sort.by(Direction.ASC, "clientId");
Pageable pageable = PagingUtils.buildPageRequest(10, 1, 100, sort);

ListResponseDTO<RegisteredClientDTO> clients = managementService.retrieveAllClients(pageable);

assertThat(clients.getTotalResults(), is(19L));
Expand Down Expand Up @@ -249,8 +251,7 @@ public void testBasicClientValidation() {
}

@Test
public void testDynamicallyRegisteredClientCanBeUpdated()
throws ParseException {
public void testDynamicallyRegisteredClientCanBeUpdated() throws ParseException {

userAuth = Mockito.mock(UsernamePasswordAuthenticationToken.class);
when(userAuth.getName()).thenReturn("test");
Expand All @@ -261,7 +262,7 @@ public void testDynamicallyRegisteredClientCanBeUpdated()
request.setGrantTypes(Sets.newHashSet(AuthorizationGrantType.CLIENT_CREDENTIALS));
RegisteredClientDTO response = registrationService.registerClient(request, userAuth);


String clientId = response.getClientId();
ClientDetailsEntity entity = clientService.findClientByClientId(clientId).orElseThrow();
assertThat(entity.isDynamicallyRegistered(), is(true));
Expand Down Expand Up @@ -296,8 +297,7 @@ public void testSecretRotation() throws ParseException {
RegisteredClientDTO updatedClient =
managementService.retrieveClientByClientId(client.getClientId()).orElseThrow();

assertThat(updatedClient.getClientSecret(),
not(equalTo(savedClient.getClientSecret())));
assertThat(updatedClient.getClientSecret(), not(equalTo(savedClient.getClientSecret())));
}

@Test
Expand Down Expand Up @@ -333,9 +333,8 @@ public void testClientOwnerAssignRemove() throws ParseException {
RegisteredClientDTO savedClient = managementService.saveNewClient(client);
assertThat(savedClient.getClientId(), is(client.getClientId()));
assertThat(savedClient.getClientSecret(), notNullValue());

ListResponseDTO<ScimUser> owners =
managementService.getClientOwners(savedClient.getClientId(),

ListResponseDTO<ScimUser> owners = managementService.getClientOwners(savedClient.getClientId(),
PagingUtils.buildUnpagedPageRequest());

assertThat(owners.getTotalResults(), is(0L));
Expand Down Expand Up @@ -417,4 +416,28 @@ public void testClientStatusChange() {
assertTrue(client.getStatusChangedOn().equals(Date.from(clock.instant())));
assertEquals("userUUID", client.getStatusChangedBy());
}

@Test
public void testClientStatusChangeWithContacts() throws ParseException {
managementService.updateClientStatus("client", false, "userUUID");
RegisteredClientDTO client = managementService.retrieveClientByClientId("client").get();
Set<String> contacts = new HashSet<String>();
contacts.add("[email protected]");
client.setContacts(contacts);
managementService.updateClient(client.getClientId(), client);

assertFalse(client.isActive());
assertTrue(client.getStatusChangedOn().equals(Date.from(clock.instant())));
assertEquals("userUUID", client.getStatusChangedBy());
}

@Test
public void testClientStatusChangeWithoutOwners() {
managementService.updateClientStatus("client-cred", false, "userUUID");
RegisteredClientDTO client = managementService.retrieveClientByClientId("client-cred").get();

assertFalse(client.isActive());
assertTrue(client.getStatusChangedOn().equals(Date.from(clock.instant())));
assertEquals("userUUID", client.getStatusChangedBy());
}
}

0 comments on commit c62a196

Please sign in to comment.