jtulach@292
|
1 |
package org.apidesign.aserverinfo.test;
|
jtulach@91
|
2 |
|
jtulach@340
|
3 |
import java.util.logging.Logger;
|
jtulach@340
|
4 |
import java.util.logging.Level;
|
jtulach@91
|
5 |
import java.net.MalformedURLException;
|
jtulach@91
|
6 |
import java.net.URL;
|
jtulach@292
|
7 |
import org.apidesign.aserverinfo.cummulativefactory.ServerConnector;
|
jtulach@292
|
8 |
import org.apidesign.aserverinfo.spi.NameProvider;
|
jtulach@292
|
9 |
import org.apidesign.aserverinfo.spi.ResetHandler;
|
jtulach@292
|
10 |
import org.apidesign.aserverinfo.spi.URLProvider;
|
jtulach@91
|
11 |
import org.junit.After;
|
jtulach@91
|
12 |
import org.junit.Before;
|
jtulach@91
|
13 |
import org.junit.Test;
|
jtulach@91
|
14 |
import static org.junit.Assert.*;
|
jtulach@91
|
15 |
|
jtulach@294
|
16 |
public class CummulativeFactoryTest {
|
jtulach@91
|
17 |
|
jtulach@294
|
18 |
public CummulativeFactoryTest() {
|
jtulach@91
|
19 |
}
|
jtulach@91
|
20 |
|
jtulach@91
|
21 |
@Before
|
jtulach@91
|
22 |
public void setUp() {
|
jtulach@91
|
23 |
}
|
jtulach@91
|
24 |
|
jtulach@91
|
25 |
@After
|
jtulach@91
|
26 |
public void tearDown() {
|
jtulach@91
|
27 |
}
|
jtulach@91
|
28 |
|
jtulach@91
|
29 |
@Test
|
jtulach@91
|
30 |
public void showUseOfCumulativeFactory() throws Exception {
|
jtulach@154
|
31 |
Prov p = new Prov();
|
jtulach@292
|
32 |
NameProvider np = p;
|
jtulach@292
|
33 |
URLProvider up = p;
|
jtulach@292
|
34 |
ResetHandler res = p;
|
jtulach@292
|
35 |
ServerConnector inf;
|
jtulach@91
|
36 |
|
jtulach@292
|
37 |
// BEGIN: ServerConnector.cumulative.creation
|
jtulach@292
|
38 |
inf = ServerConnector.empty().nameProvider(np).urlProvider(up).reset(res);
|
jtulach@292
|
39 |
// END: ServerConnector.cumulative.creation
|
jtulach@91
|
40 |
|
jtulach@154
|
41 |
assertEquals("API Design Server", inf.getName());
|
jtulach@154
|
42 |
assertEquals("http://www.apidesign.org", inf.getURL().toExternalForm());
|
jtulach@154
|
43 |
inf.reset();
|
jtulach@154
|
44 |
assertEquals("Once reset", 1, p.resets);
|
jtulach@91
|
45 |
|
jtulach@91
|
46 |
}
|
jtulach@114
|
47 |
|
jtulach@114
|
48 |
@Test
|
jtulach@114
|
49 |
public void showVerboseUseOfCumulativeFactory() throws Exception {
|
jtulach@114
|
50 |
Prov prov = new Prov();
|
jtulach@292
|
51 |
ServerConnector info;
|
jtulach@114
|
52 |
|
jtulach@292
|
53 |
// BEGIN: ServerConnector.cumulative.creation.verbose
|
jtulach@292
|
54 |
ServerConnector empty = ServerConnector.empty();
|
jtulach@292
|
55 |
ServerConnector name = empty.nameProvider(prov);
|
jtulach@292
|
56 |
ServerConnector urlAndName = name.urlProvider(prov);
|
jtulach@114
|
57 |
info = urlAndName.reset(prov);
|
jtulach@292
|
58 |
// END: ServerConnector.cumulative.creation.verbose
|
jtulach@114
|
59 |
|
jtulach@114
|
60 |
assertEquals("API Design Server", info.getName());
|
jtulach@114
|
61 |
assertEquals("http://www.apidesign.org", info.getURL().toExternalForm());
|
jtulach@114
|
62 |
info.reset();
|
jtulach@114
|
63 |
assertEquals("Once reset", 1, prov.resets);
|
jtulach@114
|
64 |
|
jtulach@114
|
65 |
}
|
jtulach@114
|
66 |
|
jtulach@114
|
67 |
|
jtulach@292
|
68 |
private static class Prov implements NameProvider, URLProvider, ResetHandler {
|
jtulach@114
|
69 |
int resets;
|
jtulach@114
|
70 |
|
jtulach@114
|
71 |
public String getName() {
|
jtulach@114
|
72 |
return "API Design Server";
|
jtulach@114
|
73 |
}
|
jtulach@114
|
74 |
|
jtulach@114
|
75 |
public URL getURL() {
|
jtulach@114
|
76 |
try {
|
jtulach@114
|
77 |
return new URL("http://www.apidesign.org");
|
jtulach@114
|
78 |
} catch (MalformedURLException ex) {
|
jtulach@340
|
79 |
Logger.getLogger(CummulativeFactoryTest.class.getName()).log(Level.SEVERE, null, ex);
|
jtulach@114
|
80 |
return null;
|
jtulach@114
|
81 |
}
|
jtulach@114
|
82 |
}
|
jtulach@114
|
83 |
|
jtulach@114
|
84 |
public void reset() {
|
jtulach@114
|
85 |
resets++;
|
jtulach@114
|
86 |
}
|
jtulach@114
|
87 |
|
jtulach@114
|
88 |
}
|
jtulach@114
|
89 |
|
jtulach@91
|
90 |
} |