1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 * 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, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18package org.apache.harmony.luni.tests.java.net;
19
20import dalvik.annotation.TestTargetClass;
21import dalvik.annotation.TestTargets;
22import dalvik.annotation.TestLevel;
23import dalvik.annotation.TestTargetNew;
24
25import java.io.Serializable;
26import java.net.HttpRetryException;
27
28import junit.framework.TestCase;
29
30import org.apache.harmony.testframework.serialization.SerializationTest;
31import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
32
33@TestTargetClass(HttpRetryException.class)
34public class HttpRetryExceptionTest extends TestCase {
35
36    private static final String LOCATION = "Http test"; //$NON-NLS-1$
37
38    private static final String DETAIL = "detail"; //$NON-NLS-1$
39
40    // comparator for HttpRetryException objects
41    private static final SerializableAssert comparator = new SerializableAssert() {
42        public void assertDeserialized(Serializable reference, Serializable test) {
43
44            HttpRetryException ref = (HttpRetryException) reference;
45            HttpRetryException tst = (HttpRetryException) test;
46
47            assertEquals("getLocation", ref.getLocation(), tst.getLocation());
48            assertEquals("responseCode", ref.responseCode(), tst.responseCode());
49            assertEquals("getReason", ref.getReason(), tst.getReason());
50            assertEquals("getMessage", ref.getMessage(), tst.getMessage());
51        }
52    };
53
54    /**
55     * @tests serialization/deserialization.
56     */
57    @TestTargetNew(
58        level = TestLevel.COMPLETE,
59        notes = "Checks serialization",
60        method = "!SerializationSelf",
61        args = {}
62    )
63    public void testSerializationSelf() throws Exception {
64        SerializationTest.verifySelf(new HttpRetryException(DETAIL, 100,
65                LOCATION), comparator);
66    }
67
68    /**
69     * @tests serialization/deserialization compatibility with RI.
70     */
71    @TestTargetNew(
72        level = TestLevel.COMPLETE,
73        notes = "Checks serialization",
74        method = "!SerializationGolden",
75        args = {}
76    )
77    public void testSerializationCompatibility() throws Exception {
78        SerializationTest.verifyGolden(this, new HttpRetryException(DETAIL,
79                100, LOCATION), comparator);
80    }
81}
82