Skip to main content
summaryrefslogtreecommitdiffstats
blob: 394bee3b7a1948a9818e9cae6c27c44faca80c2d (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
/*******************************************************************************
 * 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.mocks;

import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider.ArtifactProxy;
import org.eclipse.osee.framework.core.dsl.integration.RestrictionHandler;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessContext;
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.AttributeTypeRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.CompareOp;
import org.eclipse.osee.framework.core.dsl.oseeDsl.Condition;
import org.eclipse.osee.framework.core.dsl.oseeDsl.HierarchyRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.MatchField;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDsl;
import org.eclipse.osee.framework.core.dsl.oseeDsl.RelationMultiplicityEnum;
import org.eclipse.osee.framework.core.dsl.oseeDsl.RelationTypeRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.SimpleCondition;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactMatcher;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XArtifactType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XAttributeTypeRef;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationSideEnum;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.access.AccessDetail;
import org.eclipse.osee.framework.core.model.access.Scope;
import org.eclipse.osee.framework.core.model.mocks.MockAccessDetailCollector;
import org.junit.Assert;

/**
 * @author Roberto E. Escobar
 */
public final class DslAsserts {

   private DslAsserts() {
      // Utility class
   }

   public static void assertNullAccessDetail(RestrictionHandler<?> handler, ObjectRestriction restriction, ArtifactProxy artifactProxy, Scope expectedScopeLevel) throws OseeCoreException {
      assertAccessDetail(handler, restriction, artifactProxy, null, null, expectedScopeLevel);
   }

   public static void assertAccessDetail(RestrictionHandler<?> handler, ObjectRestriction restriction, ArtifactProxy artifactProxy, Object expectedAccessObject, PermissionEnum expectedPermission, Scope expectedScopeLevel) throws OseeCoreException {
      MockAccessDetailCollector collector = new MockAccessDetailCollector();
      handler.process(restriction, artifactProxy, collector, new Scope());
      AccessDetail<?> actualDetail = collector.getAccessDetails();
      if (expectedAccessObject == null) {
         Assert.assertNull(actualDetail);
      } else {
         Assert.assertNotNull(actualDetail);
         Assert.assertEquals(expectedPermission, actualDetail.getPermission());
         Assert.assertEquals(expectedAccessObject, actualDetail.getAccessObject());
         Assert.assertEquals(expectedScopeLevel, actualDetail.getScope());
      }
   }

   public static void assertEquals(OseeDsl model1, OseeDsl model2) {
      Assert.assertEquals(model1.getAccessDeclarations().size(), model2.getAccessDeclarations().size());
      Assert.assertEquals(model1.getArtifactMatchRefs().size(), model2.getArtifactMatchRefs().size());
      Assert.assertEquals(model1.getArtifactTypes().size(), model2.getArtifactTypes().size());
      Assert.assertEquals(model1.getAttributeTypes().size(), model2.getAttributeTypes().size());
      Assert.assertEquals(model1.getEnumOverrides().size(), model2.getEnumOverrides().size());
      Assert.assertEquals(model1.getEnumTypes().size(), model2.getEnumTypes().size());
      Assert.assertEquals(model1.getImports().size(), model2.getImports().size());
      Assert.assertEquals(model1.getRelationTypes().size(), model2.getRelationTypes().size());
   }

   public static void assertEquals(Condition condition, MatchField expField, CompareOp expOp, String expExpression) {
      SimpleCondition simpCondition = (SimpleCondition) condition;
      Assert.assertEquals(expField, simpCondition.getField());
      Assert.assertEquals(expOp, simpCondition.getOp());
      Assert.assertEquals(expExpression, simpCondition.getExpression());
   }

   public static void assertEquals(XArtifactMatcher matcher, String name) {
      Assert.assertEquals(name, matcher.getName());
   }

   public static void assertEquals(XArtifactType artifactType, String expName, String expGuid, String[] inheritsFrom, String... attributeNames) {
      Assert.assertEquals(expName, artifactType.getName());
      Assert.assertEquals(expGuid, artifactType.getTypeGuid());

      int index = 0;
      Assert.assertEquals(inheritsFrom.length, artifactType.getSuperArtifactTypes().size());
      for (XArtifactType ref : artifactType.getSuperArtifactTypes()) {
         Assert.assertEquals(inheritsFrom[index++], ref.getName());
      }

      index = 0;
      Assert.assertEquals(attributeNames.length, artifactType.getValidAttributeTypes().size());
      for (XAttributeTypeRef ref : artifactType.getValidAttributeTypes()) {
         Assert.assertEquals(attributeNames[index++], ref.getValidAttributeType().getName());
      }
   }

   public static void assertEquals(XAttributeType type, String expName, String expGuid, String baseType, String dataProvider, String min, String max, String tagger, String description, String defaultValue, String ext) {
      Assert.assertEquals(expName, type.getName());
      Assert.assertEquals(expGuid, type.getTypeGuid());

      Assert.assertEquals(baseType, type.getBaseAttributeType());
      Assert.assertEquals(dataProvider, type.getDataProvider());
      Assert.assertEquals(min, type.getMin());
      Assert.assertEquals(max, type.getMax());
      Assert.assertEquals(tagger, type.getTaggerId());
      Assert.assertEquals(description, type.getDescription());
      Assert.assertEquals(defaultValue, type.getDefaultValue());
      Assert.assertEquals(ext, type.getFileExtension());
   }

   public static void assertEquals(XRelationType type, String expName, String expGuid, String sideA, String aName, String aGuid, String sideB, String bName, String bGuid, String orderType, RelationMultiplicityEnum mult) {
      Assert.assertEquals(expName, type.getName());
      Assert.assertEquals(expGuid, type.getTypeGuid());

      XArtifactType aArt = type.getSideAArtifactType();
      Assert.assertEquals(sideA, type.getSideAName());
      Assert.assertEquals(aName, aArt.getName());
      Assert.assertEquals(aGuid, aArt.getTypeGuid());

      XArtifactType bArt = type.getSideBArtifactType();
      Assert.assertEquals(sideB, type.getSideBName());
      Assert.assertEquals(bName, bArt.getName());
      Assert.assertEquals(bGuid, bArt.getTypeGuid());

      Assert.assertEquals(orderType, type.getDefaultOrderType());
      Assert.assertEquals(mult, type.getMultiplicity());
   }

   public static void assertEquals(AccessContext context, String expName, String expGuid, String[] inheritsFrom) {
      Assert.assertEquals(expName, context.getName());
      Assert.assertEquals(expGuid, context.getGuid());

      int index = 0;
      Assert.assertEquals(inheritsFrom.length, context.getSuperAccessContexts().size());
      for (AccessContext ref : context.getSuperAccessContexts()) {
         Assert.assertEquals(inheritsFrom[index++], ref.getName());
      }
   }

   public static void assertEquals(ArtifactTypeRestriction restriction, AccessPermissionEnum permission, String artTypeName) {
      Assert.assertEquals(permission, restriction.getPermission());
      XArtifactType ref = restriction.getArtifactTypeRef();
      Assert.assertEquals(artTypeName, ref.getName());
   }

   public static void assertEquals(AttributeTypeRestriction restriction, AccessPermissionEnum permission, String attrTypeName, String artTypeName) {
      Assert.assertEquals(permission, restriction.getPermission());

      Assert.assertEquals(attrTypeName, restriction.getAttributeTypeRef().getName());

      XArtifactType ref = restriction.getArtifactTypeRef();
      Assert.assertEquals(artTypeName, ref.getName());
   }

   public static void assertEquals(RelationTypeRestriction restriction, AccessPermissionEnum permission, String relType, XRelationSideEnum sideEnum) {
      Assert.assertEquals(permission, restriction.getPermission());
      Assert.assertEquals(relType, restriction.getRelationTypeRef().getName());
      Assert.assertEquals(sideEnum, restriction.getRestrictedToSide());
   }

   public static void assertEquals(HierarchyRestriction restriction, String matcherName) {
      Assert.assertEquals(matcherName, restriction.getArtifactMatcherRef().getName());
   }
}

Back to the top