CatalogueTest.cpp 619 KB
Newer Older
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2015-2021 CERN
4
5
6
7
 * @license        This program is free software: you can redistribute it and/or modify
 *                 it under the terms of the GNU General Public License as published by
 *                 the Free Software Foundation, either version 3 of the License, or
 *                 (at your option) any later version.
8
 *
9
10
11
12
 *                 This program is distributed in the hope that it will be useful,
 *                 but WITHOUT ANY WARRANTY; without even the implied warranty of
 *                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *                 GNU General Public License for more details.
13
 *
14
15
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18
19
 */

#include "catalogue/ArchiveFileRow.hpp"
#include "catalogue/CatalogueTest.hpp"
20
#include "catalogue/SchemaVersion.hpp"
21
#include "common/Constants.hpp"
22
#include "common/exception/Exception.hpp"
23
#include "common/exception/UserError.hpp"
24
#include "common/make_unique.hpp"
25
26
27
#include "common/threading/Thread.hpp"
#include "common/threading/Mutex.hpp"
#include "common/threading/MutexLocker.hpp"
28
29
#include "rdbms/wrapper/ConnFactoryFactory.hpp"
#include "rdbms/Conn.hpp"
30
#include "InsertFileRecycleLog.hpp"
31
#include "RdbmsCatalogue.hpp"
32

33
#include <algorithm>
34
#include <gtest/gtest.h>
Steven Murray's avatar
Steven Murray committed
35
#include <iomanip>
36
#include <limits>
37
38
39
40
41
42
#include <map>
#include <memory>
#include <set>

namespace unitTests {

43
44
45
46
47
48
49
const uint32_t PUBLIC_DISK_USER = 9751;
const uint32_t PUBLIC_DISK_GROUP = 9752;
const uint32_t DISK_FILE_OWNER_UID = 9753;
const uint32_t DISK_FILE_GID = 9754;
const uint32_t NON_EXISTENT_DISK_FILE_OWNER_UID = 9755;
const uint32_t NON_EXISTENT_DISK_FILE_GID = 9756;

50
namespace {
51
52
53
54
55
56
57
58
59
60
  cta::common::dataStructures::SecurityIdentity getLocalAdmin() {
    using namespace cta;

    common::dataStructures::SecurityIdentity localAdmin;
    localAdmin.username = "local_admin_user";
    localAdmin.host = "local_admin_host";

    return localAdmin;
  }

61
62
63
64
65
66
67
68
69
70
  cta::common::dataStructures::SecurityIdentity getAdmin() {
    using namespace cta;

    common::dataStructures::SecurityIdentity admin;
    admin.username = "admin_user_name";
    admin.host = "admin_host";

    return admin;
  }

71
72
73
74
75
76
  cta::common::dataStructures::VirtualOrganization getVo() {
    using namespace cta;

    common::dataStructures::VirtualOrganization vo;
    vo.name = "vo";
    vo.comment = "Creation of virtual organization vo";
77
78
    vo.readMaxDrives = 1;
    vo.writeMaxDrives = 1;
79
80
81
    return vo;
  }

Steven Murray's avatar
Steven Murray committed
82
83
84
85
86
87
88
89
90
91
92
  cta::common::dataStructures::VirtualOrganization getAnotherVo() {
    using namespace cta;

    common::dataStructures::VirtualOrganization vo;
    vo.name = "anotherVo";
    vo.comment = "Creation of another virtual organization vo";
    vo.readMaxDrives = 1;
    vo.writeMaxDrives = 1;
    return vo;
  }

93
94
95
96
97
98
99
100
101
102
103
  cta::common::dataStructures::StorageClass getStorageClass() {
    using namespace cta;

    common::dataStructures::StorageClass storageClass;
    storageClass.name = "storage_class_single_copy";
    storageClass.nbCopies = 1;
    storageClass.vo.name = getVo().name;
    storageClass.comment = "Creation of storage class with 1 copy on tape";
    return storageClass;
  }

Steven Murray's avatar
Steven Murray committed
104
105
106
107
108
109
110
111
112
113
114
  cta::common::dataStructures::StorageClass getAnotherStorageClass() {
    using namespace cta;

    common::dataStructures::StorageClass storageClass;
    storageClass.name = "another_storage_class";
    storageClass.nbCopies = 1;
    storageClass.vo.name = getVo().name;
    storageClass.comment = "Creation of another storage class";
    return storageClass;
  }

115
116
117
118
119
120
121
122
123
124
125
  cta::common::dataStructures::StorageClass getStorageClassDualCopy() {
    using namespace cta;

    common::dataStructures::StorageClass storageClass;
    storageClass.name = "storage_class_dual_copy";
    storageClass.nbCopies = 2;
    storageClass.vo.name = getVo().name;
    storageClass.comment = "Creation of storage class with 2 copies on tape";
    return storageClass;
  }

126
  cta::catalogue::MediaType getMediaType() {
127
128
129
    using namespace cta;

    catalogue::MediaType mediaType;
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    mediaType.name = "media_type";
    mediaType.capacityInBytes = (uint64_t)10 * 1000 * 1000 * 1000 * 1000;
    mediaType.cartridge = "cartridge";
    mediaType.comment = "comment";
    mediaType.maxLPos = 100;
    mediaType.minLPos = 1;
    mediaType.nbWraps = 500;
    mediaType.primaryDensityCode = 50;
    mediaType.secondaryDensityCode = 50;

    return mediaType;
  }

  cta::catalogue::CreateTapeAttributes getTape1() {
144
    using namespace cta;
145

146
    catalogue::CreateTapeAttributes tape;
147
    tape.vid = "VIDONE";
148
    tape.mediaType = getMediaType().name;
149
150
151
152
    tape.vendor = "vendor";
    tape.logicalLibraryName = "logical_library";
    tape.tapePoolName = "tape_pool";
    tape.full = false;
153
    tape.state = common::dataStructures::Tape::ACTIVE;
154
155
156
157
158
    tape.comment = "Creation of tape one";

    return tape;
  }

159
  cta::catalogue::CreateTapeAttributes getTape2() {
160
    // Tape 2 is an exact copy of tape 1 except for its VID and comment
161
    auto tape = getTape1();
162
163
164
165
    tape.vid = "VIDTWO";
    tape.comment = "Creation of tape two";
    return tape;
  }
166
167
168
169
170
171
172
173
174
175
176
177
178
  
