com.google.gson.internal.StringMap Java Examples

The following examples show how to use com.google.gson.internal.StringMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonMember() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "Location/Country");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class);
  checkMember(jsonMap, null);

  StringMap<Object> source = (StringMap<Object>) jsonMap.get(SOURCE);
  checkProperty(source, null, "Location");

  StringMap<Object> path = (StringMap<Object>) jsonMap.get(PATH);
  checkProperty(path, null, "Country");
}
 
Example #2
Source File: EntryJsonCreateTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createEntryEmployee() throws Exception {
  String content = "{iVBORw0KGgoAAAANSUhEUgAAAB4AAAAwCAIAAACJ9F2zAAAAA}";

  assertNotNull(content);
  HttpResponse response = postUri("Employees", content, HttpContentType.TEXT_PLAIN, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("7", map.get("EmployeeId"));
  assertEquals("Employee 7", map.get("EmployeeName"));
  assertNull(map.get("EntryData"));
  response = callUri("Employees('7')/$value");
  checkMediaType(response, HttpContentType.TEXT_PLAIN);
}
 
Example #3
Source File: EntryJsonCreateTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createEntryRoomWithLink() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"1\",\"Name\":\"Room 104\","
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}";
  assertNotNull(content);
  HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("104", map.get("Id"));
  assertEquals("Room 104", map.get("Name"));
  @SuppressWarnings("unchecked")
  StringMap<Object> employeesMap = (StringMap<Object>) map.get("nr_Employees");
  assertNotNull(employeesMap);
  @SuppressWarnings("unchecked")
  StringMap<String> deferredMap = (StringMap<String>) employeesMap.get("__deferred");
  assertNotNull(deferredMap);
  assertEquals(getEndpoint() + "Rooms('104')/nr_Employees", deferredMap.get("uri"));
}
 
Example #4
Source File: EntryJsonCreateInlineTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createEntryRoomWithInlineEmptyFeedObject() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2,"
      + "\"nr_Employees\":{\"results\":[]},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}";
  HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);
  checkEtag(response, "W/\"2\"");

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("104", map.get("Id"));
  assertEquals("Room 104", map.get("Name"));

  @SuppressWarnings("unchecked")
  StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata");
  assertNotNull(metadataMap);
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id"));
  assertEquals("RefScenario.Room", metadataMap.get("type"));
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri"));
}
 
Example #5
Source File: EntryJsonCreateInlineTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createEntryRoomWithInlineEmptyFeedArray() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2,"
      + "\"nr_Employees\":[],"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}";
  HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);
  checkEtag(response, "W/\"2\"");

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("104", map.get("Id"));
  assertEquals("Room 104", map.get("Name"));

  @SuppressWarnings("unchecked")
  StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata");
  assertNotNull(metadataMap);
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id"));
  assertEquals("RefScenario.Room", metadataMap.get("type"));
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri"));
}
 
Example #6
Source File: EntryJsonCreateInlineTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@Test
public void createThreeLevelsDeepInsert() throws Exception {
  String content = "{\"Name\" : \"Room 2\",\"nr_Building\" : {\"Name\" : \"Building 2\",\"nb_Rooms\" : {\"results\" : [{"
      + "\"nr_Employees\" : {\"__deferred\" : {\"uri\" : \"" + getEndpoint() + "Rooms('1')/nr_Employees\""
      + "}},\"nr_Building\" : {\"__deferred\" : {\"uri\" : \"" + getEndpoint() + "/Rooms('1')/nr_Building\""
      + "}}}]}}}";

  HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);

  String body = getBody(response);

  //Check inline building
  StringMap<?> map = getStringMap(body);
  map = (StringMap<?>) map.get("nr_Building");
  assertNotNull(map);
  assertEquals("Building 2", map.get("Name"));

  //Check inline rooms of the inline building
  map = (StringMap<?>) map.get("nb_Rooms");
  assertNotNull(map);

  ArrayList<?> results = (ArrayList<?>) map.get("results");
  assertNotNull(results);
  assertEquals(2, results.size());
}
 
Example #7
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonMember2() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "Location/Country/PostalCode");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class);
  checkMember(jsonMap, null);

  StringMap<Object> source1 = (StringMap<Object>) jsonMap.get(SOURCE);
  checkMember(source1, null);

  StringMap<Object> source2 = (StringMap<Object>) source1.get(SOURCE);
  checkProperty(source2, null, "Location");

  StringMap<Object> path1 = (StringMap<Object>) source1.get(PATH);
  checkProperty(path1, null, "Country");

  StringMap<Object> path = (StringMap<Object>) jsonMap.get(PATH);
  checkProperty(path, null, "PostalCode");
}
 
