Package com.nurkiewicz.jdbcrepository.repositories

Examples of com.nurkiewicz.jdbcrepository.repositories.BoardingPass


  private BoardingPassRepository repository;

  @Test
  public void shouldStoreEntityWithCompoundPrimaryKey() throws Exception {
    //given
    final BoardingPass entity = new BoardingPass("FOO-100", 42, "Smith", "B01");

    //when
    repository.save(entity);

    //then
    final BoardingPass found = repository.findOne(pk("FOO-100", 42));
    assertThat(found).isEqualTo(new BoardingPass("FOO-100", 42, "Smith", "B01"));
  }
View Full Code Here


  }

  @Test
  public void shouldAllowStoringMultipleEntitiesDifferingByOnePrimaryKeyColumn() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    repository.save(new BoardingPass("FOO-100", 2, "Johnson", "C02"));
    repository.save(new BoardingPass("BAR-100", 1, "Gordon", "D03"));
    repository.save(new BoardingPass("BAR-100", 2, "Who", "E04"));

    //when
    final BoardingPass foundFlight = repository.findOne(pk("BAR-100", 1));

    //then
    assertThat(foundFlight).isEqualTo(new BoardingPass("BAR-100", 1, "Gordon", "D03"));
  }
View Full Code Here

  }

  @Test
  public void shouldAllowUpdatingByPrimaryKey() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    final BoardingPass secondSeat = repository.save(new BoardingPass("FOO-100", 2, "Johnson", "C02"));

    secondSeat.setPassenger("Jameson");
    secondSeat.setSeat("C03");

    //when
    repository.save(secondSeat);

    //then
    assertThat(repository.count()).isEqualTo(2);
    final BoardingPass foundUpdated = repository.findOne(pk("FOO-100", 2));
    assertThat(foundUpdated).isEqualTo(new BoardingPass("FOO-100", 2, "Jameson", "C03"));
  }
View Full Code Here

  }

  @Test
  public void shouldDeleteByCompoundPrimaryKey() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));

    //when
    repository.delete(pk("FOO-100", 1));

    //then
View Full Code Here

  }

  @Test
  public void shouldAllowSortingByAllPrimaryKeyColumns() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    repository.save(new BoardingPass("FOO-100", 2, "Johnson", "C02"));
    repository.save(new BoardingPass("BAR-100", 2, "Who", "E04"));
    repository.save(new BoardingPass("BAR-100", 1, "Gordon", "D03"));

    //when
    final List<BoardingPass> all = repository.findAll(
        new Sort(
            new Order(ASC, "flight_no"),
            new Order(DESC, "seq_no")
        )
    );

    //then
    assertThat(all).containsExactly(
        new BoardingPass("BAR-100", 2, "Who", "E04"),
        new BoardingPass("BAR-100", 1, "Gordon", "D03"),
        new BoardingPass("FOO-100", 2, "Johnson", "C02"),
        new BoardingPass("FOO-100", 1, "Smith", "B01")
    );
  }
View Full Code Here

  }

  @Test
  public void shouldReturnFirstPageOfSortedResults() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    repository.save(new BoardingPass("FOO-100", 2, "Johnson", "C02"));
    repository.save(new BoardingPass("BAR-100", 2, "Who", "E04"));
    repository.save(new BoardingPass("BAR-100", 1, "Gordon", "D03"));

    //when
    final Page<BoardingPass> page = repository.findAll(
        new PageRequest(0, 3,
            new Sort(
                new Order(ASC, "flight_no"),
                new Order(DESC, "seq_no")
            )
        ));

    //then
    assertThat(page.getTotalElements()).isEqualTo(4);
    assertThat(page.getTotalPages()).isEqualTo(2);
    assertThat(page.getContent()).containsExactly(
        new BoardingPass("BAR-100", 2, "Who", "E04"),
        new BoardingPass("BAR-100", 1, "Gordon", "D03"),
        new BoardingPass("FOO-100", 2, "Johnson", "C02")
    );
  }
View Full Code Here

  }

  @Test
  public void shouldReturnLastPageOfSortedResults() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    repository.save(new BoardingPass("FOO-100", 2, "Johnson", "C02"));
    repository.save(new BoardingPass("BAR-100", 2, "Who", "E04"));
    repository.save(new BoardingPass("BAR-100", 1, "Gordon", "D03"));

    //when
    final Page<BoardingPass> page = repository.findAll(
        new PageRequest(1, 3,
            new Sort(
                new Order(ASC, "flight_no"),
                new Order(DESC, "seq_no")
            )
        ));

    //then
    assertThat(page.getContent()).containsExactly(new BoardingPass("FOO-100", 1, "Smith", "B01"));
  }
View Full Code Here

  }

  @Test
  public void shouldReturnNothingWhenFindingByListOfIdsButListEmpty() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    repository.save(new BoardingPass("FOO-100", 2, "Smith", "B01"));
    repository.save(new BoardingPass("FOO-100", 3, "Smith", "B01"));

    //when
    final Iterable<BoardingPass> none = repository.findAll(Collections.<Object[]>emptyList());

    //then
View Full Code Here

  }

  @Test
  public void shouldSelectOneRecordById() throws Exception {
    //given
    repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01"));
    final Object[] idOfSecond = repository.save(new BoardingPass("FOO-100", 2, "Smith", "B01")).getId();
    repository.save(new BoardingPass("FOO-100", 3, "Smith", "B01"));

    //when
    final List<BoardingPass> oneRecord = Lists.newArrayList(repository.findAll(Arrays.<Object[]>asList(idOfSecond)));

    //then
View Full Code Here

  }

  @Test
  public void shouldSelectMultipleRecordsById() throws Exception {
    //given
    final Object[] idOfFirst = repository.save(new BoardingPass("FOO-100", 1, "Smith", "B01")).getId();
    repository.save(new BoardingPass("FOO-100", 2, "Smith", "B01"));
    final Object[] idOfThird = repository.save(new BoardingPass("FOO-100", 3, "Smith", "B01")).getId();

    //when
    final List<BoardingPass> boardingPasses = Lists.newArrayList(repository.findAll(Arrays.asList(idOfFirst, idOfThird)));

    //then
View Full Code Here

TOP

Related Classes of com.nurkiewicz.jdbcrepository.repositories.BoardingPass

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.