package org.osiam.client;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.osiam.client.OsiamUserService;
import org.osiam.client.ServiceBuilder;
import org.osiam.resources.scim.User;

import com.sun.jersey.api.client.UniformInterfaceException;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.UUID;

import static org.junit.Assert.assertEquals;

public class UserServiceIT {

    private String accessToken = "2b534de7-d248-4f86-a508-e4decd0a3795";
    private String validUserUUID = "4a51b8fa-e4c5-4164-8864-b52a1bb5ca17";
    private String endpointAddress = "http://localhost:8080/osiam-server";
    private URI serviceEndpoint;
    private String redirectAddress = "http://localhost:5000/oauth2";
    private URI redirectURL;
    private String clientId = "example-client";
    private String clientSecret = "secret";
    private OsiamUserService service;

    @Before
    public void setUp() throws URISyntaxException {

        serviceEndpoint = new URI(endpointAddress);
        redirectURL = new URI(redirectAddress);

        service = ServiceBuilder.buildUserService(serviceEndpoint, clientId, redirectURL, clientSecret);
    }

    /* Attention this test does not work automated for now! Please provide a valid access token before using it */

    @Test
    public void getValidUser() {
        User user = service.getUserByUUID(UUID.fromString(validUserUUID), accessToken);

        assertEquals(validUserUUID, user.getId());
        assertEquals("tobias", user.getExternalId());
        assertEquals(null, user.getNickName());
    }
    
    @Test(expected = UniformInterfaceException.class)
    public void getInvalidUser() {
    	service.getUserByUUID(UUID.fromString("b01e0710-e9b9-4181-995f-4f1f59dc2999"), accessToken);       
    }
}

@@ -470,44 +470,44 @@
  = %22
-2b534de7-d248-4f86-a508-e4decd0a3795
+5dffcca8-59be-46d2-90c7-fbc6fb8451ac
 %22;%0A 
@@ -1807,10 +1807,225 @@
  %0A    %7D%0A
+    %0A    @Test(expected = UniformInterfaceException.class)%0A    public void provideWrongAccessToken() %7B%0A    %09service.getUserByUUID(UUID.fromString(%22b01e0710-e9b9-4181-995f-4f1f59dc2999%22), %22wrongToken%22);       %0A    %7D%0A
 %7D%0A

Test wrong access token added