Search in sources :

Example 1 with UmaLabelsStore

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();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel) Test(org.testng.annotations.Test)

Example 2 with UmaLabelsStore

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);
}
Also used : ContextHelper(org.forgerock.openam.rest.resource.ContextHelper) UmaLabelsStore(org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore) ExtensionFilterManager(org.forgerock.openam.oauth2.extensions.ExtensionFilterManager) ResourceSetDescriptionValidator(org.forgerock.oauth2.restlet.resources.ResourceSetDescriptionValidator) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with UmaLabelsStore

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);
}
Also used : ResourceSetRegistrationHook(org.forgerock.oauth2.restlet.resources.ResourceSetRegistrationHook) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Request(org.restlet.Request) ResourceRegistrationFilter(org.forgerock.openam.oauth2.extensions.ResourceRegistrationFilter) ResourceSetDescriptionValidator(org.forgerock.oauth2.restlet.resources.ResourceSetDescriptionValidator) ChallengeResponse(org.restlet.data.ChallengeResponse) ExceptionHandler(org.forgerock.oauth2.restlet.ExceptionHandler) ChallengeResponse(org.restlet.data.ChallengeResponse) Response(org.restlet.Response) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2ProviderSettingsFactory(org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory) ResourceSetStore(org.forgerock.oauth2.resources.ResourceSetStore) AccessToken(org.forgerock.oauth2.core.AccessToken) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) UmaLabelsStore(org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore) ExtensionFilterManager(org.forgerock.openam.oauth2.extensions.ExtensionFilterManager) HashSet(java.util.HashSet) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with UmaLabelsStore

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();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel) Test(org.testng.annotations.Test)

Aggregations

ResourceException (org.forgerock.json.resource.ResourceException)2 ResourceResponse (org.forgerock.json.resource.ResourceResponse)2 ResourceSetDescriptionValidator (org.forgerock.oauth2.restlet.resources.ResourceSetDescriptionValidator)2 ExtensionFilterManager (org.forgerock.openam.oauth2.extensions.ExtensionFilterManager)2 ResourceSetLabel (org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)2 UmaLabelsStore (org.forgerock.openam.oauth2.resources.labels.UmaLabelsStore)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 Test (org.testng.annotations.Test)2 HashSet (java.util.HashSet)1 JsonValue (org.forgerock.json.JsonValue)1 AccessToken (org.forgerock.oauth2.core.AccessToken)1 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)1 OAuth2ProviderSettingsFactory (org.forgerock.oauth2.core.OAuth2ProviderSettingsFactory)1 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)1 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)1 ExceptionHandler (org.forgerock.oauth2.restlet.ExceptionHandler)1 ResourceSetRegistrationHook (org.forgerock.oauth2.restlet.resources.ResourceSetRegistrationHook)1 ResourceRegistrationFilter (org.forgerock.openam.oauth2.extensions.ResourceRegistrationFilter)1 ContextHelper (org.forgerock.openam.rest.resource.ContextHelper)1 Request (org.restlet.Request)1