Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d1e57ee9d64a75be6bbc1728626cf51ef9cdefa4 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/****************************************************************************
* Copyright (c) 2004 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.core;

import java.util.Arrays;

import org.eclipse.ecf.core.AbstractContainer;
import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.ContainerCreateException;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.ContainerTypeDescription;
import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.core.identity.Namespace;
import org.eclipse.ecf.core.provider.IContainerInstantiator;
import org.eclipse.ecf.core.security.IConnectContext;

public class ContainerFactoryCreateTest extends ContainerFactoryAbstractTestCase {

	private static final String INTENTTWO = "intenttwo";

	private static final String INTENTONE = "intentone";

	protected static final String CONTAINER_TYPE_NAME = ContainerFactoryCreateTest.class.getName();

	protected static final String BASE_CONTAINER_TYPE_NAME = "ecf.base";

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.core.ContainerFactoryAbstractTestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		getFixture().addDescription(createContainerTypeDescription());
	}

	/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.core.ContainerFactoryAbstractTestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		getFixture().removeDescription(createContainerTypeDescription());
		super.tearDown();
	}

	protected ContainerTypeDescription createContainerTypeDescription() {
		return new ContainerTypeDescription(CONTAINER_TYPE_NAME, new IContainerInstantiator() {
			public IContainer createInstance(ContainerTypeDescription description, Object[] parameters) throws ContainerCreateException {
				return new AbstractContainer() {
					public void connect(ID targetID, IConnectContext connectContext) throws ContainerConnectException {
					}

					public void disconnect() {
					}

					public Namespace getConnectNamespace() {
						return null;
					}

					public ID getConnectedID() {
						return null;
					}

					public ID getID() {
						return null;
					}

				};
			}

			public String[] getSupportedAdapterTypes(ContainerTypeDescription description) {
				return new String[] {"one"};
			}

			public Class[][] getSupportedParameterTypes(ContainerTypeDescription description) {
				return new Class[][] {{String.class, Class.class}};
			}

			public String[] getSupportedIntents(
					ContainerTypeDescription description) {
				return new String[] { INTENTONE, INTENTTWO } ;
			}
		}, DESCRIPTION);
	}

	public void testCreateContainer1() throws Exception {
		final IContainer container = ContainerFactory.getDefault().createContainer(CONTAINER_TYPE_NAME);
		assertNotNull(container);
	}

	public void testCreateContainer2() throws Exception {
		final IContainer container = ContainerFactory.getDefault().createContainer(CONTAINER_TYPE_NAME);
		assertNotNull(container);
	}

	public void testCreateContainer3() throws Exception {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		assertNotNull(desc);
		final IContainer container = ContainerFactory.getDefault().createContainer(desc);
		assertNotNull(container);
	}

	public void testCreateContainer4() throws Exception {
		try {
			ContainerFactory.getDefault().createContainer((String) null, (Object[]) null);
			fail();
		} catch (final ContainerCreateException e) {
		}
	}

	public void testCreateContainer5() throws Exception {
		try {
			ContainerFactory.getDefault().createContainer((ContainerTypeDescription) null);
			fail();
		} catch (final ContainerCreateException e) {
		}
	}

	public void testCreateContainer6() throws Exception {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		assertNotNull(desc);
		final IContainer container = ContainerFactory.getDefault().createContainer(desc, IDFactory.getDefault().createGUID());
		assertNotNull(container);
	}

	public void testCreateContainer7() throws Exception {
		final IContainer container = ContainerFactory.getDefault().createContainer(CONTAINER_TYPE_NAME, IDFactory.getDefault().createGUID());
		assertNotNull(container);
	}

	public void testCreateContainer8() throws Exception {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		assertNotNull(desc);
		final IContainer container = ContainerFactory.getDefault().createContainer(desc, IDFactory.getDefault().createGUID(), new Object[] {"param"});
		assertNotNull(container);
	}

	public void testCreateContainer9() throws Exception {
		final IContainer container = ContainerFactory.getDefault().createContainer(CONTAINER_TYPE_NAME, IDFactory.getDefault().createGUID(), new Object[] {"param"});
		assertNotNull(container);
	}

	public void testCreateBaseContainer0() throws Exception {
		final IContainer base = ContainerFactory.getDefault().createContainer();
		assertNotNull(base);
	}

	public void testCreateBaseContainer1() throws Exception {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(BASE_CONTAINER_TYPE_NAME);
		assertNotNull(desc);
		final IContainer base = ContainerFactory.getDefault().createContainer(desc, IDFactory.getDefault().createGUID());
		assertNotNull(base);
	}

	public void testCreateBaseContainer2() throws Exception {
		final IContainer base = ContainerFactory.getDefault().createContainer(BASE_CONTAINER_TYPE_NAME, IDFactory.getDefault().createGUID());
		assertNotNull(base);
	}

	public void testCreateBaseContainer3() throws Exception {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(BASE_CONTAINER_TYPE_NAME);
		assertNotNull(desc);
		final IContainer base = ContainerFactory.getDefault().createContainer(desc, new Object[] {IDFactory.getDefault().createGUID().getName()});
		assertNotNull(base);
	}

	public void testCreateBaseContainer4() throws Exception {
		final IContainer base = ContainerFactory.getDefault().createContainer(BASE_CONTAINER_TYPE_NAME, new Object[] {IDFactory.getDefault().createGUID()});
		assertNotNull(base);
	}

	public void testCreateBaseContainer5() throws Exception {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(BASE_CONTAINER_TYPE_NAME);
		assertNotNull(desc);
		final IContainer base = ContainerFactory.getDefault().createContainer(desc, IDFactory.getDefault().createGUID(), new Object[] {"param"});
		assertNotNull(base);
	}

	public void testCreateBaseContainer6() throws Exception {
		final IContainer base = ContainerFactory.getDefault().createContainer(BASE_CONTAINER_TYPE_NAME, IDFactory.getDefault().createGUID(), new Object[] {"param"});
		assertNotNull(base);
	}

	public void testContainerTypeDescriptionGetName() {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		assertTrue(desc.getName().equals(CONTAINER_TYPE_NAME));
	}

	public void testContainerTypeDescriptionGetDescription() {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		assertTrue(desc.getDescription().equals(DESCRIPTION));
	}

	public void testContainerTypeDescriptionGetSupportedAdapterTypes() {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		final String[] adapterTypes = desc.getSupportedAdapterTypes();
		assertTrue(adapterTypes.length > 0);
		assertTrue(Arrays.asList(adapterTypes).contains("one"));
	}

	public void testContainerTypeDescriptionGetSupportedParemeterTypes() {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		final Class[][] parameterTypes = desc.getSupportedParameterTypes();
		assertTrue(parameterTypes.length == 1);
		assertTrue(parameterTypes[0].length == 2);
		assertTrue(parameterTypes[0][0].equals(String.class));
		assertTrue(parameterTypes[0][1].equals(Class.class));

	}
	public void testContainerTypeDescriptionGetSupportedIntents() {
		final ContainerTypeDescription desc = ContainerFactory.getDefault().getDescriptionByName(CONTAINER_TYPE_NAME);
		final String[] intents = desc.getSupportedIntents();
		assertTrue(intents.length == 2);
		assertTrue(intents[0] == INTENTONE);
		assertTrue(intents[1] == INTENTTWO);
	}
}

Back to the top