use of com.zimbra.cs.ldap.ZMutableEntry in project zm-mailbox by Zimbra.
the class TestLdapZMutableEntry method mapToAttrsBinarySingle.
@Test
public void mapToAttrsBinarySingle() throws Exception {
int NUM_BYTES_IN_BINARY_DATA = 64;
String KEY_SINGLE_BINARY = Provisioning.A_userSMIMECertificate;
String KEY_SINGLE_BINARY_TRANSFER = Provisioning.A_userCertificate;
BinaryLdapData.Content VALUE_BINARY = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
BinaryLdapData.Content VALUE_BINARY_TRANSFER = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
Map<String, Object> attrMap = new HashMap<String, Object>();
attrMap.put(KEY_SINGLE_BINARY, VALUE_BINARY.getString());
attrMap.put(KEY_SINGLE_BINARY_TRANSFER, VALUE_BINARY_TRANSFER.getString());
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrMap);
/*
* this will fail. We do not handle binary data in this path,
* nor is there a use case for it.
*
* Note: ZMutableEntry and ZAttributes encapsulate a
* SDK(UBID or JNDI) native Entry/Attributes. Binary data
* are always stored in byte[] in those. When the SDK object
* is "mapped" to a Map<String, Object>, used in Provisioning,
* it is then base64 encoded, and appear as a String.
*/
// String valueGot = entry.getAttrString(KEY_SINGLE_BINARY);
// assertEquals(VALUE1.getString(), valueGot);
// this will work, because the ZAttribute.getAttrs() base64 encode
// the binary data when putting them in the Map<String, Object>.
// contains binary data
Map<String, Object> attrMapGot = entry.getAttributes().getAttrs();
Object valueGot = attrMapGot.get(KEY_SINGLE_BINARY);
assertTrue(valueGot instanceof String);
assertTrue(((String) valueGot).equals(VALUE_BINARY.getString()));
// is binary transfer
attrMapGot = entry.getAttributes().getAttrs();
valueGot = attrMapGot.get(KEY_SINGLE_BINARY_TRANSFER);
assertTrue(valueGot instanceof String);
assertTrue(((String) valueGot).equals(VALUE_BINARY_TRANSFER.getString()));
}
use of com.zimbra.cs.ldap.ZMutableEntry in project zm-mailbox by Zimbra.
the class TestLdapZMutableEntry method setAttr.
@Test
public void setAttr() throws Exception {
String KEY = "key";
String VALUE1 = "value1";
String VALUE2 = "value2";
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.setAttr(KEY, VALUE1);
// should REPLACE
entry.setAttr(KEY, VALUE2);
ZAttributes zattrs = entry.getAttributes();
Map<String, Object> attrs = zattrs.getAttrs();
Object valueGot = attrs.get(KEY);
assertTrue(valueGot instanceof String);
}
use of com.zimbra.cs.ldap.ZMutableEntry in project zm-mailbox by Zimbra.
the class TestLdapZMutableEntry method getAttrString.
@Test
public void getAttrString() throws Exception {
String KEY = "key";
String VALUE1 = "value1";
String VALUE2 = "value2";
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.setAttr(KEY, VALUE1);
// single value
String valueGot = entry.getAttrString(KEY);
assertEquals(VALUE1, valueGot);
// multi value - should just return the first one
Set<String> values = new HashSet<String>();
values.add(VALUE2);
entry.addAttr(KEY, values);
valueGot = entry.getAttrString(KEY);
// order is not guaranteed
assertTrue(VALUE1.equals(valueGot) || VALUE2.equals(valueGot));
}
use of com.zimbra.cs.ldap.ZMutableEntry in project zm-mailbox by Zimbra.
the class TestLdapZMutableEntry method addAttr.
@Test
public void addAttr() throws Exception {
String KEY = "key";
String VALUE1 = "value1";
String VALUE2 = "value2";
String VALUE3 = "value3";
ZMutableEntry entry = LdapClient.createMutableEntry();
Set<String> values = new HashSet<String>();
values.add(VALUE1);
values.add(VALUE2);
entry.addAttr(KEY, values);
values.clear();
values.add(VALUE1);
values.add(VALUE3);
// should MERGE
entry.addAttr(KEY, values);
ZAttributes zattrs = entry.getAttributes();
Map<String, Object> attrs = zattrs.getAttrs();
Object valueGot = attrs.get(KEY);
assertTrue(valueGot instanceof String[]);
List<String> valuesGot = Arrays.asList((String[]) valueGot);
assertTrue(valuesGot.contains(VALUE1));
assertTrue(valuesGot.contains(VALUE2));
assertTrue(valuesGot.contains(VALUE3));
}
use of com.zimbra.cs.ldap.ZMutableEntry in project zm-mailbox by Zimbra.
the class TestLdapZMutableEntry method mapToAttrsBinaryMulti.
@Test
public void mapToAttrsBinaryMulti() throws Exception {
int NUM_BYTES_IN_BINARY_DATA = 64;
String KEY_MULTI_BINARY = Provisioning.A_userSMIMECertificate;
String KEY_MULTI_BINARY_TRANSFER = Provisioning.A_userCertificate;
BinaryLdapData.Content VALUE_BINARY_1 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
BinaryLdapData.Content VALUE_BINARY_2 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
BinaryLdapData.Content VALUE_BINARY_TRANSFER_1 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
BinaryLdapData.Content VALUE_BINARY_TRANSFER_2 = BinaryLdapData.Content.generateContent(NUM_BYTES_IN_BINARY_DATA);
Map<String, Object> attrMap = new HashMap<String, Object>();
attrMap.put(KEY_MULTI_BINARY, new String[] { VALUE_BINARY_1.getString(), VALUE_BINARY_2.getString() });
attrMap.put(KEY_MULTI_BINARY_TRANSFER, new String[] { VALUE_BINARY_TRANSFER_1.getString(), VALUE_BINARY_TRANSFER_2.getString() });
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrMap);
// contains binary data
Map<String, Object> attrMapGot = entry.getAttributes().getAttrs();
Object valueGot = attrMapGot.get(KEY_MULTI_BINARY);
assertTrue(valueGot instanceof String[]);
List<String> valuesGot = Arrays.asList((String[]) valueGot);
assertTrue(valuesGot.contains(VALUE_BINARY_1.getString()));
assertTrue(valuesGot.contains(VALUE_BINARY_2.getString()));
// is binary transfer
attrMapGot = entry.getAttributes().getAttrs();
valueGot = attrMapGot.get(KEY_MULTI_BINARY_TRANSFER);
assertTrue(valueGot instanceof String[]);
valuesGot = Arrays.asList((String[]) valueGot);
assertTrue(valuesGot.contains(VALUE_BINARY_TRANSFER_1.getString()));
assertTrue(valuesGot.contains(VALUE_BINARY_TRANSFER_2.getString()));
}
Aggregations