author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 15 Nov 2008 08:25:52 +0100 | |
changeset 295 | d6fa728fb2ba |
child 340 | 9c1a298e51a9 |
permissions | -rw-r--r-- |
jtulach@295 | 1 |
package org.apidesign.aserverinfo.test; |
jtulach@295 | 2 |
|
jtulach@295 | 3 |
import java.net.MalformedURLException; |
jtulach@295 | 4 |
import java.net.URL; |
jtulach@295 | 5 |
import org.apidesign.aserverinfo.magicalbagfactory.ServerConnector; |
jtulach@295 | 6 |
import org.apidesign.aserverinfo.spi.NameProvider; |
jtulach@295 | 7 |
import org.apidesign.aserverinfo.spi.ResetHandler; |
jtulach@295 | 8 |
import org.apidesign.aserverinfo.spi.URLProvider; |
jtulach@295 | 9 |
import org.junit.After; |
jtulach@295 | 10 |
import org.junit.Before; |
jtulach@295 | 11 |
import org.junit.Test; |
jtulach@295 | 12 |
import static org.junit.Assert.*; |
jtulach@295 | 13 |
import org.openide.util.Exceptions; |
jtulach@295 | 14 |
import org.openide.util.Lookup; |
jtulach@295 | 15 |
import org.openide.util.lookup.AbstractLookup; |
jtulach@295 | 16 |
import org.openide.util.lookup.InstanceContent; |
jtulach@295 | 17 |
|
jtulach@295 | 18 |
public class MagicalBagFactoryTest { |
jtulach@295 | 19 |
|
jtulach@295 | 20 |
public MagicalBagFactoryTest() { |
jtulach@295 | 21 |
} |
jtulach@295 | 22 |
|
jtulach@295 | 23 |
@Before |
jtulach@295 | 24 |
public void setUp() { |
jtulach@295 | 25 |
} |
jtulach@295 | 26 |
|
jtulach@295 | 27 |
@After |
jtulach@295 | 28 |
public void tearDown() { |
jtulach@295 | 29 |
} |
jtulach@295 | 30 |
|
jtulach@295 | 31 |
@Test |
jtulach@295 | 32 |
public void showUseOfMagicalBagFactory() throws Exception { |
jtulach@295 | 33 |
Prov provider = new Prov(); |
jtulach@295 | 34 |
ServerConnector inf; |
jtulach@295 | 35 |
|
jtulach@295 | 36 |
// BEGIN: ServerConnector.magicalbag.creation |
jtulach@295 | 37 |
InstanceContent magicalContent = new InstanceContent(); |
jtulach@295 | 38 |
Lookup magicalBag = new AbstractLookup(magicalContent); |
jtulach@295 | 39 |
magicalContent.add(provider); |
jtulach@295 | 40 |
|
jtulach@295 | 41 |
inf = ServerConnector.create(magicalBag); |
jtulach@295 | 42 |
// END: ServerConnector.magicalbag.creation |
jtulach@295 | 43 |
|
jtulach@295 | 44 |
assertEquals("API Design Server", inf.getName()); |
jtulach@295 | 45 |
assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm()); |
jtulach@295 | 46 |
inf.reset(); |
jtulach@295 | 47 |
assertEquals("Once reset", 1, provider.resets); |
jtulach@295 | 48 |
|
jtulach@295 | 49 |
provider.resets = 0; |
jtulach@295 | 50 |
// BEGIN: ServerConnector.magicalbag.change |
jtulach@295 | 51 |
magicalContent.remove(provider); |
jtulach@295 | 52 |
inf.reset(); |
jtulach@295 | 53 |
assertEquals("No reset called now", 0, provider.resets); |
jtulach@295 | 54 |
// END: ServerConnector.magicalbag.change |
jtulach@295 | 55 |
} |
jtulach@295 | 56 |
|
jtulach@295 | 57 |
private static class Prov implements NameProvider, URLProvider, ResetHandler { |
jtulach@295 | 58 |
int resets; |
jtulach@295 | 59 |
|
jtulach@295 | 60 |
public String getName() { |
jtulach@295 | 61 |
return "API Design Server"; |
jtulach@295 | 62 |
} |
jtulach@295 | 63 |
|
jtulach@295 | 64 |
public URL getURL() { |
jtulach@295 | 65 |
try { |
jtulach@295 | 66 |
return new URL("http://www.apidesign.org"); |
jtulach@295 | 67 |
} catch (MalformedURLException ex) { |
jtulach@295 | 68 |
Exceptions.printStackTrace(ex); |
jtulach@295 | 69 |
return null; |
jtulach@295 | 70 |
} |
jtulach@295 | 71 |
} |
jtulach@295 | 72 |
|
jtulach@295 | 73 |
public void reset() { |
jtulach@295 | 74 |
resets++; |
jtulach@295 | 75 |
} |
jtulach@295 | 76 |
|
jtulach@295 | 77 |
} |
jtulach@295 | 78 |
|
jtulach@295 | 79 |
} |