1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.sail.common.util;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.logging.Logger;
28
29 import net.sf.sail.common.persistance.memory.MemoryAgent;
30 import net.sf.sail.core.beans.Pod;
31 import net.sf.sail.core.beans.UnknownPodException;
32 import net.sf.sail.core.curnit.Curnit;
33 import net.sf.sail.core.entity.IAgent;
34 import net.sf.sail.core.entity.Role;
35 import net.sf.sail.core.entity.RoleRuleException;
36 import net.sf.sail.core.entity.User;
37 import net.sf.sail.core.uuid.CurnitUuid;
38 import net.sf.sail.core.uuid.OfferingUuid;
39 import net.sf.sail.core.uuid.PodUuid;
40 import net.sf.sail.core.uuid.SessionUuid;
41 import net.sf.sail.core.uuid.UserUuid;
42
43 import org.apache.commons.lang.StringUtils;
44 import org.doomdark.uuid.UUID;
45
46
47
48
49
50
51 public class MockData {
52
53
54
55 private static final Logger logger = Logger.getLogger(MockData.class
56 .getName());
57
58 public static final CurnitUuid CURNIT_ID_1 = new CurnitUuid(
59 "cccccc01-0000-0000-0000-000000000000");
60
61 public static final SessionUuid SESSION_ID_1 = new SessionUuid(new UUID()
62 .toByteArray());
63
64 public static final OfferingUuid RUN_ID_1 = new OfferingUuid(new UUID()
65 .toByteArray());
66
67 public static final UserUuid USER_ID_1 = new UserUuid(UUID.valueOf(
68 "abcdef01-0000-0000-0000-000000000000").toByteArray());
69
70 public static final UserUuid USER_ID_2 = new UserUuid(UUID.valueOf(
71 "abcdef02-0000-0000-0000-000000000000").toByteArray());
72
73 static int userSerial = 1;
74
75 public static User fakeUser(UserUuid userUuid) {
76 return new User(userUuid, "fakeUser" + userSerial++);
77 }
78
79 public static Curnit getMockCurnit() {
80 Pod rootPod = getMockPod(0);
81 return getMockCurnit(rootPod);
82 }
83
84 public static Curnit getMockCurnit(Pod rootPod) {
85 Curnit curnit = new Curnit();
86 curnit.setCurnitId(CURNIT_ID_1);
87 try {
88 curnit.setRootPodId(rootPod.getPodId());
89 } catch (UnknownPodException e) {
90
91 e.printStackTrace();
92
93 throw new RuntimeException(e);
94 }
95 return curnit;
96 }
97
98 public static Pod getMockPod(int i) {
99 String tail = StringUtils.leftPad(Integer.toString(i), 12, '0');
100 Pod pod = new Pod();
101 PodUuid podId = new PodUuid("bbbbbbbb-0000-0000-0000-" + tail);
102 pod.setPodId(podId);
103 return pod;
104 }
105
106
107
108
109
110
111
112 public static Collection<IAgent> simpleAgentSet(Collection<User> users) {
113 Collection<IAgent> agents = new ArrayList<IAgent>(users.size() + 1);
114
115 IAgent groupAgent = new MemoryAgent(Role.RUN_WORKGROUP);
116 agents.add(groupAgent);
117
118 for (User user : users) {
119 try {
120 groupAgent.addUser(user.getUserUUID());
121 IAgent individualAgent = new MemoryAgent(Role.INDIVIDUAL);
122 individualAgent.addUser(user.getUserUUID());
123 agents.add(individualAgent);
124 } catch (RoleRuleException e) {
125
126 logger.severe("Collection - : exception: " + e);
127 }
128 }
129
130 return agents;
131 }
132 }