Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Automate OpenidConnect Clients API test #992
- Loading branch information
Showing
4 changed files
with
247 additions
and
129 deletions.
There are no files selected for viewing
127 changes: 0 additions & 127 deletions
127
client/src/main/java/org/gluu/oxtrust/api/test/OxAuthClientRepositoryImpl.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
client/src/test/java/org/gluu/oxtrust/api/openidconnect/OpenIdConnectClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package org.gluu.oxtrust.api.openidconnect; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import org.gluu.oxtrust.api.GluuOxAuthClient; | ||
import org.gluu.oxtrust.model.OxAuthApplicationType; | ||
import org.gluu.oxtrust.model.OxAuthScope; | ||
import org.junit.Assert; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.xdi.oxauth.model.common.GrantType; | ||
import org.xdi.oxauth.model.common.ResponseType; | ||
|
||
public class OpenIdConnectClientTest { | ||
|
||
private String inum; | ||
private static String searchPattern = "scim"; | ||
private OxAuthClientRepository clientRepository; | ||
private GluuOxAuthClient client; | ||
private static boolean canRunOtherTest = false; | ||
|
||
@BeforeClass | ||
public static void testConnection() { | ||
try { | ||
OxAuthClientRepository clientRepository = new OxAuthClientRepository(); | ||
clientRepository.searchClients(searchPattern, 1); | ||
canRunOtherTest = true; | ||
} catch (Exception e) { | ||
System.out.println("***********************"); | ||
System.out.println("ERROR OCCURS: POSSIBLE CAUSES"); | ||
System.out.println("1. MAKE SURE THE HOSTNAME DEFINE IN CONFIGURATION FILE IS RESOLVABLE"); | ||
System.out.println("2. MAKE SURE THE CERTS FILE ARE IMPORTED IN JAVA KEY STORE"); | ||
System.out.println("***********************"); | ||
} | ||
} | ||
|
||
@Before | ||
public void setup() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
clientRepository = new OxAuthClientRepository(); | ||
} | ||
|
||
@Test | ||
public void getAllClientsTest() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("List clients"); | ||
System.out.println("=================="); | ||
|
||
List<GluuOxAuthClient> clients = clientRepository.getAllClients(); | ||
|
||
Assert.assertNotNull(clients); | ||
Assert.assertTrue(!clients.isEmpty()); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
@Test | ||
public void searchClients() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("Search clients"); | ||
System.out.println("=================="); | ||
|
||
List<GluuOxAuthClient> clientsFound = clientRepository.searchClients(searchPattern, 2); | ||
|
||
Assert.assertNotNull(clientsFound); | ||
Assert.assertTrue(!clientsFound.isEmpty()); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
@Test | ||
public void getClientScopesTest() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("Get clients scopes"); | ||
System.out.println("=================="); | ||
client = clientRepository.searchClients(searchPattern, 1).get(0); | ||
inum = client.getInum(); | ||
|
||
List<OxAuthScope> scopes = clientRepository.getClientScopes(inum); | ||
|
||
Assert.assertNotNull(scopes); | ||
Assert.assertTrue(!scopes.isEmpty()); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
@Test | ||
public void getClientByInum() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("Get client by inum"); | ||
System.out.println("=================="); | ||
client = clientRepository.addClient(generatedNewClient()); | ||
inum = client.getInum(); | ||
|
||
client = clientRepository.getClientByInum(inum); | ||
|
||
Assert.assertNotNull(client); | ||
Assert.assertEquals(inum, client.getInum()); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
@Test | ||
public void addClientTest() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("Add new client"); | ||
System.out.println("=================="); | ||
|
||
client = clientRepository.addClient(generatedNewClient()); | ||
|
||
Assert.assertNotNull(client); | ||
Assert.assertNotNull(client.getInum()); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
@Test | ||
public void updateClientTest() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("Update client"); | ||
System.out.println("=================="); | ||
client = clientRepository.addClient(generatedNewClient()); | ||
inum = client.getInum(); | ||
String displayName = "UpdatedClient"; | ||
client.setDisplayName(displayName); | ||
|
||
client = clientRepository.updateClient(client); | ||
|
||
Assert.assertNotNull(client); | ||
Assert.assertNotNull(client.getInum()); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
@Test | ||
public void deleteClientTest() { | ||
Assume.assumeTrue(canRunOtherTest); | ||
System.out.println("=================="); | ||
System.out.println("Delete client"); | ||
System.out.println("=================="); | ||
client = clientRepository.addClient(generatedNewClient()); | ||
inum = client.getInum(); | ||
|
||
clientRepository.deleteClient(inum); | ||
|
||
Assert.assertNull(clientRepository.getClientByInum(inum)); | ||
System.out.println("*******************"); | ||
System.out.println("Done"); | ||
} | ||
|
||
private GluuOxAuthClient generatedNewClient() { | ||
int next1 = new Random().nextInt(100); | ||
int next2 = new Random().nextInt(50); | ||
String clientName = "NewAddedClient" + next1 + next2; | ||
GluuOxAuthClient gluuOxAuthClient = new GluuOxAuthClient(); | ||
gluuOxAuthClient.setDescription(""); | ||
gluuOxAuthClient.setDisplayName(clientName); | ||
gluuOxAuthClient.setOxAuthAppType(OxAuthApplicationType.WEB); | ||
GrantType[] grantTypes = { GrantType.AUTHORIZATION_CODE }; | ||
gluuOxAuthClient.setGrantTypes(grantTypes); | ||
ResponseType[] responseTypes = { ResponseType.CODE, ResponseType.ID_TOKEN }; | ||
gluuOxAuthClient.setResponseTypes(responseTypes); | ||
gluuOxAuthClient.setOxAuthRedirectURIs(Arrays.asList("https://gasmyr.livevision.com" + next1)); | ||
return gluuOxAuthClient; | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
client/src/test/java/org/gluu/oxtrust/api/openidconnect/OxAuthClientRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.gluu.oxtrust.api.openidconnect; | ||
|
||
import java.util.List; | ||
|
||
import org.gluu.oxtrust.api.BaseRepository; | ||
import org.gluu.oxtrust.api.GluuOxAuthClient; | ||
import org.gluu.oxtrust.api.proxy.OxAuthClientProxy; | ||
import org.gluu.oxtrust.model.OxAuthScope; | ||
import org.jboss.resteasy.client.jaxrs.ResteasyClient; | ||
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; | ||
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget; | ||
|
||
public class OxAuthClientRepository extends BaseRepository { | ||
|
||
private String PATH = "restv1/api/clients"; | ||
private ResteasyClient client; | ||
|
||
public OxAuthClientRepository() { | ||
super(); | ||
PATH = baseURI + PATH; | ||
client = new ResteasyClientBuilder().build(); | ||
} | ||
|
||
public List<GluuOxAuthClient> getAllClients() { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
return client.getClients(); | ||
} | ||
|
||
public List<GluuOxAuthClient> searchClients(String searchPattern, int size) { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
return client.searchClients(searchPattern, size); | ||
} | ||
|
||
public List<OxAuthScope> getClientScopes(String inum) { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
return client.getClientScopes(inum); | ||
} | ||
|
||
public void deleteClient(String inum) { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
client.deleteClient(inum); | ||
} | ||
|
||
public GluuOxAuthClient addClient(GluuOxAuthClient gluuOxAuthClient) { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
return client.createClient(gluuOxAuthClient); | ||
} | ||
|
||
public GluuOxAuthClient updateClient(GluuOxAuthClient gluuOxAuthClient) { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
return client.updateClient(gluuOxAuthClient); | ||
} | ||
|
||
public GluuOxAuthClient getClientByInum(String inum) { | ||
ResteasyWebTarget target = client.target(PATH); | ||
OxAuthClientProxy client = target.proxy(OxAuthClientProxy.class); | ||
try { | ||
return client.getClient(inum); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
|
||
} | ||
} |