Esempio n. 1
0
 @Before
 public void setUp() {
   if (!isInitialized) {
     ident1 = JunitTestHelper.createAndPersistIdentityAsUser(UUID.randomUUID().toString());
     ident2 = JunitTestHelper.createAndPersistIdentityAsUser(UUID.randomUUID().toString());
   }
 }
 @Before
 public void setUp() {
   if (!isInitialized) {
     ident1 = JunitTestHelper.createAndPersistIdentityAsUser("frtuse-1");
     ident2 = JunitTestHelper.createAndPersistIdentityAsUser("frtuse-2");
     ident3 = JunitTestHelper.createAndPersistIdentityAsUser("frtuse-3");
   }
 }
Esempio n. 3
0
 /** @see junit.framework.TestCase#setUp() */
 @Before
 public void setUp() throws Exception {
   ident1 = JunitTestHelper.createAndPersistIdentityAsUser("test-1");
   ident2 = JunitTestHelper.createAndPersistIdentityAsUser("test-2");
   ident3 = JunitTestHelper.createAndPersistIdentityAsUser("test-3");
   identities = new Identity[] {ident1, ident2, ident3};
   marking = applicationContext.getBean(MarkDAO.class);
 }
Esempio n. 4
0
  @Test
  public void testFindProperties() {
    // create identities, group and resource
    OLATResource res = JunitTestHelper.createRandomResource();
    Identity id1 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-8-" + UUID.randomUUID().toString());
    Identity id2 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-9-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            id1, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    String category = "cat3";
    String propertyName = "TestProperty3";
    String textValue = "textValue3";
    Property p =
        pm.createPropertyInstance(
            id1,
            group,
            res,
            category,
            propertyName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            textValue);
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id2,
            group,
            res,
            category,
            propertyName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            textValue);
    pm.saveProperty(p);
    List<Property> propertyList =
        pm.findProperties(
            id1,
            group,
            res.getResourceableTypeName(),
            res.getResourceableId(),
            category,
            propertyName);
    assertEquals(1, propertyList.size());
    assertEquals(propertyName, propertyList.get(0).getName());
    assertEquals(textValue, propertyList.get(0).getTextValue());
    int deletedCount1 = pm.deleteProperties(id1, group, res, category, propertyName);
    Assert.assertEquals(1, deletedCount1);
    int deletedCount2 = pm.deleteProperties(id2, group, res, category, propertyName);
    Assert.assertEquals(1, deletedCount2);
  }
Esempio n. 5
0
  /** testUserInsertFindDelete */
  @Test
  public void testUserInsertFindDelete() {
    // create identity and property
    Identity id =
        JunitTestHelper.createAndPersistIdentityAsUser("user-prop-" + UUID.randomUUID().toString());
    Property p =
        pm.createUserPropertyInstance(
            id,
            "catuser",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    p = pm.findUserProperty(id, "catuser", "TestProperty");
    assertNotNull(p);
    assertEquals(p.getStringValue(), "stringValue");
    assertEquals(p.getFloatValue(), new Float(1.1));
    assertEquals(p.getTextValue(), "textValue");

    pm.deleteProperty(p);
    p = pm.findUserProperty(id, "catuser", "TestProperty");
    assertNull(p);
    dbInstance.commitAndCloseSession();
  }
Esempio n. 6
0
  /** testGetAllResourceTypeNames */
  @Test
  public void testGetAllResourceTypeNames() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-3-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    // create a property
    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "catall",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    Assert.assertNotNull(p.getResourceTypeName());
    List<String> resTypeNames = pm.getAllResourceTypeNames();
    assertTrue(resTypeNames.contains(ores.getResourceableTypeName()));
  }
Esempio n. 7
0
  /** testListProperties */
  @Test
  public void testListProperties() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-4-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "cat",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);

    List<Property> entries =
        PropertyManager.getInstance()
            .listProperties(
                identity,
                group,
                ores.getResourceableTypeName(),
                ores.getResourceableId(),
                "cat",
                "TestProperty");
    Assert.assertNotNull(entries);
    Assert.assertEquals(1, entries.size());

    Property prop = entries.get(0);
    assertEquals(ores.getResourceableTypeName(), prop.getResourceTypeName());
    assertEquals(ores.getResourceableId(), prop.getResourceTypeId());

    int numOfEntries =
        PropertyManager.getInstance()
            .countProperties(
                identity,
                group,
                ores.getResourceableTypeName(),
                ores.getResourceableId(),
                "cat",
                "TestProperty",
                null,
                null);
    Assert.assertEquals(entries.size(), numOfEntries);
  }
