Java Code Examples for com.google.gson.internal.StringMap

The following examples show how to use com.google.gson.internal.StringMap. These examples are extracted from open source projects. 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 Project: zeppelin   Author: apache   File: HeliumRestApiTest.java    License: 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 #2
Source Project: zeppelin   Author: apache   File: HeliumRestApiTest.java    License: 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 #3
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #4
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #5
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #6
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #7
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateInlineTest.java    License: 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 #8
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateInlineTest.java    License: 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 #9
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateInlineTest.java    License: 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 #10
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateTest.java    License: 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 #11
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateTest.java    License: 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 #12
Source Project: zeppelin   Author: apache   File: InterpreterSetting.java    License: 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 #13
Source Project: zeppelin   Author: apache   File: HeliumRestApiTest.java    License: 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 Project: zeppelin   Author: apache   File: HeliumRestApiTest.java    License: 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 #15
Source Project: zeppelin   Author: apache   File: HeliumRestApiTest.java    License: 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 #16
Source Project: tajo   Author: apache   File: TestQueryResource.java    License: 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 #17
Source Project: SeleniumBestPracticesBook   Author: dimacus   File: ProductValidationTest.java    License: 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 #18
Source Project: SeleniumBestPracticesBook   Author: dimacus   File: ProductValidationTest.java    License: 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 #19
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #20
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #21
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #22
Source Project: cloud-odata-java   Author: SAP   File: FilterToJsonTest.java    License: 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 #23
Source Project: cloud-odata-java   Author: SAP   File: AbstractRefJsonTest.java    License: 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 #24
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateInlineTest.java    License: 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 #25
Source Project: cloud-odata-java   Author: SAP   File: EntryJsonCreateTest.java    License: 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 #26
Source Project: zeppelin   Author: apache   File: NotebookRestApiTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testRunParagraphSynchronously() throws IOException {
  LOG.info("Running testRunParagraphSynchronously");
  Note note1 = null;
  try {
    note1 = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous);
    note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);

    Paragraph p = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);

    // run non-blank paragraph
    String title = "title";
    String text = "%sh\n sleep 1";
    p.setTitle(title);
    p.setText(text);

    PostMethod post = httpPost("/notebook/run/" + note1.getId() + "/" + p.getId(), "");
    assertThat(post, isAllowed());
    Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
        new TypeToken<Map<String, Object>>() {}.getType());
    assertEquals(resp.get("status"), "OK");
    post.releaseConnection();
    assertNotEquals(p.getStatus(), Job.Status.READY);

    // Check if the paragraph is emptied
    assertEquals(title, p.getTitle());
    assertEquals(text, p.getText());

    // run invalid code
    text = "%sh\n invalid_cmd";
    p.setTitle(title);
    p.setText(text);

    post = httpPost("/notebook/run/" + note1.getId() + "/" + p.getId(), "");
    assertEquals(500, post.getStatusCode());
    resp = gson.fromJson(post.getResponseBodyAsString(),
            new TypeToken<Map<String, Object>>() {}.getType());
    assertEquals("INTERNAL_SERVER_ERROR", resp.get("status"));
    StringMap stringMap = (StringMap) resp.get("body");
    assertEquals("ERROR", stringMap.get("code"));
    List<StringMap> interpreterResults = (List<StringMap>) stringMap.get("msg");
    assertTrue(interpreterResults.get(0).toString(),
            interpreterResults.get(0).get("data").toString().contains("invalid_cmd: command not found"));
    post.releaseConnection();
    assertNotEquals(p.getStatus(), Job.Status.READY);

    // Check if the paragraph is emptied
    assertEquals(title, p.getTitle());
    assertEquals(text, p.getText());
  } finally {
    // cleanup
    if (null != note1) {
      TestUtils.getInstance(Notebook.class).removeNote(note1, anonymous);
    }
  }
}
 
Example #27
Source Project: SeleniumBestPracticesBook   Author: dimacus   File: TestData.java    License: Apache License 2.0 4 votes vote down vote up
public static List<StringMap> getProductsFromApi(){
  return JSONFixtures.parseJsonFixtures();
}
 
Example #28
Source Project: SeleniumBestPracticesBook   Author: dimacus   File: JSONFixtures.java    License: 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 Project: SeleniumBestPracticesBook   Author: dimacus   File: TestData.java    License: Apache License 2.0 4 votes vote down vote up
public static List<StringMap> getProductsFromApi(){
  return JSONFixtures.parseJsonFixtures();
}
 
Example #30
Source Project: SeleniumBestPracticesBook   Author: dimacus   File: JSONFixtures.java    License: Apache License 2.0 4 votes vote down vote up
public static List<StringMap> parseJsonFixtures(){
  return ((List<StringMap>) new Gson().fromJson(json, LinkedList.class));
}