/*
 * Copyright (C) 2013 tarent AG
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.osiam.client;

import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.osiam.client.oauth.Scope;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;

import com.github.springtestdbunit.DbUnitTestExecutionListener;
import com.github.springtestdbunit.annotation.DatabaseOperation;
import com.github.springtestdbunit.annotation.DatabaseSetup;
import com.github.springtestdbunit.annotation.DatabaseTearDown;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/context.xml")
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
        DbUnitTestExecutionListener.class })
@DatabaseSetup("/database_seed_groups.xml")
@DatabaseTearDown(value = "/database_tear_down.xml", type = DatabaseOperation.DELETE_ALL)
public class OsiamConnectorIT extends AbstractIntegrationTestBase {

    @Test
    public void when_combined_endpoint_is_set_both_endpoints_are_valid() {
        final OsiamConnector osiamConnector = new OsiamConnector.Builder()
                .setEndpoint(OSIAM_HOST)
                .setClientId("example-client")
                .setClientSecret("secret")
                .build();
        accessToken = osiamConnector.retrieveAccessToken("marissa", "koala", Scope.ADMIN);
        assertNotNull(osiamConnector.getUser(VALID_USER_ID, accessToken));
        assertNotNull(osiamConnector.getGroup(VALID_GROUP_ID, accessToken));
    }
}

@@ -2787,11 +2787,1064 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void retrieve_access_token_when_only_the_auth_server_endpoint_is_set() %7B%0A        final OsiamConnector osiamConnector = new OsiamConnector.Builder()%0A                .setAuthServerEndpoint(AUTH_ENDPOINT_ADDRESS)%0A                .setClientId(%22example-client%22)%0A                .setClientSecret(%22secret%22)%0A                .build();%0A        assertNotNull(osiamConnector.retrieveAccessToken(%22marissa%22, %22koala%22, Scope.ADMIN));%0A    %7D%0A%0A    @Test%0A    public void get_user_and_group_when_only_the_resource_server_endpoint_is_set() %7B%0A        final OsiamConnector osiamConnector = new OsiamConnector.Builder()%0A                .setResourceServerEndpoint(RESOURCE_ENDPOINT_ADDRESS)%0A                .setClientId(%22example-client%22)%0A                .setClientSecret(%22secret%22)%0A                .build();%0A        accessToken = OSIAM_CONNECTOR.retrieveAccessToken(%22marissa%22, %22koala%22, Scope.ADMIN);%0A        assertNotNull(osiamConnector.getUser(VALID_USER_ID, accessToken));%0A        assertNotNull(osiamConnector.getGroup(VALID_GROUP_ID, accessToken));%0A    %7D
 %0A%7D%0A

Test the connector with only one endpoint set