  cta::catalogue::CreateMountPolicyAttributes getMountPolicy1() {
    using namespace cta;
    
    catalogue::CreateMountPolicyAttributes mountPolicy;
    mountPolicy.name = "mount_policy";
    mountPolicy.archivePriority = 1;
    mountPolicy.minArchiveRequestAge = 2;
    mountPolicy.retrievePriority = 3;
    mountPolicy.minRetrieveRequestAge = 4;
    mountPolicy.comment = "Create mount policy";
    return mountPolicy;
  }
179
180
}

181
182
183
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
184
cta_catalogue_CatalogueTest::cta_catalogue_CatalogueTest():
185
        m_dummyLog("dummy", "dummy"),
186
        m_localAdmin(getLocalAdmin()),
187
        m_admin(getAdmin()),
188
        m_vo(getVo()),
Steven Murray's avatar
Steven Murray committed
189
        m_anotherVo(getAnotherVo()),
190
        m_storageClassSingleCopy(getStorageClass()),
Steven Murray's avatar
Steven Murray committed
191
        m_anotherStorageClass(getAnotherStorageClass()),
192
193
194
195
        m_storageClassDualCopy(getStorageClassDualCopy()),
        m_mediaType(getMediaType()),
        m_tape1(getTape1()),
        m_tape2(getTape2()) {
196
197
198
199
200
201
202
203
}

//------------------------------------------------------------------------------
// Setup
//------------------------------------------------------------------------------
void cta_catalogue_CatalogueTest::SetUp() {
  using namespace cta;
  using namespace cta::catalogue;
204
  log::LogContext dummyLc(m_dummyLog);
205
  try {
206
    CatalogueFactory *const *const catalogueFactoryPtrPtr = GetParam();
207

208
209
210
211
212
213
214
215
216
    if(nullptr == catalogueFactoryPtrPtr) {
      throw exception::Exception("Global pointer to the catalogue factory pointer for unit-tests in null");
    }

    if(nullptr == (*catalogueFactoryPtrPtr)) {
      throw exception::Exception("Global pointer to the catalogue factoryfor unit-tests in null");
    }

    m_catalogue = (*catalogueFactoryPtrPtr)->create();
217

218
219
220
221
222
    {
      const std::list<common::dataStructures::AdminUser> adminUsers = m_catalogue->getAdminUsers();
      for(auto &adminUser: adminUsers) {
        m_catalogue->deleteAdminUser(adminUser.name);
      }
223
    }
224
225
226
    {
      const std::list<common::dataStructures::ArchiveRoute> archiveRoutes = m_catalogue->getArchiveRoutes();
      for(auto &archiveRoute: archiveRoutes) {
227
        m_catalogue->deleteArchiveRoute(archiveRoute.storageClassName,
228
229
          archiveRoute.copyNb);
      }
230
    }
231
232
233
234
235
    {
      const std::list<common::dataStructures::RequesterMountRule> rules = m_catalogue->getRequesterMountRules();
      for(auto &rule: rules) {
        m_catalogue->deleteRequesterMountRule(rule.diskInstance, rule.name);
      }
236
    }
237
238
239
240
241
242
    {
      const std::list<common::dataStructures::RequesterGroupMountRule> rules =
        m_catalogue->getRequesterGroupMountRules();
      for(auto &rule: rules) {
        m_catalogue->deleteRequesterGroupMountRule(rule.diskInstance, rule.name);
      }
243
    }
244
    {
245
246
247
248
      // The iterator returned from m_catalogue->getArchiveFilesItor() will lock
      // an SQLite file database, so copy all of its results into a list in
      // order to release the lock before moving on to deleting database rows
      auto itor = m_catalogue->getArchiveFilesItor();
249
      std::list<common::dataStructures::ArchiveFile> archiveFiles;
250
      while(itor.hasMore()) {
251
252
253
254
        archiveFiles.push_back(itor.next());
      }

      for(const auto &archiveFile: archiveFiles) {
255
        m_catalogue->DO_NOT_USE_deleteArchiveFile_DO_NOT_USE(archiveFile.diskInstance, archiveFile.archiveFileID, dummyLc);
256
      }
257
    }
258
    
259
260
261
262
263
264
265
266
    {
      //Delete all the entries from the recycle log table
      auto itor = m_catalogue->getFileRecycleLogItor();
      std::list<common::dataStructures::FileRecycleLog> filesRecycleLog;
      while(itor.hasMore()){
        m_catalogue->deleteFilesFromRecycleLog(itor.next().vid,dummyLc);
      }
    }
267
268
269
270
271
    {
      const std::list<common::dataStructures::Tape> tapes = m_catalogue->getTapes();
      for(auto &tape: tapes) {
        m_catalogue->deleteTape(tape.vid);
      }
272
    }
273
274
275
276
277
278
    {
      const auto mediaTypes = m_catalogue->getMediaTypes();
      for(auto &mediaType: mediaTypes) {
        m_catalogue->deleteMediaType(mediaType.name);
      }
    }
279
280
281
    {
      const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();
      for(auto &storageClass: storageClasses) {
282
        m_catalogue->deleteStorageClass(storageClass.name);
283
      }
284
    }
285
    {
286
      const std::list<TapePool> tapePools = m_catalogue->getTapePools();
287
288
289
      for(auto &tapePool: tapePools) {
        m_catalogue->deleteTapePool(tapePool.name);
      }
290
    }
291
292
293
294
295
    {
      const std::list<common::dataStructures::LogicalLibrary> logicalLibraries = m_catalogue->getLogicalLibraries();
      for(auto &logicalLibrary: logicalLibraries) {
        m_catalogue->deleteLogicalLibrary(logicalLibrary.name);
      }
296
    }
297
298
299
300
301
    {
      const std::list<common::dataStructures::MountPolicy> mountPolicies = m_catalogue->getMountPolicies();
      for(auto &mountPolicy: mountPolicies) {
        m_catalogue->deleteMountPolicy(mountPolicy.name);
      }
302
    }
303
304
305
306
307
308
    {
      const auto diskSystems = m_catalogue->getAllDiskSystems();
      for(auto &ds: diskSystems) {
        m_catalogue->deleteDiskSystem(ds.name);
      }
    }
309
310
311
312
313
314
    {
      const auto virtualOrganizations = m_catalogue->getVirtualOrganizations();
      for(auto &vo: virtualOrganizations) {
        m_catalogue->deleteVirtualOrganization(vo.name);
      }
    }
315
316
317
318
319

    if(!m_catalogue->getAdminUsers().empty()) {
      throw exception::Exception("Found one of more admin users after emptying the database");
    }

320
321
    if(m_catalogue->getArchiveFilesItor().hasMore()) {
      throw exception::Exception("Found one of more archive files after emptying the database");
322
323
    }

324
325
    if(!m_catalogue->getArchiveRoutes().empty()) {
      throw exception::Exception("Found one of more archive routes after emptying the database");
326
    }
327
328
329
    
    if(m_catalogue->getFileRecycleLogItor().hasMore()){
      throw exception::Exception("Found one or more files in the file recycle log after emptying the database");
330
331
    }

332
333
    if(!m_catalogue->getAllDiskSystems().empty()) {
      throw exception::Exception("Found one of more disk systems after emptying the database");
334
335
336
337
338
339
    }

    if(!m_catalogue->getLogicalLibraries().empty()) {
      throw exception::Exception("Found one of more logical libraries after emptying the database");
    }

340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
    if(!m_catalogue->getMediaTypes().empty()) {
      throw exception::Exception("Found one of more media types after emptying the database");
    }

    if(!m_catalogue->getMountPolicies().empty()) {
      throw exception::Exception("Found one of more mount policies after emptying the database");
    }

    if(!m_catalogue->getRequesterGroupMountRules().empty()) {
      throw exception::Exception("Found one of more requester group mount rules after emptying the database");
    }

    if(!m_catalogue->getRequesterMountRules().empty()) {
      throw exception::Exception("Found one of more requester mount rules after emptying the database");
    }

    if(!m_catalogue->getStorageClasses().empty()) {
      throw exception::Exception("Found one of more storage classes after emptying the database");
    }

360
361
362
    if(!m_catalogue->getTapes().empty()) {
      throw exception::Exception("Found one of more tapes after emptying the database");
    }
363
364
365
366
367
368
369
370

    if(!m_catalogue->getTapePools().empty()) {
      throw exception::Exception("Found one of more tape pools after emptying the database");
    }

    if(!m_catalogue->getVirtualOrganizations().empty()) {
      throw exception::Exception("Found one of more virtual organizations after emptying the database");
    }
371
  } catch(exception::Exception &ex) {
372
373
    ex.getMessage().str(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
    throw;
374
375
376
377
378
379
380
381
382
383
  }
}

//------------------------------------------------------------------------------
// TearDown
//------------------------------------------------------------------------------
void cta_catalogue_CatalogueTest::TearDown() {
  m_catalogue.reset();
}

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
//------------------------------------------------------------------------------
// LogicaLibraryListToMap
//------------------------------------------------------------------------------
std::map<std::string, cta::common::dataStructures::LogicalLibrary> cta_catalogue_CatalogueTest::logicalLibraryListToMap(
  const std::list<cta::common::dataStructures::LogicalLibrary> &listOfLibs) {
  using namespace cta;

  try {
    std::map<std::string, cta::common::dataStructures::LogicalLibrary> nameToLib;

    for (auto &lib: listOfLibs) {
      if(nameToLib.end() != nameToLib.find(lib.name)) {
        throw exception::Exception(std::string("Duplicate logical library: value=") + lib.name);
      }
      nameToLib[lib.name] = lib;
    }

    return nameToLib;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

407
408
409
410
411
412
413
414
415
416
//------------------------------------------------------------------------------
// tapeListToMap
//------------------------------------------------------------------------------
std::map<std::string, cta::common::dataStructures::Tape> cta_catalogue_CatalogueTest::tapeListToMap(
  const std::list<cta::common::dataStructures::Tape> &listOfTapes) {
  using namespace cta;

  try {
    std::map<std::string, cta::common::dataStructures::Tape> vidToTape;

417
    for (auto &tape: listOfTapes) {
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
      if(vidToTape.end() != vidToTape.find(tape.vid)) {
        throw exception::Exception(std::string("Duplicate VID: value=") + tape.vid);
      }
      vidToTape[tape.vid] = tape;
    }

    return vidToTape;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

//------------------------------------------------------------------------------
// archiveFileItorToMap
//------------------------------------------------------------------------------
std::map<uint64_t, cta::common::dataStructures::ArchiveFile> cta_catalogue_CatalogueTest::archiveFileItorToMap(
434
  cta::catalogue::Catalogue::ArchiveFileItor &itor) {
435
436
437
438
439
  using namespace cta;

  try {
    std::map<uint64_t, common::dataStructures::ArchiveFile> m;
    while(itor.hasMore()) {
440
      const auto archiveFile = itor.next();
441
442
443
444
445
446
447
448
449
450
451
452
453
      if(m.end() != m.find(archiveFile.archiveFileID)) {
        exception::Exception ex;
        ex.getMessage() << "Archive file with ID " << archiveFile.archiveFileID << " is a duplicate";
        throw ex;
      }
      m[archiveFile.archiveFileID] = archiveFile;
    }
    return m;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
//------------------------------------------------------------------------------
// archiveFileListToMap
//------------------------------------------------------------------------------
std::map<uint64_t, cta::common::dataStructures::ArchiveFile> cta_catalogue_CatalogueTest::archiveFileListToMap(
  const std::list<cta::common::dataStructures::ArchiveFile> &listOfArchiveFiles) {
  using namespace cta;

  try {
    std::map<uint64_t, common::dataStructures::ArchiveFile> archiveIdToArchiveFile;

    for (auto &archiveFile: listOfArchiveFiles) {
      if(archiveIdToArchiveFile.end() != archiveIdToArchiveFile.find(archiveFile.archiveFileID)) {
        throw exception::Exception(std::string("Duplicate archive file ID: value=") + std::to_string(archiveFile.archiveFileID));
      }
      archiveIdToArchiveFile[archiveFile.archiveFileID] = archiveFile;
    }

    return archiveIdToArchiveFile;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
//------------------------------------------------------------------------------
// adminUserListToMap
//------------------------------------------------------------------------------
std::map<std::string, cta::common::dataStructures::AdminUser> cta_catalogue_CatalogueTest::adminUserListToMap(
  const std::list<cta::common::dataStructures::AdminUser> &listOfAdminUsers) {
  using namespace cta;

  try {
    std::map<std::string, common::dataStructures::AdminUser> m;

    for(auto &adminUser: listOfAdminUsers) {
      if(m.end() != m.find(adminUser.name)) {
        exception::Exception ex;
        ex.getMessage() << "Admin user " << adminUser.name << " is a duplicate";
        throw ex;
      }
      m[adminUser.name] = adminUser;
    }
    return m;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
//------------------------------------------------------------------------------
// mediaTypeWithLogsListToMap
//------------------------------------------------------------------------------
std::map<std::string, cta::catalogue::MediaTypeWithLogs> cta_catalogue_CatalogueTest::mediaTypeWithLogsListToMap(
  const std::list<cta::catalogue::MediaTypeWithLogs> &listOfMediaTypes) {
  using namespace cta;

  try {
    std::map<std::string, cta::catalogue::MediaTypeWithLogs> m;

    for(auto &mediaType: listOfMediaTypes) {
      if(m.end() != m.find(mediaType.name)) {
        exception::Exception ex;
        ex.getMessage() << "Media type " << mediaType.name << " is a duplicate";
        throw ex;
      }
      m[mediaType.name] = mediaType;
    }
    return m;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
//------------------------------------------------------------------------------
// tapePoolListToMap
//------------------------------------------------------------------------------
std::map<std::string, cta::catalogue::TapePool> cta_catalogue_CatalogueTest::tapePoolListToMap(
  const std::list<cta::catalogue::TapePool> &listOfTapePools) {
  using namespace cta;

  try {
    std::map<std::string, cta::catalogue::TapePool> m;

    for(auto &tapePool: listOfTapePools) {
      if(m.end() != m.find(tapePool.name)) {
        exception::Exception ex;
        ex.getMessage() << "Tape pool " << tapePool.name << " is a duplicate";
        throw ex;
      }
      m[tapePool.name] = tapePool;
    }

    return m;
  } catch(exception::Exception &ex) {
    throw exception::Exception(std::string(__FUNCTION__) + " failed: " + ex.getMessage().str());
  }
}

550
551
552
TEST_P(cta_catalogue_CatalogueTest, createAdminUser) {
  using namespace cta;

553
554
  const std::string createAdminUserComment = "Create admin user";
  m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment);
555
556
557
558
559
560

  {
    std::list<common::dataStructures::AdminUser> admins;
    admins = m_catalogue->getAdminUsers();
    ASSERT_EQ(1, admins.size());

561
    const common::dataStructures::AdminUser a = admins.front();
562

563
564
565
566
567
568
    ASSERT_EQ(m_admin.username, a.name);
    ASSERT_EQ(createAdminUserComment, a.comment);
    ASSERT_EQ(m_localAdmin.username, a.creationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.creationLog.host);
    ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
569
570
571
572
573
574
  }
}

TEST_P(cta_catalogue_CatalogueTest, createAdminUser_same_twice) {
  using namespace cta;

575
  m_catalogue->createAdminUser(m_localAdmin, m_admin.username, "comment 1");
576

577
  ASSERT_THROW(m_catalogue->createAdminUser(m_localAdmin, m_admin.username, "comment 2"), exception::UserError);
578
579
580
581
582
}

TEST_P(cta_catalogue_CatalogueTest, deleteAdminUser) {
  using namespace cta;

583
584
  const std::string createAdminUserComment = "Create admin user";
  m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment);
585
586
587
588
589
590

  {
    std::list<common::dataStructures::AdminUser> admins;
    admins = m_catalogue->getAdminUsers();
    ASSERT_EQ(1, admins.size());

591
    const common::dataStructures::AdminUser a = admins.front();
592

593
594
595
596
597
598
    ASSERT_EQ(m_admin.username, a.name);
    ASSERT_EQ(createAdminUserComment, a.comment);
    ASSERT_EQ(m_localAdmin.username, a.creationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.creationLog.host);
    ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
599
600
  }

601
  m_catalogue->deleteAdminUser(m_admin.username);
602
603
604
605

  ASSERT_TRUE(m_catalogue->getAdminUsers().empty());
}

606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
TEST_P(cta_catalogue_CatalogueTest, createAdminUser_emptyStringUsername) {
  using namespace cta;

  const std::string adminUsername = "";
  const std::string createAdminUserComment = "Create admin user";
  ASSERT_THROW(m_catalogue->createAdminUser(m_localAdmin, adminUsername, createAdminUserComment),
    catalogue::UserSpecifiedAnEmptyStringUsername);
}

TEST_P(cta_catalogue_CatalogueTest, createAdminUser_emptyStringComment) {
  using namespace cta;

  const std::string createAdminUserComment = "";
  ASSERT_THROW(m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment),
    catalogue::UserSpecifiedAnEmptyStringComment);
}

623
TEST_P(cta_catalogue_CatalogueTest, deleteAdminUser_non_existent) {
624
625
  using namespace cta;

626
  ASSERT_THROW(m_catalogue->deleteAdminUser("non_existent_admin_user"), exception::UserError);
627
628
}

629
630
631
TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment) {
  using namespace cta;

632
633
  const std::string createAdminUserComment = "Create admin user";
  m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment);
634
635
636
637
638
639

  {
    std::list<common::dataStructures::AdminUser> admins;
    admins = m_catalogue->getAdminUsers();
    ASSERT_EQ(1, admins.size());

640
    const common::dataStructures::AdminUser a = admins.front();
641

642
643
644
645
646
647
    ASSERT_EQ(m_admin.username, a.name);
    ASSERT_EQ(createAdminUserComment, a.comment);
    ASSERT_EQ(m_localAdmin.username, a.creationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.creationLog.host);
    ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
648
649
650
  }

  const std::string modifiedComment = "Modified comment";
651
  m_catalogue->modifyAdminUserComment(m_localAdmin, m_admin.username, modifiedComment);
652
653

  {
654
655
656
    std::list<common::dataStructures::AdminUser> admins;
    admins = m_catalogue->getAdminUsers();
    ASSERT_EQ(1, admins.size());
657

658
    const common::dataStructures::AdminUser a = admins.front();
659

660
661
662
663
664
665
    ASSERT_EQ(m_admin.username, a.name);
    ASSERT_EQ(modifiedComment, a.comment);
    ASSERT_EQ(m_localAdmin.username, a.creationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.creationLog.host);
    ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
666
667
668
  }
}

669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment_emptyStringUsername) {
  using namespace cta;

  const std::string adminUsername = "";
  const std::string modifiedComment = "Modified comment";
  ASSERT_THROW(m_catalogue->modifyAdminUserComment(m_localAdmin, adminUsername, modifiedComment),
    catalogue::UserSpecifiedAnEmptyStringUsername);
}

TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment_emptyStringComment) {
  using namespace cta;

  const std::string createAdminUserComment = "Create admin user";
  m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment);

  {
    std::list<common::dataStructures::AdminUser> admins;
    admins = m_catalogue->getAdminUsers();
    ASSERT_EQ(1, admins.size());

    const common::dataStructures::AdminUser a = admins.front();

    ASSERT_EQ(m_admin.username, a.name);
    ASSERT_EQ(createAdminUserComment, a.comment);
    ASSERT_EQ(m_localAdmin.username, a.creationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.creationLog.host);
    ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
  }

  const std::string modifiedComment = "";
  ASSERT_THROW(m_catalogue->modifyAdminUserComment(m_localAdmin, m_admin.username, modifiedComment),
    catalogue::UserSpecifiedAnEmptyStringComment);
}

704
705
706
707
TEST_P(cta_catalogue_CatalogueTest, modifyAdminUserComment_nonExtistentAdminUser) {
  using namespace cta;

  const std::string modifiedComment = "Modified comment";
708
  ASSERT_THROW(m_catalogue->modifyAdminUserComment(m_localAdmin, m_admin.username, modifiedComment),
709
710
711
    exception::UserError);
}

712
713
714
TEST_P(cta_catalogue_CatalogueTest, isAdmin_false) {
  using namespace cta;

Steven Murray's avatar
Steven Murray committed
715
  ASSERT_FALSE(m_catalogue->isAdmin(m_admin));
716
717
718
719
720
}

TEST_P(cta_catalogue_CatalogueTest, isAdmin_true) {
  using namespace cta;

721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
  const std::string createAdminUserComment = "Create admin user";
  m_catalogue->createAdminUser(m_localAdmin, m_admin.username, createAdminUserComment);

  {
    std::list<common::dataStructures::AdminUser> admins;
    admins = m_catalogue->getAdminUsers();
    ASSERT_EQ(1, admins.size());

    const common::dataStructures::AdminUser a = admins.front();

    ASSERT_EQ(m_admin.username, a.name);
    ASSERT_EQ(createAdminUserComment, a.comment);
    ASSERT_EQ(m_localAdmin.username, a.creationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.creationLog.host);
    ASSERT_EQ(m_localAdmin.username, a.lastModificationLog.username);
    ASSERT_EQ(m_localAdmin.host, a.lastModificationLog.host);
  }

  ASSERT_TRUE(m_catalogue->isAdmin(m_admin));
740
741
742
743
744
}

TEST_P(cta_catalogue_CatalogueTest, createStorageClass) {
  using namespace cta;

745
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
746
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
747

748
  const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();
749
750

  ASSERT_EQ(1, storageClasses.size());
751
  
752
753
754
755
  ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
  ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
  ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
  ASSERT_EQ(m_storageClassSingleCopy.vo.name, storageClasses.front().vo.name);
756
  
757
  const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
Steven Murray's avatar
Steven Murray committed
758
759
  ASSERT_EQ(m_admin.username, creationLog.username);
  ASSERT_EQ(m_admin.host, creationLog.host);
760

761
  const common::dataStructures::EntryLog lastModificationLog = storageClasses.front().lastModificationLog;
762
763
764
765
766
767
  ASSERT_EQ(creationLog, lastModificationLog);
}

TEST_P(cta_catalogue_CatalogueTest, createStorageClass_same_twice) {
  using namespace cta;

768
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
769
770
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
  ASSERT_THROW(m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy), exception::UserError);
771
772
}

773
774
775
TEST_P(cta_catalogue_CatalogueTest, createStorageClass_emptyStringStorageClassName) {
  using namespace cta;

776
  auto storageClass = m_storageClassSingleCopy;
777
  storageClass.name = "";
778
779
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
  ASSERT_THROW(m_catalogue->createStorageClass(m_admin, storageClass), catalogue::UserSpecifiedAnEmptyStringStorageClassName);
780
781
782
783
784
}

TEST_P(cta_catalogue_CatalogueTest, createStorageClass_emptyStringComment) {
  using namespace cta;

785
  auto storageClass = m_storageClassSingleCopy;
786
  storageClass.comment = "";
787
788
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
  ASSERT_THROW(m_catalogue->createStorageClass(m_admin, storageClass), catalogue::UserSpecifiedAnEmptyStringComment);
789
790
}

791
792
793
TEST_P(cta_catalogue_CatalogueTest, createStorageClass_emptyStringVo) {
  using namespace cta;

794
  auto storageClass = m_storageClassSingleCopy;
795
  storageClass.vo.name = "";
796
  ASSERT_THROW(m_catalogue->createStorageClass(m_admin, storageClass), catalogue::UserSpecifiedAnEmptyStringVo);
797
798
799
800
801
}

TEST_P(cta_catalogue_CatalogueTest, createStorageClass_nonExistingVo) {
  using namespace cta;

802
  auto storageClass = m_storageClassSingleCopy;
803
  storageClass.vo.name = "NonExistingVO";
804
  ASSERT_THROW(m_catalogue->createStorageClass(m_admin, storageClass), exception::UserError);
805
806
}

807
808
809
TEST_P(cta_catalogue_CatalogueTest, deleteStorageClass) {
  using namespace cta;

810
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
811
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
812

813
  const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();
814
815
816

  ASSERT_EQ(1, storageClasses.size());

817
818
819
  ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
  ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
  ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
820

821
  const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
Steven Murray's avatar
Steven Murray committed
822
823
  ASSERT_EQ(m_admin.username, creationLog.username);
  ASSERT_EQ(m_admin.host, creationLog.host);
824

825
  const common::dataStructures::EntryLog lastModificationLog = storageClasses.front().lastModificationLog;
826
827
  ASSERT_EQ(creationLog, lastModificationLog);

828
  m_catalogue->deleteStorageClass(m_storageClassSingleCopy.name);
829
830
831
  ASSERT_TRUE(m_catalogue->getStorageClasses().empty());
}

832
TEST_P(cta_catalogue_CatalogueTest, deleteStorageClass_non_existent) {
833
834
  using namespace cta;

835
  ASSERT_THROW(m_catalogue->deleteStorageClass("non_existent_storage_class"), exception::UserError);
836
837
}

838
839
840
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassNbCopies) {
  using namespace cta;

841
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
842
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
843
844
845
846
847
848

  {
    const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();

    ASSERT_EQ(1, storageClasses.size());

849
    
850
851
852
    ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
    ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
    ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
853
854

    const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
Steven Murray's avatar
Steven Murray committed
855
856
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
857
858
859
860
861
862

    const common::dataStructures::EntryLog lastModificationLog = storageClasses.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const uint64_t modifiedNbCopies = 5;
863
  m_catalogue->modifyStorageClassNbCopies(m_admin, m_storageClassSingleCopy.name, modifiedNbCopies);
864
865
866
867
868
869

  {
    const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();

    ASSERT_EQ(1, storageClasses.size());

870
    
871
    ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
872
    ASSERT_EQ(modifiedNbCopies, storageClasses.front().nbCopies);
873
    ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
874
875

    const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
Steven Murray's avatar
Steven Murray committed
876
877
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
878
879
880
  }
}

881
882
883
884
885
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassNbCopies_nonExistentStorageClass) {
  using namespace cta;

  const std::string storageClassName = "storage_class";
  const uint64_t nbCopies = 5;
886
  ASSERT_THROW(m_catalogue->modifyStorageClassNbCopies(m_admin, storageClassName, nbCopies), exception::UserError);
887
888
}

889
890
891
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassComment) {
  using namespace cta;

892
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
893
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
894
895
896
897
898
899

  {
    const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();

    ASSERT_EQ(1, storageClasses.size());

900
    
901
902
903
    ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
    ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
    ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
904
905

    const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
Steven Murray's avatar
Steven Murray committed
906
907
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
908
909
910
911
912
913

    const common::dataStructures::EntryLog lastModificationLog = storageClasses.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const std::string modifiedComment = "Modified comment";
914
  m_catalogue->modifyStorageClassComment(m_admin, m_storageClassSingleCopy.name, modifiedComment);
915
916
917
918
919
920

  {
    const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();

    ASSERT_EQ(1, storageClasses.size());

921
    
922
923
    ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
    ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
924
925
926
    ASSERT_EQ(modifiedComment, storageClasses.front().comment);

    const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
Steven Murray's avatar
Steven Murray committed
927
928
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
929
930
931
  }
}

932
933
934
935
936
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassComment_nonExistentStorageClass) {
  using namespace cta;

  const std::string storageClassName = "storage_class";
  const std::string comment = "Comment";
937
  ASSERT_THROW(m_catalogue->modifyStorageClassComment(m_admin, storageClassName, comment), exception::UserError);
938
939
}

940
941
942
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassName) {
  using namespace cta;

943
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
944
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
945
946
947
948
949
950

  {
    const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();

    ASSERT_EQ(1, storageClasses.size());

951
    
952
953
954
    ASSERT_EQ(m_storageClassSingleCopy.name, storageClasses.front().name);
    ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
    ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
955
956
957
958
959
960
961
962
963
964

    const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);

    const common::dataStructures::EntryLog lastModificationLog = storageClasses.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const std::string newStorageClassName = "new_storage_class_name";
965
  m_catalogue->modifyStorageClassName(m_admin, m_storageClassSingleCopy.name, newStorageClassName);
966
967
968
969
970
971

  {
    const std::list<common::dataStructures::StorageClass> storageClasses = m_catalogue->getStorageClasses();

    ASSERT_EQ(1, storageClasses.size());

972
    
973
    ASSERT_EQ(newStorageClassName, storageClasses.front().name);
974
975
    ASSERT_EQ(m_storageClassSingleCopy.nbCopies, storageClasses.front().nbCopies);
    ASSERT_EQ(m_storageClassSingleCopy.comment, storageClasses.front().comment);
976
977
978
979
980
981
982
983
984
985
986
987

    const common::dataStructures::EntryLog creationLog = storageClasses.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
  }
}

TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassName_nonExistentStorageClass) {
  using namespace cta;

  const std::string currentStorageClassName = "storage_class";
  const std::string newStorageClassName = "new_storage_class";
988
  ASSERT_THROW(m_catalogue->modifyStorageClassName(m_admin, currentStorageClassName, newStorageClassName), exception::UserError);
989
990
}

991
992
993
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassName_newNameAlreadyExists) {
  using namespace cta;

994
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
995
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
996
  
997
  auto storageClass2 = m_storageClassSingleCopy;
998
999
  storageClass2.name = "storage_class2";
  
1000
  m_catalogue->createStorageClass(m_admin, storageClass2);
1001
1002
  
  //Try to rename the first storage class with the name of the second one
1003
  ASSERT_THROW(m_catalogue->modifyStorageClassName(m_admin, m_storageClassSingleCopy.name, storageClass2.name), exception::UserError);
1004
1005
}

