@Test public void createAndFindPlatformEntityAndItsChildren() throws Exception { String expectedPlatformName = "platformOne"; String expectedVideoGameName1 = "Some Awesome title"; String expectedVideoGameName2 = "Another Awesome title"; Date dateReleased = new Date(); PlatformEntity platformEntity = new PlatformEntity(); platformEntity.setPlatformName(expectedPlatformName); VideoGameEntity videoGameEntity1 = new VideoGameEntity(); videoGameEntity1.setVideoGameName(expectedVideoGameName1); videoGameEntity1.setDateReleased(dateReleased); videoGameEntity1.setVideoGameStatusType(VideoGameStatusType.COMPLETED); videoGameEntity1.setPlatformEntity(platformEntity); VideoGameEntity videoGameEntity2 = new VideoGameEntity(); videoGameEntity2.setVideoGameName(expectedVideoGameName2); videoGameEntity2.setDateReleased(dateReleased); videoGameEntity2.setVideoGameStatusType(VideoGameStatusType.BACKLOG); videoGameEntity2.setPlatformEntity(platformEntity); platformEntity.getVideoGameEntities().add(videoGameEntity1); platformEntity.getVideoGameEntities().add(videoGameEntity2); PlatformEntity savedPlatformEntity = platformService.create(platformEntity); assertionsForPlatformEntityAndChildVideoGameEntity( expectedPlatformName, expectedVideoGameName1, expectedVideoGameName2, dateReleased, savedPlatformEntity); PlatformEntity retrievedPlatformEntity = platformService.findById(savedPlatformEntity.getPlatformId()); assertThat(retrievedPlatformEntity.getPlatformId(), is(savedPlatformEntity.getPlatformId())); assertionsForPlatformEntityAndChildVideoGameEntity( expectedPlatformName, expectedVideoGameName1, expectedVideoGameName2, dateReleased, retrievedPlatformEntity); List<PlatformEntity> platformEntities = platformService.findAll(); assertThat(platformEntities.size(), is(3)); assertionsForPlatformEntityAndChildVideoGameEntity( expectedPlatformName, expectedVideoGameName1, expectedVideoGameName2, dateReleased, retrievedPlatformEntity); }
@Test public void createAndFindVideoGameEntityAndItsParent() throws Exception { PlatformEntity platformEntity = new PlatformEntity(); String platformName = "I am a platform"; platformEntity.setPlatformName(platformName); Date videoGamedateReleased = new Date(); String videoGameName = "new title"; VideoGameEntity videoGameEntity = new VideoGameEntity(); videoGameEntity.setDateReleased(videoGamedateReleased); videoGameEntity.setVideoGameStatusType(VideoGameStatusType.PLAYING); videoGameEntity.setVideoGameName(videoGameName); videoGameEntity.setPlatformEntity(platformEntity); VideoGameEntity savedVideoGameEntity = videoGameService.create(videoGameEntity); VideoGameEntity retrievedVideoGameEntity = videoGameService.findById(savedVideoGameEntity.getVideoGameId()); assertThat( retrievedVideoGameEntity.getVideoGameId(), is(savedVideoGameEntity.getVideoGameId())); assertThat( retrievedVideoGameEntity.getVideoGameName(), is(savedVideoGameEntity.getVideoGameName())); assertThat(retrievedVideoGameEntity.getVideoGameStatusType(), is(VideoGameStatusType.PLAYING)); assertThat(retrievedVideoGameEntity.getPlatformEntity().getPlatformName(), is(platformName)); }