コード例 #1
0
ファイル: TestProvAttr.java プロジェクト: huu0510/z-pec
 private void setAttr(Entry entry, String attrName, String value) throws ServiceException {
   Map<String, Object> attrs = new HashMap<String, Object>();
   attrs.put(attrName, value);
   prov.modifyAttrs(entry, attrs);
   String newValue = entry.getAttr(attrName, false);
   assertEquals(value, newValue);
 }
コード例 #2
0
ファイル: TestProvAttr.java プロジェクト: huu0510/z-pec
 private void unsetByNull(Entry entry, String attrName) throws ServiceException {
   Map<String, Object> attrs = new HashMap<String, Object>();
   attrs.put(attrName, null);
   prov.modifyAttrs(entry, attrs);
   String newValue = entry.getAttr(attrName, false);
   assertNull(newValue);
 }
コード例 #3
0
ファイル: TestProvAttr.java プロジェクト: huu0510/z-pec
  @Test
  public void testSingleValuedAttr() throws Exception {
    Account acct = getAccount();
    Map<String, Object> attrs = new HashMap<String, Object>();

    String attrName = Provisioning.A_zimbraInterceptAddress;
    String V = "*****@*****.**";

    String value = acct.getAttr(attrName);
    assertNull(value);

    // set a value
    attrs.clear();
    attrs.put(attrName, V);
    prov.modifyAttrs(acct, attrs);
    value = acct.getAttr(attrName);
    assertEquals(V, value);

    // delete the value by passing ""
    unsetByEmptyString(acct, attrName);

    // set a value
    attrs.clear();
    attrs.put(attrName, V);
    prov.modifyAttrs(acct, attrs);
    value = acct.getAttr(attrName);
    assertEquals(V, value);

    // delete the value by passing null
    unsetByNull(acct, attrName);

    // set a value
    attrs.clear();
    attrs.put(attrName, V);
    prov.modifyAttrs(acct, attrs);
    value = acct.getAttr(attrName);
    assertEquals(V, value);

    // delete the value by passing -{attr anme}
    attrs.clear();
    attrs.put("-" + attrName, V);
    prov.modifyAttrs(acct, attrs);
    value = acct.getAttr(attrName);
    assertNull(value);
  }
コード例 #4
0
ファイル: TestProvAttr.java プロジェクト: huu0510/z-pec
  @Test
  public void testMultiValuedAttr() throws Exception {
    Account acct = getAccount();
    Map<String, Object> attrs = new HashMap<String, Object>();

    String attrName = Provisioning.A_zimbraMailForwardingAddress;
    String V1 = "*****@*****.**";
    String V2 = "*****@*****.**";

    String value;
    Set<String> values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 0);

    // set a value
    attrs.clear();
    attrs.put(attrName, V1);
    prov.modifyAttrs(acct, attrs);
    values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 1 && values.contains(V1));

    // add a value
    attrs.clear();
    attrs.put("+" + attrName, V2);
    prov.modifyAttrs(acct, attrs);
    values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 2 && values.contains(V1) && values.contains(V2));

    // removing a value
    attrs.clear();
    attrs.put("-" + attrName, V1);
    prov.modifyAttrs(acct, attrs);
    values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 1 && values.contains(V2));

    // delete all values by passing ""
    attrs.clear();
    attrs.put(attrName, "");
    prov.modifyAttrs(acct, attrs);
    value = acct.getAttr(attrName);
    assertNull(value);
    values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 0);

    // set 2 values
    attrs.clear();
    attrs.put(attrName, new String[] {V1, V2});
    prov.modifyAttrs(acct, attrs);
    values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 2 && values.contains(V1) && values.contains(V2));

    // delete all values by passing null
    attrs.clear();
    attrs.put(attrName, null);
    prov.modifyAttrs(acct, attrs);
    value = acct.getAttr(attrName);
    assertNull(value);
    values = acct.getMultiAttrSet(attrName);
    assertTrue(values != null && values.size() == 0);
  }
コード例 #5
0
ファイル: TestProvAttr.java プロジェクト: huu0510/z-pec
  @Test
  public void testCallbackMailSignature() throws Exception {
    Account acct = getAccount();
    String attrName = Provisioning.A_zimbraPrefMailSignature;

    unsetTest(acct, attrName);

    // set a limit on cos
    Cos cos = getCos();
    setAttr(cos, Provisioning.A_zimbraMailSignatureMaxLength, "10");

    // cannot have signature longer than the max len
    boolean good = false;
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(attrName, "12345678901");
    try {
      prov.modifyAttrs(acct, attrs);
    } catch (ServiceException e) {
      if (ServiceException.INVALID_REQUEST.equals(e.getCode())
          && e.getMessage().contains("is longer than the limited value")) good = true;
    }
    assertTrue(good);
  }
コード例 #6
0
ファイル: TestProvAttr.java プロジェクト: huu0510/z-pec
  @Test
  public void testDurationAttr() throws Exception {
    Server server = getServer();
    String attrName = Provisioning.A_zimbraHsmAge;

    String strValue;
    long msValue;
    long secValue;
    Map<String, Object> attrs = new HashMap<String, Object>();

    // nnnnn([hmsd]|ms)

    // d (day)
    attrs.put(attrName, "1d");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1d", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_DAY, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(Constants.SECONDS_PER_DAY, secValue);

    // h (hour)
    attrs.put(attrName, "1h");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1h", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_HOUR, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(Constants.SECONDS_PER_HOUR, secValue);

    // m (minute)
    attrs.put(attrName, "1m");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1m", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_MINUTE, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(Constants.SECONDS_PER_MINUTE, secValue);

    // s (second)
    attrs.put(attrName, "1s");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1s", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_SECOND, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);

    // default (== s)
    attrs.put(attrName, "1");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(Constants.MILLIS_PER_SECOND, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);

    // ms (milli second)
    attrs.put(attrName, "1ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(1, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(0, secValue);

    attrs.put(attrName, "500ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("500ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(500, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);

    attrs.put(attrName, "1000ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1000ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(1000, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);

    attrs.put(attrName, "1001ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("1001ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(1001, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);

    attrs.put(attrName, "999ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("999ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(999, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(1, secValue);

    attrs.put(attrName, "0ms");
    prov.modifyAttrs(server, attrs);
    strValue = server.getAttr(attrName);
    assertEquals("0ms", strValue);
    msValue = server.getTimeInterval(attrName, 0);
    assertEquals(0, msValue);
    secValue = server.getTimeIntervalSecs(attrName, 0);
    assertEquals(0, secValue);

    // invalid unit
    boolean good = false;
    attrs.put(attrName, "1y");
    try {
      prov.modifyAttrs(server, attrs);
    } catch (AccountServiceException e) {
      if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode())) good = true;
    }
    assertTrue(good);

    good = false;
    attrs.put(attrName, "1mm");
    try {
      prov.modifyAttrs(server, attrs);
    } catch (AccountServiceException e) {
      if (AccountServiceException.INVALID_ATTR_VALUE.equals(e.getCode())) good = true;
    }
    assertTrue(good);
  }