/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxauth.model.uma;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.gluu.oxauth.model.common.GrantType;
import org.gluu.oxauth.model.common.Id;
import org.gluu.oxauth.model.uma.PermissionTicket;
import org.gluu.oxauth.model.uma.RPTResponse;
import org.gluu.oxauth.model.uma.RptIntrospectionResponse;
import org.gluu.oxauth.model.uma.UmaMetadata;
import org.gluu.oxauth.model.uma.UmaNeedInfoResponse;
import org.gluu.oxauth.model.uma.UmaResource;
import org.gluu.oxauth.model.uma.UmaResourceResponse;
import org.gluu.oxauth.model.uma.UmaScopeDescription;
import org.gluu.oxauth.model.uma.UmaTokenResponse;
import org.gluu.oxauth.model.uma.wrapper.Token;
import org.jboss.resteasy.client.ClientResponse;

import javax.ws.rs.core.Response;
import java.util.Arrays;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

/**
 * @author Yuriy Zabrovarnyy
 */
public class UmaTestUtil {

    private UmaTestUtil() {
    }

    public static void assert_(UmaScopeDescription p_scopeDescription) {
        assertNotNull(p_scopeDescription, "Scope description is null");
        assertTrue(StringUtils.isNotBlank(p_scopeDescription.getName()), "Scope name is empty");
    }

    public static void assert_(RptIntrospectionResponse p_rptStatus) {
        assertNotNull(p_rptStatus, "Token response status is null");
        assertTrue(p_rptStatus.getActive(), "Token is not active");
        assertTrue(p_rptStatus.getPermissions() != null && !p_rptStatus.getPermissions().isEmpty(), "Permissions are empty.");
        assertNotNull(p_rptStatus.getExpiresAt(), "Expiration date is null");
    }

    public static void assert_(UmaMetadata metadata) {
        assertNotNull(metadata, "Metadata is null");
        assertTrue(ArrayUtils.contains(metadata.getGrantTypesSupported(), GrantType.OXAUTH_UMA_TICKET.getValue()));
        assertNotNull(metadata.getIssuer(), "Issuer isn't correct");
        assertNotNull(metadata.getTokenEndpoint(), "Token endpoint isn't correct");
        assertNotNull(metadata.getIntrospectionEndpoint(), "Introspection endpoint isn't correct");
        assertNotNull(metadata.getResourceRegistrationEndpoint(), "Resource registration endpoint isn't correct");
        assertNotNull(metadata.getPermissionEndpoint(), "Permission registration endpoint isn't correct");
        assertNotNull(metadata.getAuthorizationEndpoint(), "Authorization request endpoint isn't correct");
    }

    public static void assert_(Token token) {
        assertNotNull(token, "The token object is null");
        assertNotNull(token.getAccessToken(), "The access token is null");
        //assertNotNull(p_token.getRefreshToken(), "The refresh token is null");
    }

    public static void assert_(UmaResourceResponse resourceResponse) {
        assertNotNull(resourceResponse, "Resource status is null");
        assertNotNull(resourceResponse.getId(), "Resource description id is null");
    }

    public static UmaResource createResource() {
        final UmaResource resource = new UmaResource();
        resource.setName("Server Photo Album");
        resource.setIconUri("http://www.example.com/icons/flower.png");
        resource.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
        resource.setType("myType");
        return resource;
    }

    public static void assert_(PermissionTicket ticket) {
        assertNotNull(ticket, "Ticket is null");
        assertTrue(StringUtils.isNotBlank(ticket.getTicket()), "Ticket is empty");
    }

    public static void assert_(RPTResponse response) {
        assertNotNull(response, "RPT response is null");
        assertNotNull(response.getRpt(), "RPT is null");
    }

    public static void assert_(ClientResponse p_response) {
        assertNotNull(p_response, "Response is null");
        assertTrue(p_response.getStatus() == Response.Status.OK.getStatusCode(), "Response http code is not OK.");
    }

    public static void assert_(Id p_id) {
        assertNotNull(p_id, "ID is null");
        assertTrue(StringUtils.isNotBlank(p_id.getId()), "ID is blank");
    }

    public static void assert_(UmaTokenResponse response) {
        assertNotNull(response, "UMA Token response is null");
        assertNotNull(response.getAccessToken(), "RPT is null");
        assertNotNull(response.getPct(), "PCT is null");
    }

    public static void assert_(UmaNeedInfoResponse response) {
        assertNotNull(response, "UMA Need Info response is null");
        assertTrue(StringUtils.isNotBlank(response.getError()), "need_info error is blank");
        assertTrue(StringUtils.isNotBlank(response.getTicket()), "need_info ticket is blank");
        assertTrue(response.getRequiredClaims() != null && !response.getRequiredClaims().isEmpty(), "need_info required claims are empty");
        assertTrue(StringUtils.isNotBlank(response.getRedirectUser()), "need_info redirect user uri is blank");
    }

}

@@ -186,321 +186,143 @@
 ort 
-org.apache.commons.lang.ArrayUtils;%0Aimport org.apache.commons.lang.StringUtils;%0Aimport org.gluu.oxauth.model.common.GrantType;%0Aimport org.gluu.oxauth.model.common.Id;%0Aimport org.gluu.oxauth.model.uma.PermissionTicket;%0Aimport org.gluu.oxauth.model.uma.RPTResponse;%0Aimport org.gluu.oxauth.model.uma.RptIntrospection
+static org.testng.Assert.assertNotNull;%0Aimport static org.testng.Assert.assertTrue;%0A%0Aimport java.util.Arrays;%0A%0Aimport javax.ws.rs.core.
 Resp
@@ -319,32 +319,33 @@
 .core.Response;%0A
+%0A
 import org.gluu.
@@ -343,249 +343,129 @@
 org.
-gluu.oxauth.model.uma.UmaMetadata;%0Aimport org.gluu.oxauth.model.uma.UmaNeedInfoResponse;%0Aimport org.gluu.oxauth.model.uma.UmaResource;%0Aimport org.gluu.oxauth.model.uma.UmaResourceResponse;%0Aimport org.gluu.oxauth.model.uma.UmaScopeDescription
+apache.commons.lang.ArrayUtils;%0Aimport org.apache.commons.lang.StringUtils;%0Aimport org.gluu.oxauth.model.common.GrantType
 ;%0Aim
@@ -495,28 +495,17 @@
 del.
-uma.UmaTokenResponse
+common.Id
 ;%0Aim
@@ -553,209 +553,8 @@
 ken;
-%0Aimport org.jboss.resteasy.client.ClientResponse;%0A%0Aimport javax.ws.rs.core.Response;%0Aimport java.util.Arrays;%0A%0Aimport static org.testng.Assert.assertNotNull;%0Aimport static org.testng.Assert.assertTrue;
 %0A%0A/*
@@ -3464,14 +3464,8 @@
 rt_(
-Client
 Resp

update to RestEasy 4