1006
1007
1008
TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassVo) {
  using namespace cta;

1009
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
1010
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
1011
  
1012
1013
1014
  auto newVo = m_vo;
  newVo.name = "newVo";
  m_catalogue->createVirtualOrganization(m_admin, newVo);
1015
  
1016
  m_catalogue->modifyStorageClassVo(m_admin, m_storageClassSingleCopy.name, newVo.name);
1017
1018
  
  auto storageClasses = m_catalogue->getStorageClasses();
1019
  ASSERT_EQ(newVo.name, storageClasses.front().vo.name);
1020
1021
1022
1023
1024
}

TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassEmptyStringVo) {
  using namespace cta;

1025
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
1026
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
1027
  
1028
  ASSERT_THROW(m_catalogue->modifyStorageClassVo(m_admin, m_storageClassSingleCopy.name, ""), catalogue::UserSpecifiedAnEmptyStringVo);
1029
1030
1031
1032
1033
}

TEST_P(cta_catalogue_CatalogueTest, modifyStorageClassVoDoesNotExist) {
  using namespace cta;

1034
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
1035
  m_catalogue->createStorageClass(m_admin, m_storageClassSingleCopy);
1036
  
1037
  ASSERT_THROW(m_catalogue->modifyStorageClassVo(m_admin, m_storageClassSingleCopy.name, "DOES_NOT_EXISTS"), exception::UserError);
1038
1039
}