Esempio n. 8
0
  @Test
  public void testFindWithResourceIdList() {
    // create resource, identity
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-2-" + UUID.randomUUID().toString());
    dbInstance.commitAndCloseSession();
    // create the property
    Property p =
        pm.createPropertyInstance(
            identity,
            null,
            ores,
            "catidlist",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    // check with empty list
    List<Property> emptyProps =
        pm.findProperties(
            ores.getResourceableTypeName(),
            Collections.<Long>emptyList(),
            "catidlist",
            "TestProperty");
    assertNotNull(emptyProps);
    Assert.assertTrue(emptyProps.isEmpty());

    // check with a real value and a dummy
    List<Long> resIds = new ArrayList<Long>();
    resIds.add(ores.getResourceableId());
    resIds.add(2456l); // dummy
    List<Property> props =
        pm.findProperties(ores.getResourceableTypeName(), resIds, "catidlist", "TestProperty");
    assertNotNull(props);
    Assert.assertEquals(1, props.size());
    Assert.assertEquals(p, props.get(0));
  }
Esempio n. 9
0
  /** testGenericInsertFindDelete */
  @Test
  public void testGenericInsertFindDelete() {
    // create resource, identity and group
    OLATResource ores = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-1-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    Property p =
        pm.createPropertyInstance(
            identity,
            group,
            ores,
            "catgeneric",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    dbInstance.commitAndCloseSession();

    p = pm.findProperty(identity, group, ores, "catgeneric", "TestProperty");
    assertNotNull(p);
    assertEquals(p.getStringValue(), "stringValue");
    assertEquals(p.getFloatValue(), new Float(1.1));
    assertEquals(p.getLongValue(), new Long(123456));
    assertEquals(p.getTextValue(), "textValue");

    pm.deleteProperty(p);
    p = pm.findProperty(identity, group, ores, "catgeneric", "TestProperty");
    assertNull(p);
  }
Esempio n. 10
0
  @Test
  public void testSync() {
    log.info("testing enrollment");
    //	 ------------------ now check with lock -------------------
    // create a group
    //	 create users
    final List<Identity> identities = new ArrayList<Identity>();
    for (int i = 0; i < MAX_COUNT + MAX_USERS_MORE; i++) {
      Identity id =
          JunitTestHelper.createAndPersistIdentityAsUser(
              "u-" + i + "-" + UUID.randomUUID().toString());
      identities.add(id);
      log.info("testSync: Identity=" + id.getName() + " created");
    }
    dbInstance.closeSession();

    final SecurityGroup group2 = BaseSecurityManager.getInstance().createAndPersistSecurityGroup();
    // make sure the lock has been written to the disk (tests for createOrFind see other methods)
    dbInstance.closeSession();

    // prepare threads
    int numOfThreads = MAX_COUNT + MAX_USERS_MORE;
    final CountDownLatch finishCount = new CountDownLatch(numOfThreads);

    // try to enrol all in the same group
    for (int i = 0; i < numOfThreads; i++) {
      final int j = i;
      new Thread(
              new Runnable() {
                public void run() {
                  try {
                    log.info("testSync: thread started j=" + j);
                    Identity id = identities.get(j);
                    //
                    PLock p2 = pessimisticLockManager.findOrPersistPLock("befinsert");
                    assertNotNull(p2);
                    doNoLockingEnrol(id, group2);
                    dbInstance.commit();
                    dbInstance.closeSession();
                  } catch (Exception e) {
                    e.printStackTrace();
                  } finally {
                    finishCount.countDown();
                  }
                }
              })
          .start();
    }

    try {
      finishCount.await(120, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      log.error("", e);
    }

    // now count
    dbInstance.closeSession();
    int cnt2 = BaseSecurityManager.getInstance().countIdentitiesOfSecurityGroup(group2);
    assertTrue(
        "cnt should be smaller or eq than allowed since synced with select for update. cnt:"
            + cnt2
            + ", max "
            + MAX_COUNT,
        cnt2 <= MAX_COUNT);
    assertTrue(
        "cnt should be eq to allowed since synced with select for update. cnt:"
            + cnt2
            + ", max "
            + MAX_COUNT,
        cnt2 == MAX_COUNT);
    log.info("cnt lock " + cnt2);
  }
Esempio n. 11
0
  @Test
  public void testFindIdentities() {
    // create identities, group and resource
    OLATResource res = JunitTestHelper.createRandomResource();
    Identity id1 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-7-" + UUID.randomUUID().toString());
    Identity id2 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-10-" + UUID.randomUUID().toString());
    Identity id3 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-11-" + UUID.randomUUID().toString());
    Identity id4 =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-12-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            id1, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    String propName = UUID.randomUUID().toString();

    Property p =
        pm.createPropertyInstance(
            id1,
            group,
            res,
            "cat",
            propName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id2,
            group,
            res,
            "cat",
            propName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id3,
            group,
            res,
            "cat",
            propName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id4,
            group,
            res,
            "cat",
            propName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id1,
            group,
            res,
            "cat2",
            propName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);
    p =
        pm.createPropertyInstance(
            id2,
            group,
            res,
            "cat2",
            propName,
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p);

    dbInstance.commitAndCloseSession();
    // now find identities
    List<Identity> ids = pm.findIdentitiesWithProperty(res, "cat", propName, false);
    assertEquals(4, ids.size());
    ids = pm.findIdentitiesWithProperty(res, "cat", propName, true);
    assertEquals(4, ids.size());
    ids = pm.findIdentitiesWithProperty(null, "cat", propName, false);
    assertEquals(4, ids.size());
    ids = pm.findIdentitiesWithProperty(null, "cat", propName, true);
    assertEquals(0, ids.size());
    ids = pm.findIdentitiesWithProperty(null, "cat2", propName, false);
    assertEquals(2, ids.size());
    ids = pm.findIdentitiesWithProperty(null, null, propName, false);
    assertEquals(4, ids.size()); // not 6, must be distinct
    ids = pm.findIdentitiesWithProperty(null, null, propName, true);
    assertEquals(0, ids.size());
  }
Esempio n. 12
0
  /**
   * testFloatValues THIS test does only success when you run it against mysql with FLOAT(65,30).
   * FLOAT(65,30) is mysql specific and if you let hibernate generate the tables automatic it will
   * result in FLOAT only and this test will fail. So this means that you have to populate the
   * tables yourself via the sql file.
   */
  @Test
  public void testFloatValues() {
    // create identity, group and resource
    OLATResource res = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-6-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    Property original, copy;
    // gs:changed to FLOAT(65,30) to be compatible with hsqldb and auto generated ddl
    // Define my own MAX float value because the db precision changed from DECIMAL(78,36) to
    // DECIMAL(65,30)
    double floatMaxValue = 1E34; // 1E35 does failed with mysql 5.0.x
    original =
        pm.createPropertyInstance(
            identity,
            group,
            res,
            "cat",
            "TestProperty",
            new Float(1234534343424213.1324534533456),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(original);
    // DBFactory.getInstance().evict(original);
    dbInstance.commitAndCloseSession();
    copy = pm.findProperty(identity, group, res, "cat", "TestProperty");
    float f1F = original.getFloatValue().floatValue();
    float copyF = copy.getFloatValue().floatValue();
    assertEquals("values differ:" + f1F + ", and " + copyF, f1F, copyF, 0.0000000001f);
    pm.deleteProperties(identity, group, res, "cat", "TestProperty");

    // note: on mysql 5.0, the standard installation is strict mode, which reports any data
    // truncation error as a real jdbc error.
    // -1e35 seems out of range for DECIMAL(65,30) so data truncation occurs???
    //                                          +-> 30 digits to the right side of decimal point
    // From mysql:
    // The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the
    // arguments in MySQL 5.1 are as follows:
    // M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions
    // of MySQL allowed a range of 1 to 254.)
    // D is the number of digits to the right of the decimal point (the scale). It has a range of 0
    // to 30 and must be no larger than M.
    original =
        pm.createPropertyInstance(
            identity,
            group,
            res,
            "cat",
            "TestProperty",
            new Float(-floatMaxValue),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(original);
    dbInstance.commitAndCloseSession();
    copy =
        pm.findProperty(
            identity,
            group,
            res,
            "cat",
            "TestProperty"); // this one failes at the moment for hsqldb with: incompatible data
                             // type in conversion: from SQL type DECIMAL to java.lang.Double,
                             // value:
                             // -9999999790214767953607394487959552.000000000000000000000000000000
    assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue());
    pm.deleteProperties(identity, group, res, "cat", "TestProperty");

    original =
        pm.createPropertyInstance(
            identity,
            group,
            res,
            "cat",
            "TestProperty",
            new Float(floatMaxValue),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(original);
    dbInstance.commitAndCloseSession();
    copy = pm.findProperty(identity, group, res, "cat", "TestProperty");
    assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue());
    pm.deleteProperties(identity, group, res, "cat", "TestProperty");

    original =
        pm.createPropertyInstance(
            identity,
            group,
            res,
            "cat",
            "TestProperty",
            new Float(Long.MAX_VALUE),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(original);
    dbInstance.commitAndCloseSession();
    copy = pm.findProperty(identity, group, res, "cat", "TestProperty");
    assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue());
    pm.deleteProperties(identity, group, res, "cat", "TestProperty");

    original =
        pm.createPropertyInstance(
            identity,
            group,
            res,
            "cat",
            "TestProperty",
            new Float(Long.MIN_VALUE),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(original);
    dbInstance.commitAndCloseSession();
    copy = pm.findProperty(identity, group, res, "cat", "TestProperty");
    assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue());
    pm.deleteProperties(identity, group, res, "cat", "TestProperty");
  }
Esempio n. 13
0
  /**
   * Performance test of 500 propertycreations per type. Rename to testPerf500Properties to include
   * this test in the test suit.
   */
  @Test
  public void testPerf500Properties() {
    // create identity, group and resource
    OLATResource res = JunitTestHelper.createRandomResource();
    Identity identity =
        JunitTestHelper.createAndPersistIdentityAsUser("prop-5-" + UUID.randomUUID().toString());
    BusinessGroup group =
        businessGroupService.createBusinessGroup(
            identity, "a buddygroup", "a desc", -1, -1, false, false, null);
    dbInstance.commitAndCloseSession();

    long start, stop;
    long count = 500;

    // create generic proerties
    log.info("----------------------------------------------------------------");
    log.info("Performance test startet. Running " + count + " cycles per test.");
    log.info("CREATE generic property test started...");
    start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
      Property p =
          pm.createPropertyInstance(
              identity,
              group,
              res,
              "perf500",
              "TestProperty" + i,
              new Float(1.1),
              new Long(123456),
              "stringValue",
              "textValue");
      pm.saveProperty(p);

      if (i % 50 == 0) {
        dbInstance.commitAndCloseSession();
      }
    }
    dbInstance.commitAndCloseSession();

    stop = System.currentTimeMillis();
    log.info(
        "CREATE generic property test: "
            + (stop - start)
            + " ms ("
            + (count * 1000 / (stop - start))
            + "/sec)");
    // some find identitites tests
    List<Identity> ids = pm.findIdentitiesWithProperty(null, null, "perf500", null, false);
    Assert.assertNotNull("Identities cannot be null", ids);
    Assert.assertFalse("Identities cannot be empty", ids.isEmpty());
    Assert.assertTrue("Identities must contains reference identity", ids.contains(identity));

    // create course and user properties
    log.info("Preparing user/group properties test. Creating additional properties..");
    start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
      Property pUser =
          pm.createUserPropertyInstance(
              identity,
              "perf500",
              "TestProperty" + i,
              new Float(1.1),
              new Long(123456),
              "stringValue",
              "textValue");
      pm.saveProperty(pUser);
      if (i % 50 == 0) {
        dbInstance.commitAndCloseSession();
      }
    }
    dbInstance.commitAndCloseSession();

    stop = System.currentTimeMillis();
    log.info("Ready : " + (stop - start) + " ms (" + (2 * count * 1000 / (stop - start)) + "/sec)");
    log.info("Starting find tests. DB holds " + count * 3 + " records.");

    // find generic property test
    log.info("FIND generic property test started...");
    start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
      Property p = pm.findProperty(identity, group, res, "perf500", "TestProperty" + i);
      assertNotNull("Must find the p (count=" + i + ")", p);
      dbInstance.commitAndCloseSession();
    }
    stop = System.currentTimeMillis();
    log.info(
        "FIND generic property test: "
            + (stop - start)
            + " ms ("
            + (count * 1000 / (stop - start))
            + "/sec)");

    // find user property test
    log.info("FIND user property test started...");
    start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
      Property p = pm.findUserProperty(identity, "perf500", "TestProperty" + i);
      assertNotNull("Must find the p (count=" + i + ")", p);
      dbInstance.commitAndCloseSession();
    }
    stop = System.currentTimeMillis();
    log.info(
        "FIND user property test: "
            + (stop - start)
            + " ms ("
            + (count * 1000 / (stop - start))
            + "/sec)");

    // find & delete
    log.info("FIND and DELETE generic property test started...");
    start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
      Property p = pm.findUserProperty(identity, "perf500", "TestProperty" + i);
      pm.deleteProperty(p);
    }
    stop = System.currentTimeMillis();
    log.info(
        "FIND and DELETE generic property test: "
            + (stop - start)
            + " ms ("
            + (count * 1000 / (stop - start))
            + "/sec)");

    log.info("----------------------------------------------------------------");
    log.info("Performance test finished.");
  }
