Package org.apache.cayenne.testdo.testmap

Examples of org.apache.cayenne.testdo.testmap.ArtGroup


     * Tests that deleting a source of a flattened relationship with CASCADE rule results
     * in deleting a join and a target.
     */
    public void testCascadeToManyFlattened() {
        // testing Artist.groupArray relationship
        ArtGroup aGroup = context.newObject(ArtGroup.class);
        aGroup.setName("Group Name");
        Artist anArtist = context.newObject(Artist.class);
        anArtist.setArtistName("A Name");
        anArtist.addToGroupArray(aGroup);
        assertTrue(anArtist.getGroupArray().contains(aGroup));

        context.commitChanges();

        SQLTemplate checkQuery = new SQLTemplate(
                Artist.class,
                "SELECT * FROM ARTIST_GROUP");
        checkQuery.setFetchingDataRows(true);
        List<?> joins1 = context.performQuery(checkQuery);
        assertEquals(1, joins1.size());

        context.deleteObjects(anArtist);

        assertEquals(PersistenceState.DELETED, aGroup.getPersistenceState());
        assertFalse(anArtist.getGroupArray().contains(aGroup));
        context.commitChanges();

        List<?> joins2 = context.performQuery(checkQuery);
        assertEquals(0, joins2.size());
View Full Code Here


     * Tests that deleting a source of a flattened relationship with NULLIFY rule results
     * in deleting a join together with the object deleted.
     */
    public void testNullifyToManyFlattened() {
        // testing ArtGroup.artistArray relationship
        ArtGroup aGroup = context.newObject(ArtGroup.class);
        aGroup.setName("Group Name");
        Artist anArtist = context.newObject(Artist.class);
        anArtist.setArtistName("A Name");
        aGroup.addToArtistArray(anArtist);

        context.commitChanges();

        // Preconditions
        assertTrue(aGroup.getArtistArray().contains(anArtist));
        assertTrue(anArtist.getGroupArray().contains(aGroup));

        SQLTemplate checkQuery = new SQLTemplate(
                Artist.class,
                "SELECT * FROM ARTIST_GROUP");
View Full Code Here

        assertEquals(0, joins2.size());
    }

    public void testNullifyToMany() {
        // ArtGroup childGroupsArray
        ArtGroup parentGroup = (ArtGroup) context.newObject("ArtGroup");
        parentGroup.setName("Parent");

        ArtGroup childGroup = (ArtGroup) context.newObject("ArtGroup");
        childGroup.setName("Child");
        parentGroup.addToChildGroupsArray(childGroup);

        // Preconditions - good to check to be sure
        assertEquals(parentGroup, childGroup.getToParentGroup());
        assertTrue(parentGroup.getChildGroupsArray().contains(childGroup));

        context.commitChanges();

        context.deleteObjects(parentGroup);

        // The things we are testing.
        assertNull(childGroup.getToParentGroup());

        // Although deleted, the property should be null (good cleanup policy)
        // assertFalse(parentGroup.getChildGroupsArray().contains(childGroup));
        context.commitChanges();
    }
View Full Code Here

                "g1"));
        List<?> results = context.performQuery(q);
        assertEquals(1, results.size());

        assertFalse(context.hasChanges());
        ArtGroup group = (ArtGroup) results.get(0);
        a1.addToGroupArray(group);
        assertTrue(context.hasChanges());

        List<?> groupList = a1.getGroupArray();
        assertEquals(1, groupList.size());
View Full Code Here

                "name",
                "g1"));
        List<?> results = context.performQuery(q);
        assertEquals(1, results.size());

        ArtGroup group = (ArtGroup) results.get(0);
        a1.addToGroupArray(group);

        List<?> groupList = a1.getGroupArray();
        assertEquals(1, groupList.size());
        assertEquals("g1", ((ArtGroup) groupList.get(0)).getName());
View Full Code Here

    public void testRemoveFromFlattenedRelationship() throws Exception {
        create1Artist1ArtGroup1ArtistGroupDataSet();

        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);

        ArtGroup group = a1.getGroupArray().get(0);
        a1.removeFromGroupArray(group);

        List<ArtGroup> groupList = a1.getGroupArray();
        assertEquals(0, groupList.size());
View Full Code Here

    // which it links.
    public void testRemoveFlattenedRelationshipAndRootRecord() throws Exception {
        create1Artist1ArtGroup1ArtistGroupDataSet();
        Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);

        ArtGroup group = a1.getGroupArray().get(0);
        a1.removeFromGroupArray(group); // Cause the delete of the link record

        context.deleteObjects(a1); // Cause the deletion of the artist

        try {
View Full Code Here

                "name",
                "g1"));
        List<?> results = context.performQuery(q);
        assertEquals(1, results.size());

        ArtGroup group = (ArtGroup) results.get(0);
        a1.addToGroupArray(group);
        group.removeFromArtistArray(a1);

        queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

            public void execute() {
                context.commitChanges();
View Full Code Here

        SelectQuery q = new SelectQuery(ArtGroup.class);
        List<?> results = context.performQuery(q);
        assertEquals(2, results.size());

        ArtGroup g1 = (ArtGroup) results.get(0);
        ArtGroup g2 = (ArtGroup) results.get(1);
        a1.addToGroupArray(g1);
        a1.addToGroupArray(g2);

        // test that there is no delete query issued when a flattened join is first
        // added and then deleted AND there are some other changes (CAY-548)
View Full Code Here

        assertEquals(0, plist.size());
    }

    public void testReflexiveRelationshipInsertOrder1() {

        ArtGroup parentGroup = context.newObject(ArtGroup.class);
        parentGroup.setName("parent");

        ArtGroup childGroup1 = context.newObject(ArtGroup.class);
        childGroup1.setName("child1");
        childGroup1.setToParentGroup(parentGroup);
        context.commitChanges();
    }
View Full Code Here

TOP

Related Classes of org.apache.cayenne.testdo.testmap.ArtGroup

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.