1040
1041
1042
TEST_P(cta_catalogue_CatalogueTest, createMediaType) {
  using namespace cta;

1043
  m_catalogue->createMediaType(m_admin, m_mediaType);
1044
1045
1046
1047
1048

  const auto mediaTypes = m_catalogue->getMediaTypes();

  ASSERT_EQ(1, mediaTypes.size());

1049
1050
1051
1052
1053
1054
1055
1056
1057
  ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
  ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
  ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
  ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
  ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
  ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
  ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
  ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
  ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
  
  const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
  ASSERT_EQ(m_admin.username, creationLog.username);
  ASSERT_EQ(m_admin.host, creationLog.host);

  const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
  ASSERT_EQ(creationLog, lastModificationLog);
}

TEST_P(cta_catalogue_CatalogueTest, createMediaType_same_twice) {
  using namespace cta;

1070
1071
  m_catalogue->createMediaType(m_admin, m_mediaType);
  ASSERT_THROW(m_catalogue->createMediaType(m_admin, m_mediaType), exception::UserError);
1072
1073
1074
1075
1076
}

TEST_P(cta_catalogue_CatalogueTest, createMediaType_emptyStringMediaTypeName) {
  using namespace cta;

1077
  auto mediaType = m_mediaType;
1078
  mediaType.name = "";
1079
  ASSERT_THROW(m_catalogue->createMediaType(m_admin, mediaType), catalogue::UserSpecifiedAnEmptyStringMediaTypeName);
1080
1081
1082
1083
1084
}

