Skip to main content
summaryrefslogtreecommitdiffstats
blob: 955e15cd9365308ca1d846f096c1020517cb1d18 (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
/*******************************************************************************
 * 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.util;

import java.io.ByteArrayOutputStream;
import java.util.Iterator;
import java.util.List;
import org.eclipse.osee.framework.core.dsl.OseeDslResourceUtil;
import org.eclipse.osee.framework.core.dsl.integration.mocks.DslAsserts;
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.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.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.XRelationSideEnum;
import org.eclipse.osee.framework.core.dsl.oseeDsl.XRelationType;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.junit.Assert;
import org.junit.Test;

/**
 * Test Case for {@link ModelUtil}
 * 
 * @author Roberto E. Escobar
 */
public class ModelUtilTest {

   private static final String TYPE_TEST_INPUT = "testTypeModel.osee";
   private static final String ACCESS_TEST_INPUT = "testAccessModel.osee";

   @Test
   public void testModelUtilLoadType() throws Exception {
      String rawXTextData = Lib.fileToString(getClass(), TYPE_TEST_INPUT);

      OseeDsl model1 = OseeDslResourceUtil.loadModel("osee:/text.osee", rawXTextData).getModel();

      Assert.assertEquals(5, model1.getArtifactTypes().size());
      Iterator<XArtifactType> type1 = model1.getArtifactTypes().iterator();
      // @formatter:off
      DslAsserts.assertEquals(type1.next(), "Artifact", "0x0000000000000001", new String[0], "Name", "Annotation");
      DslAsserts.assertEquals(type1.next(), "Requirement", "0x0000000000000015", new String[] {"Artifact"}, "WordML");
      DslAsserts.assertEquals(type1.next(), "Software Requirement", "0x0000000000000018", new String[] {"Requirement"});
      DslAsserts.assertEquals(type1.next(), "System Requirement", "0x000000000000001E", new String[] {"Requirement"});
      DslAsserts.assertEquals(type1.next(), "SubSystem Requirement", "0x000000000000001D", new String[] {"Requirement"});
      // @formatter:on

      Assert.assertEquals(3, model1.getAttributeTypes().size());
      Iterator<XAttributeType> type2 = model1.getAttributeTypes().iterator();
      DslAsserts.assertEquals(type2.next(), "Name", "0x1000000000000070", "StringAttribute",
         "DefaultAttributeDataProvider", "1", "1", "DefaultAttributeTaggerProvider", //
         "Descriptive Name", "unnamed", null);
      DslAsserts.assertEquals(type2.next(), "Annotation", "0x1000000000000076", "CompressedContentAttribute",
         "UriAttributeDataProvider", "0", "unlimited", "DefaultAttributeTaggerProvider", //
         "the version \'1.0\' is this \"1.2.0\"", null, null);
      DslAsserts.assertEquals(type2.next(), "WordML", "0x100000000000007A", "WordAttribute",
         "UriAttributeDataProvider", "0", "1", "XmlAttributeTaggerProvider",
         "value must comply with WordML xml schema",
         "<w:p xmlns:w=\"http://schemas.microsoft.com/office/word/2003/wordml\"><w:r><w:t></w:t></w:r></w:p>", "xml");

      Assert.assertEquals(1, model1.getRelationTypes().size());
      Iterator<XRelationType> type3 = model1.getRelationTypes().iterator();
      DslAsserts.assertEquals(type3.next(), "Requirement Relation", "0x2000000000000157", "requirement-sideA",
         "Requirement", "0x0000000000000015", "subsystem-sideB", "SubSystem Requirement", "0x000000000000001D",
         "Lexicographical_Ascending", RelationMultiplicityEnum.ONE_TO_MANY);

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      OseeDslResourceUtil.saveModel(model1, "osee:/text.osee", outputStream, false);
      outputStream.flush();
      String value = outputStream.toString("UTF-8");
      modelEquals(rawXTextData, value);

      OseeDsl model2 = OseeDslResourceUtil.loadModel("osee:/text2.osee", value).getModel();
      DslAsserts.assertEquals(model1, model2);
   }

   @Test
   public void testModelUtilLoadAccess() throws Exception {
      String rawXTextData = Lib.fileToString(getClass(), ACCESS_TEST_INPUT);

      OseeDsl model1 = OseeDslResourceUtil.loadModel("osee:/text.osee", rawXTextData).getModel();
      Assert.assertEquals(2, model1.getArtifactTypes().size());
      Iterator<XArtifactType> type1 = model1.getArtifactTypes().iterator();
      DslAsserts.assertEquals(type1.next(), "Artifact", "0x0000000000000001", new String[0]);
      DslAsserts.assertEquals(type1.next(), "Software Requirement", "0x0000000000000002", new String[] {"Artifact"});

      Assert.assertEquals(1, model1.getAttributeTypes().size());
      Iterator<XAttributeType> type2 = model1.getAttributeTypes().iterator();
      DslAsserts.assertEquals(type2.next(), "Qualification Method", "0x1000000000000056", "StringAttribute",
         "DefaultAttributeDataProvider", "0", "1", null, null, "test", null);

      Assert.assertEquals(1, model1.getRelationTypes().size());
      Iterator<XRelationType> type3 = model1.getRelationTypes().iterator();
      DslAsserts.assertEquals(type3.next(), "Requirement Relation", "0x2000000000000163", "requirement-sideA",
         "Software Requirement", "0x0000000000000002", "artifact-sideB", "Artifact", "0x0000000000000001",
         "Lexicographical_Ascending", RelationMultiplicityEnum.ONE_TO_MANY);

      Assert.assertEquals(3, model1.getArtifactMatchRefs().size());
      Iterator<XArtifactMatcher> type4 = model1.getArtifactMatchRefs().iterator();
      // @formatter:off
      XArtifactMatcher matcher = type4.next();
      DslAsserts.assertEquals(matcher, "Software Items");
      DslAsserts.assertEquals(matcher.getConditions().get(0), MatchField.ARTIFACT_GUID, CompareOp.EQ, "AAMFEcWy0xc4e3tcem99");
      matcher = type4.next();
      DslAsserts.assertEquals(matcher, "Systems");
      DslAsserts.assertEquals(matcher.getConditions().get(0), MatchField.BRANCH_NAME, CompareOp.LIKE, "\\w+");
      matcher = type4.next();
      DslAsserts.assertEquals(matcher, "SubSystems");
      DslAsserts.assertEquals(matcher.getConditions().get(0), MatchField.ARTIFACT_NAME, CompareOp.EQ, "xx");
      // @formatter:on

      Assert.assertEquals(2, model1.getAccessDeclarations().size());
      Iterator<AccessContext> type5 = model1.getAccessDeclarations().iterator();
      AccessContext context1 = type5.next();
      DslAsserts.assertEquals(context1, "System Context", "AAMFEcWy0xc4e3tcem11", new String[0]);
      List<ObjectRestriction> restrictions1 = context1.getAccessRules();
      Assert.assertEquals(1, restrictions1.size());
      DslAsserts.assertEquals(((ArtifactTypeRestriction) restrictions1.iterator().next()), AccessPermissionEnum.DENY,
         "Artifact");

      List<HierarchyRestriction> hierarchy1 = context1.getHierarchyRestrictions();
      Assert.assertEquals(3, hierarchy1.size());

      Iterator<HierarchyRestriction> heirar = hierarchy1.iterator();
      DslAsserts.assertEquals(heirar.next(), "Software Items");
      DslAsserts.assertEquals(heirar.next(), "Systems");
      DslAsserts.assertEquals(heirar.next(), "SubSystems");

      AccessContext context2 = type5.next();
      DslAsserts.assertEquals(context2, "subsystem.requirement.writer", "AAMFEcWy0xc4e3tcem22",
         new String[] {"System Context"});
      List<ObjectRestriction> restrictions2 = context2.getAccessRules();
      Assert.assertEquals(4, restrictions2.size());
      Iterator<ObjectRestriction> restIt = restrictions2.iterator();
      // @formatter:off
      DslAsserts.assertEquals(((AttributeTypeRestriction) restIt.next()), AccessPermissionEnum.DENY, "Qualification Method", "Software Requirement");
      DslAsserts.assertEquals(((AttributeTypeRestriction) restIt.next()), AccessPermissionEnum.ALLOW, "Qualification Method", "Software Requirement");
      DslAsserts.assertEquals(((AttributeTypeRestriction) restIt.next()), AccessPermissionEnum.ALLOW, "Qualification Method", "Software Requirement");
      DslAsserts.assertEquals(((RelationTypeRestriction) restIt.next()), AccessPermissionEnum.DENY, "Requirement Relation", XRelationSideEnum.SIDE_A);

      // @formatter:on

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      OseeDslResourceUtil.saveModel(model1, "osee:/text.osee", outputStream, false);
      outputStream.flush();
      String value = outputStream.toString("UTF-8");
      modelEquals(rawXTextData, value);

      OseeDsl model2 = OseeDslResourceUtil.loadModel("osee:/text2.osee", value).getModel();
      DslAsserts.assertEquals(model1, model2);
   }

   private static void modelEquals(String rawExpected, String actual) {
      String expected = rawExpected.replaceAll("\n", System.getProperty("line.separator"));
      Assert.assertEquals(expected, actual);
   }
}

Back to the top