Skip to content

Commit

Permalink
#360 - Create stress/load test which should cover all APIs with mocke…
Browse files Browse the repository at this point in the history
…d OP
  • Loading branch information
duttarnab committed Sep 8, 2019
1 parent 1d8943f commit 271e36e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 13 deletions.
@@ -1,6 +1,7 @@
package org.gluu.oxd.server.op;

import org.gluu.oxauth.client.*;
import org.gluu.oxauth.client.uma.UmaClientFactory;
import org.gluu.oxauth.model.jwt.Jwt;
import org.gluu.oxd.rs.protect.resteasy.PatProvider;
import org.gluu.oxd.rs.protect.resteasy.ResourceRegistrar;
Expand All @@ -20,7 +21,7 @@ public interface OpClientFactory {

public RegisterClient createRegisterClient(String url);

public OpenIdConfigurationClient createOpenIdConfigurationClient(String url);
public OpenIdConfigurationClient createOpenIdConfigurationClient(String url) throws Exception;

public AuthorizeClient createAuthorizeClient(String url);

Expand All @@ -32,5 +33,7 @@ public interface OpClientFactory {

public ClientFactory createClientFactory();

public UmaClientFactory createUmaClientFactory();

public ClientRequest createClientRequest(String uriTemplate, ClientExecutor executor) throws Exception;
}
@@ -1,6 +1,7 @@
package org.gluu.oxd.server.op;

import org.gluu.oxauth.client.*;
import org.gluu.oxauth.client.uma.UmaClientFactory;
import org.gluu.oxauth.model.jwt.Jwt;
import org.gluu.oxd.rs.protect.resteasy.PatProvider;
import org.gluu.oxd.rs.protect.resteasy.ResourceRegistrar;
Expand Down Expand Up @@ -32,7 +33,7 @@ public RegisterClient createRegisterClient(String url) {
return new RegisterClient(url);
}

public OpenIdConfigurationClient createOpenIdConfigurationClient(String url) {
public OpenIdConfigurationClient createOpenIdConfigurationClient(String url) throws Exception{
return new OpenIdConfigurationClient(url);
}

Expand All @@ -48,6 +49,10 @@ public ClientFactory createClientFactory() {
return ClientFactory.instance();
}

public UmaClientFactory createUmaClientFactory() {
return UmaClientFactory.instance();
}

public Validator createValidator(Jwt idToken, OpenIdConfigurationResponse discoveryResponse, PublicOpKeyService keyService) {
return new Validator(idToken, discoveryResponse, keyService);
}
Expand Down
Expand Up @@ -5,6 +5,7 @@

import com.google.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.gluu.oxd.server.op.OpClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.gluu.oxauth.client.OpenIdConfigurationClient;
Expand Down Expand Up @@ -42,12 +43,14 @@ public class DiscoveryService {
private final HttpService httpService;
private final RpService rpService;
private final ValidationService validationService;
private final OpClientFactory opClientFactory;

@Inject
public DiscoveryService(HttpService httpService, RpService rpService, ValidationService validationService) {
public DiscoveryService(HttpService httpService, RpService rpService, ValidationService validationService, OpClientFactory opClientFactory) {
this.httpService = httpService;
this.rpService = rpService;
this.validationService = validationService;
this.opClientFactory = opClientFactory;
}

public OpenIdConfigurationResponse getConnectDiscoveryResponseByOxdId(String oxdId) {
Expand All @@ -69,7 +72,7 @@ public OpenIdConfigurationResponse getConnectDiscoveryResponse(String opHost, St
if (r != null) {
return r;
}
final OpenIdConfigurationClient client = new OpenIdConfigurationClient(getConnectDiscoveryUrl(opHost, opDiscoveryPath));
final OpenIdConfigurationClient client = opClientFactory.createOpenIdConfigurationClient(getConnectDiscoveryUrl(opHost, opDiscoveryPath));
client.setExecutor(httpService.getClientExecutor());
final OpenIdConfigurationResponse response = client.execOpenIdConfiguration();
LOG.trace("Discovery response: {} ", response.getEntity());
Expand Down Expand Up @@ -107,7 +110,7 @@ public UmaMetadata getUmaDiscovery(String opHost, String opDiscoveryPath) {
if (r != null) {
return r;
}
final UmaMetadata response = UmaClientFactory.instance().createMetadataService(
final UmaMetadata response = opClientFactory.createUmaClientFactory().createMetadataService(
getUmaDiscoveryUrl(opHost, opDiscoveryPath), httpService.getClientExecutor()).getMetadata();
LOG.trace("Uma discovery response: {} ", response);
umaMap.put(opHost, response);
Expand Down
Expand Up @@ -14,12 +14,12 @@ public class EnableMocksListener implements IAnnotationTransformer {
public void transform(ITestAnnotation annotation, Class testClass,
Constructor testConstructor, Method testMethod){

System.out.println("===============>"+testMethod.getName());
System.out.println("***************>"+isTestDisabled(testMethod.getName()));
if (isTestDisabled(testMethod.getName())) {
annotation.setEnabled(false);
} else {
annotation.setEnabled(true);
if (testMethod != null) {
if (isTestDisabled(testMethod.getName())) {
annotation.setEnabled(false);
} else {
annotation.setEnabled(true);
}
}
}

Expand Down
Expand Up @@ -5,9 +5,12 @@
import org.glassfish.jersey.message.internal.OutboundJaxrsResponse;
import org.glassfish.jersey.message.internal.OutboundMessageContext;
import org.gluu.oxauth.client.*;
import org.gluu.oxauth.client.uma.UmaClientFactory;
import org.gluu.oxauth.client.uma.UmaMetadataService;
import org.gluu.oxauth.model.common.TokenType;
import org.gluu.oxauth.model.jwt.Jwt;
import org.gluu.oxauth.model.uma.PermissionTicket;
import org.gluu.oxauth.model.uma.UmaMetadata;
import org.gluu.oxd.common.Jackson2;
import org.gluu.oxd.common.introspection.CorrectRptIntrospectionResponse;
import org.gluu.oxd.rs.protect.Condition;
Expand Down Expand Up @@ -104,8 +107,16 @@ public RegisterClient createRegisterClient(String url) {
}

@Override
public OpenIdConfigurationClient createOpenIdConfigurationClient(String url) {
return null;
public OpenIdConfigurationClient createOpenIdConfigurationClient(String url) throws Exception {

OpenIdConfigurationClient client = mock(OpenIdConfigurationClient.class);

OpenIdConfigurationResponse response = new OpenIdConfigurationResponse(200);
response.setEntity("DUMMY_ENTITY");
response.setRegistrationEndpoint("DUMMY_REGISTRATION_ENDPOINT");
response.setEndSessionEndpoint("DUMMY_ENDSESSION_ENDPOINT");
when(client.execOpenIdConfiguration()).thenReturn(response);
return client;
}

@Override
Expand Down Expand Up @@ -170,6 +181,18 @@ public ClientFactory createClientFactory() {
return clientFactory;
}

public UmaClientFactory createUmaClientFactory() {
UmaClientFactory umaClientFactory = mock(UmaClientFactory.class);
UmaMetadataService umaMetadataService = mock(UmaMetadataService.class);

UmaMetadata umaMetadata = new UmaMetadata();

when(umaClientFactory.createMetadataService(any(), any())).thenReturn(umaMetadataService);
when(umaMetadataService.getMetadata()).thenReturn(umaMetadata);

return umaClientFactory;
}

public ClientRequest createClientRequest(String uriTemplate, ClientExecutor executor) throws Exception {
ClientRequest client = mock(ClientRequest.class);

Expand Down

0 comments on commit 271e36e

Please sign in to comment.