Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cffe7d69fcbee6ba7e67dc8f7ab6550e910ee4e2 (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
/*********************************************************************
 * Copyright (c) 2004, 2007 Boeing
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Boeing - initial API and implementation
 **********************************************************************/

package org.eclipse.osee.framework.ui.skynet.artifact;

import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Annotation;
import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Name;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.access.PermissionStatus;
import org.eclipse.osee.framework.core.data.ArtifactToken;
import org.eclipse.osee.framework.core.data.ArtifactTypeId;
import org.eclipse.osee.framework.core.data.AttributeTypeGeneric;
import org.eclipse.osee.framework.core.data.AttributeTypeId;
import org.eclipse.osee.framework.core.data.AttributeTypeToken;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.RelationTypeSide;
import org.eclipse.osee.framework.core.data.RelationTypeToken;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.jdk.core.result.XResultData;
import org.eclipse.osee.framework.skynet.core.AccessPolicy;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.artifact.prompt.IHandlePromptChange;
import org.eclipse.osee.framework.ui.skynet.artifact.prompt.IPromptFactory;
import org.junit.Assert;
import org.junit.Test;

/**
 * Test Case for {@link ArtifactPromptChange}
 *
 * @author Jeff C. Phillips
 */
public class ArtifactPromptChangeTest {

   @Test
   public void test() {
      boolean persist = true;
      List<Artifact> artifacts = new ArrayList<>();

      MockPromptFactory MockPromptFactory = new MockPromptFactory();
      AccessPolicy policyHandler = new MockAccessPolicyHandler();
      MockPromptFactory.createPrompt(Annotation, "", artifacts, persist, false);

      ArtifactPrompt artifactPromptChange = new ArtifactPrompt(MockPromptFactory, policyHandler);

      Assert.assertFalse(artifactPromptChange.promptChangeAttribute(Annotation, artifacts, persist, false));
      Assert.assertTrue(artifactPromptChange.promptChangeAttribute(Name, artifacts, persist, false));
   }

   private static class MockAccessPolicyHandler implements AccessPolicy {

      @Override
      public PermissionStatus hasArtifactTypePermission(BranchId branch, Collection<? extends ArtifactTypeId> artifactTypes, PermissionEnum permission, Level level) {
         return new PermissionStatus();
      }

      @Override
      public boolean isReadOnly(Artifact artifact) {
         return false;
      }

      @Override
      public PermissionStatus hasBranchPermission(BranchId branch, PermissionEnum permission, Level level) {
         return new PermissionStatus();
      }

      @Override
      public PermissionStatus hasAttributeTypePermission(Collection<? extends ArtifactToken> artifacts, AttributeTypeId attributeType, PermissionEnum permission, Level level) {
         return new PermissionStatus();
      }

      @Override
      public PermissionStatus hasArtifactPermission(Collection<Artifact> artifacts, PermissionEnum permission, Level level) {
         return new PermissionStatus();
      }

      @Override
      public PermissionStatus canRelationBeModified(Artifact subject, Collection<Artifact> toBeRelated, RelationTypeSide relationTypeSide, Level level) {
         return new PermissionStatus();
      }

      @Override
      public void removePermissions(BranchId branch) {
         //
      }

      @Override
      public XResultData isDeleteable(Collection<ArtifactToken> artifacts, XResultData results) {
         return new XResultData();
      }

      @Override
      public XResultData isRenamable(Collection<ArtifactToken> artifacts, XResultData results) {
         return new XResultData();
      }

      @Override
      public XResultData isDeleteableRelation(ArtifactToken artifact, RelationTypeToken relationType, XResultData results) {
         return new XResultData();
      }

      @Override
      public void ensurePopulated() {
         // do nothing
      }

   }

   private static class MockPromptFactory implements IPromptFactory {
      @Override
<<<<<<< HEAD
      public IHandlePromptChange createPrompt(AttributeTypeToken attributeType, String displayName, Collection<? extends Artifact> artifacts, boolean persist, boolean multiLine) {
=======
      public IHandlePromptChange createPrompt(AttributeTypeGeneric<?> attributeType, String displayName, Collection<? extends Artifact> artifacts, boolean persist, boolean multiLine) {
>>>>>>> f09ad7a724... refactor[TW16547]: Use AttributeTypeGeneric with ArtifactPrompt
         return new TestPromptChange(attributeType, persist);
      }
   }
   private static class TestPromptChange implements IHandlePromptChange {
      private final AttributeTypeId attributeType;
      private final boolean persist;

      public TestPromptChange(AttributeTypeId attributeType, boolean persist) {
         super();
         this.attributeType = attributeType;
         this.persist = persist;
      }

      @Override
      public boolean promptOk() {
         return true;
      }

      @Override
      public boolean store() {
         return persist && attributeType.equals(Name);
      }
   }
}

Back to the top