r.setSecret("secret");
r = resourceServerRepository.save(r);
// Create and save a client
Client client = new Client();
client.setName("name");
client.setClientId("clientid");
// Let them meet each other
r.setClients(new HashSet(Arrays.asList(client)));
client.setResourceServer(r);
client = repo.save(client);
// Create an access token
AccessToken at = new AccessToken("mytoken", new AuthenticatedPrincipal("username"), client, 0, null);
at = accessTokenRepository.save(at);
assertEquals(at, accessTokenRepository.findOne(at.getId()));
// Create an authorization request
AuthorizationRequest ar = new AuthorizationRequest("foo", "faa", "boo", null, "boo", "boo");
ar.setClient(client);
ar = authorizationRequestRepository.save(ar);
assertEquals(ar, authorizationRequestRepository.findOne(ar.getId()));
// Make sure things are saved; the relation between clients and access tokens is unidirectional; therefore a
// delete would not work with attached entities.
entityManager.clear();
final long clientId = client.getId();
repo.delete(client);
assertNull(repo.findOne(clientId));
assertNull(accessTokenRepository.findOne(at.getId()));
assertNull(authorizationRequestRepository.findOne(ar.getId()));