Esempio n. 14
0
  @Test
  public void testDeleteUserData() {
    // create some identities and properties
    Identity id1 =
        JunitTestHelper.createAndPersistIdentityAsUser(
            "del-user-1-" + UUID.randomUUID().toString());
    Identity id2 =
        JunitTestHelper.createAndPersistIdentityAsUser(
            "del-user-2-" + UUID.randomUUID().toString());
    Property p10 =
        pm.createPropertyInstance(
            id1,
            null,
            null,
            "prop-del-1",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p10);
    Property p11 =
        pm.createPropertyInstance(
            id1,
            null,
            null,
            "prop-del-2",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p11);
    Property p20 =
        pm.createPropertyInstance(
            id2,
            null,
            null,
            "prop-del-3",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p20);
    dbInstance.commitAndCloseSession();

    // delete user 1 datas
    pm.deleteUserData(id1, "del-" + id1.getName(), null);
    dbInstance.commitAndCloseSession();

    // check if really deleted
    Property p10x = pm.findUserProperty(id1, "prop-del-1", "TestProperty");
    assertNull(p10x);
    Property p11x = pm.findUserProperty(id1, "prop-del-2", "TestProperty");
    assertNull(p11x);

    // check if id2 has still its properties
    Property p20x = pm.findUserProperty(id2, "prop-del-3", "TestProperty");
    assertNotNull(p20x);
  }
