use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class ClientTest method should_not_able_to_create_client_which_is_resource_itself_with_wrong_not_existing_resource_ids.
@Test
public void should_not_able_to_create_client_which_is_resource_itself_with_wrong_not_existing_resource_ids() {
Client client = ClientUtility.getClientAsNonResource(UUID.randomUUID().toString());
ResponseEntity<String> exchange = ClientUtility.createClient(client);
Assert.assertEquals(HttpStatus.BAD_REQUEST, exchange.getStatusCode());
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class ClientUtility method getInvalidClientAsResource.
public static Client getInvalidClientAsResource(String... resourceIds) {
Client client = getClientRaw(resourceIds);
Set<ClientType> strings = new HashSet<>();
strings.add(ClientType.FRONTEND_APP);
strings.add(ClientType.FIRST_PARTY);
client.setTypes(strings);
client.setResourceIndicator(true);
return client;
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class ClientUtility method getClientRaw.
/**
* create password grant client with given resource ids.
*
* @param resourceIds resource client ids
* @return client
*/
public static Client getClientRaw(String... resourceIds) {
Client client = new Client();
client.setName(UUID.randomUUID().toString().replace("-", ""));
client.setClientSecret(UUID.randomUUID().toString().replace("-", ""));
client.setGrantTypeEnums(new HashSet<>(Collections.singletonList(GrantTypeEnum.PASSWORD)));
client.setAccessTokenValiditySeconds(1800);
client.setRefreshTokenValiditySeconds(null);
client.setHasSecret(true);
client.setResourceIds(new HashSet<>(Arrays.asList(resourceIds)));
return client;
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class ClientIdempotentTest method create_client_w_same_changeId_two_times.
@Test
public void create_client_w_same_changeId_two_times() {
Client oldClient = ClientUtility.getClientAsResource(AppConstant.CLIENT_ID_RESOURCE_ID);
String s = UUID.randomUUID().toString();
ResponseEntity<String> client1 = ClientUtility.createClient(oldClient, s);
Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
ResponseEntity<String> client2 = ClientUtility.createClient(oldClient, s);
Assert.assertEquals(HttpStatus.OK, client2.getStatusCode());
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class ClientIdempotentTest method create_client_w_same_changeId_two_times_concurrent.
@Test
public void create_client_w_same_changeId_two_times_concurrent() {
Client oldClient = ClientUtility.getClientAsResource(AppConstant.CLIENT_ID_RESOURCE_ID);
String s = UUID.randomUUID().toString();
AtomicReference<Integer> success = new AtomicReference<>(0);
AtomicReference<Integer> failed = new AtomicReference<>(0);
Runnable runnable2 = () -> {
TestContext.init();
ResponseEntity<String> client1 = ClientUtility.createClient(oldClient, s);
if (client1.getStatusCode().is2xxSuccessful()) {
success.set(success.get() + 1);
}
if (client1.getStatusCode().is4xxClientError()) {
failed.set(failed.get() + 1);
}
};
ArrayList<Runnable> runnables = new ArrayList<>();
runnables.add(runnable2);
runnables.add(runnable2);
try {
assertConcurrent("", runnables, 30000);
Assert.assertEquals(1, (int) success.get());
Assert.assertEquals(1, (int) failed.get());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations