@@ -0,0 +1,2928 @@
+package com.continuuity.passport.passportClient;%0A%0Aimport com.continuuity.common.utils.PortDetector;%0Aimport com.continuuity.passport.http.client.AccountProvider;%0Aimport com.continuuity.passport.http.client.PassportClient;%0Aimport com.continuuity.passport.server.MockServer;%0Aimport com.google.gson.FieldNamingPolicy;%0Aimport com.google.gson.Gson;%0Aimport com.google.gson.GsonBuilder;%0Aimport org.apache.http.HttpResponse;%0Aimport org.apache.http.client.HttpClient;%0Aimport org.apache.http.client.methods.HttpPost;%0Aimport org.apache.http.entity.StringEntity;%0Aimport org.apache.http.impl.client.DefaultHttpClient;%0Aimport org.junit.AfterClass;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0Aimport java.io.IOException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Aimport static org.junit.Assert.assertTrue;%0A%0A/**%0A *%0A */%0Apublic class TestPassportClient %7B%0A%0A  private static MockServer server ;%0A  private static int port;%0A%0A  @BeforeClass%0A  public static void startServer() throws Exception %7B%0A    port = PortDetector.findFreePort();%0A    server = new MockServer(port);%0A    System.out.println(%22Starting server%22);%0A    server.start();%0A    Thread.sleep(1000);%0A    assertTrue(server.isStarted());%0A    Map%3CString,String%3E accountHash=  new HashMap%3CString, String%3E();%0A    accountHash.put(%22email_id%22, %22john@smith.com%22);%0A    accountHash.put(%22first_name%22, %22john%22);%0A    accountHash.put(%22last_name%22, %22smith%22);%0A    accountHash.put(%22company%22, %22continuuity%22);%0A%0A    addAccount(accountHash);%0A    System.out.println(%22Added account%22);%0A %7D%0A  @Test%0A  public void testValidAccount()%7B%0A    PassportClient client = new PassportClient();%0A    System.out.println(%22Trying to get account%22);%0A    AccountProvider accountProvider = client.getAccount(%22http%22,%22localhost%22,port,%22apiKey1%22);%0A    System.out.println(%22Got an account%22);%0A%0A    assert (accountProvider !=null);%0A    System.out.println(accountProvider.getAccountId());%0A    assert (%221%22.equals(accountProvider.getAccountId()));%0A    System.out.println(%22Tested%22);%0A  %7D%0A%0A  @Test(expected = RuntimeException.class)%0A  public void testInvalidAccount() %7B%0A    PassportClient client = new PassportClient();%0A    AccountProvider accountProvider = client.getAccount(%22http%22,%22localhost%22,port,%22apiKey100%22);%0A%0A  %7D%0A%0A  @AfterClass%0A  public static void stopServer() throws Exception %7B%0A     server.stop();%0A     Thread.sleep(1000);%0A  %7D%0A%0A%0A  private static void addAccount(Map%3CString,String%3E account) throws IOException %7B%0A    Gson gson =new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();%0A%0A    HttpPost post = new HttpPost(String.format(%22http://localhost:%25d/passport/v1/account%22,port));%0A    StringEntity entity =  new StringEntity(gson.toJson(account));%0A    entity.setContentType(%22application/json%22);%0A    post.setEntity(entity);%0A%0A    HttpClient client = new DefaultHttpClient();%0A    HttpResponse response = client.execute(post);%0A%0A    assert(response.getStatusLine().getStatusCode() == 200);%0A  %7D%0A%0A%0A%7D%0A

Add Test cases for passport client