Search in sources :

Example 26 with User

use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method loadRatingByUserNameAndStars.

@Test
public void loadRatingByUserNameAndStars() {
    Filter userNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    userNameFilter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    Collection<Rating> ratings = session.loadAll(Rating.class, userNameFilter);
    assertThat(ratings).hasSize(2);
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 27 with User

use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method loadFilmByUserAndRatingUserPlays.

@Test
public void loadFilmByUserAndRatingUserPlays() {
    Filter userFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    userFilter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class));
    Filter playsFilter = new Filter("level", ComparisonOperator.EQUALS, "ok");
    playsFilter.setOwnerEntityType(Movie.class);
    playsFilter.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("plays", Plays.class));
    Filters filters = userFilter.and(playsFilter);
    Collection<Movie> films = session.loadAll(Movie.class, filters);
    assertThat(films).hasSize(2);
}
Also used : Movie(org.neo4j.ogm.domain.cineasts.annotated.Movie) Filters(org.neo4j.ogm.cypher.Filters) User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Plays(org.neo4j.ogm.domain.cineasts.annotated.Plays) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Example 28 with User

use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method nestedFilteringMustThrowExceptionWithOrInThePipeline.

@Test
public void nestedFilteringMustThrowExceptionWithOrInThePipeline() {
    // rated by the user who doesn't own Catty or by the user who owns Catty
    Filter filterA = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterA.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterA.setNegated(true);
    Filter alwaysTrueFilter = new Filter(new FilterFunction() {

        private Filter theFilter;

        @Override
        public Object getValue() {
            return null;
        }

        @Override
        public Map<String, Object> parameters(UnaryOperator createUniqueParameterName, PropertyValueTransformer valueTransformer) {
            return Collections.emptyMap();
        }

        @Override
        public String expression(String nodeIdentifier, String filteredProperty, UnaryOperator createUniqueParameterName) {
            return "1 = 1 ";
        }
    });
    alwaysTrueFilter.setBooleanOperator(BooleanOperator.OR);
    Filter filterB = new Filter("name", ComparisonOperator.EQUALS, "Catty");
    filterB.setNestedPath(new Filter.NestedPathSegment("ratings", Rating.class), new Filter.NestedPathSegment("user", User.class), new Filter.NestedPathSegment("pets", Pet.class));
    filterB.setBooleanOperator(BooleanOperator.AND);
    Filters filters = new Filters(filterA, alwaysTrueFilter, filterB);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> session.loadAll(Movie.class, filters)).withMessage("Filters containing nested paths cannot be combined via the logical OR operator.");
}
Also used : FilterFunction(org.neo4j.ogm.cypher.function.FilterFunction) PropertyValueTransformer(org.neo4j.ogm.cypher.PropertyValueTransformer) User(org.neo4j.ogm.domain.cineasts.annotated.User) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Filters(org.neo4j.ogm.cypher.Filters) Filter(org.neo4j.ogm.cypher.Filter) UnaryOperator(java.util.function.UnaryOperator) Map(java.util.Map) Pet(org.neo4j.ogm.domain.cineasts.annotated.Pet) Test(org.junit.Test)

Example 29 with User

use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method shouldModifyStringArraysCorrectly.

// GH-125
@Test
public void shouldModifyStringArraysCorrectly() throws MalformedURLException {
    User user = new User("joker", "Joker", "password");
    URL[] urls = new URL[3];
    urls[0] = new URL("http://www.apple.com");
    urls[1] = new URL("http://www.google.com");
    urls[2] = new URL("http://www.neo4j.com");
    user.setUrls(urls);
    String[] nicknames = new String[2];
    nicknames[0] = "batman";
    nicknames[1] = "robin";
    user.setNicknames(nicknames);
    session.save(user);
    user.getUrls()[0] = new URL("http://www.graphaware.com");
    user.getNicknames()[0] = "batgirl";
    session.save(user);
    // Test that arrays with and without custom converters are saved and loaded correctly when their content is updated
    user = session.load(User.class, user.getLogin());
    assertThat(user.getUrls().length).isEqualTo(3);
    assertThat(user.getUrls()[0].toString()).isEqualTo("http://www.graphaware.com");
    assertThat(user.getUrls()[1].toString()).isEqualTo("http://www.google.com");
    assertThat(user.getUrls()[2].toString()).isEqualTo("http://www.neo4j.com");
    assertThat(user.getNicknames().length).isEqualTo(2);
    assertThat(user.getNicknames()[0]).isEqualTo("batgirl");
    assertThat(user.getNicknames()[1]).isEqualTo("robin");
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) URL(java.net.URL) Test(org.junit.Test)

Example 30 with User

use of org.neo4j.ogm.domain.cineasts.annotated.User in project neo4j-ogm by neo4j.

the class CineastsIntegrationTest method loadRatingByUserName.

@Test
public void loadRatingByUserName() {
    Filter userNameFilter = new Filter("name", ComparisonOperator.EQUALS, "Michal");
    Filter ratingFilter = new Filter("stars", ComparisonOperator.EQUALS, 5);
    userNameFilter.setNestedPath(new Filter.NestedPathSegment("user", User.class));
    Collection<Rating> ratings = session.loadAll(Rating.class, userNameFilter.and(ratingFilter));
    assertThat(ratings).hasSize(1);
}
Also used : User(org.neo4j.ogm.domain.cineasts.annotated.User) Filter(org.neo4j.ogm.cypher.Filter) Rating(org.neo4j.ogm.domain.cineasts.annotated.Rating) Test(org.junit.Test)

Aggregations

User (org.neo4j.ogm.domain.cineasts.annotated.User)46 Test (org.junit.Test)45 Movie (org.neo4j.ogm.domain.cineasts.annotated.Movie)25 Rating (org.neo4j.ogm.domain.cineasts.annotated.Rating)24 Filter (org.neo4j.ogm.cypher.Filter)19 ExtendedUser (org.neo4j.ogm.domain.cineasts.annotated.ExtendedUser)17 Map (java.util.Map)12 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Filters (org.neo4j.ogm.cypher.Filters)3 Pet (org.neo4j.ogm.domain.cineasts.annotated.Pet)3 Pagination (org.neo4j.ogm.cypher.query.Pagination)2 SortOrder (org.neo4j.ogm.cypher.query.SortOrder)2 Plays (org.neo4j.ogm.domain.cineasts.annotated.Plays)2 Result (org.neo4j.ogm.model.Result)2 Session (org.neo4j.ogm.session.Session)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1