01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.harmony.jndi.provider.ldap;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.harmony.jndi.provider.ldap.asn1.Utils;
26: import org.apache.harmony.security.asn1.ASN1Integer;
27:
28: public class LdapResultTest extends TestCase {
29: public void test_decodeValues_$LObject() {
30: int resultCode = 10;
31: String matchedDN = "matchedDN";
32: String errorMessage = "errorMessage";
33: String[] referrals = new String[] { "referrals0", "referrals1",
34: "referrals2" };
35: List<byte[]> list = new ArrayList<byte[]>();
36: list.add(Utils.getBytes(referrals[0]));
37: list.add(Utils.getBytes(referrals[1]));
38: list.add(Utils.getBytes(referrals[2]));
39:
40: Object[] values = new Object[] {
41: ASN1Integer.fromIntValue(resultCode),
42: Utils.getBytes(matchedDN),
43: Utils.getBytes(errorMessage), list };
44:
45: LdapResult result = new LdapResult();
46: result.decodeValues(values);
47:
48: assertEquals(resultCode, result.getResultCode());
49: assertEquals(matchedDN, result.getMachedDN());
50: assertEquals(errorMessage, result.getErrorMessage());
51: assertEquals(referrals.length, result.getReferrals().length);
52:
53: for (int i = 0; i < result.getReferrals().length; ++i) {
54: String referral = result.getReferrals()[i];
55: assertEquals(referrals[i], referral);
56: }
57:
58: values[3] = null;
59: result = new LdapResult();
60: result.decodeValues(values);
61:
62: assertEquals(resultCode, result.getResultCode());
63: assertEquals(matchedDN, result.getMachedDN());
64: assertEquals(errorMessage, result.getErrorMessage());
65: assertNull(result.getReferrals());
66:
67: values[3] = new ArrayList<byte[]>();
68: result = new LdapResult();
69: result.decodeValues(values);
70:
71: assertEquals(resultCode, result.getResultCode());
72: assertEquals(matchedDN, result.getMachedDN());
73: assertEquals(errorMessage, result.getErrorMessage());
74: assertNull(result.getReferrals());
75: }
76:
77: }
|