blob: 1b26c7341ba67d65e10e7c71826d7e1a86bec270 (
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
|
/****************************************************************************
* Copyright (c) 2008 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.securestorage;
import junit.framework.TestCase;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDCreateException;
import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.internal.tests.securestorage.Activator;
import org.eclipse.ecf.storage.IIDStore;
import org.eclipse.equinox.security.storage.ISecurePreferences;
/**
*
*/
public class IDStoreTest extends TestCase {
IIDStore idStore;
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
idStore = Activator.getDefault().getIDStore();
}
protected void clearStore() {
final ISecurePreferences[] namespaces = idStore.getNamespaceNodes();
for (int i = 0; i < namespaces.length; i++) {
namespaces[i].removeNode();
}
}
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
clearStore();
idStore = null;
}
public void testIDStore() {
assertNotNull(idStore);
}
protected ISecurePreferences addGUID() throws IDCreateException {
final ID newGUID = IDFactory.getDefault().createGUID();
return idStore.getNode(newGUID);
}
protected ISecurePreferences addStringID(String value) throws IDCreateException {
final ID newID = IDFactory.getDefault().createStringID(value);
return idStore.getNode(newID);
}
public void testStoreGUID() throws Exception {
final ISecurePreferences prefs = addGUID();
assertNotNull(prefs);
}
public void testStoreGUIDs() throws Exception {
testStoreGUID();
testStoreGUID();
testStoreGUID();
}
public void testListEmptyNamespaces() throws Exception {
final ISecurePreferences[] namespaces = idStore.getNamespaceNodes();
assertNotNull(namespaces);
}
public void testOneNamespace() throws Exception {
testStoreGUID();
testStoreGUID();
final ISecurePreferences[] namespaces = idStore.getNamespaceNodes();
assertTrue(namespaces.length == 1);
}
public void testTwoNamespace() throws Exception {
testStoreGUID();
addStringID("1");
final ISecurePreferences[] namespaces = idStore.getNamespaceNodes();
assertTrue(namespaces.length == 2);
}
public void testGetNamespaceNode() throws Exception {
final ID newGUID = IDFactory.getDefault().createGUID();
idStore.getNode(newGUID);
final ISecurePreferences prefs = idStore.getNamespaceNode(newGUID.getNamespace());
assertNotNull(prefs);
assertTrue(prefs.name().equals(newGUID.getNamespace().getName()));
}
}
|