TEST_P(cta_catalogue_CatalogueTest, createMediaType_emptyStringComment) {
  using namespace cta;

1085
  auto mediaType = m_mediaType;
1086
  mediaType.comment = "";
1087
  ASSERT_THROW(m_catalogue->createMediaType(m_admin, mediaType), catalogue::UserSpecifiedAnEmptyStringComment);
1088
1089
1090
1091
1092
}

TEST_P(cta_catalogue_CatalogueTest, createMediaType_emptyStringCartridge) {
  using namespace cta;

1093
  auto mediaType = m_mediaType;
1094
  mediaType.cartridge = "";
1095
  ASSERT_THROW(m_catalogue->createMediaType(m_admin, mediaType), catalogue::UserSpecifiedAnEmptyStringCartridge);
1096
1097
}

1098
1099
1100
TEST_P(cta_catalogue_CatalogueTest, createMediaType_zeroCapacity) {
  using namespace cta;

1101
  auto mediaType = m_mediaType;
1102
  mediaType.capacityInBytes = 0;
1103
  ASSERT_THROW(m_catalogue->createMediaType(m_admin, mediaType), catalogue::UserSpecifiedAZeroCapacity);
1104
1105
}

1106
1107
1108
TEST_P(cta_catalogue_CatalogueTest, deleteMediaType) {
  using namespace cta;

1109
  m_catalogue->createMediaType(m_admin, m_mediaType);
1110
1111
1112
1113
1114

  const auto mediaTypes = m_catalogue->getMediaTypes();

  ASSERT_EQ(1, mediaTypes.size());

1115
1116
1117
1118
1119
1120
1121
1122
1123
  ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
  ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
  ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
  ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
  ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
  ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
  ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
  ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
  ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1124
1125
1126
1127
1128
1129
1130
1131
  
  const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
  ASSERT_EQ(m_admin.username, creationLog.username);
  ASSERT_EQ(m_admin.host, creationLog.host);

  const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
  ASSERT_EQ(creationLog, lastModificationLog);

1132
  m_catalogue->deleteMediaType(m_mediaType.name);
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142

  ASSERT_TRUE(m_catalogue->getMediaTypes().empty());
}

