2b80cafea78bbfbcec2dced96f49bb4d497e7cc0
[packetcable.git] / protocol_plugins.packetcable / src / test / java / org / pcmm / test / PCMMWorkflowTest.java
1 package org.pcmm.test;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.fail;
6
7 import java.net.InetAddress;
8 import java.net.UnknownHostException;
9
10 import org.pcmm.PCMMGlobalConfig;
11 import org.junit.AfterClass;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14 import org.pcmm.rcd.ICMTS;
15 import org.pcmm.rcd.IPCMMPolicyServer;
16 import org.pcmm.rcd.IPCMMPolicyServer.IPSCMTSClient;
17 import org.pcmm.rcd.impl.CMTS;
18 import org.pcmm.rcd.impl.PCMMPolicyServer;
19
20 public class PCMMWorkflowTest {
21
22         /**
23          * CMTS emulator, when testing with a real CMTS this should be set to null
24          * and shoudln't be started
25          */
26         private static ICMTS cmts;
27         /**
28          * CMTS host address, when testing with a real CMTS this should be CMTS
29          * address
30          */
31         private static InetAddress host;
32
33         private static IPCMMPolicyServer server;
34         private static IPSCMTSClient client;
35
36         private static boolean real_cmts = false;
37
38         //@BeforeClass
39         public static void setUpBeforeClass() throws Exception {
40                 // comment this when using real CMTS
41                 // ###################################
42                 if (real_cmts == true) {
43                      cmts = null;
44                 } else {
45                      cmts = new CMTS();
46                      cmts.startServer();
47                 }
48                 // ###################################
49
50                 server = new PCMMPolicyServer();
51                 try {
52                         if (real_cmts == true) {
53                              // this should be set to the cmts host ex :
54                              host = InetAddress.getByName(PCMMGlobalConfig.DefaultCMTS);
55                              host = InetAddress.getByName("10.200.90.3");
56                              // InetAddress.getByName("my-cmts-host-name");
57                         } else {
58                              host = InetAddress.getLocalHost();
59                         }
60                         assertNotNull(host);
61                 } catch (UnknownHostException uhe) {
62                         fail("could not get host address ");
63         }
64                 setupConnection();
65         }
66
67         //@AfterClass
68         public static void tearDownAfterClass() throws Exception {
69                 tearDown();
70                 if (cmts != null)
71                         cmts.stopServer();
72         }
73
74         // @Before
75         public static void setupConnection() {
76                 client = server.requestCMTSConnection(host);
77                 assertNotNull(client);
78                 //System.out.println("MM minor version =  MM major version :: CMTS exhausted all protocol selection attempts Major = " + client.getVersionInfo().getMajorVersionNB() + " Minor = " + client.getVersionInfo().getMinorVersionNB());
79         }
80
81         // @After
82         public static void tearDown() throws Exception {
83                 assertNotNull(client);
84                 assertTrue("Client disconnection failed", client.disconnect());
85         }
86
87         
88         //@Test
89         public void testGateSet() {
90                 assertNotNull(client);
91                 assertTrue("Gate-Set failed", client.gateSet());
92         }
93
94         //@Test
95         public void testGateDelete() {
96                 assertNotNull(client);
97                 assertTrue("Gate-Delete failed", client.gateDelete());
98
99         }
100
101         //@Test
102         public void testGateInfo() {
103                 assertNotNull(client);
104                 assertTrue("Gate-Info failed", client.gateInfo());
105         }
106
107         //@Test
108         public void testGateSynchronize() {
109                 assertNotNull(client);
110                 assertTrue("Gate-Synchronize failed", client.gateSynchronize());
111         }
112
113 }