Example #8
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonBinaryLiteral() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "'a' eq 'b'");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class);
  checkBinary(jsonMap, "eq", "Edm.Boolean");

  StringMap<Object> left = (StringMap<Object>) jsonMap.get(LEFT);
  checkLiteral(left, "Edm.String", "a");

  StringMap<Object> right = (StringMap<Object>) jsonMap.get(RIGHT);
  checkLiteral(right, "Edm.String", "b");
}
 
Example #9
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonBinaryProperty() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "a eq b");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class);
  checkBinary(jsonMap, "eq", null);

  StringMap<Object> left = (StringMap<Object>) jsonMap.get(LEFT);
  checkProperty(left, null, "a");

  StringMap<Object> right = (StringMap<Object>) jsonMap.get(RIGHT);
  checkProperty(right, null, "b");
}
 
Example #10
Source File: HeliumRestApiTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllEnabledPackageInfo() throws IOException {
  // No enabled packages initially
  GetMethod get1 = httpGet("/helium/enabledPackage");
  assertThat(get1, isAllowed());
  Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
              new TypeToken<Map<String, Object>>() { }.getType());
  List<StringMap<Object>> body1 = (List<StringMap<Object>>) resp1.get("body");
  assertEquals(body1.size(), 0);

  // Enable "name1" package
  helium.enable("name1", "artifact1");

  GetMethod get2 = httpGet("/helium/enabledPackage");
  assertThat(get2, isAllowed());
  Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
          new TypeToken<Map<String, Object>>() { }.getType());
  List<StringMap<Object>> body2 = (List<StringMap<Object>>) resp2.get("body");

  assertEquals(body2.size(), 1);
  StringMap<Object> pkg = (StringMap<Object>) body2.get(0).get("pkg");
  assertEquals(pkg.get("name"), "name1");
}
 
Example #11
Source File: HeliumRestApiTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnableDisablePackage() throws IOException {
  String packageName = "name1";
  PostMethod post1 = httpPost("/helium/enable/" + packageName, "");
  assertThat(post1, isAllowed());
  post1.releaseConnection();

  GetMethod get1 = httpGet("/helium/package/" + packageName);
  Map<String, Object> resp1 = gson.fromJson(get1.getResponseBodyAsString(),
          new TypeToken<Map<String, Object>>() { }.getType());
  List<StringMap<Object>> body1 = (List<StringMap<Object>>) resp1.get("body");
  assertEquals(body1.get(0).get("enabled"), true);

  PostMethod post2 = httpPost("/helium/disable/" + packageName, "");
  assertThat(post2, isAllowed());
  post2.releaseConnection();

  GetMethod get2 = httpGet("/helium/package/" + packageName);
  Map<String, Object> resp2 = gson.fromJson(get2.getResponseBodyAsString(),
          new TypeToken<Map<String, Object>>() { }.getType());
  List<StringMap<Object>> body2 = (List<StringMap<Object>>) resp2.get("body");
  assertEquals(body2.get(0).get("enabled"), false);
}
 
Example #12
Source File: ProductValidationTest.java    From SeleniumBestPracticesBook with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllProductsWithApiResponse() throws Exception {
  for (StringMap productInfo : TestData.getProductsFromApi()) {
    selenium.get(TestData.getBaseUrl() + productInfo.get("url"));
    verifyProductInfo(productInfo);
  }
}
 
Example #13
Source File: HeliumRestApiTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSinglePackageInfo() throws IOException {
  String packageName = "name1";
  GetMethod get = httpGet("/helium/package/" + packageName);
  assertThat(get, isAllowed());
  Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
          new TypeToken<Map<String, Object>>() { }.getType());
  List<StringMap<Object>> body = (List<StringMap<Object>>) resp.get("body");

  assertEquals(body.size(), 1);
  StringMap<Object> pkg = (StringMap<Object>) body.get(0).get("pkg");
  assertEquals(pkg.get("name"), "name1");
}
 