TEST_P(cta_catalogue_CatalogueTest, deleteMediaType_nonExistentMediaType) {
  using namespace cta;

  ASSERT_THROW(m_catalogue->deleteMediaType("media_type"), exception::UserError);
}

1143
1144
1145
1146
TEST_P(cta_catalogue_CatalogueTest, deleteMediaType_usedByTapes) {
  using namespace cta;

  log::LogContext dummyLc(m_dummyLog);
1147
  const bool logicalLibraryIsDisabled = false;
1148
1149
1150
1151
  const uint64_t nbPartialTapes = 2;
  const bool isEncrypted = true;
  const cta::optional<std::string> supply("value for the supply pool mechanism");

1152
  m_catalogue->createMediaType(m_admin, m_mediaType);
1153
  m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
1154
1155
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
  m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
1156
  m_catalogue->createTape(m_admin, m_tape1);
1157
1158
   
  //Media type is used by at least one tape, deleting it should throw an exception
1159
  ASSERT_THROW(m_catalogue->deleteMediaType(m_tape1.mediaType), exception::UserError);
1160
1161
}

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
TEST_P(cta_catalogue_CatalogueTest, getTapes_non_existent_tape_pool) {
  using namespace cta;

  log::LogContext dummyLc(m_dummyLog);
  const bool logicalLibraryIsDisabled = false;
  const uint64_t nbPartialTapes = 2;
  const bool isEncrypted = true;
  const cta::optional<std::string> supply("value for the supply pool mechanism");

  m_catalogue->createMediaType(m_admin, m_mediaType);
  m_catalogue->createLogicalLibrary(m_admin, m_tape1.logicalLibraryName, logicalLibraryIsDisabled, "Create logical library");
  m_catalogue->createVirtualOrganization(m_admin, m_vo);
  m_catalogue->createTapePool(m_admin, m_tape1.tapePoolName, m_vo.name, nbPartialTapes, isEncrypted, supply, "Create tape pool");
  m_catalogue->createTape(m_admin, m_tape1);
   
  {
    cta::catalogue::TapeSearchCriteria criteria;
    criteria.tapePool = "non_existent";
    ASSERT_THROW(m_catalogue->getTapes(criteria), catalogue::UserSpecifiedANonExistentTapePool);
  }
}

