Search in sources :

Example 1 with ImageResource

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);
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceRecordVO(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) MockResourcesDAO(com.agiletec.aps.services.mock.MockResourcesDAO) DataSource(javax.sql.DataSource)

Example 2 with ImageResource

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);
        }
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 3 with ImageResource

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;
    }
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface) AttachResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)

Example 4 with ImageResource

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);
        }
    }
}
Also used : ImageResource(com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource) MockResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.mock.MockResourceDataBean) ResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceDataBean) ResourceInstance(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Aggregations

ImageResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.ImageResource)4 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)4 MockResourcesDAO (com.agiletec.aps.services.mock.MockResourcesDAO)1 Category (com.agiletec.aps.system.services.category.Category)1 MockResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.mock.MockResourceDataBean)1 AttachResource (com.agiletec.plugins.jacms.aps.system.services.resource.model.AttachResource)1 ResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceDataBean)1 ResourceInstance (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInstance)1 ResourceRecordVO (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceRecordVO)1 DataSource (javax.sql.DataSource)1