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
|
/*******************************************************************************
* 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.dsl.integration.internal;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.dsl.integration.mocks.DslAsserts;
import org.eclipse.osee.framework.core.dsl.integration.mocks.MockArtifactProxy;
import org.eclipse.osee.framework.core.dsl.integration.mocks.MockModel;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ArtifactTypeRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.access.Scope;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Test;
/**
* Test Case for {@link ArtifactTypeRestrictionHandler}
*
* @author Roberto E. Escobar
*/
public class ArtifactTypeRestrictionHandlerTest extends BaseRestrictionHandlerTest<ArtifactTypeRestriction> {
public ArtifactTypeRestrictionHandlerTest() {
super(new ArtifactTypeRestrictionHandler(), MockModel.createArtifactTypeRestriction(),
MockModel.createAttributeTypeRestriction());
}
@Test
public void testProcessDataNotMatchesRestriction() throws OseeCoreException {
IArtifactType artifactType = CoreArtifactTypes.Requirement;
XArtifactType artifactTypeRef = MockModel.createXArtifactType(artifactType.getGuid(), artifactType.getName());
ArtifactTypeRestriction restriction = MockModel.createArtifactTypeRestriction();
restriction.setPermission(AccessPermissionEnum.ALLOW);
restriction.setArtifactTypeRef(artifactTypeRef);
ArtifactType artifactType2 = new ArtifactType(GUID.create(), "Some Artifact Type", false);
MockArtifactProxy artData = new MockArtifactProxy(GUID.create(), artifactType2);
Scope expectedScope = new Scope().add("fail");
DslAsserts.assertNullAccessDetail(getRestrictionHandler(), restriction, artData, expectedScope);
}
@Test
public void testProcessCreateAccessDetail() throws OseeCoreException {
IArtifactType artifactType = CoreArtifactTypes.Requirement;
XArtifactType artifactTypeRef = MockModel.createXArtifactType(artifactType.getGuid(), artifactType.getName());
ArtifactTypeRestriction restriction = MockModel.createArtifactTypeRestriction();
restriction.setPermission(AccessPermissionEnum.ALLOW);
restriction.setArtifactTypeRef(artifactTypeRef);
ArtifactType expectedAccessObject = new ArtifactType(artifactType.getGuid(), artifactType.getName(), false);
MockArtifactProxy artData = new MockArtifactProxy(GUID.create(), expectedAccessObject);
Scope expectedScope = new Scope();
DslAsserts.assertAccessDetail(getRestrictionHandler(), restriction, artData, expectedAccessObject,
PermissionEnum.WRITE, expectedScope);
}
@Test
public void testProcessArtifactTypeInheritance() throws OseeCoreException {
IArtifactType artifactType = CoreArtifactTypes.Artifact;
XArtifactType artifactTypeRef = MockModel.createXArtifactType(artifactType.getGuid(), artifactType.getName());
ArtifactTypeRestriction restriction = MockModel.createArtifactTypeRestriction();
restriction.setPermission(AccessPermissionEnum.ALLOW);
restriction.setArtifactTypeRef(artifactTypeRef);
ArtifactType expectedAccessObject =
new ArtifactType(CoreArtifactTypes.Requirement.getGuid(), CoreArtifactTypes.Requirement.getName(), false);
MockArtifactProxy artData = new MockArtifactProxy(GUID.create(), expectedAccessObject);
Scope expectedScope = new Scope();
DslAsserts.assertNullAccessDetail(getRestrictionHandler(), restriction, artData, expectedScope);
// Make expectedAccessObject inherit from ArtifactType
Set<ArtifactType> superTypes = new HashSet<ArtifactType>();
superTypes.add(new ArtifactType(CoreArtifactTypes.Artifact.getGuid(), CoreArtifactTypes.Artifact.getName(), false));
expectedAccessObject.setSuperTypes(superTypes);
DslAsserts.assertAccessDetail(getRestrictionHandler(), restriction, artData, expectedAccessObject,
PermissionEnum.WRITE, expectedScope);
}
}
|