use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.
the class MetadataDaoTest method testShouldSearchMetadataByClassAndKeyValuePair.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testShouldSearchMetadataByClassAndKeyValuePair() {
EntityVO entityVO = new EntityVO(ID_1, CLASS_1);
Map<String, PipeConfValue> data = new HashMap<>();
data.put(DATA_KEY_1, new PipeConfValue(null, DATA_VALUE_1));
data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_1));
MetadataEntry metadataToSave = new MetadataEntry();
metadataToSave.setEntity(entityVO);
metadataToSave.setData(data);
metadataDao.registerMetadataItem(metadataToSave);
EntityVO entityVO2 = new EntityVO(ID_1, CLASS_2);
metadataToSave.setEntity(entityVO2);
metadataToSave.setData(data);
metadataDao.registerMetadataItem(metadataToSave);
List<EntityVO> loadedEntities = metadataDao.searchMetadataByClassAndKeyValue(CLASS_1, Collections.singletonMap(DATA_KEY_1, new PipeConfValue(null, DATA_VALUE_1)));
Assert.assertEquals(1, loadedEntities.size());
Assert.assertEquals(entityVO, loadedEntities.get(0));
}
use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.
the class MetadataDaoTest method testOneMetadata.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testOneMetadata() {
EntityVO entityVO = new EntityVO(ID_1, CLASS_1);
Map<String, PipeConfValue> data = new HashMap<>();
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
MetadataEntry metadataToSave = new MetadataEntry();
metadataToSave.setEntity(entityVO);
metadataToSave.setData(data);
// metadata registration
metadataDao.registerMetadataItem(metadataToSave);
MetadataEntry createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// add key to metadata
data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
metadataDao.uploadMetadataItemKey(entityVO, DATA_KEY_2, DATA_VALUE_2, DATA_TYPE_2);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// delete key from metadata
data.clear();
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
metadataDao.deleteMetadataItemKey(entityVO, DATA_KEY_2);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// update metadata
data.clear();
data.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
metadataToSave.setData(data);
metadataDao.uploadMetadataItem(metadataToSave);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
Assert.assertEquals(data, createdMetadata.getData());
// delete several keys from metadata
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
data.put(DATA_KEY_3, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_1));
metadataToSave.setData(data);
Set<String> keysToDelete = new HashSet<>();
keysToDelete.add(DATA_KEY_1);
keysToDelete.add(DATA_KEY_3);
keysToDelete.add(NON_EXISTING_DATA_KEY);
metadataDao.deleteMetadataItemKeys(metadataToSave, keysToDelete);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertEquals(ID_1, createdMetadata.getEntity().getEntityId());
Assert.assertEquals(CLASS_1, createdMetadata.getEntity().getEntityClass());
data.remove(DATA_KEY_1);
data.remove(DATA_KEY_3);
Assert.assertEquals(data, createdMetadata.getData());
// delete metadata
metadataDao.deleteMetadataItem(entityVO);
createdMetadata = metadataDao.loadMetadataItem(entityVO);
Assert.assertNull(createdMetadata);
}
use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.
the class MetadataDaoTest method testListMetadata.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testListMetadata() {
EntityVO entity1 = new EntityVO(ID_1, CLASS_1);
Map<String, PipeConfValue> data1 = new HashMap<>();
data1.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
MetadataEntry metadataToSave1 = new MetadataEntry();
metadataToSave1.setEntity(entity1);
metadataToSave1.setData(data1);
EntityVO entity2 = new EntityVO(ID_2, CLASS_2);
Map<String, PipeConfValue> data2 = new HashMap<>();
data2.put(DATA_KEY_2, new PipeConfValue(DATA_TYPE_2, DATA_VALUE_2));
MetadataEntry metadataToSave2 = new MetadataEntry();
metadataToSave2.setEntity(entity2);
metadataToSave2.setData(data2);
metadataDao.registerMetadataItem(metadataToSave1);
metadataDao.registerMetadataItem(metadataToSave2);
List<EntityVO> entities = new ArrayList<>();
entities.add(entity1);
entities.add(entity2);
List<MetadataEntry> metadataEntries = new ArrayList<>();
metadataEntries.add(metadataToSave1);
metadataEntries.add(metadataToSave2);
List<MetadataEntry> createdMetadata = metadataDao.loadMetadataItems(entities);
Assert.assertEquals(metadataEntries, createdMetadata);
metadataDao.deleteMetadataItem(entity1);
metadataDao.deleteMetadataItem(entity2);
createdMetadata = metadataDao.loadMetadataItems(entities);
Assert.assertNull(createdMetadata);
}
use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.
the class MetadataDaoTest method createItems.
private Pair<EntityVO, MetadataEntry> createItems(String issueName, AclClass aclClass, boolean createMetadata) {
EntityVO entity = new EntityVO(1L, aclClass);
Issue issue = getIssue(issueName, entity);
issueDao.createIssue(issue);
MetadataEntry metadataEntry = new MetadataEntry();
if (createMetadata) {
metadataEntry.setEntity(entity);
metadataEntry.setData(new HashMap<>());
metadataDao.registerMetadataItem(metadataEntry);
}
return new ImmutablePair<>(entity, metadataEntry);
}
use of com.epam.pipeline.controller.vo.EntityVO in project cloud-pipeline by epam.
the class FolderDaoTest method createObjectMetadata.
private List<FolderWithMetadata> createObjectMetadata(List<Folder> folders) {
Map<String, PipeConfValue> data = new HashMap<>();
data.put(DATA_KEY_1, new PipeConfValue(DATA_TYPE_1, DATA_VALUE_1));
MetadataEntry metadataToSave = new MetadataEntry();
List<FolderWithMetadata> foldersWithMetadata = new ArrayList<>();
folders.forEach(folder -> {
metadataToSave.setEntity(new EntityVO(folder.getId(), AclClass.FOLDER));
metadataToSave.setData(data);
metadataDao.registerMetadataItem(metadataToSave);
FolderWithMetadata folderWithMetadata = convertToFolderWithMetadata(folder);
folderWithMetadata.setData(data);
foldersWithMetadata.add(folderWithMetadata);
});
return foldersWithMetadata;
}
Aggregations