Package com.lbslocal.api.view

Source Code of com.lbslocal.api.view.DraggableApiTest

package com.lbslocal.api.view;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Assert;
import org.junit.Test;

import com.lbslocal.test.helpers.HttpClient;
import com.lbslocal.test.helpers.Response;
import com.lbslocal.test.helpers.TestConstants;

public class DraggableApiTest {

  @Test
  public void shouldRetrieveTheApiVersion() throws Exception {
    Response responseFromApi = HttpClient.doGet(TestConstants.getDraggableApiUrl());
   
    System.out.println(responseFromApi.getBody());
   
    Assert.assertEquals("200", responseFromApi.getStatusCode());

    Response responseFromApiGz = HttpClient.doGet(getApiGzUriFromResponseBody(responseFromApi.getBody()));
   
    System.out.println(responseFromApiGz.getBody());
   
    String[] versionAndRevision = getVersionFromResponseBody(responseFromApiGz.getBody());
   
    Assert.assertEquals("1.0", versionAndRevision[0]);
    Assert.assertEquals("1", versionAndRevision[1]);
  }
 
  private String getApiGzUriFromResponseBody(String body) {
    Matcher matcherUri =
      Pattern
        .compile("script src=\"([^\"]*)\"")
        .matcher(body);
    matcherUri.find();
 
    return matcherUri.group(1);
  }
 
  private String[] getVersionFromResponseBody(String body) {
    String patternForVersion =
      "^var LBS=\\{VERSION_NUMBER\\:\"LBS ([^\\s]*) -- \\$Revision\\: ([^\\s]*)";
   
    Matcher matcherVersion =
      Pattern
        .compile(patternForVersion)
        .matcher(body);
    matcherVersion.find();
   
    String[] versionAndRevision = new String[2];
    versionAndRevision[0] = matcherVersion.group(1);
    versionAndRevision[1] = matcherVersion.group(2);
   
    return versionAndRevision;
  }
}
TOP

Related Classes of com.lbslocal.api.view.DraggableApiTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.