public void testDeleteValue() {
   Item valueItem = storedItem(VALUE_ID);
   db().delete(valueItem);
   db().commit();
   Holder holder = retrieveOnlyInstance(Holder.class);
   Assert.areEqual(1, holder._map.size());
   Assert.isNull(holder._map.get(storedItem(KEY_ID)));
 }
Ejemplo n.º 2
0
 private void peek(Item original, int depth) {
   Item peeked = (Item) db().peekPersisted(original, depth, true);
   for (int i = 0; i <= depth; i++) {
     Assert.isNotNull(peeked, "Failed to peek at child " + i + " at depth " + depth);
     Assert.isFalse(db().isStored(peeked));
     peeked = peeked.child;
   }
   Assert.isNull(peeked);
 }
Ejemplo n.º 3
0
 public String getStartIp() {
   if (Assert.isEmptyString(ips) == true) {
     return "";
   }
   String[] ipMinMax = parseIpMinWithMaxValue(ips);
   if (Assert.isNull(ipMinMax) == true || ipMinMax.length <= 0) {
     return "";
   }
   return ipMinMax[0];
 }
Ejemplo n.º 4
0
 public static void areEqual(Iterator expected, Iterator actual) {
   if (null == expected) {
     Assert.isNull(actual);
     return;
   }
   Assert.isNotNull(actual);
   while (expected.hasNext()) {
     Assert.isTrue(actual.hasNext());
     Assert.areEqual(expected.next(), actual.next());
   }
   Assert.isFalse(actual.hasNext());
 }
Ejemplo n.º 5
0
  public void testGetStoredFields() {
    assertStoredField(Item.class, FIELD_NAME, ITEM_NAME, String.class, true, false);
    assertStoredField(ItemParent.class, "_array", null, String.class, false, true);

    StoredClass itemStoredClass = itemStoredClass();
    StoredField storedField = itemStoredClass.storedField(FIELD_NAME, null);
    StoredField sameStoredField = itemStoredClass.getStoredFields()[0];
    StoredField otherStoredField = storedClass(ItemParent.class).getStoredFields()[0];
    Assert.equalsAndHashcode(storedField, sameStoredField, otherStoredField);

    Assert.isNull(itemStoredClass.storedField("", null));
  }
  protected void assertValues(ExtObjectContainer objectContainer, Object[] values) {
    for (int i = 0; i < data.length; i++) {
      Item item = (Item) values[i];
      assertAreEqual(data[i], item._typedPrimitive);
      assertAreEqual(new Short(data[i]), item._typedWrapper);
      assertAreEqual(new Short(data[i]), item._untyped);
    }

    Item nullItem = (Item) values[values.length - 1];
    assertAreEqual((short) 0, nullItem._typedPrimitive);
    assertPrimitiveWrapperIsNullJavaOnly(nullItem._typedWrapper);
    Assert.isNull(nullItem._untyped);
  }
