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
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.access.test.internal.cm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.eclipse.osee.framework.access.IAccessProvider;
import org.eclipse.osee.framework.access.internal.cm.CmAccessProvider;
import org.eclipse.osee.framework.access.test.mocks.MockCMWithAccessModel;
import org.eclipse.osee.framework.access.test.mocks.MockConfigurationManagementProvider;
import org.eclipse.osee.framework.core.data.IAccessContextId;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.IBasicArtifact;
import org.eclipse.osee.framework.core.model.access.AccessData;
import org.eclipse.osee.framework.core.model.access.AccessModel;
import org.eclipse.osee.framework.core.model.mocks.MockDataFactory;
import org.eclipse.osee.framework.jdk.core.util.Compare;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* Test Case for {@link CmAccessProvider}
*
* @author Roberto E. Escobar
*/
public class CmAccessProviderTest {
private static IBasicArtifact<?> expectedUser;
private static Object expectedObject;
private static IAccessContextId contextId1;
@BeforeClass
public static void setup() {
expectedUser = MockDataFactory.createArtifact(13);
expectedObject = new Object();
contextId1 = MockDataFactory.createAccessContextId(GUID.create(), "context1");
}
@Test
public void testCmProviderReturnsNull() throws OseeCoreException {
Collection<Object> objects = new ArrayList<Object>();
objects.add(expectedObject);
MockConfigurationManagementProvider cmProvider =
new MockConfigurationManagementProvider(expectedUser, expectedObject, null);
IAccessProvider accessProvider = new CmAccessProvider(cmProvider);
AccessData accessData = new AccessData();
accessProvider.computeAccess(expectedUser, objects, accessData);
Assert.assertTrue(cmProvider.wasGetCMCalled());
}
@Test
public void testCmProvider() throws OseeCoreException {
MockAccessModel accessModel = new MockAccessModel();
MockCMWithAccessModel cm =
new MockCMWithAccessModel(accessModel, expectedUser, expectedObject, false, Collections.singleton(contextId1));
Collection<Object> objects = new ArrayList<Object>();
objects.add(expectedObject);
MockConfigurationManagementProvider cmProvider =
new MockConfigurationManagementProvider(expectedUser, expectedObject, cm);
IAccessProvider accessProvider = new CmAccessProvider(cmProvider);
AccessData accessData = new AccessData();
accessProvider.computeAccess(expectedUser, objects, accessData);
Assert.assertTrue(cmProvider.wasGetCMCalled());
Assert.assertTrue(accessModel.wasComputeAccessCalled);
Assert.assertEquals(contextId1, accessModel.contextId);
Assert.assertTrue(!Compare.isDifferent(objects, accessModel.objectsToCheck));
Assert.assertEquals(accessData, accessModel.accessData);
}
private final class MockAccessModel implements AccessModel {
protected boolean wasComputeAccessCalled;
protected IAccessContextId contextId;
protected Collection<Object> objectsToCheck;
protected AccessData accessData;
@Override
public void computeAccess(IAccessContextId contextId, Collection<Object> objectsToCheck, AccessData accessData) {
wasComputeAccessCalled = true;
this.contextId = contextId;
this.objectsToCheck = objectsToCheck;
this.accessData = accessData;
}
}
}
|