use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource in project entando-core by entando.
the class TestResourceDAO method testAddDeleteResource.
public void testAddDeleteResource() throws Throwable {
DataSource dataSource = (DataSource) this.getApplicationContext().getBean("portDataSource");
MockResourcesDAO mockResourcesDao = new MockResourcesDAO();
mockResourcesDao.setDataSource(dataSource);
ResourceInterface resource = new ImageResource();
resource.setId("temp");
resource.setDescr("temp");
resource.setMainGroup(Group.FREE_GROUP_NAME);
resource.setType("Image");
resource.setFolder("/temp");
// resource.setBaseURL("temp");
ResourceRecordVO resourceRecordVO = null;
try {
mockResourcesDao.deleteResource("temp");
} catch (Throwable t) {
throw t;
}
_resourceDao.addResource(resource);
resourceRecordVO = _resourceDao.loadResourceVo(resource.getId());
assertEquals(resourceRecordVO.getDescr().equals("temp"), true);
_resourceDao.deleteResource(resource.getId());
resourceRecordVO = _resourceDao.loadResourceVo(resource.getId());
assertNull(resourceRecordVO);
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource in project entando-core by entando.
the class ResourceManagerIntegrationTest method testUpdateResource.
public void testUpdateResource() throws Throwable {
String oldDescr = null;
List<Category> oldCategories = null;
try {
ResourceInterface resource = this._resourceManager.loadResource("44");
assertTrue(resource instanceof ImageResource);
assertEquals(resource.getDescription(), "logo");
assertEquals(resource.getCategories().size(), 1);
assertTrue(resource.isMultiInstance());
oldCategories = resource.getCategories();
oldDescr = resource.getDescription();
String newDescr = "New Description";
resource.setDescription(newDescr);
resource.setCategories(new ArrayList<Category>());
this._resourceManager.updateResource(resource);
resource = this._resourceManager.loadResource("44");
assertEquals(resource.getDescription(), newDescr);
assertEquals(resource.getCategories().size(), 0);
} catch (Throwable t) {
throw t;
} finally {
if (oldCategories != null && oldDescr != null) {
ResourceInterface resource = this._resourceManager.loadResource("44");
resource.setCategories(oldCategories);
resource.setDescription(oldDescr);
this._resourceManager.updateResource(resource);
}
}
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource in project entando-core by entando.
the class ResourceManagerIntegrationTest method testLoadResource.
public void testLoadResource() throws Throwable {
try {
ResourceInterface resource = this._resourceManager.loadResource("44");
assertTrue(resource instanceof ImageResource);
assertTrue(resource.isMultiInstance());
assertEquals(resource.getDescription(), "logo");
assertEquals(resource.getCategories().size(), 1);
resource = this._resourceManager.loadResource("7");
assertTrue(resource instanceof AttachResource);
assertFalse(resource.isMultiInstance());
assertEquals(resource.getDescription(), "configurazione");
assertEquals(resource.getCategories().size(), 0);
} catch (Throwable t) {
throw t;
}
}
use of com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource in project entando-core by entando.
the class ResourceManagerIntegrationTest method testAddRemoveImageResource.
private void testAddRemoveImageResource(String mainGroup) throws Throwable {
List<String> allowedGroups = this.getAllGroupCodes();
ResourceInterface res = null;
String resDescrToAdd = "Entando Logo";
String resourceType = "Image";
String categoryCodeToAdd = "resCat1";
ResourceDataBean bean = this.getMockResource(resourceType, mainGroup, resDescrToAdd, categoryCodeToAdd);
try {
List<String> resourcesId = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
assertEquals(1, resourcesId.size());
this._resourceManager.addResource(bean);
resourcesId = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, null, allowedGroups);
assertEquals(resourcesId.size(), 1);
resourcesId = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, categoryCodeToAdd, allowedGroups);
assertEquals(resourcesId.size(), 1);
res = this._resourceManager.loadResource(resourcesId.get(0));
assertTrue(res instanceof ImageResource);
assertEquals(res.getCategories().size(), 1);
assertEquals(res.getDescription(), resDescrToAdd);
ResourceInstance instance0 = ((ImageResource) res).getInstance(0, null);
assertEquals("entando_logo.jpg", res.getMasterFileName());
assertEquals("image/jpeg", instance0.getMimeType());
resourcesId = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
assertEquals(resourcesId.size(), 2);
} catch (Throwable t) {
throw t;
} finally {
if (res != null) {
this._resourceManager.deleteResource(res);
List<String> resources = _resourceManager.searchResourcesId(resourceType, resDescrToAdd, null, allowedGroups);
assertEquals(resources.size(), 0);
resources = _resourceManager.searchResourcesId(resourceType, null, categoryCodeToAdd, allowedGroups);
assertEquals(resources.size(), 1);
}
}
}
Aggregations