001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestServiceInfo.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.proxy;
030:
031: import javax.jbi.servicedesc.ServiceEndpoint;
032:
033: import javax.xml.namespace.QName;
034:
035: /**
036: * Tests for the InstanceEntry class
037: *
038: * @author Sun Microsystems, Inc.
039: */
040: public class TestServiceInfo extends junit.framework.TestCase {
041: /**
042: * The constructor for this testcase, forwards the test name to
043: * the jUnit TestCase base class.
044: * @param aTestName String with the name of this test.
045: */
046: public TestServiceInfo(String aTestName) {
047: super (aTestName);
048: }
049:
050: /**
051: * Setup for the test. This creates the ComponentRegistry instance
052: * and other objects needed for the tests.
053: * @throws Exception when set up fails for any reason.
054: */
055: public void setUp() throws Exception {
056: super .setUp();
057: }
058:
059: /**
060: * Cleanup for the test.
061: * @throws Exception when tearDown fails for any reason.
062: */
063: public void tearDown() throws Exception {
064: super .tearDown();
065: }
066:
067: // ============================= test methods ================================
068:
069: /**
070: * testBasics
071: * @throws Exception if an unexpected error occurs
072: */
073: public void testBasics() throws Exception {
074: QName sn;
075: ServiceEndpoint se = new ServiceEndpointImpl(sn = new QName(
076: "service"), "endpoint");
077: RegistrationInfo ri;
078: RegistrationInfo ri2;
079: ServiceInfo si;
080: String instance;
081: String instance2;
082:
083: si = new ServiceInfo(se);
084: assertEquals(si.getServiceEndpoint(), se);
085: assertEquals(si.getInstanceCount(), 0);
086: ri = new RegistrationInfo(se, "i", null, "add");
087: ri2 = new RegistrationInfo(se, "j", null, "add");
088: si.addInstance(ri);
089: assertEquals(si.getInstanceCount(), 1);
090: assertEquals(si.mDepth, 0);
091: instance = si.getInstance();
092: assertEquals(instance, "i");
093: assertEquals(si.mDepth, 1);
094: instance = si.getInstance();
095: assertEquals(instance, "i");
096: assertEquals(si.mDepth, 2);
097: si.returnInstance("i");
098: assertEquals(si.mDepth, 1);
099: si.returnInstance("i");
100: assertEquals(si.mDepth, 0);
101: si.addInstance(ri2);
102: assertEquals(si.getInstanceCount(), 2);
103: instance = si.getInstance();
104: instance2 = si.getInstance();
105: assertEquals(si.mDepth, 2);
106: assertTrue(!instance.equals(instance2));
107: si.returnInstance(instance2);
108: si.returnInstance(instance);
109: assertEquals(si.mDepth, 0);
110: assertEquals(si.removeInstance("i"), false);
111: assertEquals(si.getInstanceCount(), 1);
112: assertEquals(si.removeInstance("j"), true);
113: assertEquals(si.getInstanceCount(), 0);
114: }
115: }
|