Package org.apache.rave.model

Examples of org.apache.rave.model.Region


    @Test
    public void save(){
        Page page = new PageImpl("1234L");
        List<Region> regions = Lists.newArrayList();
        Region item = new RegionImpl("1111L");
        regions.add(item);
        page.setRegions(regions);

        expect(template.findOne(new Query(Criteria.where("regions").elemMatch(Criteria.where("_id").is("1111L"))))).andReturn(page);
        expect(template.save(isA(Page.class))).andReturn(page);
        replay(template);

        Region result = repo.save(item);
        assertThat(result.getId(), is(equalTo("1111L")));
        assertThat(result, is(sameInstance(item)));

    }
View Full Code Here


    @Test
    public void save_null(){
        Page page = new PageImpl("1234L");
        List<Region> regions = Lists.newArrayList();
        Region item = new RegionImpl();
        item.setPage(page);
        regions.add(item);
        page.setRegions(regions);

        expect(template.get("1234L")).andReturn(page);
        expect(template.save(isA(Page.class))).andReturn(page);
        replay(template);

        Region result = repo.save(item);
        assertNull(result.getId());

    }
View Full Code Here

    @Test
     public void delete(){
        Page page = new PageImpl("1234L");
        List<Region> regions = Lists.newArrayList();
        Region item = new RegionImpl("1111L");
        regions.add(item);
        page.setRegions(regions);

        expect(template.findOne(new Query(Criteria.where("regions").elemMatch(Criteria.where("_id").is("1111L"))))).andReturn(page);
        expect(template.save(isA(Page.class))).andReturn(page);
View Full Code Here

    @Test (expected = IllegalStateException.class)
    public void delete_null(){
        Page page = new PageImpl("1234L");
        List<Region> regions = Lists.newArrayList();
        Region item = new RegionImpl();
        regions.add(item);
        page.setRegions(regions);

        repo.delete(item);
    }
View Full Code Here

    }

    private void removeRegion(Page page, Region item) {
        Iterator<Region> iterator = page.getRegions().iterator();
        while(iterator.hasNext()) {
            Region region = iterator.next();
            if(region.getId().equals(item.getId())) {
                iterator.remove();
                return;
            }
        }
    }
View Full Code Here

        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());

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

        assertThat(actual, is(not(sameInstance(regionWidget))));
        assertThat(actual.getId(), is(equalTo("1")));
    }
View Full Code Here

    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));

        assertThat(saved.getRegionWidgets().size(), is(equalTo(1)));
        assertThat(widget, is(nullValue()));
    }
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void delete_jpaObject() {
        Region r = repository.get(REGION_ID);
        assertThat(r, is(notNullValue()));
        repository.delete(r);
        r = repository.get(REGION_ID);
        assertThat(r, is(nullValue()));
    }
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void delete_implObject() {
        Region r = repository.get(REGION_ID);
        assertThat(r, is(notNullValue()));
        RegionImpl impl = new RegionImpl(r.getId());
        repository.delete(impl);
        r = repository.get(REGION_ID);
        assertThat(r, is(nullValue()));
    }
View Full Code Here

        return savedWidget;
    }

    private RegionWidget addNewRegionWidget(RegionWidget item) {
        Page page = getPageFromRepository(item);
        Region parent = getRegionById(item.getRegion().getId(), page.getRegions());
        if(parent == null) throw new IllegalStateException("Unable to find parent for page");
        parent.getRegionWidgets().add(item);
        Page saved = template.save(page);
        return getRegionById(parent.getId(), saved.getRegions()).getRegionWidgets().get(parent.getRegionWidgets().size() -1);
    }
View Full Code Here

TOP

Related Classes of org.apache.rave.model.Region

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.