1184
1185
1186
1187
1188
1189
1190
TEST_P(cta_catalogue_CatalogueTest, createTape_deleteStorageClass) {
  // TO BE DONE
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeName) {
  using namespace cta;

1191
  m_catalogue->createMediaType(m_admin, m_mediaType);
1192
1193
1194
1195
1196
1197

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1198
1199
1200
1201
1202
1203
1204
1205
1206
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
  
    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);

    const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const std::string newMediaTypeName = "new_media_type";
1217
  m_catalogue->modifyMediaTypeName(m_admin, m_mediaType.name, newMediaTypeName);
1218
1219
1220
1221
1222
1223
1224

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

    ASSERT_EQ(newMediaTypeName, mediaTypes.front().name);
1225
1226
1227
1228
1229
1230
1231
1232
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
  
    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
  }
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeName_nonExistentMediaType) {
  using namespace cta;

  const std::string currentName = "media_type";
  const std::string newName = "new_media_type";
  ASSERT_THROW(m_catalogue->modifyMediaTypeName(m_admin, currentName, newName), exception::UserError);
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeName_newNameAlreadyExists) {
  using namespace cta;

1251
  m_catalogue->createMediaType(m_admin, m_mediaType);
1252

1253
  auto mediaType2 = m_mediaType;
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
  mediaType2.name = "media_type_2";

  m_catalogue->createMediaType(m_admin, mediaType2);

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(2, mediaTypes.size());

    const auto mediaTypeMap = mediaTypeWithLogsListToMap(mediaTypes);

    ASSERT_EQ(2, mediaTypeMap.size());

1267
    auto mediaType1Itor = mediaTypeMap.find(m_mediaType.name);
1268
1269
    ASSERT_TRUE(mediaType1Itor != mediaTypeMap.end());

1270
1271
1272
1273
1274
1275
1276
1277
1278
    ASSERT_EQ(m_mediaType.name, mediaType1Itor->second.name);
    ASSERT_EQ(m_mediaType.cartridge, mediaType1Itor->second.cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaType1Itor->second.capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaType1Itor->second.primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaType1Itor->second.secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaType1Itor->second.nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaType1Itor->second.minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaType1Itor->second.maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaType1Itor->second.comment);
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
  
    const common::dataStructures::EntryLog creationLog1 = mediaType1Itor->second.creationLog;
    ASSERT_EQ(m_admin.username, creationLog1.username);
    ASSERT_EQ(m_admin.host, creationLog1.host);

    const common::dataStructures::EntryLog lastModificationLog1 = mediaType1Itor->second.lastModificationLog;
    ASSERT_EQ(creationLog1, lastModificationLog1);

    auto mediaType2Itor = mediaTypeMap.find(mediaType2.name);
    ASSERT_TRUE(mediaType2Itor != mediaTypeMap.end());

    ASSERT_EQ(mediaType2.name, mediaType2Itor->second.name);
    ASSERT_EQ(mediaType2.cartridge, mediaType2Itor->second.cartridge);
    ASSERT_EQ(mediaType2.capacityInBytes, mediaType2Itor->second.capacityInBytes);
    ASSERT_EQ(mediaType2.primaryDensityCode, mediaType2Itor->second.primaryDensityCode);
    ASSERT_EQ(mediaType2.secondaryDensityCode, mediaType2Itor->second.secondaryDensityCode);
    ASSERT_EQ(mediaType2.nbWraps, mediaType2Itor->second.nbWraps);
    ASSERT_EQ(mediaType2.minLPos, mediaType2Itor->second.minLPos);
    ASSERT_EQ(mediaType2.maxLPos, mediaType2Itor->second.maxLPos);
    ASSERT_EQ(mediaType2.comment, mediaType2Itor->second.comment);
  
    const common::dataStructures::EntryLog creationLog2 = mediaType2Itor->second.creationLog;
    ASSERT_EQ(m_admin.username, creationLog2.username);
    ASSERT_EQ(m_admin.host, creationLog2.host);

    const common::dataStructures::EntryLog lastModificationLog2 = mediaType2Itor->second.lastModificationLog;
    ASSERT_EQ(creationLog2, lastModificationLog2);
  }

  // Try to rename the first media type with the name of the second one