Ejemplo n.º 7
0
  /**
   *
   * 获取IP范围值.
   *
   * <pre>
   * @param ip
   * @return Object[0](String) Object[1] Long
   *
   * 示例:
   * bulidIPScopeList("61.235.91.9-61.235.91.11")
   *
   * 结果:
   * 61.235.91.9,1038834441
   * 61.235.91.10,1038834442
   * 61.235.91.11,1038834443
   * </pre>
   */
  public static List<Object[]> bulidIPScopeList(String ip) {

    // 返回结果集
    List<Object[]> ipResultList = new ArrayList<Object[]>();

    try {
      if (Assert.isEmptyString(ip) == true) {
        return ipResultList;
      }
      String[] ipMinMax = parseIpMinWithMaxValue(ip);
      if (Assert.isNull(ipMinMax) == true || ipMinMax.length <= 0) {
        return ipResultList;
      }
      String ipStart = ipMinMax[0];
      String ipEnd = ipMinMax[1];
      return bulidIPScopeList(ipStart, ipEnd);
      /*if (ip.indexOf("-") > -1) {
      	String ipStart = ip.split("-")[0];
      	String ipEnd = ip.split("-")[1];
      	// 验证参数是否为空
      	if (Assert.isEmptyString(ipStart) == true || Assert.isEmptyString(ipEnd) == true) {
      		return ipResultList;
      	}
      	// 验证参数是否确定为IP
      	if (isIpV4(ipStart) == true && isIpV4(ipEnd) == true) {
      		return bulidIPScopeList(ipStart, ipEnd);
      	}
      } else if (ip.indexOf("/") > -1) {
      	String ipStart = ip.split("/")[0];
      	int mask = Integer.parseInt(ip.split("/")[1]);
      	// 验证参数是否为空
      	if (Assert.isEmptyString(ipStart) == true) {
      		return ipResultList;
      	}
      	// 验证是否为IP
      	if (isIpV4(ipStart) == true) {
      		return bulidIPScopeList(ipStart, mask);
      	}
      } else {
      	if (isIpV4(ip) == true) {
      		ipResultList.add(new Object[] { ip, getIPV4Value(ip) });
      	}
      }*/
    } catch (Exception e) {
      theLogger.exception(e);
    }

    return ipResultList;
  }
Ejemplo n.º 8
0
 protected void assertNullItem(Object obj) throws Exception {
   ReflectClass claxx = reflector().forObject(obj);
   ReflectField[] fields = claxx.getDeclaredFields();
   for (int i = 0; i < fields.length; ++i) {
     ReflectField field = fields[i];
     if (field.isStatic() || field.isTransient()) {
       continue;
     }
     ReflectClass type = field.getFieldType();
     if (container().classMetadataForReflectClass(type).isValueType()) {
       continue;
     }
     Object value = field.get(obj);
     Assert.isNull(value);
   }
 }
Ejemplo n.º 9
0
  protected void assertRetrievedItem(Object obj) throws Exception {
    ArrayList item = (ArrayList) obj;
    IntItem intItem = (IntItem) item.get(0);
    TAIntItem taIntItem = (TAIntItem) item.get(1);

    Assert.isNotNull(intItem);
    Assert.isNotNull(taIntItem);

    Assert.areEqual(100, intItem.value);
    Assert.areEqual(new Integer(200), intItem.i);
    Assert.areEqual(new Integer(300), intItem.obj);

    Assert.areEqual(0, taIntItem.value);
    isPrimitiveNull(taIntItem.i);
    Assert.isNull(taIntItem.obj);
  }
Ejemplo n.º 10
0
  public void testDeactivateDepth() throws Exception {
    TALinkedListItem item = (TALinkedListItem) retrieveOnlyInstance();
    TALinkedList list = item.list();
    TALinkedList next3 = list.nextN(3);
    TALinkedList next5 = list.nextN(5);

    Assert.isNotNull(next3.next());
    Assert.isNotNull(next5.next());

    db().deactivate(list, 4);

    Assert.isNull(list.next);
    Assert.areEqual(0, list.value);

    // FIXME: test fails if uncomenting the following assertion.
    //	    	Assert.isNull(next3.next);
    Assert.isNotNull(next5.next);
  }
 private void tDefaultArray(Object[] arr) {
   Assert.areEqual(DEFAULT.length, arr.length);
   String str[] = new String[DEFAULT.length];
   System.arraycopy(DEFAULT, 0, str, 0, DEFAULT.length);
   for (int i = 0; i < arr.length; i++) {
     boolean found = false;
     for (int j = 0; j < str.length; j++) {
       if (arr[i].equals(str[j])) {
         str[j] = null;
         found = true;
       }
     }
     Assert.isTrue(found);
   }
   for (int j = 0; j < str.length; j++) {
     Assert.isNull(str[j]);
   }
 }
