KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tunnels > TunnelsTests


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.tunnels;
21
22 import static org.junit.Assert.assertEquals;
23
24 import java.util.Calendar JavaDoc;
25 import java.util.List JavaDoc;
26
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29
30 import com.sslexplorer.boot.HostService;
31 import com.sslexplorer.policyframework.ResourceType;
32 import com.sslexplorer.testcontainer.policyframework.AbstractTestPolicyEnabledResource;
33
34 public class TunnelsTests extends AbstractTestPolicyEnabledResource<Tunnel> {
35
36     @BeforeClass
37     public static void oneTimeSetUp() throws Exception JavaDoc {
38         setUp("sslexplorer-agent,sslexplorer-community-tunnels");
39     }
40
41     @Override JavaDoc
42     public Tunnel getEmptyResource() throws Exception JavaDoc {
43         Calendar JavaDoc calendar = Calendar.getInstance();
44         return new DefaultTunnel(-1, "", "a ", -1, 0, false, "", "", 8080, new HostService(""), null, calendar, calendar);
45     }
46
47     @Override JavaDoc
48     public Tunnel getNormalResource() throws Exception JavaDoc {
49         Calendar JavaDoc calendar = Calendar.getInstance();
50         return new DefaultTunnel(getDefaultRealm().getRealmID(), "tunnel", "a tunnel", -1, 0, false, "TCP", "username", 8080, new HostService("localhost"), null, calendar, calendar);
51     }
52
53     @Override JavaDoc
54     public Tunnel getNullResource() throws Exception JavaDoc {
55         Calendar JavaDoc calendar = Calendar.getInstance();
56         return new DefaultTunnel(-1, null, null, -1, 0, false, null, null, 8080, new HostService(""), null, calendar, calendar);
57     }
58
59     @Override JavaDoc
60     public Tunnel createResource(Tunnel tunnel) throws Exception JavaDoc {
61         return getTunnelService().createTunnel(tunnel.getRealmID(), tunnel.getResourceName(), tunnel.getResourceDescription(), tunnel.getType(), tunnel.isAutoStart(),
62             tunnel.getTransport(), tunnel.getUsername(), tunnel.getSourcePort(), tunnel.getDestination(), tunnel.getSourceInterface());
63     }
64     
65     @Override JavaDoc
66     public Tunnel updateResource(Tunnel tunnel) throws Exception JavaDoc {
67         getTunnelService().updateTunnel(tunnel.getResourceId(), tunnel.getResourceName(), tunnel.getResourceDescription(), tunnel.getType(), tunnel.isAutoStart(),
68             tunnel.getTransport(), tunnel.getUsername(), tunnel.getSourcePort(), tunnel.getDestination(), tunnel.getSourceInterface());
69         return getTunnelService().getTunnel(tunnel.getResourceId());
70     }
71     
72     @Override JavaDoc
73     public ResourceType getResourceType() throws Exception JavaDoc {
74       return TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE;
75     }
76
77     @Override JavaDoc
78     public Tunnel deleteResource(Tunnel resource) throws Exception JavaDoc {
79         return getTunnelService().removeTunnel(resource.getResourceId());
80     }
81
82     @Override JavaDoc
83     public Tunnel getResource(Tunnel resource) throws Exception JavaDoc {
84         return getTunnelService().getTunnel(resource.getResourceId());
85     }
86     
87     protected static TunnelDatabase getTunnelService() throws Exception JavaDoc {
88         return TunnelDatabaseFactory.getInstance();
89     }
90     
91     @Override JavaDoc
92     public List JavaDoc<Tunnel> getAllResources() throws Exception JavaDoc {
93         return getTunnelService().getTunnels();
94     }
95     
96     @Test
97     public void createUncommonTunnel() throws Exception JavaDoc {
98         DefaultTunnel tunnel = new DefaultTunnel(-1, "à2à£$-_=+$%%^", "à2à-_=+2à£$", -1, 0, false,
99             "à2à£$-_=+$%%^w", "à2à£$%$%%^grre-_=+", 8080, new HostService("localhost"), null, Calendar.getInstance(), Calendar.getInstance());
100         assertEquals("There should not be any Tunnel", 0, getTunnelService().getTunnels().size());
101         Tunnel createdTunnel = createResource(tunnel);
102         assertEquals("There should not be any Tunnel", 1, getTunnelService().getTunnels().size());
103         deleteResource(createdTunnel);
104     }
105 }
Popular Tags