Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/DaoTests.cs @ 5402

Last change on this file since 5402 was 5402, checked in by cneumuel, 13 years ago

#1233

  • single sign on with HL
  • local plugins are uploaded if not available online (user can force the useage of local plugins)
  • changed plugin and plugindata db-schema
  • plugin dao tests
File size: 4.7 KB
Line 
1using System;
2using System.Text;
3using System.Collections.Generic;
4using System.Linq;
5using Microsoft.VisualStudio.TestTools.UnitTesting;
6using HeuristicLab.Services.Hive.Common.DataTransfer;
7using HeuristicLab.Services.Hive.Common.ServiceContracts;
8using HeuristicLab.Clients.Hive.Slave.Tests;
9using HeuristicLab.Clients.Hive;
10using HeuristicLab.Services.Hive.DataAccess;
11
12namespace HeuristicLab.Services.Hive.Tests {
13  using DA = HeuristicLab.Services.Hive.DataAccess;
14  using DT = HeuristicLab.Services.Hive.Common.DataTransfer;
15
16  [TestClass]
17  public class DaoTests {
18
19    [ClassInitialize]
20    public static void MyClassInitialize(TestContext testContext) {
21      PluginLoader.pluginAssemblies.Any();
22      ServiceLocator.Instance = new MockServiceLocator(ServiceLocator.Instance);
23    }
24   
25    private IHiveService GetLocalService() {
26      return new HiveService();
27    }
28
29    [TestMethod]
30    public void TestJobDao() {
31      IHiveDao dao = ServiceLocator.Instance.HiveDao;
32     
33      DT.Job job1 = new DT.Job();
34      job1.DateCreated = DateTime.Now;
35
36      DT.Plugin plugin1 = new DT.Plugin();
37      plugin1.Name = "Tests.MyPlugin";
38      plugin1.Version = new Version("1.0.0.0");
39      plugin1.UserId = Guid.Empty;
40      plugin1.IsLocal = true;
41      plugin1.DateCreated = DateTime.Now;
42
43      DT.PluginData pluginData1 = new DT.PluginData();
44      pluginData1.PluginId = plugin1.Id;
45      pluginData1.FileName = "Tests.MyPlugin-1.0.dll";
46      pluginData1.Data = new byte[] { 0, 1, 2, 3, 4, 5 };
47
48      plugin1.Id = dao.AddPlugin(plugin1);
49      pluginData1.PluginId = plugin1.Id;
50      pluginData1.Id = dao.AddPluginData(pluginData1);
51
52      job1.PluginsNeededIds.Add(plugin1.Id);
53
54      job1.Id = dao.AddJob(job1);
55
56      DT.Job job1loaded = dao.GetJob(job1.Id);
57      Assert.AreEqual(job1.Id, job1loaded.Id);
58      Assert.AreEqual(job1.CoresNeeded, job1loaded.CoresNeeded);
59      Assert.AreEqual(null, job1loaded.DateCalculated);
60      Assert.AreEqual(job1.DateCreated.ToString(), job1loaded.DateCreated.ToString());
61      Assert.AreEqual(null, job1loaded.DateFinished);
62      Assert.IsTrue(job1.PluginsNeededIds.SequenceEqual(job1loaded.PluginsNeededIds));
63     
64      dao.DeleteJob(job1.Id);
65
66      Assert.AreEqual(null, dao.GetJob(job1.Id));
67    }
68
69    [TestMethod]
70    public void TestSlaveDao() {
71      IHiveDao dao = ServiceLocator.Instance.HiveDao;
72      DT.SlaveGroup slaveGroup = new DT.SlaveGroup() {
73        Name = "Test"
74      };
75      slaveGroup.Id = dao.AddSlaveGroup(slaveGroup);
76
77      DT.Slave slave = new DT.Slave() {
78        Name = "Test"
79      };
80      slave.Id= dao.AddSlave(slave);
81
82      dao.DeleteSlave(slave.Id);
83      dao.DeleteSlaveGroup(slaveGroup.Id);
84    }
85
86    [TestMethod]
87    public void TestJobDaoWaiting() {
88      IHiveDao dao = ServiceLocator.Instance.HiveDao;
89
90      DT.Job job = new DT.Job();
91      job.DateCreated = DateTime.Now;
92      job.JobState = JobState.Waiting;
93      job.Id = dao.AddJob(job);
94
95      // todo
96    }
97
98    [TestMethod]
99    public void TestPluginDao() {
100      IHiveDao dao = ServiceLocator.Instance.HiveDao;
101
102      DT.Plugin plugin1 = new DT.Plugin();
103      plugin1.DateCreated = DateTime.Now;
104      plugin1.IsLocal = false;
105      plugin1.Name = "Tests.MyPlugin";
106      plugin1.Version = new Version("1.0.0.0");
107      plugin1.UserId = Guid.Empty;
108
109      plugin1.Id = dao.AddPlugin(plugin1);
110
111      DT.Plugin plugin1loaded = dao.GetPlugin(plugin1.Id);
112      Assert.AreEqual(plugin1.Id, plugin1loaded.Id);
113      Assert.AreEqual(plugin1.Name, plugin1loaded.Name);
114      Assert.AreEqual(plugin1.Version, plugin1loaded.Version);
115      Assert.AreEqual(plugin1.UserId, plugin1loaded.UserId);
116      Assert.AreEqual(plugin1.DateCreated.ToString(), plugin1loaded.DateCreated.ToString());
117      Assert.AreEqual(plugin1.IsLocal, plugin1loaded.IsLocal);
118
119      DT.PluginData pluginData1 = new DT.PluginData();
120      pluginData1.PluginId = plugin1.Id;
121      pluginData1.FileName = "Tests.MyPlugin-1.0.dll";
122      pluginData1.Data = new byte[] { 0, 1, 2, 3, 4, 5 };
123
124      pluginData1.Id = dao.AddPluginData(pluginData1);
125
126      DT.PluginData pluginData1loaded = dao.GetPluginData(pluginData1.Id);
127      Assert.AreEqual(pluginData1.Id, pluginData1loaded.Id);
128
129      Assert.AreEqual(pluginData1.PluginId, pluginData1loaded.PluginId);
130      Assert.AreEqual(pluginData1.FileName, pluginData1loaded.FileName);
131      Assert.IsTrue(pluginData1.Data.SequenceEqual(pluginData1loaded.Data));
132
133      dao.DeletePluginData(pluginData1.Id);
134      dao.DeletePlugin(plugin1.Id);
135
136      Assert.AreEqual(null, dao.GetPlugin(plugin1.Id));
137      Assert.AreEqual(null, dao.GetPluginData(pluginData1.Id));
138    }
139
140  }
141}
Note: See TracBrowser for help on using the repository browser.