use of org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore in project OpenAM by OpenRock.
the class UmaLabelResourceTest method createInstance.
/**
* Should successfully create an UMA Label.
*/
@Test
public void createInstance() throws ResourceException {
//Given
JsonValue umaLabel = json(object(field(NAME_ATTRIBUTE_NAME, LABEL_NAME), field(TYPE_ATTRIBUTE_NAME, LABEL_TYPE)));
given(createRequest.getContent()).willReturn(umaLabel);
given(contextHelper.getRealm(serverContext)).willReturn(REALM_NAME);
given(contextHelper.getUserId(serverContext)).willReturn(RESOURCE_OWNER_ID);
final ResourceSetLabel resourceSetLabel = new ResourceSetLabel(null, LABEL_NAME, LabelType.valueOf(LABEL_TYPE), Collections.EMPTY_SET);
given(umaLabelsStore.create(REALM_NAME, RESOURCE_OWNER_ID, resourceSetLabel)).willReturn(resourceSetLabel);
//When
Promise<ResourceResponse, ResourceException> promise = umaLabelResource.createInstance(serverContext, createRequest);
//Then
verify(umaLabelsStore, Mockito.times(1)).create(REALM_NAME, RESOURCE_OWNER_ID, resourceSetLabel);
assertThat(promise).succeeded();
}
use of org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore in project OpenAM by OpenRock.
the class ResourceSetResourceTest method setup.
@BeforeMethod
public void setup() {
resourceSetService = mock(ResourceSetService.class);
contextHelper = mock(ContextHelper.class);
umaLabelsStore = mock(UmaLabelsStore.class);
validator = mock(ResourceSetDescriptionValidator.class);
ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
resource = new ResourceSetResource(resourceSetService, contextHelper, umaLabelsStore, validator, extensionFilterManager);
}
use of org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore in project OpenAM by OpenRock.
the class ResourceSetRegistrationEndpointTest method setup.
@BeforeMethod
@SuppressWarnings("unchecked")
public void setup() throws ServerException, InvalidGrantException, NotFoundException {
store = mock(ResourceSetStore.class);
validator = mock(ResourceSetDescriptionValidator.class);
OAuth2RequestFactory<?, Request> requestFactory = mock(OAuth2RequestFactory.class);
Set<ResourceSetRegistrationHook> hooks = new HashSet<>();
hook = mock(ResourceSetRegistrationHook.class);
hooks.add(hook);
labelRegistration = mock(ResourceSetLabelRegistration.class);
ExtensionFilterManager extensionFilterManager = mock(ExtensionFilterManager.class);
resourceRegistrationFilter = mock(ResourceRegistrationFilter.class);
given(extensionFilterManager.getFilters(ResourceRegistrationFilter.class)).willReturn(Collections.singletonList(resourceRegistrationFilter));
OAuth2ProviderSettingsFactory providerSettingsFactory = mock(OAuth2ProviderSettingsFactory.class);
OAuth2ProviderSettings providerSettings = mock(OAuth2ProviderSettings.class);
given(providerSettingsFactory.get(Matchers.<OAuth2Request>anyObject())).willReturn(providerSettings);
given(providerSettings.getResourceSetStore()).willReturn(store);
ExceptionHandler exceptionHandler = mock(ExceptionHandler.class);
UmaLabelsStore umaLabelsStore = mock(UmaLabelsStore.class);
endpoint = spy(new ResourceSetRegistrationEndpoint(providerSettingsFactory, validator, requestFactory, hooks, labelRegistration, extensionFilterManager, exceptionHandler, umaLabelsStore, jacksonRepresentationFactory));
Request request = mock(Request.class);
ChallengeResponse challengeResponse = new ChallengeResponse(ChallengeScheme.HTTP_BASIC);
challengeResponse.setRawValue("PAT");
given(request.getChallengeResponse()).willReturn(challengeResponse);
given(endpoint.getRequest()).willReturn(request);
AccessToken accessToken = mock(AccessToken.class);
given(accessToken.getClientId()).willReturn("CLIENT_ID");
given(accessToken.getResourceOwnerId()).willReturn("RESOURCE_OWNER_ID");
response = mock(Response.class);
given(endpoint.getResponse()).willReturn(response);
OAuth2Request oAuth2Request = mock(OAuth2Request.class);
given(requestFactory.create(Matchers.<Request>anyObject())).willReturn(oAuth2Request);
given(oAuth2Request.getToken(AccessToken.class)).willReturn(accessToken);
}
use of org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore in project OpenAM by OpenRock.
the class UmaLabelResourceTest method deleteLabel.
/**
* Should successfully delete a label.
*/
@Test
public void deleteLabel() throws ResourceException {
//Given
final ResourceSetLabel resourceSetLabel = new ResourceSetLabel(LABEL_ID, LABEL_NAME, LabelType.valueOf(LABEL_TYPE), Collections.EMPTY_SET);
given(contextHelper.getRealm(serverContext)).willReturn(REALM_NAME);
given(contextHelper.getUserId(serverContext)).willReturn(RESOURCE_OWNER_ID);
given(umaLabelsStore.read(REALM_NAME, RESOURCE_OWNER_ID, LABEL_ID)).willReturn(resourceSetLabel);
given(deleteRequest.getRevision()).willReturn(String.valueOf(resourceSetLabel.hashCode()));
//When
Promise<ResourceResponse, ResourceException> promise = umaLabelResource.deleteInstance(serverContext, LABEL_ID, deleteRequest);
//Then
verify(umaLabelsStore, Mockito.times(1)).delete(REALM_NAME, RESOURCE_OWNER_ID, LABEL_ID);
assertThat(promise).succeeded();
}
Aggregations