Example #14
Source File: EntryJsonCreateTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Test
public void createEntryRoom() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}";
  assertNotNull(content);
  HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("104", map.get("Id"));
  assertEquals("Room 104", map.get("Name"));
  @SuppressWarnings("unchecked")
  StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata");
  assertNotNull(metadataMap);
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id"));
  assertEquals("RefScenario.Room", metadataMap.get("type"));
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri"));

  response = callUri("Rooms('104')/Seats/$value");
  body = getBody(response);
  assertEquals("4", body);
}
 
Example #15
Source File: EntryJsonCreateInlineTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@Test
public void createEntryRoomWithInlineFeedEmployee() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2,"
      + "\"nr_Employees\":{\"results\":[{"
      + "\"__metadata\":{"
      + "\"id\":\"" + getEndpoint() + "Employees('1')\","
      + "\"type\":\"RefScenario.Employee\","
      + "\"content_type\":\"image/jpeg\","
      + "\"media_src\":\"" + getEndpoint() + "Employees('1')/$value\","
      + "\"edit_media\":\"" + getEndpoint() + "Employees('1')/$value\"},"
      + " \"EmployeeName\": \"Walter Winter\","
      + "\"ManagerId\": \"1\","
      + "\"RoomId\": \"1\","
      + "\"TeamId\": \"1\","
      + "\"Age\": 52,"
      + "\"Location\":{\"City\":{\"PostalCode\":\"69124\",\"CityName\":\"Heidelberg\"},"
      + "              \"Country\":\"Germany\"},"
      + "\"ImageUrl\": \"" + getEndpoint() + "Employees('1')/$value\"}]},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}";

  HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("104", map.get("Id"));
  assertEquals("Room 104", map.get("Name"));

  @SuppressWarnings("unchecked")
  StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata");
  assertNotNull(metadataMap);
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id"));
  assertEquals("RefScenario.Room", metadataMap.get("type"));
  assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri"));
}
 
Example #16
Source File: HeliumRestApiTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAllPackageConfigs() throws IOException {
  GetMethod get = httpGet("/helium/config/");
  assertThat(get, isAllowed());
  Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
          new TypeToken<Map<String, Object>>() { }.getType());
  StringMap<Object> body = (StringMap<Object>) resp.get("body");
  // ToDo: Apply config with POST command and check update
  assertEquals(body.size(), 0);
}
 
Example #17
Source File: HeliumRestApiTest.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPackageConfig() throws IOException {
  String packageName = "name1";
  String artifact = "artifact1";
  GetMethod get = httpGet("/helium/config/" + packageName + "/" + artifact);
  assertThat(get, isAllowed());
  Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
          new TypeToken<Map<String, Object>>() { }.getType());
  StringMap<Object> body = (StringMap<Object>) resp.get("body");
  assertTrue(body.containsKey("confPersisted"));
}
 
Example #18
Source File: AbstractRefJsonTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
public StringMap<?> getStringMap(final String body) {
  Gson gson = new Gson();
  final StringMap<?> map = gson.fromJson(body, new TypeToken<StringMap<?>>() {}.getType());
  if (map.get("d") instanceof StringMap<?>) {
    return (StringMap<?>) map.get("d");
  } else {
    return map;
  }
}
 
Example #19
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
private void checkBinary(final StringMap<Object> binary, final String expectedOperator, final String expectedType) throws Exception {
  assertEquals(ExpressionKind.BINARY.toString(), binary.get(NODETYPE));
  assertEquals(expectedOperator, binary.get(OPERATOR));
  assertEquals(expectedType, binary.get(TYPE));
  assertNotNull(binary.get(LEFT));
  assertNotNull(binary.get(RIGHT));
}
 
Example #20
Source File: InterpreterSetting.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public void setProperties(Object object) {
  if (object instanceof StringMap) {
    StringMap<String> map = (StringMap) properties;
    Properties newProperties = new Properties();
    for (String key : map.keySet()) {
      newProperties.put(key, map.get(key));
    }
    this.properties = newProperties;
  } else {
    this.properties = object;
  }
}
 
Example #21
Source File: ProductValidationTest.java    From SeleniumBestPracticesBook with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllProductsWithApiResponse() throws Exception {
  for (StringMap productInfo : TestData.getProductsFromApi()) {
    selenium.get(TestData.getBaseUrl() + productInfo.get("url"));
    verifyProductInfo(productInfo);
  }
}
 
