public void testContains_unordered_ArrayOfArray() {
    Person person0 = Person.getInstance();
    Person person1 = Person.getInstance();

    Object[][] arrays = {
      {"Blue", "Yellow", "Red"},
      {
        person0, person1,
      },
      {
        new Integer(100), new Integer(200), new Integer(300),
      },
    };

    Object[][] newArrays = {
      {"Blue", "Yellow", "Red"},
      {
        person0, person1,
      },
      {
        new Integer(100), new Integer(200), new Integer(300),
      },
    };

    unorderedAttribute.add(arrays);
    assertFalse(unorderedAttribute.contains(newArrays));
    // TO DO: behavior of array of array
  }
  public void testSet_ordered_Simple() throws NamingException {
    Person person = Person.getInstance();
    orderedAttribute.add(person);
    Person person2 = Person.getInstance();

    assertEquals(person, orderedAttribute.set(0, person2));
    assertEquals(person2, orderedAttribute.get(0));
  }
  public void testAdd_order_ExistingValue() throws NamingException, CloneNotSupportedException {
    Person person = Person.getInstance();
    Person clonePerson = (Person) person.clone();

    assertTrue(orderedAttribute.add(person));
    assertTrue(orderedAttribute.add(clonePerson));
    assertEquals(2, orderedAttribute.size());
    assertEquals(orderedAttribute.get(0), orderedAttribute.get(1));
  }
  public void testAdd_unorder_ExistingValue() throws CloneNotSupportedException, NamingException {
    Person person = Person.getInstance();
    Person clonePerson = (Person) person.clone();
    unorderedAttribute.add(person);

    assertFalse(unorderedAttribute.add(clonePerson));
    assertEquals(1, unorderedAttribute.size());
    assertEquals(clonePerson, unorderedAttribute.get(0));
  }
  /** test equals with different value */
  public void testNotEquals_ByValue() {
    String ID = "not equals";
    Person person0 = Person.getInstance();
    Person person1 = Person.getInstance();

    BasicAttribute attribute0 = new BasicAttribute(ID, person0);
    BasicAttribute attribute1 = new BasicAttribute(ID, person1);

    assertFalse(attribute0.equals(attribute1));
  }
  /** test contains */
  public void testContains_unordered() {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(persons[i]);
    }

    for (int i = 0; i < count; i++) {
      assertTrue(unorderedAttribute.contains(persons[i]));
    }
    Person person = Person.getInstance();
    assertFalse(unorderedAttribute.contains(person));
  }
  /** test equals */
  public void testEquals() throws CloneNotSupportedException {
    String ID = "equals";
    Person person = Person.getInstance();
    Person personClone = (Person) person.clone();
    BasicAttribute attribute0 = new BasicAttribute(ID);
    attribute0.add(person);

    BasicAttribute attribute1 = new BasicAttribute(ID);
    attribute1.add(personClone);

    assertTrue(attribute0.equals(attribute1));
    assertTrue(attribute1.equals(attribute0));
    assertFalse(attribute0.equals(null));
  }
 /** Test Result(Object o, Attributes a) with the first param o as null */
 public void testConstructor_ObjectNull() {
   Person person = Person.getInstance();
   BasicAttributes attributes = new BasicAttributes("Anyuser", person);
   DirStateFactory.Result result = new DirStateFactory.Result(null, attributes);
   assertNull(result.getObject());
   assertEquals(attributes, result.getAttributes());
 }
  public void testHashCode_intArrayValue() {
    int[] numbers = new int[10];
    for (int i = 0; i < numbers.length; i++) {
      numbers[i] = i * 10;
    }
    String id = "int-Array";
    BasicAttribute attribute = new BasicAttribute(id, numbers);
    Person person = Person.getInstance();
    attribute.add(person);
    int hashCode = id.hashCode() + person.hashCode();
    for (int element : numbers) {
      hashCode += element;
    }

    assertEquals(hashCode, attribute.hashCode());
  }
