Skip to main content
summaryrefslogtreecommitdiffstats
blob: d742daf0a7ee5e197c6749f26463096e68503e6f (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
/*******************************************************************************
 * 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.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IRelationType;
import org.eclipse.osee.framework.core.dsl.oseeDsl.AccessPermissionEnum;
import org.eclipse.osee.framework.core.dsl.oseeDsl.ObjectRestriction;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeDslFactory;
import org.eclipse.osee.framework.core.dsl.oseeDsl.OseeType;
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.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.enums.RelationSide;
import org.eclipse.osee.framework.jdk.core.type.Id;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.HexUtil;
import org.junit.Assert;
import org.junit.Test;

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

   @Test
   public void testIsSideRestricted() throws OseeCoreException {
      checkIsRestricted(XRelationSideEnum.BOTH, true, true);
      checkIsRestricted(XRelationSideEnum.SIDE_A, true, false);
      checkIsRestricted(XRelationSideEnum.SIDE_B, false, true);
   }

   @Test(expected = OseeArgumentException.class)
   public void testIsSideRestrictionXRelationSideEnumNullCheck() throws OseeCoreException {
      OseeUtil.isRestrictedSide(null, RelationSide.SIDE_A);
   }

   @Test(expected = OseeArgumentException.class)
   public void testIsSideRestrictionRelationSideNullCheck() throws OseeCoreException {
      OseeUtil.isRestrictedSide(XRelationSideEnum.BOTH, null);
   }

   @Test
   public void testGetPermission() throws OseeCoreException {
      ObjectRestriction restriction = OseeDslFactory.eINSTANCE.createObjectRestriction();
      restriction.setPermission(AccessPermissionEnum.ALLOW);
      Assert.assertEquals(AccessPermissionEnum.ALLOW, restriction.getPermission());

      PermissionEnum expectedEnum = PermissionEnum.WRITE;
      PermissionEnum actualEnum = OseeUtil.getPermission(restriction);
      Assert.assertEquals(expectedEnum, actualEnum);

      restriction.setPermission(AccessPermissionEnum.DENY);
      Assert.assertEquals(AccessPermissionEnum.DENY, restriction.getPermission());
      expectedEnum = PermissionEnum.READ;
      actualEnum = OseeUtil.getPermission(restriction);
      Assert.assertEquals(expectedEnum, actualEnum);
   }

   @Test
   public void testToTokenArtifactType() throws OseeCoreException {
      XArtifactType type = OseeDslFactory.eINSTANCE.createXArtifactType();
      IArtifactType expected = CoreArtifactTypes.GlobalPreferences;

      setupToToken(type, expected);

      Object actual = OseeUtil.toToken(type);
      Assert.assertEquals(expected, actual);

      type.setUuid("0x1111111111111111");
      actual = OseeUtil.toToken(type);
      Assert.assertFalse(expected.equals(actual));
   }

   @Test
   public void testToTokenAttributeType() throws OseeCoreException {
      XAttributeType type = OseeDslFactory.eINSTANCE.createXAttributeType();
      IAttributeType expected = CoreAttributeTypes.Description;

      setupToToken(type, expected);

      Object actual = OseeUtil.toToken(type);
      Assert.assertEquals(expected, actual);

      type.setUuid("0x1111111111111111");
      actual = OseeUtil.toToken(type);
      Assert.assertFalse(expected.equals(actual));
   }

   @Test
   public void testToTokenRelationType() throws OseeCoreException {
      XRelationType type = OseeDslFactory.eINSTANCE.createXRelationType();
      IRelationType expected = CoreRelationTypes.Allocation__Component;

      setupToToken(type, expected);

      Object actual = OseeUtil.toToken(type);
      Assert.assertEquals(expected, actual);

      type.setUuid("0x1111111111111111");
      actual = OseeUtil.toToken(type);
      Assert.assertFalse(expected.equals(actual));
   }

   private static void setupToToken(OseeType typeToCheck, Id expected) throws OseeCoreException {
      String name = "bogus name"; // This should not affect equality
      typeToCheck.setName(name);
      String uuid = HexUtil.toString(expected.getId());
      typeToCheck.setUuid(uuid);

      Assert.assertEquals(name, typeToCheck.getName());
      Assert.assertEquals(expected.getId().longValue(), HexUtil.toLong(typeToCheck.getUuid()));
      Assert.assertEquals(uuid, typeToCheck.getUuid());
   }

   private static void checkIsRestricted(XRelationSideEnum side, boolean expectedSideA, boolean expectedSideB) throws OseeCoreException {
      boolean actual = OseeUtil.isRestrictedSide(side, RelationSide.SIDE_A);
      String message = String.format("[%s] - Side A error - expected[%s] actual[%s]", side, expectedSideA, actual);
      Assert.assertEquals(message, expectedSideA, actual);

      actual = OseeUtil.isRestrictedSide(side, RelationSide.SIDE_B);
      message = String.format("[%s] - Side B error - expected[%s] actual[%s]", side, expectedSideB, actual);
      Assert.assertEquals(message, expectedSideB, actual);
   }
}

Back to the top