Package org.apache.rave.portal.model

Examples of org.apache.rave.portal.model.JpaRegion


    @Autowired
    private JpaRegionConverter regionConverter;

    @Test
    public void noConversion() {
        Region region = new JpaRegion();
        assertThat(regionConverter.convert(region), is(sameInstance(region)));
    }
View Full Code Here


        region.setLocked(false);
        region.setPage(new JpaPage());
        region.setRegionWidgets(new ArrayList<RegionWidget>());
        region.setRenderOrder(9);

        JpaRegion converted = regionConverter.convert(region);
        assertThat(converted, is(not(sameInstance(region))));
        assertThat(converted, is(instanceOf(JpaRegion.class)));
        assertThat(converted.getRegionWidgets(), is(equalTo(region.getRegionWidgets())));
        assertThat(converted.getEntityId().toString(), is(equalTo(region.getId())));
        assertThat(converted.getId(), is(equalTo(region.getId())));
        assertThat(converted.getPage(), is(instanceOf(Page.class)));
        assertThat(converted.getRenderOrder(), is(equalTo(region.getRenderOrder())));
        assertThat(converted.isLocked(), is(equalTo(region.isLocked())));
    }
View Full Code Here

    public JpaRegion convert(Region source) {
        return source instanceof JpaRegion ? (JpaRegion) source : createEntity(source);
    }

    private JpaRegion createEntity(Region source) {
        JpaRegion converted = null;
        if (source != null) {
            TypedQuery<JpaRegion> query = manager.createNamedQuery(JpaRegion.FIND_BY_ENTITY_ID, JpaRegion.class);
            query.setParameter(JpaRegion.ENTITY_ID_PARAM, source.getId() == null ? null : Long.parseLong(source.getId()));
            converted = getSingleResult(query.getResultList());

            if (converted == null) {
                converted = new JpaRegion();
            }
            updateProperties(source, converted);
        }
        return converted;
    }
View Full Code Here

    @Autowired
    private RegionRepository repository;

    @Test
    public void getById_validId() {
        JpaRegion region = (JpaRegion)repository.get(REGION_ID);
        assertThat(region, is(notNullValue()));
        assertThat(region.getEntityId(), is(equalTo(1L)));
        assertThat(region.getRegionWidgets().size(), is(equalTo(2)));
    }
View Full Code Here

        assertThat(region.getRegionWidgets().size(), is(equalTo(2)));
    }

    @Test
    public void getById_invalidId() {
        JpaRegion region = (JpaRegion)repository.get(INVALID_REGION_ID);
        assertThat(region, is(nullValue()));
    }
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void save_newEntity() {
        JpaRegion region = new JpaRegion();
        region.setRegionWidgets(new ArrayList<RegionWidget>());
        JpaRegion saved = (JpaRegion)repository.save(region);
        manager.flush();
        assertThat(saved, is(sameInstance(region)));
        assertThat(saved.getEntityId(), is(notNullValue()));
    }
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void save_existingEntity() {
        JpaRegion region = new JpaRegion();
        region.setEntityId(1L);
        region.setRegionWidgets(new ArrayList<RegionWidget>());
        JpaRegion saved = (JpaRegion)repository.save(region);
        manager.flush();
        assertThat(saved, is(not(sameInstance(region))));
        assertThat(saved.getEntityId(), is(equalTo(region.getEntityId())));
    }
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void save_cascadePersist() {
        JpaRegion region = new JpaRegion();
        region.setRegionWidgets(new ArrayList<RegionWidget>());
        RegionWidget regionWidget = new JpaRegionWidget();
        region.getRegionWidgets().add(regionWidget);

        JpaRegion saved = (JpaRegion)repository.save(region);
        manager.flush();

        assertThat(saved.getRegionWidgets().size(), is(equalTo(1)));
        RegionWidget actual = saved.getRegionWidgets().get(0);

        assertThat(actual, is(sameInstance(regionWidget)));
        assertThat(actual.getId(), is(notNullValue()));
    }
View Full Code Here

    @Test
    @Rollback(true)
    public void save_cascadeMerge() {

        JpaRegion region = new JpaRegion(1L);
        region.setEntityId(1L);
        region.setRegionWidgets(new ArrayList<RegionWidget>());
        RegionWidget regionWidget = new JpaRegionWidget(1L);
        region.getRegionWidgets().add(regionWidget);

        System.out.println(region.toString());

        Region saved = repository.save(region);
        manager.flush();

        System.out.println(saved.toString());
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void save_cascadeOrphan() {
        JpaRegion region = (JpaRegion)repository.get("1");
        String id = region.getRegionWidgets().get(0).getId();
        region.getRegionWidgets().remove(0);

        Region saved = repository.save(region);
        manager.flush();
        RegionWidget widget = manager.find(JpaRegionWidget.class, Long.parseLong(id));
View Full Code Here

TOP

Related Classes of org.apache.rave.portal.model.JpaRegion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.