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
|
/*******************************************************************************
* Copyright (c) 2010 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.message.test.mocks;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.enums.OseeCacheEnum;
import org.eclipse.osee.framework.core.message.BranchCreationRequest;
import org.eclipse.osee.framework.core.message.BranchCreationResponse;
import org.eclipse.osee.framework.core.message.CacheUpdateRequest;
import org.eclipse.osee.framework.core.model.BranchFactory;
import org.eclipse.osee.framework.core.model.OseeModelFactoryService;
import org.eclipse.osee.framework.core.model.TransactionRecordFactory;
import org.eclipse.osee.framework.core.model.change.ArtifactChangeItem;
import org.eclipse.osee.framework.core.model.change.ChangeVersion;
import org.eclipse.osee.framework.core.model.type.ArtifactTypeFactory;
import org.eclipse.osee.framework.core.model.type.AttributeTypeFactory;
import org.eclipse.osee.framework.core.model.type.OseeEnumTypeFactory;
import org.eclipse.osee.framework.core.model.type.RelationTypeFactory;
import org.eclipse.osee.framework.core.services.IOseeModelFactoryService;
import org.eclipse.osee.framework.jdk.core.type.OseeArgumentException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
public final class MockRequestFactory {
private MockRequestFactory() {
// Utility class
}
public static IOseeModelFactoryService createFactoryService() {
return new OseeModelFactoryService(new BranchFactory(), new TransactionRecordFactory(),
new ArtifactTypeFactory(), new AttributeTypeFactory(), new RelationTypeFactory(), new OseeEnumTypeFactory());
}
public static ArtifactChangeItem createArtifactChangeItem() throws OseeArgumentException {
int artId = (int) Math.random();
Long gammaIdNumber = Long.valueOf((int) Math.random());
int artTypeId = artId * 10;
ArtifactChangeItem changeItem =
new ArtifactChangeItem(artId, artTypeId, gammaIdNumber, ModificationType.getMod(1));
populateChangeVersion(changeItem.getDestinationVersion(), 22);
populateChangeVersion(changeItem.getCurrentVersion(), 15);
return changeItem;
}
public static ChangeVersion createChangeVersion(int index) {
ModificationType modType = ModificationType.values()[index % ModificationType.values().length];
return new ChangeVersion("change_version_value_" + index, (long) (index * Integer.MAX_VALUE), modType);
}
public static void populateChangeVersion(ChangeVersion changeVersion, int index) {
ModificationType modType = ModificationType.values()[index % ModificationType.values().length];
changeVersion.setGammaId((long) (index * Integer.MAX_VALUE));
changeVersion.setModType(modType);
changeVersion.setValue("change_version_value_" + index);
}
public static CacheUpdateRequest createRequest(int index) {
OseeCacheEnum cacheEnum = OseeCacheEnum.values()[Math.abs(index % OseeCacheEnum.values().length)];
List<Integer> guids = new ArrayList<Integer>();
for (int j = 1; j <= index * 3; j++) {
guids.add(j * index);
}
return new CacheUpdateRequest(cacheEnum, guids);
}
public static BranchCreationRequest createBranchCreateRequest(int index) {
BranchType branchType = BranchType.values()[Math.abs(index % BranchType.values().length)];
String branchName = "branch_" + index;
int parentBranchId = index;
int associatedArtifactId = index * 3;
int sourceTransactionId = index * 7;
long branchUuid = Lib.generateUuid();
int authorId = index * 7;
String creationComment = "creation_comment_" + index;
int mergeFromAddressingQueryId = -1;
int destinationBranchId = -1;
return new BranchCreationRequest(branchType, sourceTransactionId, parentBranchId, branchName, branchUuid,
associatedArtifactId, authorId, creationComment, mergeFromAddressingQueryId, destinationBranchId);
}
public static Object createBranchCreateResponse(int index) {
return new BranchCreationResponse(index);
}
}
|