Example #22
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonUnary() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "not 'a'");
  String jsonString = toJson(expression);

  StringMap<Object> jsonMap = new Gson().fromJson(jsonString, StringMap.class);
  checkUnary(jsonMap, UnaryOperator.NOT, null);

  StringMap<Object> operand = (StringMap<Object>) jsonMap.get(OPERAND);
  checkLiteral(operand, "Edm.String", "a");
}
 
Example #23
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonMethod() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "concat('aa','b')");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class);
  checkMethod(jsonMap, MethodOperator.CONCAT, "Edm.String");

  List<Object> parameter = (List<Object>) jsonMap.get(PARAMETERS);
  checkLiteral((StringMap<Object>) parameter.get(0), "Edm.String", "aa");
  checkLiteral((StringMap<Object>) parameter.get(1), "Edm.String", "b");
}
 
Example #24
Source File: FilterToJsonTest.java    From cloud-odata-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testToJsonBinaryAdd() throws Exception {
  FilterExpression expression = UriParser.parseFilter(null, null, "1d add 2d add 3d add 4d");
  String jsonString = toJson(expression);
  Gson gsonConverter = new Gson();

  StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class);
  checkBinary(jsonMap, "add", "Edm.Double");

  StringMap<Object> left1 = (StringMap<Object>) jsonMap.get(LEFT);
  checkBinary(left1, "add", "Edm.Double");

  StringMap<Object> left2 = (StringMap<Object>) left1.get(LEFT);
  checkBinary(left2, "add", "Edm.Double");

  StringMap<Object> literal1 = (StringMap<Object>) left2.get(LEFT);
  checkLiteral(literal1, "Edm.Double", "1");

  StringMap<Object> literal2 = (StringMap<Object>) left2.get(RIGHT);
  checkLiteral(literal2, "Edm.Double", "2");

  StringMap<Object> literal3 = (StringMap<Object>) left1.get(RIGHT);
  checkLiteral(literal3, "Edm.Double", "3");

  StringMap<Object> right1 = (StringMap<Object>) jsonMap.get(RIGHT);
  checkLiteral(right1, "Edm.Double", "4");
}
 
Example #25
Source File: TestQueryResource.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAllQueries() throws Exception {
  String sessionId = generateNewSessionAndGetId();
  SubmitQueryRequest queryRequest = createNewQueryRequest("select * from lineitem");

  GetSubmitQueryResponse response = restClient.target(queriesURI)
      .request().header(tajoSessionIdHeaderName, sessionId)
      .post(Entity.entity(queryRequest, MediaType.APPLICATION_JSON),
              new GenericType<>(GetSubmitQueryResponse.class));

  assertNotNull(response);
  assertEquals(ResultCode.OK, response.getResultCode());
  String location = response.getUri().toString();
  assertTrue(location != null && !location.isEmpty());
  
  String queryId = location.lastIndexOf('/') >= 0?
	location.substring(location.lastIndexOf('/')+1):null;
      
  assertTrue(queryId != null && !queryId.isEmpty());
  
  Map<String, List<StringMap>> queriesMap = restClient.target(queriesURI)
      .request().get(new GenericType<>(Map.class));
  
  assertNotNull(queriesMap);
  
  List<StringMap> queryInfoList = queriesMap.get("queries");
  assertNotNull(queryInfoList);
  
  boolean assertQueryIdFound = false;
  for (StringMap queryInfo: queryInfoList) {
    if (queryId.equals(queryInfo.get("queryIdStr"))) {
      assertQueryIdFound = true;
    }
  }
  
  assertTrue(assertQueryIdFound);
}
 
Example #26
Source File: JSONFixtures.java    From SeleniumBestPracticesBook with Apache License 2.0 4 votes vote down vote up
public static List<StringMap> parseJsonFixtures(){
  return ((List<StringMap>) new Gson().fromJson(json, LinkedList.class));
}
 
Example #27
Source File: TestData.java    From SeleniumBestPracticesBook with Apache License 2.0 4 votes vote down vote up
public static List<StringMap> getProductsFromApi(){
  return JSONFixtures.parseJsonFixtures();
}
 
Example #28
Source File: JSONFixtures.java    From SeleniumBestPracticesBook with Apache License 2.0 4 votes vote down vote up
public static List<StringMap> parseJsonFixtures(){
  return ((List<StringMap>) new Gson().fromJson(json, LinkedList.class));
}
 
