@Test public void canUseQueriesWithEnumAsParameterForInQuery() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.genre IN (:genre)", Movie.class ) .setParameter( "genre", EnumSet.of( Genre.DRAMA, Genre.COMEDY ) ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "To thatch a roof", "Barnie" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test public void canUseDateParameterForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.releaseDate = :releaseDate", Movie.class ) .setParameter( "releaseDate", new GregorianCalendar( 1958, 3, 2 ).getTime() ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "South by Southeast" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test public void canUseByteAsParameterForInComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.viewerRating IN (:viewerRating)", Movie.class ) .setParameter( "viewerRating", Arrays.asList( (byte) 8, (byte) 9 ) ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "To thatch a roof", "South by Southeast" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test public void canUseEnumAsParameterForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.genre = :genre", Movie.class ) .setParameter( "genre", Genre.THRILLER ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "South by Southeast", "Front Door" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test public void canUseBooleanAsParameterForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.suitableForKids = :suitable", Movie.class ) .setParameter( "suitable", Boolean.FALSE ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "Front Door", "Barnie" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test public void canUseByteForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.viewerRating = 8", Movie.class ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "To thatch a roof" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test public void canUseByteAsParameterForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.viewerRating = :viewerRating", Movie.class ) .setParameter( "viewerRating", (byte) 8 ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "To thatch a roof" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test @Ignore("TODO HQLPARSER-59") public void canUseDateLiteralForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.releaseDate = '02 April 1958'", Movie.class ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "South by Southeast" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test @Ignore("TODO HQLPARSER-59") public void canUseEnumLiteralForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.genre = org.hibernate.ogm.backendtck.queries.enums.Genre.THRILLER", Movie.class ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "South by Southeast", "Front Door" ); entityManager.getTransaction().commit(); entityManager.close(); }
@Test @Ignore("TODO HQLPARSER-59") public void canUseBooleanLiteralForSimpleComparison() { EntityManager entityManager = getFactory().createEntityManager(); entityManager.getTransaction().begin(); List<Movie> thrillers = entityManager.createQuery( "SELECT m FROM Movie m WHERE m.suitableForKids = FALSE", Movie.class ) .getResultList(); assertThat( thrillers ).onProperty( "title" ).containsOnly( "Front Door", "Barnie" ); entityManager.getTransaction().commit(); entityManager.close(); }
assertThat( hypothesis ).onProperty( "author" ).containsOnly( alma ); assertThat( hypothesis ).onProperty( "author" ).containsOnly( alma ); assertThat( hypothesis ).onProperty( "author" ).containsOnly( alfred ); assertThat( hypothesis ).onProperty( "id" ).containsExactly( "13", "15", "14", "16" );
assertThat( hypothesis ).onProperty( "author" ).containsOnly( alma, alfred );
assertThat( bob.getAttendedTournaments() ).onProperty( "name" ).contains( "British Open", "Player's Championship" ); loadedParticipant.getAttendedTournaments().remove( session.get( Tournament.class, britishOpen.getId() ) ); transaction.commit(); assertThat( bob.getAttendedTournaments() ).onProperty( "name" ).contains( "Player's Championship" );
@Test @TestForIssue(jiraKey = "OGM-917") public void canRetrieveListOfEntityWithSingleColumnEmbeddableId() throws Exception { Session session = openSession(); Transaction transaction = session.beginTransaction(); // given session.persist( new SingleBoardComputer( new SingleBoardComputerPk( "sbc-1" ), "Raspberry Pi" ) ); session.persist( new SingleBoardComputer( new SingleBoardComputerPk( "sbc-2" ), "BeagleBone" ) ); transaction.commit(); session.clear(); transaction = session.beginTransaction(); // when @SuppressWarnings("unchecked") List<SingleBoardComputer> computers = session.createQuery( "From SingleBoardComputer" ).list(); // then assertThat( computers ).onProperty( "name" ).containsOnly( "Raspberry Pi", "BeagleBone" ); for ( SingleBoardComputer sbc : computers ) { session.delete( sbc ); } transaction.commit(); session.close(); }
@Test public void testUpdateToElementOfOrderedListIsApplied() throws Exception { // insert entity with embedded collection inTransaction( session -> { grandMother.getGrandChildren().add( new GrandChild( "Luke" ) ); grandMother.getGrandChildren().add( new GrandChild( "Leia" ) ); session.persist( grandMother ); } ); // do an update to one of the elements inTransaction( session -> { GrandMother nana = (GrandMother) session.get( GrandMother.class, grandMother.getId() ); assertThat( nana.getGrandChildren() ).onProperty( "name" ).containsExactly( "Luke", "Leia" ); nana.getGrandChildren().get( 0 ).setName( "Lisa" ); } ); inTransaction( session -> { // assert update has been propagated GrandMother nana = (GrandMother) session.get( GrandMother.class, grandMother.getId() ); assertThat( nana.getGrandChildren() ).onProperty( "name" ).containsExactly( "Lisa", "Leia" ); } ); }
@Test public void testRemovalOfElementFromOrderedListIsApplied() throws Exception { // insert entity with embedded collection inTransaction( session -> { grandMother.getGrandChildren().add( new GrandChild( "Luke" ) ); grandMother.getGrandChildren().add( new GrandChild( "Leia" ) ); session.persist( grandMother ); } ); // remove one of the elements inTransaction( session -> { GrandMother nana = (GrandMother) session.get( GrandMother.class, grandMother.getId() ); nana.getGrandChildren().remove( 0 ); } ); // assert removal has been propagated inTransaction( session -> { grandMother = (GrandMother) session.get( GrandMother.class, grandMother.getId() ); assertThat( grandMother.getGrandChildren() ).onProperty( "name" ).containsExactly( "Leia" ); } ); }
assertThat( basket.getId() ).isEqualTo( basket.getId() ); assertThat( basket.getProducts() ) .onProperty( "name" ).containsOnly( beer.getName(), pretzel.getName() ); tx.commit();
MultiAddressAccount loadedAccount = (MultiAddressAccount) session.get( MultiAddressAccount.class, account.getLogin() ); assertThat( loadedAccount ).as( "Cannot load persisted object" ).isNotNull(); assertThat( loadedAccount.getAddresses() ).onProperty( "city" ).containsOnly( "Paris", "Rome" ); assertThat( loadedAccount.getAddresses() ).onProperty( "zipCode" ).containsOnly( "75007", "00184" ); assertThat( loadedAccount.getAddresses() ).onProperty( "country" ).containsOnly( "France", "Italy" ); assertThat( loadedAccount.getAddresses() ).onProperty( "street2" ).containsOnly( null, null ); assertThat( loadedAccount.getAddresses() ).onProperty( "type" ).containsOnly( new AddressType( "primary" ), null ); assertThat( secondLoadedAccount.getAddresses() ).onProperty( "city" ).contains( "Paris", "Rome" ); assertThat( secondLoadedAccount.getAddresses() ).onProperty( "country" ).contains( "USA", "Germany" ); session.delete( secondLoadedAccount ); transaction.commit();
assertThat( grandMother.getGrandChildren() ).onProperty( "name" ).containsExactly( "Leia" );