001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.jndi.provider.ldap;
019:
020: import javax.naming.ldap.Control;
021:
022: import junit.framework.TestCase;
023:
024: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1Encodable;
025: import org.apache.harmony.jndi.provider.ldap.asn1.ASN1TestUtils;
026: import org.apache.harmony.jndi.provider.ldap.asn1.LdapASN1Constant;
027: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
028: import org.apache.harmony.security.asn1.ASN1Integer;
029:
030: public class LdapMessageTest extends TestCase {
031:
032: static class MockAbandonRequest implements ASN1Encodable {
033: int messageId;
034:
035: public MockAbandonRequest(int id) {
036: messageId = id;
037: }
038:
039: public void encodeValues(Object[] values) {
040: values[0] = ASN1Integer.fromIntValue(messageId);
041: }
042:
043: }
044:
045: static class MockDeleteRequest implements ASN1Encodable {
046: String dn;
047:
048: public MockDeleteRequest(String dn) {
049: this .dn = dn;
050: }
051:
052: public void encodeValues(Object[] values) {
053: values[0] = Utils.getBytes(dn);
054: }
055:
056: }
057:
058: static class MockExtendedRequest implements ASN1Encodable {
059: String name;
060:
061: String value;
062:
063: public MockExtendedRequest(String name, String value) {
064: this .name = name;
065: this .value = value;
066: }
067:
068: public void encodeValues(Object[] values) {
069: values[0] = Utils.getBytes(name);
070: values[1] = Utils.getBytes(value);
071: }
072:
073: }
074:
075: public void test_constructor() {
076: LdapMessage message = new LdapMessage(null);
077: assertNull(message.getControls());
078: assertNull(message.getResponseOp());
079: assertEquals(-1, message.getMessageId());
080: assertEquals(-1, message.getOperationIndex());
081: }
082:
083: public void test_encodeValues_$LObject() {
084: LdapMessage message = new LdapMessage(
085: LdapASN1Constant.OP_ABANDON_REQUEST,
086: new MockAbandonRequest(1), null);
087: ASN1TestUtils
088: .checkEncode(message, LdapASN1Constant.LDAPMessage);
089:
090: message = new LdapMessage(LdapASN1Constant.OP_DEL_REQUEST,
091: new MockDeleteRequest("dn"), null);
092: ASN1TestUtils
093: .checkEncode(message, LdapASN1Constant.LDAPMessage);
094:
095: message = new LdapMessage(LdapASN1Constant.OP_DEL_REQUEST,
096: new MockDeleteRequest("dn"), new Control[0]);
097: ASN1TestUtils
098: .checkEncode(message, LdapASN1Constant.LDAPMessage);
099:
100: message = new LdapMessage(LdapASN1Constant.OP_EXTENDED_REQUEST,
101: new MockExtendedRequest("extended", "test"),
102: new Control[0]);
103: ASN1TestUtils
104: .checkEncode(message, LdapASN1Constant.LDAPMessage);
105: }
106: }
|