Example #1
0
 public static JsonNode entityToJson(Entity entity) throws LeanException {
   ObjectNode json = getObjectMapper().createObjectNode();
   json.put("_id", entity.getKey().getId());
   json.putPOJO("_kind", entity.getKind());
   json.putPOJO("_account", entity.getProperty("_account"));
   Map<String, Object> props = entity.getProperties();
   for (Map.Entry<String, Object> prop : props.entrySet()) {
     addTypedNode(json, prop.getKey(), prop.getValue());
   }
   return json;
 }
 public void testInsert() throws EntityNotFoundException {
   HasTableAndColumnsInMappingJDO htacim = new HasTableAndColumnsInMappingJDO();
   htacim.setFoo("foo val");
   makePersistentInTxn(htacim, TXN_START_END);
   assertNotNull(htacim.getId());
   Entity entity =
       ds.get(KeyFactory.createKey(HasTableAndColumnsInMappingJDO.TABLE_NAME, htacim.getId()));
   assertNotNull(entity);
   assertEquals(HasTableAndColumnsInMappingJDO.TABLE_NAME, entity.getKind());
   assertEquals("foo val", entity.getProperty(HasTableAndColumnsInMappingJDO.FOO_COLUMN_NAME));
 }
Example #3
0
  /**
   * Returns an instance of {@code TestReport} representing the given test report entity.
   *
   * @param entity the test report entity.
   * @return the {@code TestReport} instance.
   * @throws java.lang.NullPointerException if {@code entity} is {@code null}.
   * @throws java.lang.IllegalArgumentException if {@code entity} king is not {@code TestReport}.
   */
  public static TestReport from(Entity entity) {
    checkNotNull(entity, "'entity' parameter cannot be null");
    checkArgument(TEST_REPORT.equals(entity.getKind()), "'entity' parameter wrong kind");

    final List<Test> failedTests = new ArrayList<>();
    try {
      final JSONArray jsonArray =
          new JSONArray(new JSONTokener(((Text) entity.getProperty("failedTests")).getValue()));
      for (int i = 0; i < jsonArray.length(); i++) {
        final Test test = Test.valueOf(jsonArray.getJSONObject(i));
        failedTests.add(test);
      }
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }

    final List<Test> ignoredTests = new ArrayList<>();
    try {
      final Text ignoredTestsEntity = (Text) entity.getProperty("ignoredTests");
      if (ignoredTestsEntity != null) {
        final JSONArray jsonArray = new JSONArray(new JSONTokener(ignoredTestsEntity.getValue()));
        for (int i = 0; i < jsonArray.length(); i++) {
          final Test test = Test.valueOf(jsonArray.getJSONObject(i));
          ignoredTests.add(test);
        }
      } else {
        log.info(
            String.format(
                "Ignored test do not have detailed information : %s [%s]",
                entity.getProperty("buildTypeId"), entity.getProperty("buildId")));
      }
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }

    return new TestReport(
        (String) entity.getProperty("buildTypeId"),
        ((Long) entity.getProperty("buildId")).intValue(),
        (Date) entity.getProperty("buildDate"),
        ((Long) entity.getProperty("buildDuration")),
        ((Long) entity.getProperty("numberOfPassedTests")).intValue(),
        ((Long) entity.getProperty("numberOfIgnoredTests")).intValue(),
        ((Long) entity.getProperty("numberOfFailedTests")).intValue(),
        failedTests,
        ignoredTests);
  }
Example #4
0
  @Test
  public void testMarshall_JSONEntity() {
    JSONEntity json = new JSONEntity();

    json.setKind("MyDocument");
    json.setId("abcdef12345");
    json.getFields().put("age", 28);
    json.getFields().put("name", "Name");

    IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, json);
    Entity e = stack.get(json);

    assertNotNull(stack);
    assertTrue(!stack.isEmpty());

    assertEquals("MyDocument", e.getKind());
  }
  public void testInsertWithCustomIdPolicy() throws EntityNotFoundException {
    setupCustomIdentifierPolicy("___", "PREFIX", "SUFFIX", "UpperCase");

    Flight f1 = new Flight();
    f1.setOrigin("BOS");
    f1.setDest("MIA");
    f1.setMe(2);
    f1.setYou(4);
    f1.setName("Harold");
    f1.setFlightNumber(400);
    pm.makePersistent(f1);
    Entity entity = ds.get(KeyFactory.stringToKey(f1.getId()));
    assertNotNull(entity);
    assertEquals(
        "PREFIX" + Flight.class.getSimpleName().toUpperCase() + "SUFFIX", entity.getKind());
    assertEquals("Harold", entity.getProperty("NAME"));
    // column name isn't generated if explicitly set
    assertEquals(400L, entity.getProperty("flight_number"));
  }