
/*
 *  Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
*/
/**
 *  @author  
 *  @since   release specific (what release of product did this appear in)
 */

package sample_apps.shared_idm.greeting;

import junit.framework.TestCase;

import com.oracle.cloud.java.service.test.HttpHelper;

public class SharedIdmGreetingTest extends TestCase {
    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    protected void setUp() {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    protected void tearDown() {
        // release objects under test here, if necessary
    }

    /**
     * Tests if the identity from shared idm can access the application.
     */
    public void testSharedIdm() {

        System.out.println("Starting test");

        String sURL = System.getProperty("app_url");
        String userName = System.getProperty("username");
        String password = System.getProperty("password");

        HttpHelper http = new HttpHelper();
        http.setAuthType(HttpHelper.AUTH_TYPE.BASIC);
        http.setUserName(userName);
        http.setPassword(password);
        String response;


        try {
            response = http.get(sURL);
            int respCode = http.getResponseCode();
            System.out.println("Response code: " + respCode);
            System.out.println("Response     :\n" +
                    http.getResponse());
            assertTrue( "Expected http response code 200. Got " + respCode, respCode == 200 );
        } catch (Exception e) {
            System.out.println("Response code: " + http.getResponseCode());
            fail("Response code: " + http.getResponseCode());
            e.printStackTrace();
        }
    }
}

