/** * Most of the shared credentials container tests work on the test one, so that things are in a * known and empty state. We have this one test that uses the real shared container, just to check * that it's correctly setup and available */ @Test public void testRealSharedCredentialsContainer() throws Exception { // Create a new instance, using the real container RemoteCredentialsServiceImpl realService = new RemoteCredentialsServiceImpl(); realService.setDictionaryService(DICTIONARY_SERVICE); realService.setNamespaceService(NAMESPACE_SERVICE); realService.setNodeService(PUBLIC_NODE_SERVICE); realService.setRepositoryHelper(REPOSITORY_HELPER); for (Entry<QName, RemoteCredentialsInfoFactory> e : ((RemoteCredentialsServiceImpl) PRIVATE_REMOTE_CREDENTIALS_SERVICE) .getCredentialsFactories() .entrySet()) { realService.registerCredentialsFactory(e.getKey(), e.getValue()); } // Run as a test user AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER_ONE); // Do a create / fetch / delete step PasswordCredentialsInfoImpl pwCredI = new PasswordCredentialsInfoImpl(); pwCredI.setRemoteUsername(TEST_REMOTE_USERNAME_ONE); pwCredI.setRemotePassword(TEST_USER_THREE); BaseCredentialsInfo credentials = null; try { // Create credentials = realService.createSharedCredentials(TEST_REMOTE_SYSTEM_ONE, pwCredI); assertEquals(TEST_REMOTE_USERNAME_ONE, credentials.getRemoteUsername()); // Update ((PasswordCredentialsInfoImpl) credentials).setRemoteUsername(TEST_REMOTE_USERNAME_TWO); ((PasswordCredentialsInfoImpl) credentials).setRemotePassword(TEST_USER_ONE); credentials = realService.updateCredentials(credentials); assertEquals(TEST_REMOTE_USERNAME_TWO, credentials.getRemoteUsername()); // Delete realService.deleteCredentials(credentials); // Tidy, and zap the test parent PUBLIC_NODE_SERVICE.deleteNode(credentials.getRemoteSystemContainerNodeRef()); credentials = null; } finally { // Tidy up if needed if (credentials != null) { AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); // Zap the credentials themselves PUBLIC_NODE_SERVICE.deleteNode(credentials.getNodeRef()); // And their test parent PUBLIC_NODE_SERVICE.deleteNode(credentials.getRemoteSystemContainerNodeRef()); } } }