1309
  ASSERT_THROW(m_catalogue->modifyMediaTypeName(m_admin, m_mediaType.name, mediaType2.name),exception::UserError);
1310
1311
1312
1313
1314
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeCartridge) {
  using namespace cta;

1315
  m_catalogue->createMediaType(m_admin, m_mediaType);
1316
1317
1318
1319
1320
1321

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1322
1323
1324
1325
1326
1327
1328
1329
1330
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);

    const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const std::string modifiedCartridge = "new_cartridge";
1341
  m_catalogue->modifyMediaTypeCartridge(m_admin, m_mediaType.name, modifiedCartridge);
1342
1343
1344
1345
1346
1347

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1348
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
1349
    ASSERT_EQ(modifiedCartridge, mediaTypes.front().cartridge);
1350
1351
1352
1353
1354
1355
1356
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
  }
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeCartridge_nonExistentMediaType) {
  using namespace cta;

  const std::string name = "media_type";
  const std::string cartridge = "cartride";
  ASSERT_THROW(m_catalogue->modifyMediaTypeCartridge(m_admin, name, cartridge), exception::UserError);
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeCapacityInBytes) {
  using namespace cta;

1375
  m_catalogue->createMediaType(m_admin, m_mediaType);
1376
1377
1378
1379
1380
1381

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1382
1383
1384
1385
1386
1387
1388
1389
1390
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1391
1392
1393
1394
1395
1396
1397
1398
1399

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);

    const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

1400
1401
  const uint64_t modifiedCapacityInBytes = m_mediaType.capacityInBytes + 7;
  m_catalogue->modifyMediaTypeCapacityInBytes(m_admin, m_mediaType.name, modifiedCapacityInBytes);
1402
1403
1404
1405
1406
1407

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1408
1409
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
1410
    ASSERT_EQ(modifiedCapacityInBytes, mediaTypes.front().capacityInBytes);
1411
1412
1413
1414
1415
1416
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
  }
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeCapacityInBytes_nonExistentMediaType) {
  using namespace cta;

  const std::string name = "media_type";
  const uint64_t capacityInBytes = 1;
  ASSERT_THROW(m_catalogue->modifyMediaTypeCapacityInBytes(m_admin, name, capacityInBytes), exception::UserError);
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypePrimaryDensityCode) {
  using namespace cta;

1435
  m_catalogue->createMediaType(m_admin, m_mediaType);
1436
1437
1438
1439
1440
1441

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1442
1443
1444
1445
1446
1447
1448
1449
1450
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);

    const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const uint8_t modifiedPrimaryDensityCode = 7;
1461
  m_catalogue->modifyMediaTypePrimaryDensityCode(m_admin, m_mediaType.name, modifiedPrimaryDensityCode);
1462
1463
1464
1465
1466
1467

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1468
1469
1470
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
1471
    ASSERT_EQ(modifiedPrimaryDensityCode, mediaTypes.front().primaryDensityCode);
1472
1473
1474
1475
1476
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);
  }
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypePrimaryDensityCode_nonExistentMediaType) {
  using namespace cta;

  const std::string name = "media_type";
  const uint8_t primaryDensityCode = 1;
  ASSERT_THROW(m_catalogue->modifyMediaTypePrimaryDensityCode(m_admin, name, primaryDensityCode), exception::UserError);
}

TEST_P(cta_catalogue_CatalogueTest, modifyMediaTypeSecondaryDensityCode) {
  using namespace cta;

1495
  m_catalogue->createMediaType(m_admin, m_mediaType);
1496
1497
1498
1499
1500
1501

  {
    const auto mediaTypes = m_catalogue->getMediaTypes();

    ASSERT_EQ(1, mediaTypes.size());

1502
1503
1504
1505
1506
1507
1508
1509
1510
    ASSERT_EQ(m_mediaType.name, mediaTypes.front().name);
    ASSERT_EQ(m_mediaType.cartridge, mediaTypes.front().cartridge);
    ASSERT_EQ(m_mediaType.capacityInBytes, mediaTypes.front().capacityInBytes);
    ASSERT_EQ(m_mediaType.primaryDensityCode, mediaTypes.front().primaryDensityCode);
    ASSERT_EQ(m_mediaType.secondaryDensityCode, mediaTypes.front().secondaryDensityCode);
    ASSERT_EQ(m_mediaType.nbWraps, mediaTypes.front().nbWraps);
    ASSERT_EQ(m_mediaType.minLPos, mediaTypes.front().minLPos);
    ASSERT_EQ(m_mediaType.maxLPos, mediaTypes.front().maxLPos);
    ASSERT_EQ(m_mediaType.comment, mediaTypes.front().comment);
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

    const common::dataStructures::EntryLog creationLog = mediaTypes.front().creationLog;
    ASSERT_EQ(m_admin.username, creationLog.username);
    ASSERT_EQ(m_admin.host, creationLog.host);

    const common::dataStructures::EntryLog lastModificationLog = mediaTypes.front().lastModificationLog;
    ASSERT_EQ(creationLog, lastModificationLog);
  }

  const uint8_t modifiedSecondaryDensityCode = 7;
1521
  m_catalogue->modifyMediaTypeSecondaryDensityCode(m_admin, m_mediaType.name, modifiedSecondaryDensityCode);
1522
1523
1524