Search in sources :

Example 51 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class EntryLinksTest method testAddLink.

@Test
public void testAddLink() throws Exception {
    Account account = AccountCreator.createTestAccount("testAddLink", false);
    String userId = account.getEmail();
    Account differentAccount = AccountCreator.createTestAccount("testAddLink2", false);
    //create strain and plasmid
    Strain strain = TestEntryCreator.createTestStrain(account);
    Plasmid plasmid = TestEntryCreator.createTestPlasmid(differentAccount);
    // give each account read permissions
    AccessPermission accessPermission = new AccessPermission(AccessPermission.Article.ACCOUNT, account.getId(), AccessPermission.Type.READ_ENTRY, plasmid.getId(), "");
    PermissionsController permissionsController = new PermissionsController();
    Assert.assertNotNull(permissionsController.addPermission(differentAccount.getEmail(), accessPermission));
    accessPermission = new AccessPermission(AccessPermission.Article.ACCOUNT, differentAccount.getId(), AccessPermission.Type.READ_ENTRY, strain.getId(), "");
    Assert.assertNotNull(permissionsController.addPermission(account.getEmail(), accessPermission));
    // add plasmid links to strain
    EntryLinks entryLinks = new EntryLinks(userId, Long.toString(strain.getId()));
    // attempt to add as a parent (expected to fail)
    Assert.assertFalse(entryLinks.addLink(plasmid.toDataTransferObject(), LinkType.PARENT));
    // now add as a child
    Assert.assertTrue(entryLinks.addLink(plasmid.toDataTransferObject(), LinkType.CHILD));
    // add second plasmid
    Plasmid plasmid2 = TestEntryCreator.createTestPlasmid(account);
    Assert.assertTrue(entryLinks.addLink(plasmid2.toDataTransferObject(), LinkType.CHILD));
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Strain(org.jbei.ice.storage.model.Strain) PermissionsController(org.jbei.ice.lib.access.PermissionsController) Test(org.junit.Test)

Example 52 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class SampleServiceTest method testGetSamplesByBarcode.

@Test
public void testGetSamplesByBarcode() throws Exception {
    Account account = AccountCreator.createTestAccount("SampleServiceTest.testGetSamplesByBarcode", false);
    String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    PartSample partSample = new PartSample();
    partSample.setLabel("test");
    StorageLocation location = new StorageLocation();
    location.setDisplay("tube");
    location.setType(SampleType.TUBE);
    partSample.setLocation(location);
    partSample = service.createSample(userId, Long.toString(strain.getId()), partSample, null);
    Assert.assertNotNull(partSample);
    List<PartSample> partSamples = service.getSamplesByBarcode(userId, location.getDisplay());
    Assert.assertNotNull(partSamples);
    Assert.assertEquals(1, partSamples.size());
}
Also used : Account(org.jbei.ice.storage.model.Account) PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 53 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class SampleServiceTest method testCreateSample.

@Test
public void testCreateSample() throws Exception {
    Account account = AccountCreator.createTestAccount("SampleServiceTest.testCreateSample", false);
    String userId = account.getEmail();
    // create 96 strains
    Map<Long, String> idPartNumberMap = new HashMap<>();
    for (int i = 0; i < 96; i += 1) {
        Strain strain = TestEntryCreator.createTestStrain(account);
        Assert.assertNotNull(strain);
        idPartNumberMap.put(strain.getId(), strain.getPartNumber());
    }
    Assert.assertEquals(96, idPartNumberMap.size());
    String mainPlate = "0000000001";
    // create main plate
    createPlateSamples(userId, mainPlate, idPartNumberMap);
    List<Storage> storageList = DAOFactory.getStorageDAO().retrieveStorageByIndex(mainPlate, SampleType.PLATE96);
    Assert.assertNotNull(storageList);
    Assert.assertEquals(1, storageList.size());
    // retrieve samples for entries
    int i = 0;
    for (String partNumber : idPartNumberMap.values()) {
        List<PartSample> samples = service.retrieveEntrySamples(userId, partNumber);
        Assert.assertNotNull(samples);
        Assert.assertTrue(samples.size() == 1);
        verifyMainPlate(samples.get(0), i, mainPlate);
        i += 1;
    }
    // create backup 1
    String backUp1Plate = "0000000002";
    createPlateSamples(userId, backUp1Plate, idPartNumberMap);
    storageList = DAOFactory.getStorageDAO().retrieveStorageByIndex(backUp1Plate, SampleType.PLATE96);
    Assert.assertNotNull(storageList);
    Assert.assertEquals(1, storageList.size());
    // retrieve samples for entries
    i = 0;
    for (String partNumber : idPartNumberMap.values()) {
        List<PartSample> samples = service.retrieveEntrySamples(userId, partNumber);
        Assert.assertNotNull(samples);
        Assert.assertTrue(samples.size() == 2);
        verifyMainPlate(samples.get(0), i, mainPlate, backUp1Plate);
        verifyMainPlate(samples.get(1), i, mainPlate, backUp1Plate);
        i += 1;
    }
    // create backup 2
    String backUp2Plate = "0000000003";
    createPlateSamples(userId, backUp2Plate, idPartNumberMap);
    storageList = DAOFactory.getStorageDAO().retrieveStorageByIndex(backUp1Plate, SampleType.PLATE96);
    Assert.assertNotNull(storageList);
    Assert.assertEquals(1, storageList.size());
    // retrieve samples for entries
    i = 0;
    for (String partNumber : idPartNumberMap.values()) {
        List<PartSample> samples = service.retrieveEntrySamples(userId, partNumber);
        Assert.assertNotNull(samples);
        Assert.assertTrue(samples.size() == 3);
        verifyMainPlate(samples.get(0), i, mainPlate, backUp1Plate, backUp2Plate);
        verifyMainPlate(samples.get(1), i, mainPlate, backUp1Plate, backUp2Plate);
        verifyMainPlate(samples.get(2), i, mainPlate, backUp1Plate, backUp2Plate);
        i += 1;
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) Storage(org.jbei.ice.storage.model.Storage) HashMap(java.util.HashMap) PartSample(org.jbei.ice.lib.dto.sample.PartSample) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 54 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class SampleServiceTest method testRetrieveEntrySamples.

@Test
public void testRetrieveEntrySamples() throws Exception {
    Account account = AccountCreator.createTestAccount("SampleServiceTest.testRetrieveEntrySamples", false);
    String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    long entryId = strain.getId();
    List<PartSample> samplesList = service.retrieveEntrySamples(userId, Long.toString(entryId));
    Assert.assertNotNull(samplesList);
    for (PartSample partSample : samplesList) {
        Assert.assertNotNull(partSample.getId());
        Assert.assertNotNull(partSample.getCreationTime());
        Assert.assertNotNull(partSample.getLabel());
        Assert.assertNotNull(partSample.getLocation());
        Assert.assertNotNull(partSample.getDepositor());
        Assert.assertNotNull(partSample.getId());
        Assert.assertNotNull(partSample.isCanEdit());
        StorageLocation location = partSample.getLocation();
        while (location.getChild() != null) {
            location = location.getChild();
            Assert.assertNotNull(location.getType());
            Assert.assertNotNull(location.getId());
            Assert.assertNotNull(location.getDisplay());
            Assert.assertNotNull(location.getName());
        }
        if (partSample.getComments() != null) {
            for (UserComment comment : partSample.getComments()) {
                Assert.assertNotNull(comment.getId());
                Assert.assertNotNull(comment.getMessage());
            }
        }
    }
}
Also used : Account(org.jbei.ice.storage.model.Account) UserComment(org.jbei.ice.lib.dto.comment.UserComment) PartSample(org.jbei.ice.lib.dto.sample.PartSample) StorageLocation(org.jbei.ice.lib.dto.StorageLocation) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Example 55 with Account

use of org.jbei.ice.storage.model.Account in project ice by JBEI.

the class CustomFieldsTest method testGetField.

@Test
public void testGetField() throws Exception {
    Account account = AccountCreator.createTestAccount("testGetField", false);
    Assert.assertNotNull(account);
    final String userId = account.getEmail();
    Strain strain = TestEntryCreator.createTestStrain(account);
    Assert.assertNotNull(strain);
    CustomField field = new CustomField(0, strain.getId(), "foo1", "bar1");
    long id = fields.createField(userId, strain.getId(), field).getId();
    CustomField created = fields.getField(userId, id);
    Assert.assertEquals(created.getName(), field.getName());
    Assert.assertEquals(created.getValue(), field.getValue());
    Assert.assertEquals(created.getId(), id);
}
Also used : Account(org.jbei.ice.storage.model.Account) Strain(org.jbei.ice.storage.model.Strain) Test(org.junit.Test)

Aggregations

Account (org.jbei.ice.storage.model.Account)153 Test (org.junit.Test)71 Group (org.jbei.ice.storage.model.Group)24 Entry (org.jbei.ice.storage.model.Entry)21 Strain (org.jbei.ice.storage.model.Strain)20 PartData (org.jbei.ice.lib.dto.entry.PartData)18 Folder (org.jbei.ice.storage.model.Folder)18 ArrayList (java.util.ArrayList)16 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 PermissionException (org.jbei.ice.lib.access.PermissionException)11 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)10 Plasmid (org.jbei.ice.storage.model.Plasmid)10 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)8 DAOException (org.jbei.ice.storage.DAOException)8 RemotePartner (org.jbei.ice.storage.model.RemotePartner)8 HibernateException (org.hibernate.HibernateException)7 HashSet (java.util.HashSet)6 Part (org.jbei.ice.storage.model.Part)6