Ejemplo n.º 12
0
  /**
   * 将long类型转为IP.
   *
   * @param ipAddress
   * @return
   */
  public static String getIPV4Value(long ipAddress) {

    if (Assert.isNull(ipAddress) == true) {
      return "";
    }
    try {
      StringBuffer result = new StringBuffer();
      result.append(String.valueOf((ipAddress >>> 24)));
      result.append(".");
      result.append(String.valueOf((ipAddress & 0x00FFFFFF) >>> 16));
      result.append(".");
      result.append(String.valueOf((ipAddress & 0x0000FFFF) >>> 8));
      result.append(".");
      result.append(String.valueOf((ipAddress & 0x000000FF)));
      return result.toString();
    } catch (Exception e) {
      theLogger.exception(e);
    }
    return "";
  }
Ejemplo n.º 13
0
  private static String[] parseIpMinWithMaxValue(String ip) {

    if (Assert.isEmptyString(ip) == true) {
      return null;
    }
    if (ip.indexOf("-") > -1) {
      String ipStart = ip.split("-")[0];
      String ipEnd = ip.split("-")[1];
      // 验证参数是否为空
      if (Assert.isEmptyString(ipStart) == true || Assert.isEmptyString(ipEnd) == true) {
        return null;
      }
      // 验证参数是否确定为IP
      if (isIpV4(ipStart) == true && isIpV4(ipEnd) == true) {
        return new String[] {ipStart, ipEnd};
      }
    } else if (ip.indexOf("/") > -1) {
      String ipStart = ip.split("/")[0];
      int mask = Integer.parseInt(ip.split("/")[1]);
      // 验证参数是否为空
      if (Assert.isEmptyString(ipStart) == true) {
        return null;
      }
      // 验证是否为IP
      if (isIpV4(ipStart) == true) {
        String[] result = getScopeMinIpMaxIpWithMask(ipStart, mask);
        if (Assert.isNull(result) == true) {
          return null;
        }
        return new String[] {result[0], result[1]};
      }
    } else {
      if (isIpV4(ip) == true) {
        return new String[] {ip, ip};
      }
    }
    return null;
  }
Ejemplo n.º 14
0
  public Long ipScopeLength() {
    if (Assert.isEmptyString(ips) == true) {
      return 0L;
    }
    String[] ipMinMax = parseIpMinWithMaxValue(ips);
    if (Assert.isNull(ipMinMax) == true || ipMinMax.length <= 0) {
      return 0L;
    }
    try {
      Long ipStartLong = getIPV4Value(ipMinMax[0]);
      Long ipEndLong = getIPV4Value(ipMinMax[1]);

      if (ipStartLong == 0 || ipEndLong == 0 || ipEndLong < ipStartLong) {
        return 0L;
      }

      Long ipLengt = (ipEndLong - ipStartLong) + 1;
      return ipLengt;
    } catch (Exception e) {
      theLogger.exception(e);
      return 0L;
    }
  }
