1 19 20 package com.sslexplorer.tunnels; 21 22 import static org.junit.Assert.assertEquals; 23 24 import java.util.Calendar ; 25 import java.util.List ; 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 { 38 setUp("sslexplorer-agent,sslexplorer-community-tunnels"); 39 } 40 41 @Override 42 public Tunnel getEmptyResource() throws Exception { 43 Calendar calendar = Calendar.getInstance(); 44 return new DefaultTunnel(-1, "", "a ", -1, 0, false, "", "", 8080, new HostService(""), null, calendar, calendar); 45 } 46 47 @Override 48 public Tunnel getNormalResource() throws Exception { 49 Calendar 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 54 public Tunnel getNullResource() throws Exception { 55 Calendar 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 60 public Tunnel createResource(Tunnel tunnel) throws Exception { 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 66 public Tunnel updateResource(Tunnel tunnel) throws Exception { 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 73 public ResourceType getResourceType() throws Exception { 74 return TunnelPlugin.SSL_TUNNEL_RESOURCE_TYPE; 75 } 76 77 @Override 78 public Tunnel deleteResource(Tunnel resource) throws Exception { 79 return getTunnelService().removeTunnel(resource.getResourceId()); 80 } 81 82 @Override 83 public Tunnel getResource(Tunnel resource) throws Exception { 84 return getTunnelService().getTunnel(resource.getResourceId()); 85 } 86 87 protected static TunnelDatabase getTunnelService() throws Exception { 88 return TunnelDatabaseFactory.getInstance(); 89 } 90 91 @Override 92 public List <Tunnel> getAllResources() throws Exception { 93 return getTunnelService().getTunnels(); 94 } 95 96 @Test 97 public void createUncommonTunnel() throws Exception { 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 |