Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Hive.Server.Core/3.2/DbTestApp.cs @ 5698

Last change on this file since 5698 was 1656, checked in by svonolfe, 16 years ago

Implemented large parts of the security DAL (#597)

File size: 7.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.PluginInfrastructure;
26using System.Net;
27using HeuristicLab.Hive.Contracts;
28using HeuristicLab.Hive.Contracts.Interfaces;
29using HeuristicLab.Hive.Server.DataAccess;
30using HeuristicLab.Hive.Contracts.BusinessObjects;
31using System.Diagnostics;
32using HeuristicLab.DataAccess.Interfaces;
33
34namespace HeuristicLab.Hive.Server {
35  [ClassInfo(Name = "Hive DB Test App",
36      Description = "Test Application for the Hive DataAccess Layer",
37      AutoRestart = true)]
38  class HiveDbTestApplication : ApplicationBase {
39  /*  private void TestClientAdapter() {
40      IClientAdapter clientAdapter =
41        ServiceLocator.GetClientAdapter();
42
43      ClientInfo client = new ClientInfo();
44      client.Login = DateTime.Now;
45      clientAdapter.Update(client);
46
47      ClientInfo clientRead =
48        clientAdapter.GetById(client.Id);
49      Debug.Assert(
50        clientRead != null &&
51        client.Id == clientRead.Id);
52
53      client.CpuSpeedPerCore = 2000;
54      clientAdapter.Update(client);
55      clientRead =
56        clientAdapter.GetById(client.Id);
57      Debug.Assert(
58       clientRead != null &&
59       client.Id == clientRead.Id &&
60       clientRead.CpuSpeedPerCore == 2000);
61
62      ICollection<ClientInfo> clients =
63        clientAdapter.GetAll();
64      int count = clients.Count;
65
66      clientAdapter.Delete(client);
67
68      clients = clientAdapter.GetAll();
69      Debug.Assert(count - 1 == clients.Count);
70    } */
71
72    private void TestClientGroupAdapter() {
73      ISessionFactory factory =
74        ServiceLocator.GetSessionFactory();
75
76      ISession session =
77        factory.GetSessionForCurrentThread();
78
79      ITransaction trans = null;
80
81      try {
82        IClientGroupAdapter clientGroupAdapter =
83        session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
84
85        trans =
86          session.BeginTransaction();
87
88        ClientInfo client =
89          new ClientInfo();
90        client.Name = "Stefan";
91        client.Login = DateTime.Now;
92
93        ClientInfo client2 =
94          new ClientInfo();
95        client2.Name = "Martin";
96        client2.Login = DateTime.Now;
97
98        ClientInfo client3 =
99          new ClientInfo();
100        client3.Name = "Heinz";
101        client3.Login = DateTime.Now;
102
103        ClientGroup group =
104          new ClientGroup();
105
106        ClientGroup subGroup =
107          new ClientGroup();
108        subGroup.Resources.Add(client);
109
110        group.Resources.Add(client3);
111        group.Resources.Add(client2);
112        group.Resources.Add(subGroup);
113
114        clientGroupAdapter.Update(group);
115
116        ClientGroup read =
117          clientGroupAdapter.GetById(group.Id);
118
119        ICollection<ClientGroup> clientGroups =
120          clientGroupAdapter.GetAll();
121
122        IClientAdapter clientAdapter =
123          session.GetDataAdapter<ClientInfo, IClientAdapter>();
124
125        clientAdapter.Delete(client3);
126
127        read =
128           clientGroupAdapter.GetById(group.Id);
129
130        clientGroupAdapter.Delete(subGroup);
131
132        read =
133           clientGroupAdapter.GetById(group.Id);
134
135        clientGroups =
136          clientGroupAdapter.GetAll();
137
138        clientGroupAdapter.Delete(group);
139
140        clientGroups =
141          clientGroupAdapter.GetAll();
142
143        clientAdapter.Delete(client);
144        clientAdapter.Delete(client2);
145      }
146      finally {
147        if (trans != null)
148          trans.Rollback();
149
150        session.EndSession();
151      }
152    }
153
154    private void InsertTestClientGroups() {
155      ISessionFactory factory =
156        ServiceLocator.GetSessionFactory();
157
158      ISession session =
159        factory.GetSessionForCurrentThread();
160
161      ITransaction trans = null;
162
163      try {
164        IClientGroupAdapter clientGroupAdapter =
165        session.GetDataAdapter<ClientGroup, IClientGroupAdapter>();
166
167        trans =
168          session.BeginTransaction();
169
170        ClientInfo client =
171          new ClientInfo();
172        client.Name = "Stefan";
173        client.Login = DateTime.Now;
174
175        ClientInfo client2 =
176          new ClientInfo();
177        client2.Name = "Martin";
178        client2.Login = DateTime.Now;
179
180        ClientGroup group =
181          new ClientGroup();
182        group.Name = "Gruppe1";
183
184        ClientGroup subGroup =
185          new ClientGroup();
186        subGroup.Name = "Untergruppe1";
187        subGroup.Resources.Add(client);
188
189        group.Resources.Add(client2);
190        group.Resources.Add(subGroup);
191
192        clientGroupAdapter.Update(group);
193
194        trans.Commit();
195      }
196      finally {
197        session.EndSession();
198      }
199    }
200
201   /* private void TestJobAdapter() {
202      IJobAdapter jobAdapter =
203        ServiceLocator.GetJobAdapter();
204      IClientAdapter clientAdapter =
205        ServiceLocator.GetClientAdapter();
206
207      Job job = new Job();
208
209      ClientInfo client = new ClientInfo();
210      client.Login = DateTime.Now;
211
212      job.Client = client;
213      jobAdapter.Update(job);
214
215      ICollection<Job> jobs = jobAdapter.GetAll();
216
217      jobAdapter.Delete(job);
218      clientAdapter.Delete(client);
219
220      jobs = jobAdapter.GetAll();
221    }
222
223    private void TestJobResultsAdapter() {
224      Job job = new Job();
225
226      ClientInfo client = new ClientInfo();
227      client.Login = DateTime.Now;
228
229      job.Client = client;
230
231      IJobResultsAdapter resultsAdapter =
232        ServiceLocator.GetJobResultsAdapter();
233
234      byte[] resultByte = {0x0f, 0x1f, 0x2f, 0x3f, 0x4f};
235
236      JobResult result = new JobResult();
237      result.Client = client;
238      result.Job = job;
239      result.Result = resultByte;
240
241      resultsAdapter.Update(result);
242
243      JobResult read =
244        resultsAdapter.GetById(result.Id);
245      Debug.Assert(
246        read.Id == result.Id &&
247        result.Client.Id == read.Client.Id &&
248        result.Job.Id == read.Job.Id &&
249        result.Result == result.Result);
250
251      int count =
252        resultsAdapter.GetAll().Count;
253
254      resultsAdapter.Delete(result);
255
256      ICollection<JobResult> allResults =
257        resultsAdapter.GetAll();
258
259      Debug.Assert(allResults.Count == count - 1);
260
261      IJobAdapter jboAdapter =
262        ServiceLocator.GetJobAdapter();
263      jboAdapter.Delete(job);
264      IClientAdapter clientAdapter =
265        ServiceLocator.GetClientAdapter();
266      clientAdapter.Delete(client);
267    }      */
268
269    private void TestTransaction() {
270      ISessionFactory factory =
271        ServiceLocator.GetSessionFactory();
272
273      ISession session =
274        factory.GetSessionForCurrentThread();
275
276      IClientAdapter clientAdapter =
277        session.GetDataAdapter<ClientInfo, IClientAdapter>();
278
279      ITransaction trans =
280        session.BeginTransaction();
281
282      ClientInfo client = new ClientInfo();
283      client.Login = DateTime.Now;
284      clientAdapter.Update(client);
285
286      trans.Rollback();
287
288      session.EndSession();
289    }
290
291    public override void Run() {
292      TestClientGroupAdapter();
293      //InsertTestClientGroups();
294    }     
295  }
296}
Note: See TracBrowser for help on using the repository browser.