Search in sources :

Example 11 with Song

use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.

the class NestedSourcePropertiesTest method shouldGenerateImplementationForPropertyNamesOnly.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldGenerateImplementationForPropertyNamesOnly() {
    generatedSource.addComparisonToFixtureFor(ArtistToChartEntry.class);
    Studio studio = new Studio();
    studio.setName("Abbey Road");
    studio.setCity("London");
    Label label = new Label();
    label.setStudio(studio);
    label.setName("EMY");
    Artist artist = new Artist();
    artist.setName("The Beatles");
    artist.setLabel(label);
    Song song = new Song();
    song.setArtist(artist);
    song.setTitle("A Hard Day's Night");
    ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map(song);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isNull();
    assertThat(chartEntry.getCity()).isEqualTo("London");
    assertThat(chartEntry.getPosition()).isEqualTo(0);
    assertThat(chartEntry.getRecordedAt()).isEqualTo("Abbey Road");
    assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
}
Also used : Artist(org.mapstruct.ap.test.nestedsourceproperties.source.Artist) Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) Label(org.mapstruct.ap.test.nestedsourceproperties.source.Label) Studio(org.mapstruct.ap.test.nestedsourceproperties.source.Studio) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 12 with Song

use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.

the class NestedTargetPropertiesTest method shouldMapNestedTargetWitUpdate.

@Test
public void shouldMapNestedTargetWitUpdate() {
    ChartEntry chartEntry = new ChartEntry();
    chartEntry.setArtistName("Prince");
    chartEntry.setChartName("US Billboard Hot Rock Songs");
    chartEntry.setCity("Minneapolis");
    chartEntry.setPosition(1);
    chartEntry.setRecordedAt("Live, First Avenue, Minneapolis");
    chartEntry.setSongTitle(null);
    Chart result = new Chart();
    result.setSong(new Song());
    result.getSong().setTitle("Raspberry Beret");
    ChartEntryToArtistUpdate.MAPPER.map(chartEntry, result);
    assertThat(result.getName()).isEqualTo("US Billboard Hot Rock Songs");
    assertThat(result.getSong()).isNotNull();
    assertThat(result.getSong().getArtist()).isNotNull();
    assertThat(result.getSong().getTitle()).isEqualTo("Raspberry Beret");
    assertThat(result.getSong().getArtist().getName()).isEqualTo("Prince");
    assertThat(result.getSong().getArtist().getLabel()).isNotNull();
    assertThat(result.getSong().getArtist().getLabel().getStudio()).isNotNull();
    assertThat(result.getSong().getArtist().getLabel().getStudio().getName()).isEqualTo("Live, First Avenue, Minneapolis");
    assertThat(result.getSong().getArtist().getLabel().getStudio().getCity()).isEqualTo("Minneapolis");
    assertThat(result.getSong().getPositions()).hasSize(1);
    assertThat(result.getSong().getPositions().get(0)).isEqualTo(1);
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) Test(org.junit.Test)

Example 13 with Song

use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.

the class ChartEntryToArtistImpl method chartSongTitle.

private String chartSongTitle(Chart chart) {
    if (chart == null) {
        return null;
    }
    Song song = chart.getSong();
    if (song == null) {
        return null;
    }
    String title = song.getTitle();
    if (title == null) {
        return null;
    }
    return title;
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song)

Example 14 with Song

use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.

the class ChartEntryToArtistImpl method chartSongArtistName.

private String chartSongArtistName(Chart chart) {
    if (chart == null) {
        return null;
    }
    Song song = chart.getSong();
    if (song == null) {
        return null;
    }
    Artist artist = song.getArtist();
    if (artist == null) {
        return null;
    }
    String name = artist.getName();
    if (name == null) {
        return null;
    }
    return name;
}
Also used : Artist(org.mapstruct.ap.test.nestedsourceproperties.source.Artist) Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song)

Example 15 with Song

use of org.mapstruct.ap.test.nestedsourceproperties.source.Song in project mapstruct by mapstruct.

the class NestedProductPropertiesTest method shouldMapNestedTargetWitUpdate.

@ProcessorTest
public void shouldMapNestedTargetWitUpdate() {
    ChartEntry chartEntry = new ChartEntry();
    chartEntry.setArtistName("Prince");
    chartEntry.setChartName("US Billboard Hot Rock Songs");
    chartEntry.setCity("Minneapolis");
    chartEntry.setPosition(1);
    chartEntry.setRecordedAt("Live, First Avenue, Minneapolis");
    chartEntry.setSongTitle(null);
    Chart result = new Chart();
    result.setSong(new Song());
    result.getSong().setTitle("Raspberry Beret");
    ChartEntryToArtistUpdate.MAPPER.map(chartEntry, result);
    assertThat(result.getName()).isEqualTo("US Billboard Hot Rock Songs");
    assertThat(result.getSong()).isNotNull();
    assertThat(result.getSong().getArtist()).isNotNull();
    assertThat(result.getSong().getTitle()).isEqualTo("Raspberry Beret");
    assertThat(result.getSong().getArtist().getName()).isEqualTo("Prince");
    assertThat(result.getSong().getArtist().getLabel()).isNotNull();
    assertThat(result.getSong().getArtist().getLabel().getStudio()).isNotNull();
    assertThat(result.getSong().getArtist().getLabel().getStudio().getName()).isEqualTo("Live, First Avenue, Minneapolis");
    assertThat(result.getSong().getArtist().getLabel().getStudio().getCity()).isEqualTo("Minneapolis");
    assertThat(result.getSong().getPositions()).hasSize(1);
    assertThat(result.getSong().getPositions().get(0)).isEqualTo(1);
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)21 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)12 WithClasses (org.mapstruct.ap.testutil.WithClasses)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)8 Artist (org.mapstruct.ap.test.nestedsourceproperties.source.Artist)6 Chart (org.mapstruct.ap.test.nestedsourceproperties.source.Chart)6 Label (org.mapstruct.ap.test.nestedsourceproperties.source.Label)5 Studio (org.mapstruct.ap.test.nestedsourceproperties.source.Studio)5 BaseChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry)4 ChartPositions (org.mapstruct.ap.test.nestedsourceproperties._target.ChartPositions)2 Test (org.junit.Test)1 ChartEntryComposed (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryComposed)1 ChartEntryLabel (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryLabel)1 ChartEntryWithBase (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryWithBase)1 ChartEntryWithMapping (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryWithMapping)1