/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.xdi.oxauth.comp;

import java.util.Arrays;
import java.util.List;

import org.gluu.site.ldap.persistence.exception.EntryPersistenceException;
import org.jboss.seam.Component;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.xdi.oxauth.BaseComponentTest;
import org.xdi.oxauth.model.registration.Client;
import org.xdi.oxauth.service.ClientService;
import org.xdi.util.StringHelper;

/**
 * @author Yuriy Movchan
 * @version 0.1, 03/24/2014
 */

public class CleanUpClientTest extends BaseComponentTest {

	@Override
	public void beforeClass() {
	}

	@Override
	public void afterClass() {
	}

	@Test
	@Parameters(value = "usedClients")
	public void cleanUpClient(String usedClients) {
		Assert.assertNotNull(usedClients);
		List<String> usedClientsList = Arrays.asList(StringHelper.split(usedClients, ",", true, false));
		output("Used clients: " + usedClientsList);

		final ClientService clientService = (ClientService) Component.getInstance(ClientService.class);
		List<Client> clients = clientService.getAllClients(new String[] { "inum" });

		Assert.assertNotNull(clients);
		output("Found clients: " + clients.size());

		int count = 0;
		for (Client client : clients) {
			String clientId = client.getClientId();
			if (!usedClientsList.contains(clientId)) {
				try {
					clientService.remove(client);
				} catch (EntryPersistenceException ex) {
					output("Failed to remove client: " + ex.getMessage());
				}
				count++;
			}
		}

		output("Removed clients: " + count);
	}
}

@@ -356,86 +356,8 @@
 rt;%0A
-import org.testng.annotations.Parameters;%0Aimport org.testng.annotations.Test;%0A
 impo
@@ -735,15 +735,19 @@
 %09%7D%0A%0A
+//
 %09@Test%0A
+//
 %09@Pa

Disable clean up test clients test