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
|
/*******************************************************************************
* 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 org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactProxy;
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.ArtifactMatchRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactMatcher;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.DefaultBasicArtifact;
import org.eclipse.osee.framework.core.model.access.Scope;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Assert;
import org.junit.Test;
/**
* Test Case for {@link ArtifactMatchRestrictionHandler}
*
* @author Roberto E. Escobar
*/
public class ArtifactMatchRestrictionHandlerTest extends BaseRestrictionHandlerTest<ArtifactMatchRestriction> {
private static final MockArtifactMatchInterpreter matcher = new MockArtifactMatchInterpreter();
public ArtifactMatchRestrictionHandlerTest() {
super(new ArtifactMatchRestrictionHandler(matcher), MockModel.createArtifactMatchRestriction(),
MockModel.createAttributeTypeRestriction());
}
@Test
public void testProcessDataNotMatchesRestriction() throws OseeCoreException {
XArtifactMatcher artifactRef = MockModel.createXArtifactMatcherRef("TestArtifact");
ArtifactMatchRestriction restriction = MockModel.createArtifactMatchRestriction();
restriction.setPermission(AccessPermissionEnum.ALLOW);
restriction.setArtifactMatcherRef(artifactRef);
matcher.setMatchesResult(false);
MockArtifactProxy artData = new MockArtifactProxy(GUID.create(), null);
Scope expectedScope = new Scope().add("fail");
DslAsserts.assertNullAccessDetail(getRestrictionHandler(), restriction, artData, expectedScope);
Assert.assertEquals(artifactRef, matcher.getMatcher());
Assert.assertEquals(artData, matcher.getProxy());
}
@Test
public void testProcessCreateAccessDetail() throws OseeCoreException {
XArtifactMatcher artifactRef = MockModel.createXArtifactMatcherRef("TestArtifact");
ArtifactMatchRestriction restriction = MockModel.createArtifactMatchRestriction();
restriction.setPermission(AccessPermissionEnum.ALLOW);
restriction.setArtifactMatcherRef(artifactRef);
matcher.setMatchesResult(true);
DefaultBasicArtifact expectedAccessObject = new DefaultBasicArtifact(1, GUID.create(), "Another Artifact");
MockArtifactProxy artData = new MockArtifactProxy(expectedAccessObject);
Scope expectedScope = new Scope().add("fail");
DslAsserts.assertAccessDetail(getRestrictionHandler(), restriction, artData, expectedAccessObject,
PermissionEnum.WRITE, expectedScope);
Assert.assertEquals(artifactRef, matcher.getMatcher());
Assert.assertEquals(artData, matcher.getProxy());
}
private static final class MockArtifactMatchInterpreter extends ArtifactMatchInterpreter {
private boolean matchesResult;
private ArtifactProxy proxy;
private XArtifactMatcher matcher;
@Override
public boolean matches(XArtifactMatcher matcher, ArtifactProxy proxy) {
this.matcher = matcher;
this.proxy = proxy;
return matchesResult;
}
public ArtifactProxy getProxy() {
return proxy;
}
public XArtifactMatcher getMatcher() {
return matcher;
}
public void setMatchesResult(boolean matchesResult) {
this.matchesResult = matchesResult;
}
}
}
|