Package org.springframework.data.neo4j.aspects

Examples of org.springframework.data.neo4j.aspects.Group


    @Test
    @Transactional
    public void testAddToOneToManyRelationship() {
        Person michael = persistedPerson("Michael", 35);
        Person david = persistedPerson("David", 25);
        Group group = persist(new Group());
        group.setPersons(new HashSet<Person>());
        group.getPersons().add(michael);
        group.getPersons().add(david);
        Collection<Person> personsFromGet = group.getPersons();
        assertEquals(new HashSet<Person>(Arrays.asList(david,michael)), personsFromGet);
        assertTrue(Set.class.isAssignableFrom(personsFromGet.getClass()));
    }
View Full Code Here


    }

    @Test
    public void testAddToOneToManyRelationshipOutsideOfTransaction() {
        Person michael = persistedPerson("Michael", 35);
        Group group = persist(new Group());
        group.getPersons().add(michael);
        group = persist(group);
        try (Transaction tx = neo4jTemplate.getGraphDatabase().beginTx()) {
            Collection<Person> personsFromGet = group.getPersons();
            assertEquals(new HashSet<>(Arrays.asList(michael)), personsFromGet);
            tx.success();
        }
    }
View Full Code Here

    @Test
    @Transactional
    public void testRemoveFromOneToManyRelationship() {
        Person michael = persistedPerson("Michael", 35);
        Person david = persistedPerson("David", 25);
        Group group = persist(new Group());
        group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
        group.getPersons().remove(david);
        assertEquals(Collections.singleton(michael), group.getPersons());
    }
View Full Code Here

    @Test
    @Transactional
    public void testRemoveAllFromOneToManyRelationship() {
        Person michael = persistedPerson("Michael", 35);
        Person david = persistedPerson("David", 25);
        Group group = persist(new Group());
        group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
        group.getPersons().removeAll(Collections.singleton(david));
        assertEquals(Collections.singleton(michael), group.getPersons());
    }
View Full Code Here

    @Test
    @Transactional
    public void testRetainAllFromOneToManyRelationship() {
        Person michael = persistedPerson("Michael", 35);
        Person david = persistedPerson("David", 25);
        Group group = persist(new Group());
        group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
        group.getPersons().retainAll(Collections.singleton(david));
        assertEquals(Collections.singleton(david), group.getPersons());
    }
View Full Code Here

    @Test
    @Transactional
    public void testClearFromOneToManyRelationship() {
        Person michael = persistedPerson("Michael", 35);
        Person david = persistedPerson("David", 25);
        Group group = persist(new Group());
        group.setPersons(new HashSet<Person>(Arrays.asList(michael, david)));
        group.getPersons().clear();
        assertEquals(Collections.<Person>emptySet(), group.getPersons());
    }
View Full Code Here

    @Test
    @Transactional
    public void testOneToManyReadOnly() {
        Person michael = persistedPerson("Michael", 35);
        Person david = persistedPerson("David", 25);
        Group group = persist(new Group());
        Set<Person> persons = new HashSet<Person>(Arrays.asList(michael, david));
        group.setPersons(persons);
        assertEquals(persons, IteratorUtil.addToCollection(group.getReadOnlyPersons().iterator(), new HashSet<Person>()));
    }
View Full Code Here


    @Test(expected = InvalidDataAccessApiUsageException.class)
    @Transactional
    public void testOneToManyReadOnlyShouldThrowExceptionOnSet() {
        Group group = persist(new Group());
        group.setReadOnlyPersons(new HashSet<Person>());
    }
View Full Code Here

    }

    @Test
    @Transactional
    public void testSingleRelatedToViaField() {
        Group group = persist(new Group());
        Person mentor = persist(new Person());
        group.setMentorship(new Mentorship(mentor,group));
        persist(group);
        final Node node = neo4jTemplate.getPersistentState(group);
        assertEquals(1,IteratorUtil.count(node.getRelationships(Direction.INCOMING,DynamicRelationshipType.withName("mentors"))));
        final Group loaded = neo4jTemplate.load(node, Group.class);
        assertEquals(group.getMentorship(),loaded.getMentorship());
        assertEquals(group.getMentorship().getId(),loaded.getMentorship().getId());
        assertEquals(mentor, group.getMentorship().getMentor());
        assertEquals(group, group.getMentorship().getGroup());
    }
View Full Code Here

    }
   
    @Test
    @Transactional
    public void testRemoveSingleRelatedToViaField() {
        Group group = persist(new Group());
        Person mentor = persist(new Person());
        group.setMentorship(new Mentorship(mentor,group));
        persist(group);
        group.setMentorship(null);
        persist(group);
        final Node node = neo4jTemplate.getPersistentState(group);
        assertEquals(0,IteratorUtil.count(node.getRelationships(Direction.INCOMING,DynamicRelationshipType.withName("mentors"))));
        final Group loaded = neo4jTemplate.load(node, Group.class);
        assertThat(loaded.getMentorship(), is(nullValue()));
    }
View Full Code Here

TOP

Related Classes of org.springframework.data.neo4j.aspects.Group

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.