Example #1
0
  public void testICalendarAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    ICalendarAttribute icalAttr = new HibICalendarAttribute();
    icalAttr.setQName(new HibQName("icalattribute"));
    icalAttr.setValue(helper.getInputStream("vjournal.ics"));
    item.addAttribute(icalAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("icalattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof ICalendarAttribute);

    net.fortuna.ical4j.model.Calendar calendar =
        (net.fortuna.ical4j.model.Calendar) attr.getValue();
    Assert.assertNotNull(calendar);

    net.fortuna.ical4j.model.Calendar expected =
        CalendarUtils.parseCalendar(helper.getInputStream("vjournal.ics"));

    Assert.assertEquals(expected.toString(), calendar.toString());

    calendar.getProperties().add(new ProdId("blah"));

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    ICalendarAttribute ica =
        (ICalendarAttribute) queryItem.getAttribute(new HibQName("icalattribute"));
    Assert.assertFalse(expected.toString().equals(ica.getValue().toString()));
  }
Example #2
0
  public void testTimestampAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    Date dateVal = new Date();
    TimestampAttribute tsAttr =
        new HibTimestampAttribute(new HibQName("timestampattribute"), dateVal);
    item.addAttribute(tsAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("timestampattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof TimestampAttribute);

    Date val = (Date) attr.getValue();
    Assert.assertTrue(dateVal.equals(val));

    dateVal.setTime(dateVal.getTime() + 101);
    attr.setValue(dateVal);

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    Attribute queryAttr = queryItem.getAttribute(new HibQName("timestampattribute"));
    Assert.assertNotNull(queryAttr);
    Assert.assertTrue(queryAttr instanceof TimestampAttribute);

    val = (Date) queryAttr.getValue();
    Assert.assertTrue(dateVal.equals(val));
  }
Example #3
0
  public void testCalendarAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    CalendarAttribute calAttr =
        new HibCalendarAttribute(new HibQName("calendarattribute"), "2002-10-10T00:00:00+05:00");
    item.addAttribute(calAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("calendarattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof CalendarAttribute);

    Calendar cal = (Calendar) attr.getValue();
    Assert.assertEquals(cal.getTimeZone().getID(), "GMT+05:00");
    Assert.assertTrue(cal.equals(calAttr.getValue()));

    attr.setValue("2003-10-10T00:00:00+02:00");

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    Attribute queryAttr = queryItem.getAttribute(new HibQName("calendarattribute"));
    Assert.assertNotNull(queryAttr);
    Assert.assertTrue(queryAttr instanceof CalendarAttribute);

    cal = (Calendar) queryAttr.getValue();
    Assert.assertEquals(cal.getTimeZone().getID(), "GMT+02:00");
    Assert.assertTrue(cal.equals(attr.getValue()));
  }
Example #4
0
  public void testXmlAttribute() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();

    org.w3c.dom.Element testElement = createTestElement();
    org.w3c.dom.Element testElement2 = createTestElement();

    testElement2.setAttribute("foo", "bar");

    Assert.assertFalse(testElement.isEqualNode(testElement2));

    XmlAttribute xmlAttr = new HibXmlAttribute(new HibQName("xmlattribute"), testElement);
    item.addAttribute(xmlAttr);

    ContentItem newItem = contentDao.createContent(root, item);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("xmlattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof XmlAttribute);

    org.w3c.dom.Element element = (org.w3c.dom.Element) attr.getValue();

    Assert.assertEquals(DomWriter.write(testElement), DomWriter.write(element));

    Date modifyDate = attr.getModifiedDate();

    // Sleep a couple millis to make sure modifyDate doesn't change
    Thread.sleep(2);

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    attr = queryItem.getAttribute(new HibQName("xmlattribute"));

    // Attribute shouldn't have been updated
    Assert.assertEquals(modifyDate, attr.getModifiedDate());

    attr.setValue(testElement2);

    // Sleep a couple millis to make sure modifyDate doesn't change
    Thread.sleep(2);
    modifyDate = attr.getModifiedDate();

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());

    attr = queryItem.getAttribute(new HibQName("xmlattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof XmlAttribute);
    // Attribute should have been updated
    Assert.assertTrue(modifyDate.before(attr.getModifiedDate()));

    element = (org.w3c.dom.Element) attr.getValue();

    Assert.assertEquals(DomWriter.write(testElement2), DomWriter.write(element));
  }
Example #5
0
  public void testContentAttributes() throws Exception {
    User user = getUser(userDao, "testuser");
    CollectionItem root = (CollectionItem) contentDao.getRootItem(user);

    ContentItem item = generateTestContent();
    item.addIntegerAttribute("intattribute", new Long(22));
    item.addBooleanAttribute("booleanattribute", Boolean.TRUE);

    DecimalAttribute decAttr =
        new HibDecimalAttribute(new HibQName("decimalattribute"), new BigDecimal("1.234567"));
    item.addAttribute(decAttr);

    // TODO: figure out db date type is handled because i'm seeing
    // issues with accuracy
    // item.addAttribute(new DateAttribute("dateattribute", new Date()));

    HashSet<String> values = new HashSet<String>();
    values.add("value1");
    values.add("value2");
    item.addMultiValueStringAttribute("multistringattribute", values);

    HashMap<String, String> dictionary = new HashMap<String, String>();
    dictionary.put("key1", "value1");
    dictionary.put("key2", "value2");
    item.addDictionaryAttribute("dictionaryattribute", dictionary);

    ContentItem newItem = contentDao.createContent(root, item);

    Assert.assertTrue(getHibItem(newItem).getId() > -1);
    Assert.assertTrue(newItem.getUid() != null);

    clearSession();

    ContentItem queryItem = contentDao.findContentByUid(newItem.getUid());

    Attribute attr = queryItem.getAttribute(new HibQName("decimalattribute"));
    Assert.assertNotNull(attr);
    Assert.assertTrue(attr instanceof DecimalAttribute);
    Assert.assertEquals(attr.getValue().toString(), "1.234567");

    Set<String> querySet = (Set<String>) queryItem.getAttributeValue("multistringattribute");
    Assert.assertTrue(querySet.contains("value1"));
    Assert.assertTrue(querySet.contains("value2"));

    Map<String, String> queryDictionary =
        (Map<String, String>) queryItem.getAttributeValue("dictionaryattribute");
    Assert.assertEquals("value1", queryDictionary.get("key1"));
    Assert.assertEquals("value2", queryDictionary.get("key2"));

    Attribute custom = queryItem.getAttribute("customattribute");
    Assert.assertEquals("customattributevalue", custom.getValue());

    helper.verifyItem(newItem, queryItem);

    // set attribute value to null
    custom.setValue(null);

    querySet.add("value3");
    queryDictionary.put("key3", "value3");

    queryItem.removeAttribute("intattribute");

    contentDao.updateContent(queryItem);

    clearSession();

    queryItem = contentDao.findContentByUid(newItem.getUid());
    querySet = (Set) queryItem.getAttributeValue("multistringattribute");
    queryDictionary = (Map) queryItem.getAttributeValue("dictionaryattribute");
    Attribute queryAttribute = queryItem.getAttribute("customattribute");

    Assert.assertTrue(querySet.contains("value3"));
    Assert.assertEquals("value3", queryDictionary.get("key3"));
    Assert.assertNotNull(queryAttribute);
    Assert.assertNull(queryAttribute.getValue());
    Assert.assertNull(queryItem.getAttribute("intattribute"));
  }