Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9a161c0588ecce92ae1099c43a49047a04dc5018 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*******************************************************************************
* Copyright (c) 2010 Composent, Inc. and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*   Composent, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.ecf.tests.server.generic;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;

import org.eclipse.ecf.server.generic.IGenericServerContainerGroup;
import org.eclipse.ecf.server.generic.IGenericServerContainerGroupFactory;

import junit.framework.TestCase;

public class GenericServerContainerGroupFactoryTest extends TestCase {

	private static final String hostname = "localhost";
	private static final int port = 4000;
	private InetAddress allAddress;
	
	private IGenericServerContainerGroupFactory gscgFactory;
	
	protected void setUp() throws Exception {
		super.setUp();
		gscgFactory = Activator.getDefault().getGenericServerContainerGroupFactory();
		allAddress = new InetSocketAddress((InetAddress) null,0).getAddress();
	}
	
	protected void tearDown() throws Exception {
		super.tearDown();
		gscgFactory = null;
	}
	
	protected IGenericServerContainerGroup createContainerGroup(InetAddress bindAddress) throws Exception {
		return gscgFactory.createContainerGroup(hostname, port, bindAddress, null);
	}
	
	protected IGenericServerContainerGroup createContainerGroup() throws Exception {
		return createContainerGroup(null);
	}
	
	protected void removeContainerGroup() throws Exception {
		gscgFactory.removeContainerGroup(hostname, port);
	}
	
	public void testCreateContainerGroup() throws Exception {
		IGenericServerContainerGroup containerGroup = createContainerGroup(null);
		assertNotNull(containerGroup);
		URI groupEndpoint = containerGroup.getGroupEndpoint();
		assertNotNull(groupEndpoint);
		assertTrue(groupEndpoint.getHost().equals(hostname));
		assertTrue(groupEndpoint.getPort()==port);
		removeContainerGroup();
	}
	
	public void testCreateContainerGroupListen() throws Exception {
		IGenericServerContainerGroup containerGroup = createContainerGroup(null);
		assertNotNull(containerGroup);
		URI groupEndpoint = containerGroup.getGroupEndpoint();
		assertNotNull(groupEndpoint);
		assertTrue(groupEndpoint.getHost().equals(hostname));
		assertTrue(groupEndpoint.getPort()==port);
		assertTrue(!containerGroup.isListening());
		containerGroup.startListening();
		assertTrue(containerGroup.isListening());
		containerGroup.stopListening();
		assertTrue(!containerGroup.isListening());
		removeContainerGroup();
	}
	

	public void testCreateContainerGroupWithBindAddress() throws Exception {
		IGenericServerContainerGroup containerGroup = createContainerGroup(this.allAddress);
		assertNotNull(containerGroup);
		URI groupEndpoint = containerGroup.getGroupEndpoint();
		assertNotNull(groupEndpoint);
		assertTrue(groupEndpoint.getHost().equals(hostname));
		assertTrue(groupEndpoint.getPort()==port);
		removeContainerGroup();
	}
	
	public void testCreateContainerGroupWithBindAddressListen() throws Exception {
		IGenericServerContainerGroup containerGroup = createContainerGroup(this.allAddress);
		assertNotNull(containerGroup);
		URI groupEndpoint = containerGroup.getGroupEndpoint();
		assertNotNull(groupEndpoint);
		assertTrue(groupEndpoint.getHost().equals(hostname));
		assertTrue(groupEndpoint.getPort()==port);
		assertTrue(!containerGroup.isListening());
		containerGroup.startListening();
		assertTrue(containerGroup.isListening());
		containerGroup.stopListening();
		assertTrue(!containerGroup.isListening());
		removeContainerGroup();
	}
	

	public void testGetContainerGroup() throws Exception {
		IGenericServerContainerGroup gscg = gscgFactory.getContainerGroup(hostname, port);
		assertNull(gscg);
		createContainerGroup();
		gscg = gscgFactory.getContainerGroup(hostname, port);
		assertNotNull(gscg);
		URI groupEndpoint = gscg.getGroupEndpoint();
		assertNotNull(groupEndpoint);
		assertTrue(groupEndpoint.getHost().equals(hostname));
		assertTrue(groupEndpoint.getPort()==port);
		removeContainerGroup();
	}

	public void testGetContainerGroups() throws Exception {
		IGenericServerContainerGroup[] gscgs = gscgFactory.getContainerGroups();
		assertNotNull(gscgs);
		assertTrue(gscgs.length == 0);
		createContainerGroup();
		gscgs = gscgFactory.getContainerGroups();
		assertNotNull(gscgs);
		assertTrue(gscgs.length == 1);
		URI groupEndpoint = gscgs[0].getGroupEndpoint();
		assertNotNull(groupEndpoint);
		assertTrue(groupEndpoint.getHost().equals(hostname));
		assertTrue(groupEndpoint.getPort()==port);
		removeContainerGroup();
	}

}

Back to the top