001: /****************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ****************************************************************************/package net.sourceforge.cruisecontrol.distributed.core;
037:
038: import junit.framework.TestCase;
039: import net.sourceforge.cruisecontrol.builders.DistributedMasterBuilderTest;
040: import net.jini.core.discovery.LookupLocator;
041: import net.jini.discovery.DiscoveryListener;
042:
043: import java.net.MalformedURLException;
044:
045: import org.apache.log4j.Logger;
046:
047: public class MulticastDiscoveryTest extends TestCase {
048:
049: private static final Logger LOG = Logger
050: .getLogger(MulticastDiscoveryTest.class);
051:
052: /*
053: private MulticastDiscovery discovery;
054:
055: protected void setUp() throws Exception {
056: DistributedMasterBuilderTest.setupInsecurePolicy();
057: discovery = new MulticastDiscovery();
058: }
059:
060: protected void tearDown() throws Exception {
061: discovery.terminate();
062: }
063: */
064:
065: /*
066: public void testMulticastDiscovery() throws Exception {
067: // TODO: There are certainly tests that could be written here, but without automating startup and shutdown of
068: // Jini these shouldn't be run with the rest of the the Cruise Control tests. Should we look into this
069: // automation for purposes of testing?
070: // NOTE: I've added nasty, but working Jini startup/shutdown methods to DistributedMasterBuilderTest
071:
072: assertNull(discovery.findMatchingServiceAndClaim());
073: }
074: */
075:
076: /*
077: public void testServiceDiscListenerToString() throws Exception {
078: final MulticastDiscovery.ServiceDiscListener serviceDiscListener = discovery.getServiceDiscListener();
079:
080: final ServiceID serviceID = new ServiceID(1, 1);
081: final PropertyEntry entry1 = new PropertyEntry("name1", "value1");
082: final String service = "fakeService";
083: final ServiceItem serviceItem = new ServiceItem(serviceID, service, new Entry[] { entry1 });
084: final Object source = "fakeSource";
085: final String action = "fakeAction";
086: final ServiceDiscoveryEvent event = new ServiceDiscoveryEvent(source, serviceItem, serviceItem);
087:
088: assertEquals(getExpectedToString(action, service, entry1),
089: serviceDiscListener.buildDiscoveryMsg(event, action));
090: }
091: private static String getExpectedToString(final String action, final Object service, final PropertyEntry entry) {
092: return "\nService " + action + ": PostEvent: class " + service.getClass().getName()
093: + "; ID:00000000-0000-0001-0000-000000000001\n"
094: + "\tEntries:\n"
095: + "\t[(name=" + entry.name + ",value=" + entry.value + ")]\n";
096: }
097: */
098:
099: public void testDummy() {
100: }
101:
102: public static MulticastDiscovery getLocalDiscovery()
103: throws MalformedURLException {
104: final LookupLocator[] unicastLocators = new LookupLocator[] { new LookupLocator(
105: DistributedMasterBuilderTest.JINI_URL_LOCALHOST) };
106:
107: return new MulticastDiscovery(unicastLocators);
108: }
109:
110: /**
111: * Expose method intended only for use by unit tests.
112: * @param multicastDiscovery lookup helper
113: */
114: public static void setDiscovery(
115: final MulticastDiscovery multicastDiscovery) {
116: final long begin = System.currentTimeMillis();
117:
118: MulticastDiscovery.setDiscovery(multicastDiscovery);
119:
120: LOG
121: .info(DistributedMasterBuilderTest.MSG_PREFIX_STATS
122: + "Unit test Agent discovery took: "
123: + (System.currentTimeMillis() - begin) / 1000f
124: + " sec");
125: }
126:
127: /** @return true if the discovery singleton variable is set, intended only for unit tests. */
128: public static boolean isDiscoverySet() {
129: return MulticastDiscovery.isDiscoverySet();
130: }
131:
132: /**
133: * Expose method intended only for use by unit tests.
134: * @return true if any LUS has been found.
135: */
136: public static boolean isDiscovered() {
137: return MulticastDiscovery.isDiscovered();
138: }
139:
140: public static void addDiscoveryListener(
141: final DiscoveryListener discoveryListener) {
142: MulticastDiscovery.addDiscoveryListener(discoveryListener);
143: }
144:
145: public static void removeDiscoveryListener(
146: final DiscoveryListener discoveryListener) {
147: MulticastDiscovery.removeDiscoveryListener(discoveryListener);
148: }
149:
150: }
|