Skip to main content
summaryrefslogtreecommitdiffstats
blob: ea11a90e2a926136fb00839d6a7fcf38ee133215 (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.core.model.test.access;

import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
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.AccessDataQuery;
import org.eclipse.osee.framework.core.model.access.AccessDetail;
import org.eclipse.osee.framework.core.model.access.PermissionStatus;
import org.eclipse.osee.framework.core.model.access.Scope;
import org.eclipse.osee.framework.core.model.test.mocks.MockArtifact;
import org.eclipse.osee.framework.core.model.test.mocks.MockDataFactory;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Assert;
import org.junit.Test;

/**
 * Test Case for {@link AccessDataQuery}
 * 
 * @author Jeff C. Phillips
 */
public class AccessDataQueryTest {

   @Test
   public void testBranch() throws OseeCoreException {
      IOseeBranch branchToCheck = CoreBranches.SYSTEM_ROOT;

      TestObject testObject = getTestData();
      AccessData data = testObject.getAccessData();

      AccessDataQuery query = new AccessDataQuery(data);
      PermissionStatus status = new PermissionStatus();

      query.branchMatches(PermissionEnum.WRITE, branchToCheck, status);
      Assert.assertTrue(status.matched());

      query.branchMatches(PermissionEnum.FULLACCESS, branchToCheck, status);
      Assert.assertFalse(status.matched());
   }

   @Test
   public void testArtifactType() throws OseeCoreException {
      TestObject testObject = getTestData();
      AccessData data = testObject.getAccessData();
      IBasicArtifact<?> artifactToCheck = testObject.getArtifact();

      AccessDataQuery query = new AccessDataQuery(data);
      PermissionStatus status = new PermissionStatus();

      query.artifactTypeMatches(PermissionEnum.WRITE, artifactToCheck, status);
      Assert.assertTrue(status.matched());

      query.artifactTypeMatches(PermissionEnum.FULLACCESS, artifactToCheck, status);
      Assert.assertFalse(status.matched());
   }

   @Test
   public void testArtifact() throws OseeCoreException {
      TestObject testObject = getTestData();
      AccessData data = testObject.getAccessData();
      IBasicArtifact<?> artifactToCheck = testObject.getArtifact();

      AccessDataQuery query = new AccessDataQuery(data);
      PermissionStatus status = new PermissionStatus();

      query.artifactMatches(PermissionEnum.WRITE, artifactToCheck, status);
      Assert.assertTrue(status.matched());
   }

   @Test
   public void testAttributeType() throws OseeCoreException {
      TestObject testObject = getTestData();
      AccessData data = testObject.getAccessData();
      IBasicArtifact<?> artifactToCheck = testObject.getArtifact();

      IAttributeType attributeType = CoreAttributeTypes.ParagraphNumber;
      IAttributeType wordAttributeType = CoreAttributeTypes.WordTemplateContent;

      data.add(artifactToCheck, new AccessDetail<IAttributeType>(attributeType, PermissionEnum.WRITE, new Scope()));
      data.add(artifactToCheck, new AccessDetail<IAttributeType>(wordAttributeType, PermissionEnum.READ, new Scope()));

      AccessDataQuery query = new AccessDataQuery(data);
      PermissionStatus status = new PermissionStatus();

      query.artifactMatches(PermissionEnum.WRITE, artifactToCheck, status);
      Assert.assertTrue(status.matched());

      query.attributeTypeMatches(PermissionEnum.READ, artifactToCheck, wordAttributeType, status);
      Assert.assertTrue(status.matched());

      query.attributeTypeMatches(PermissionEnum.WRITE, artifactToCheck, wordAttributeType, status);
      Assert.assertFalse(status.matched());

      query.artifactTypeMatches(PermissionEnum.WRITE, artifactToCheck, status);
      Assert.assertTrue(status.matched());

      query.artifactTypeMatches(PermissionEnum.FULLACCESS, artifactToCheck, status);
      Assert.assertFalse(status.matched());
   }

   @Test
   public void testArtifactMatchesAll() throws OseeCoreException {
      AccessData data = new AccessData();
      IOseeBranch branch = CoreBranches.COMMON;
      IArtifactType artifactType = CoreArtifactTypes.AbstractSoftwareRequirement;
      IBasicArtifact<?> artifact1 = new MockArtifact("1", "one", branch, artifactType, 1);
      IBasicArtifact<?> artifact2 = new MockArtifact("2", "two", branch, artifactType, 2);

      data.add(artifact1, new AccessDetail<IBasicArtifact<?>>(artifact1, PermissionEnum.READ, new Scope()));
      data.add(artifact2, new AccessDetail<IBasicArtifact<?>>(artifact2, PermissionEnum.WRITE, new Scope()));

      AccessDataQuery query = new AccessDataQuery(data);

      Assert.assertTrue(query.matchesAll(PermissionEnum.READ));
      Assert.assertFalse(query.matchesAll(PermissionEnum.WRITE));
   }

   @Test
   public void testBranchMatchesAll() throws OseeCoreException {
      AccessData data = new AccessData();
      IOseeBranch common = CoreBranches.COMMON;
      IOseeBranch branch = CoreBranches.SYSTEM_ROOT;

      data.add(common, new AccessDetail<IOseeBranch>(common, PermissionEnum.READ, new Scope()));
      data.add(branch, new AccessDetail<IOseeBranch>(branch, PermissionEnum.WRITE, new Scope()));

      AccessDataQuery query = new AccessDataQuery(data);

      Assert.assertTrue(query.matchesAll(PermissionEnum.READ));
      Assert.assertFalse(query.matchesAll(PermissionEnum.WRITE));
   }

   @Test
   public void testArtifactMatches() throws OseeCoreException {
      IOseeBranch branch = CoreBranches.COMMON;
      IBasicArtifact<?> accessArtifact = new MockArtifact(GUID.create(), "test1", branch, CoreArtifactTypes.Folder, 45);
      IBasicArtifact<?> typeAccessArtifact =
         new MockArtifact(GUID.create(), "test2", branch, CoreArtifactTypes.Folder, 46);
      IBasicArtifact<?> noAccessArtifact =
         new MockArtifact(GUID.create(), "test3", branch, CoreArtifactTypes.Folder, 47);
      IArtifactType artType = TokenFactory.createArtifactType("AAMFDg_wmiYHHY5swJwA", "Folder");

      AccessDetail<?> specificArtDetail =
         MockDataFactory.createAccessDetails(accessArtifact, PermissionEnum.DENY, "",
            new Scope().add("very").add("specific"));
      AccessDetail<?> legacyArtDetail =
         MockDataFactory.createAccessDetails(accessArtifact, PermissionEnum.FULLACCESS, "", Scope.createLegacyScope());
      AccessDetail<?> typeDetail =
         MockDataFactory.createAccessDetails(artType, PermissionEnum.WRITE, "", new Scope().add("very"));

      AccessData data = new AccessData();
      data.add(accessArtifact, specificArtDetail);
      data.add(accessArtifact, legacyArtDetail);
      data.add(accessArtifact, typeDetail);
      data.add(typeAccessArtifact, typeDetail);

      AccessDataQuery query = new AccessDataQuery(data);
      PermissionStatus ps = new PermissionStatus();
      query.artifactMatches(PermissionEnum.WRITE, accessArtifact, ps);
      Assert.assertFalse(ps.matched());

      ps = new PermissionStatus();
      query.artifactMatches(PermissionEnum.WRITE, typeAccessArtifact, ps);
      Assert.assertTrue(ps.matched());

      ps = new PermissionStatus();
      query.artifactMatches(PermissionEnum.WRITE, noAccessArtifact, ps);
      Assert.assertTrue(ps.matched());
   }

   private TestObject getTestData() throws OseeCoreException {
      IOseeBranch branchToCheck = CoreBranches.SYSTEM_ROOT;
      IArtifactType artifactType = CoreArtifactTypes.AbstractSoftwareRequirement;
      IBasicArtifact<?> artifactToCheck = new MockArtifact(GUID.create(), "Hello", branchToCheck, artifactType, 12);
      AccessData data = new AccessData();

      data.add(branchToCheck, new AccessDetail<IOseeBranch>(branchToCheck, PermissionEnum.WRITE, new Scope()));
      data.add(artifactToCheck, new AccessDetail<IBasicArtifact<?>>(artifactToCheck, PermissionEnum.WRITE, new Scope()));
      data.add(artifactToCheck, new AccessDetail<IArtifactType>(artifactType, PermissionEnum.WRITE, new Scope()));

      return new TestObject(artifactToCheck, data);
   }

   private class TestObject {
      final IBasicArtifact<?> artifact;
      final AccessData accessData;

      public TestObject(IBasicArtifact<?> artifact, AccessData accessData) {
         super();
         this.artifact = artifact;
         this.accessData = accessData;
      }

      public IBasicArtifact<?> getArtifact() {
         return artifact;
      }

      public AccessData getAccessData() {
         return accessData;
      }
   }
}

Back to the top