Esempio n. 15
0
  @Test
  public void testFindWithIdentityList() {
    // create identities, resource and properties
    Identity id1 =
        JunitTestHelper.createAndPersistIdentityAsUser("cat-id-1-" + UUID.randomUUID().toString());
    Identity id2 =
        JunitTestHelper.createAndPersistIdentityAsUser("cat-id-2-" + UUID.randomUUID().toString());
    Identity id3 =
        JunitTestHelper.createAndPersistIdentityAsUser("cat-id-3-" + UUID.randomUUID().toString());
    OLATResource ores = JunitTestHelper.createRandomResource();
    Property p1 =
        pm.createPropertyInstance(
            id1,
            null,
            ores,
            "catidentlist",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p1);
    Property p2 =
        pm.createPropertyInstance(
            id2,
            null,
            ores,
            "catidentlist",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p2);
    Property p3 =
        pm.createPropertyInstance(
            id3,
            null,
            ores,
            "catidentlist",
            "TestProperty",
            new Float(1.1),
            new Long(123456),
            "stringValue",
            "textValue");
    pm.saveProperty(p3);
    dbInstance.commitAndCloseSession();

    // check with empty list
    List<Property> emptyProps =
        pm.findProperties(Collections.<Identity>emptyList(), ores, "catidentlist", "TestProperty");
    assertNotNull(emptyProps);
    Assert.assertTrue(emptyProps.isEmpty());

    // check with a real value and a dummy
    List<Identity> identities = new ArrayList<Identity>();
    identities.add(id1);
    identities.add(id2);

    List<Property> props = pm.findProperties(identities, ores, "catidentlist", "TestProperty");
    assertNotNull(props);
    Assert.assertEquals(2, props.size());
    Assert.assertTrue(props.contains(p1));
    Assert.assertTrue(props.contains(p2));
  }