Ejemplo n.º 10
0
  public void testSet_ordered_OldValueNull() throws NamingException {
    orderedAttribute.add(null);
    Person person = Person.getInstance();

    assertNull(orderedAttribute.set(0, person));
    assertEquals(person, orderedAttribute.get(0));
  }
Ejemplo n.º 11
0
  /** test equals with different ordering setting */
  public void testNotEquals_ByOrderFlag() {
    String ID = "not equals";
    Person person = Person.getInstance();
    BasicAttribute attribute0 = new BasicAttribute(ID, person, false);
    BasicAttribute attribute1 = new BasicAttribute(ID, person, true);

    assertFalse(attribute0.equals(attribute1));
  }
 /** Test Result(Object o, Attributes a) with normal values */
 public void testConstructor_Simple() {
   Person person = Person.getInstance();
   BasicAttributes attributes = new BasicAttributes("Anyuser", person);
   String strObj = "Harmony";
   DirStateFactory.Result result = new DirStateFactory.Result(strObj, attributes);
   assertEquals(strObj, result.getObject());
   assertEquals(attributes, result.getAttributes());
 }
Ejemplo n.º 13
0
 public void testRemove2_DuplicateValue() throws NamingException {
   Person person = Person.getInstance();
   orderedAttribute.add(0, person);
   orderedAttribute.add(1, "signal");
   orderedAttribute.add(2, person);
   assertTrue(orderedAttribute.remove(person));
   assertEquals(2, orderedAttribute.size());
   assertEquals(person, orderedAttribute.get(1));
 }
Ejemplo n.º 14
0
 public void testGet_ordered() throws NamingException {
   int count = 5;
   Person[] persons = new Person[count];
   for (int i = 0; i < count; i++) {
     persons[i] = Person.getInstance();
     orderedAttribute.add(persons[i]);
   }
   assertEquals(orderedAttribute.get(0), orderedAttribute.get());
 }
Ejemplo n.º 15
0
 public void testGet2_undered_tooLarge() throws NamingException {
   Person person = Person.getInstance();
   unorderedAttribute.add(person);
   try {
     unorderedAttribute.get(unorderedAttribute.size());
     fail("get(size()), throw IndexOutOfBoundsException.");
   } catch (IndexOutOfBoundsException e) {
   }
 }
Ejemplo n.º 16
0
 public void testSet_unorder_ExistValue() {
   Person person = Person.getInstance();
   unorderedAttribute.add(person);
   try {
     unorderedAttribute.set(0, person);
     fail("Should throw IllegalStateException.");
   } catch (IllegalStateException e) {
   }
 }
Ejemplo n.º 17
0
 public void testContains_ordered_array() {
   int count = 5;
   Person[] persons = new Person[count];
   for (int i = 0; i < count; i++) {
     persons[i] = Person.getInstance();
   }
   Person[] newPersons = new Person[count];
   System.arraycopy(persons, 0, newPersons, 0, count);
   orderedAttribute.add(persons);
   assertTrue(orderedAttribute.contains(newPersons));
 }
Ejemplo n.º 18
0
  /** TEST: boolean remove(Object obj) */
  public void testRemove2_simple() {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(persons[i]);
    }

    for (int i = 0; i < count; i++) {
      assertTrue(unorderedAttribute.remove(persons[i]));
    }
  }
Ejemplo n.º 19
0
  public void testAdd2_unorder_Simple() throws NamingException {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(i, persons[i]);
    }

    for (int i = 0; i < count; i++) {
      assertEquals(persons[i], unorderedAttribute.get(i));
    }
  }
Ejemplo n.º 20
0
  public void testGetAll_unordered() throws NamingException {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(persons[i]);
    }

    NamingEnumeration<?> enumeration = unorderedAttribute.getAll();
    int i = 0;
    while (enumeration.hasMore()) {
      assertEquals(persons[i++], enumeration.next());
    }
  }
Ejemplo n.º 21
0
  /**
   * 1. Check ordered.equals(unordered) 2. Check unordered.equals(ordered) 3. Check the values have
   * the same order
   */
  public void testEquals_Ordered_Unordered_1() {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
    }

    for (int i = 0; i < count; i++) {
      orderedAttribute.add(persons[i]);
      unorderedAttribute.add(persons[i]);
    }
    assertFalse(orderedAttribute.equals(unorderedAttribute));
    assertFalse(unorderedAttribute.equals(orderedAttribute));
  }