Example #29
Source File: EntryJsonCreateInlineTest.java    From cloud-odata-java with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void createEntryRoomWithInlineFeedObject() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Buildings('2')\","
      + "\"uri\":\"" + getEndpoint() + "Buildings('2')\",\"type\":\"RefScenario.Building\"},"
      + "\"Id\":\"2\",\"Name\":\"Building 2\",\"Image\":null,"
      + "\"nb_Rooms\":{\"results\":[{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('2')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('2')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"2\\\"\"},"
      + "\"Id\":\"2\",\"Name\":\"Room 2\",\"Seats\":5,\"Version\":2,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Building\"}}},"
      + "{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('3')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('3')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"3\",\"Name\":\"Room 3\",\"Seats\":2,\"Version\":3,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Building\"}}}]}}}";

  HttpResponse response = callUri("Buildings('4')/nb_Rooms('104')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.NOT_FOUND);
  getBody(response);
  response = callUri("Buildings('4')/nb_Rooms('105')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.NOT_FOUND);
  getBody(response);

  response = postUri("Buildings", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("4", map.get("Id"));
  assertEquals("Building 2", map.get("Name"));

  StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata");
  assertNotNull(metadataMap);
  assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("id"));
  assertEquals("RefScenario.Building", metadataMap.get("type"));
  assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("uri"));

  StringMap<Object> navProperty = (StringMap<Object>) map.get("nb_Rooms");
  assertNotNull(navProperty);
  List<StringMap<String>> results = (ArrayList<StringMap<String>>) navProperty.get("results");
  assertNotNull(results);
  for (int i = 0; i < results.size(); i++) {
    StringMap<String> resultMap = results.get(i);
    switch (i) {
    case 0:
      assertEquals("Room 2", resultMap.get("Name"));
      assertEquals("104", resultMap.get("Id"));
      break;
    case 1:
      assertEquals("105", resultMap.get("Id"));
      assertEquals("Room 3", resultMap.get("Name"));
    }
  }
  response = callUri("Buildings('4')/nb_Rooms('104')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
  assertEquals("5", getBody(response));

  response = callUri("Buildings('4')/nb_Rooms('105')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
  assertEquals("2", getBody(response));
}
 
Example #30
Source File: EntryJsonCreateInlineTest.java    From cloud-odata-java with Apache License 2.0 4 votes vote down vote up
@Test
public void createEntryRoomWithInlineFeedArray() throws Exception {
  String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Buildings('2')\","
      + "\"uri\":\"" + getEndpoint() + "Buildings('2')\",\"type\":\"RefScenario.Building\"},"
      + "\"Id\":\"2\",\"Name\":\"Building 2\",\"Image\":null,"
      + "\"nb_Rooms\":[{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('2')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('2')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"2\\\"\"},"
      + "\"Id\":\"2\",\"Name\":\"Room 2\",\"Seats\":5,\"Version\":2,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Building\"}}},"
      + "{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('3')\","
      + "\"uri\":\"" + getEndpoint() + "Rooms('3')\",\"type\":\"RefScenario.Room\","
      + "\"etag\":\"W/\\\"3\\\"\"},"
      + "\"Id\":\"3\",\"Name\":\"Room 3\",\"Seats\":2,\"Version\":3,"
      + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Employees\"}},"
      + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Building\"}}}]}}";

  HttpResponse response = postUri("Buildings", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED);
  checkMediaType(response, HttpContentType.APPLICATION_JSON);
  //checkEtag(response, "W/\"2\"");

  String body = getBody(response);
  StringMap<?> map = getStringMap(body);
  assertEquals("4", map.get("Id"));
  assertEquals("Building 2", map.get("Name"));

  @SuppressWarnings("unchecked")
  StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata");
  assertNotNull(metadataMap);
  assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("id"));
  assertEquals("RefScenario.Building", metadataMap.get("type"));
  assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("uri"));

  response = callUri("Buildings('4')/nb_Rooms('104')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
  body = getBody(response);
  map = getStringMap(body);
  assertEquals("104", map.get("Id"));
  assertEquals("Room 2", map.get("Name"));
  response = callUri("Buildings('4')/nb_Rooms('104')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
  body = getBody(response);
  assertEquals("5", body);

  response = callUri("Buildings('4')/nb_Rooms('105')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
  body = getBody(response);
  map = getStringMap(body);
  assertEquals("105", map.get("Id"));
  assertEquals("Room 3", map.get("Name"));
  response = callUri("Buildings('4')/nb_Rooms('105')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
  body = getBody(response);
  assertEquals("2", body);
}