Ejemplo n.º 15
0
  /**
   * Handle document type definition with validation of publicId and systemId.
   *
   * @param received
   * @param source
   * @param validationContext
   * @param namespaceContext
   */
  private void doDocumentTypeDefinition(
      Node received,
      Node source,
      XmlMessageValidationContext validationContext,
      NamespaceContext namespaceContext,
      TestContext context) {

    Assert.isTrue(
        source instanceof DocumentType,
        "Missing document type definition in expected xml fragment");

    DocumentType receivedDTD = (DocumentType) received;
    DocumentType sourceDTD = (DocumentType) source;

    if (log.isDebugEnabled()) {
      log.debug(
          "Validating document type definition: "
              + receivedDTD.getPublicId()
              + " ("
              + receivedDTD.getSystemId()
              + ")");
    }

    if (!StringUtils.hasText(sourceDTD.getPublicId())) {
      Assert.isNull(
          receivedDTD.getPublicId(),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type public id not equal",
              sourceDTD.getPublicId(),
              receivedDTD.getPublicId()));
    } else if (sourceDTD.getPublicId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Document type public id: '"
                + receivedDTD.getPublicId()
                + "' is ignored by placeholder '"
                + CitrusConstants.IGNORE_PLACEHOLDER
                + "'");
      }
    } else {
      Assert.isTrue(
          StringUtils.hasText(receivedDTD.getPublicId())
              && receivedDTD.getPublicId().equals(sourceDTD.getPublicId()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type public id not equal",
              sourceDTD.getPublicId(),
              receivedDTD.getPublicId()));
    }

    if (!StringUtils.hasText(sourceDTD.getSystemId())) {
      Assert.isNull(
          receivedDTD.getSystemId(),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type system id not equal",
              sourceDTD.getSystemId(),
              receivedDTD.getSystemId()));
    } else if (sourceDTD.getSystemId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Document type system id: '"
                + receivedDTD.getSystemId()
                + "' is ignored by placeholder '"
                + CitrusConstants.IGNORE_PLACEHOLDER
                + "'");
      }
    } else {
      Assert.isTrue(
          StringUtils.hasText(receivedDTD.getSystemId())
              && receivedDTD.getSystemId().equals(sourceDTD.getSystemId()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type system id not equal",
              sourceDTD.getSystemId(),
              receivedDTD.getSystemId()));
    }

    validateXmlTree(
        received.getNextSibling(),
        source.getNextSibling(),
        validationContext,
        namespaceContext,
        context);
  }
  /** @deprecated using deprecated api */
  private void runElementTest(Data data, boolean onOriginal) throws Exception {

    Map otherMap = new HashMap();

    AtomData atom = null;

    tDefaultValues(data);

    int itCount = 0;
    Iterator i = data.i_map.keySet().iterator();
    while (i.hasNext()) {
      String str = (String) i.next();
      itCount++;
      atom = (AtomData) data.i_map.get(str);
      Assert.areEqual(str, atom.name);
      otherMap.put(str, atom);
    }
    Assert.areEqual(DEFAULT.length, itCount);

    Assert.areEqual(DEFAULT.length, data.i_map.size());
    Assert.isFalse(data.i_map.isEmpty());
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    data.i_map.get("great");
    Assert.areEqual("great", ((AtomData) data.i_map.get("great")).name);
    db().deactivate(data.i_map, Integer.MAX_VALUE);

    if (onOriginal) {
      Query q = newQuery();
      Data template = new Data();
      template.i_map = db().collections().newHashMap(1);
      template.i_map.put("cool", new AtomData("cool"));
      q.constrain(template);
      ObjectSet qResult = q.execute();
      Assert.areEqual(1, qResult.size());
      Assert.areEqual(data, qResult.next());
    }

    Assert.isTrue(data.i_map.keySet().containsAll(otherMap.keySet()));

    Object[] arr = data.i_map.keySet().toArray();
    tDefaultArray(arr);

    String[] cmp = new String[DEFAULT.length];
    System.arraycopy(DEFAULT, 0, cmp, 0, DEFAULT.length);

    i = data.i_map.keySet().iterator();
    while (i.hasNext()) {
      String str = (String) i.next();
      boolean found = false;
      for (int j = 0; j < cmp.length; j++) {
        if (str.equals(cmp[j])) {
          cmp[j] = null;
          found = true;
        }
      }
      Assert.isTrue(found);
    }

    for (int j = 0; j < cmp.length; j++) {
      Assert.isNull(cmp[j]);
    }

    db().deactivate(data.i_map, Integer.MAX_VALUE);
    Assert.isFalse(data.i_map.isEmpty());
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    data.i_map.put("yup", new AtomData("yup"));

    db().store(data.i_map);
    db().store(data.i_map);
    db().store(data.i_map);
    db().store(data.i_helper);
    db().store(data.i_helper);
    db().store(data.i_helper);
    db().commit();

    Assert.areEqual(4, data.i_map.size());

    atom = (AtomData) data.i_map.get("yup");
    Assert.areEqual("yup", atom.name);

    AtomData removed = (AtomData) data.i_map.remove("great");

    Assert.areEqual("great", removed.name);
    Assert.isNull(data.i_map.remove("great"));
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    Assert.areEqual(3, data.i_map.size());

    Assert.isTrue(data.i_map.keySet().removeAll(otherMap.keySet()));
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    Assert.isFalse(data.i_map.keySet().removeAll(otherMap.keySet()));
    Assert.areEqual(1, data.i_map.size());
    i = data.i_map.keySet().iterator();
    String str = (String) i.next();
    Assert.areEqual("yup", str);
    Assert.isFalse(i.hasNext());

    data.i_map.clear();
    Assert.isTrue(data.i_map.isEmpty());
    Assert.areEqual(0, data.i_map.size());

    setDefaultValues(data.i_map);

    String[] strArr = new String[1];
    strArr = (String[]) data.i_map.keySet().toArray(strArr);
    tDefaultArray(strArr);

    data.i_map.clear();
    data.i_map.put("zero", "zero");

    for (int j = 0; j < COUNT; j++) {
      data.i_map.put(MORE + j, new AtomData(MORE + j));
    }
    Assert.areEqual(COUNT + 1, data.i_map.size());
    lookupLast(data);

    db().deactivate(data.i_map, Integer.MAX_VALUE);
    lookupLast(data);
    lookupLast(data);

    reopen();
    restoreMembers(data);
    lookupLast(data);

    atom = new AtomData("double");

    data.i_map.put("double", atom);

    int previousSize = data.i_map.size();

    db().deactivate(data.i_map, Integer.MAX_VALUE);

    AtomData doubleAtom = (AtomData) data.i_map.put("double", new AtomData("double"));
    Assert.areSame(atom, doubleAtom);

    Assert.areEqual(previousSize, data.i_map.size());
    data.i_map.put("double", doubleAtom);

    db().commit();

    data.i_map.put("rollBack", "rollBack");
    data.i_map.put("double", new AtomData("nono"));

    db().rollback();
    Assert.isNull(data.i_map.get("rollBack"));
    Assert.areEqual(previousSize, data.i_map.size());
    atom = (AtomData) data.i_map.get("double");
    Assert.areSame(atom, doubleAtom);
    Assert.isTrue(data.i_map.containsKey("double"));
    Assert.isFalse(data.i_map.containsKey("rollBack"));

    otherMap.clear();
    otherMap.put("other1", doubleAtom);
    otherMap.put("other2", doubleAtom);

    data.i_map.putAll(otherMap);
    db().deactivate(data.i_map, Integer.MAX_VALUE);

    Assert.areSame(doubleAtom, data.i_map.get("other1"));
    Assert.areSame(doubleAtom, data.i_map.get("other2"));

    data.i_map.clear();
    Assert.areEqual(0, data.i_map.size());
    setDefaultValues(data.i_map);

    int j = 0;
    i = data.i_map.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      if (key.equals("cool")) {
        i.remove();
      }
      j++;
    }
    Assert.areEqual(2, data.i_map.size());
    Assert.isFalse(data.i_map.containsKey("cool"));
    Assert.areEqual(3, j);

    data.i_map.put("double", doubleAtom);
    ((Db4oMap) data.i_map).deleteRemoved(true);
    data.i_map.keySet().remove("double");
    Assert.isFalse(db().isStored(doubleAtom));
    ((Db4oMap) data.i_map).deleteRemoved(false);

    data.i_map.clear();
    Assert.areEqual(0, data.i_map.size());
    setDefaultValues(data.i_map);
  }
 public void test() {
   db().query(Item.class);
   Assert.isNull(container().classMetadataForName(Item.class.getName()));
 }
Ejemplo n.º 18
0
 @Test
 public void isNullDoesNotThrowExceptionIfArgumentIsNullWithMessage() {
   Assert.isNull(null, "Bla");
 }
Ejemplo n.º 19
0
 @Test
 public void isNullDoesNotThrowExceptionIfArgumentIsNull() {
   Assert.isNull(null);
 }
Ejemplo n.º 20
0
 @Test(expected = IllegalArgumentException.class)
 public void isNullThrowsExceptionIfArgumentIsNotNull() {
   Assert.isNull(new Object());
 }
Ejemplo n.º 21
0
 public void testUnknownStoredClass() {
   Assert.isNull(storedClass(this.getClass()));
 }