Ejemplo n.º 22
0
  /** Object remove(int i) */
  public void testRemove_simple() throws NamingException {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(persons[i]);
    }

    assertEquals(persons[0], unorderedAttribute.remove(0));

    for (int i = 0; i < count - 1; i++) {
      assertSame(persons[i + 1], unorderedAttribute.get(i));
    }
  }
Ejemplo n.º 23
0
  public void testAdd_order_Simple() throws NamingException {
    int count = 5;

    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      assertTrue(orderedAttribute.add(persons[i]));
    }

    for (int i = 0; i < count; i++) {
      assertSame(persons[i], orderedAttribute.get(i));
    }

    assertEquals(count, orderedAttribute.size());
  }
Ejemplo n.º 24
0
  public void testSet_unorder_ExistValueArray() {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
    }
    Person[] newPersons = new Person[count];
    System.arraycopy(persons, 0, newPersons, 0, count);

    unorderedAttribute.add(persons);
    try {
      unorderedAttribute.set(0, newPersons);
      fail("Should throw IllegalStateException.");
    } catch (IllegalStateException e) {
    }
  }
Ejemplo n.º 25
0
  public void testEquals_Array() throws CloneNotSupportedException {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
    }
    Person[] newPersons = new Person[count];
    System.arraycopy(persons, 0, newPersons, 0, count);

    String id = "Array Attribute";
    BasicAttribute attribute0 = new BasicAttribute(id, persons, true);

    BasicAttribute attribute1 = new BasicAttribute(id, newPersons, true);

    assertTrue(attribute0.equals(attribute1));
    assertTrue(attribute1.equals(attribute0));
    assertFalse(attribute0.equals(null));
  }
Ejemplo n.º 26
0
  public void testEquals_diff_ordered() {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
    }
    String id = "un-Ordered";
    BasicAttribute unordered0 = new BasicAttribute(id);
    BasicAttribute unordered1 = new BasicAttribute(id);
    for (int i = 0; i < count; i++) {
      unordered0.add(persons[i]);
    }

    for (int i = count - 1; i > -1; i--) {
      unordered1.add(persons[i]);
    }
    assertEquals(unordered0.size(), unordered1.size());
    assertTrue(unordered0.equals(unordered1));
  }
Ejemplo n.º 27
0
  public void testClone_unordered() throws NamingException {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(persons[i]);
    }

    BasicAttribute cloneAttribute = (BasicAttribute) unorderedAttribute.clone();

    for (int i = 0; i < count; i++) {
      assertSame(unorderedAttribute.get(i), cloneAttribute.get(i));
    }
    assertFalse(cloneAttribute.isOrdered());
    assertEquals(unorderedAttribute.getID(), cloneAttribute.getID());
    // assertNotSame(unorderedAttribute.values, cloneAttribute.values);
    cloneAttribute.add("new object");
    assertEquals(unorderedAttribute.size() + 1, cloneAttribute.size());
  }
Ejemplo n.º 28
0
  public void testSerializable_Simple() throws ClassNotFoundException, IOException {
    int count = 5;
    Person[] persons = new Person[count];
    for (int i = 0; i < count; i++) {
      persons[i] = Person.getInstance();
      unorderedAttribute.add(persons[i]);
    }

    // write to byte array
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(unorderedAttribute);
    byte[] buffer = baos.toByteArray();

    // read from byte array
    ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
    ObjectInputStream ois = new ObjectInputStream(bais);
    BasicAttribute attribute2 = (BasicAttribute) ois.readObject();

    assertEquals(unorderedAttribute, attribute2);
  }
Ejemplo n.º 29
0
 public void testRemove2_NotMatch() {
   Person person = Person.getInstance();
   unorderedAttribute.add(person);
   Person person2 = Person.getInstance();
   assertFalse(unorderedAttribute.remove(person2));
 }