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
|
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.tests.services.resolver;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.osgi.service.resolver.*;
import org.osgi.framework.BundleException;
public class StateComparisonTest extends AbstractStateTest {
public StateComparisonTest(String testName) {
super(testName);
}
public void testAddition() throws BundleException {
State state1 = buildEmptyState();
State state2 = state1.getFactory().createState(state1);
StateDelta delta = state1.compare(state2);
assertEquals("1.0", 0, delta.getChanges().length);
delta = state2.compare(state1);
assertEquals("1.1", 0, delta.getChanges().length);
String A_MANIFEST = "Bundle-SymbolicName: org.eclipse.a\nBundle-Version: 1.0\n";
BundleDescription bundleA = state2.getFactory().createBundleDescription(parseManifest(A_MANIFEST), "org.eclipse.a", -1);
assertTrue("2.0", state2.addBundle(bundleA));
delta = state1.compare(state2);
assertEquals("2.1", 1, delta.getChanges().length);
BundleDelta removal = delta.getChanges()[0];
assertEquals("2.2", bundleA, removal.getBundle());
assertEquals("2.3", BundleDelta.REMOVED, removal.getType());
delta = state2.compare(state1);
assertEquals("3.1", 1, delta.getChanges().length);
BundleDelta addition = delta.getChanges()[0];
assertEquals("3.2", bundleA, addition.getBundle());
assertEquals("3.3", BundleDelta.ADDED, addition.getType());
}
public void testRemoval() throws BundleException {
State state1 = buildSimpleState();
State state2 = state1.getFactory().createState(state1);
StateDelta delta = state1.compare(state2);
assertEquals("1.0", 0, delta.getChanges().length);
delta = state2.compare(state1);
assertEquals("1.1", 0, delta.getChanges().length);
BundleDescription bundle1 = state1.getBundleByLocation("org.eclipse.b1");
assertNotNull("1.9", bundle1);
assertTrue("2.0", state1.removeBundle(bundle1));
delta = state1.compare(state2);
assertEquals("2.1", 1, delta.getChanges().length);
BundleDelta removal = delta.getChanges()[0];
assertEquals("2.2", bundle1, removal.getBundle());
assertEquals("2.3", BundleDelta.REMOVED, removal.getType());
delta = state2.compare(state1);
assertEquals("3.1", 1, delta.getChanges().length);
BundleDelta addition = delta.getChanges()[0];
assertEquals("3.2", bundle1, addition.getBundle());
assertEquals("3.3", BundleDelta.ADDED, addition.getType());
}
public void testUpdate() throws BundleException {
State state1 = buildSimpleState();
State state2 = state1.getFactory().createState(state1);
StateDelta delta = state1.compare(state2);
assertEquals("1.0", 0, delta.getChanges().length);
delta = state2.compare(state1);
assertEquals("1.1", 0, delta.getChanges().length);
assertNotNull("1.9", state1.getBundleByLocation("org.eclipse.b1"));
String A_MANIFEST = "Bundle-SymbolicName: org.eclipse.b1\nBundle-Version: 2.0\n";
BundleDescription bundle1 = state1.getFactory().createBundleDescription(parseManifest(A_MANIFEST), "org.eclipse.b1", 1);
assertTrue("2.0", state1.updateBundle(bundle1));
delta = state1.compare(state2);
assertEquals("2.1", 1, delta.getChanges().length);
BundleDelta update = delta.getChanges()[0];
assertEquals("2.2", bundle1, update.getBundle());
assertEquals("2.3", BundleDelta.UPDATED, update.getType());
delta = state2.compare(state1);
assertEquals("3.1", 0, delta.getChanges().length);
}
public static Test suite() {
return new TestSuite(StateComparisonTest.class);
}
}
|