Search in sources :

Example 11 with ChartEntry

use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry 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 ChartEntry

use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry in project mapstruct by mapstruct.

the class NestedProductPropertiesTest method shouldMapNestedTarget.

@ProcessorTest
public void shouldMapNestedTarget() {
    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("Purple Rain");
    Chart result = ChartEntryToArtist.MAPPER.map(chartEntry);
    assertThat(result.getName()).isEqualTo("US Billboard Hot Rock Songs");
    assertThat(result.getSong()).isNotNull();
    assertThat(result.getSong().getArtist()).isNotNull();
    assertThat(result.getSong().getTitle()).isEqualTo("Purple Rain");
    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 : ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 13 with ChartEntry

use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry 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 14 with ChartEntry

use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry in project mapstruct by mapstruct.

the class NestedTargetPropertiesTest method shouldMapNestedComposedTarget.

@Test
public void shouldMapNestedComposedTarget() {
    ChartEntry chartEntry1 = new ChartEntry();
    chartEntry1.setArtistName("Prince");
    chartEntry1.setCity("Minneapolis");
    chartEntry1.setRecordedAt("Live, First Avenue, Minneapolis");
    chartEntry1.setSongTitle("Purple Rain");
    ChartEntry chartEntry2 = new ChartEntry();
    chartEntry2.setChartName("Italian Singles Chart");
    chartEntry2.setPosition(32);
    Chart result = ChartEntryToArtist.MAPPER.map(chartEntry1, chartEntry2);
    assertThat(result.getName()).isEqualTo("Italian Singles Chart");
    assertThat(result.getSong()).isNotNull();
    assertThat(result.getSong().getArtist()).isNotNull();
    assertThat(result.getSong().getTitle()).isEqualTo("Purple Rain");
    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(32);
}
Also used : ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) Test(org.junit.Test)

Example 15 with ChartEntry

use of org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry in project mapstruct by mapstruct.

the class NestedSourcePropertiesConstructorTest method shouldGenerateImplementationForPropertyNamesOnly.

@ProcessorTest
@WithClasses({ ArtistToChartEntry.class })
public void shouldGenerateImplementationForPropertyNamesOnly() {
    generatedSource.addComparisonToFixtureFor(ArtistToChartEntry.class);
    Studio studio = new Studio("Abbey Road", "London");
    Label label = new Label("EMY", studio);
    Artist artist = new Artist("The Beatles", label);
    Song song = new Song(artist, "A Hard Day's Night", Collections.emptyList());
    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.constructor.nestedsource.source.Artist) Song(org.mapstruct.ap.test.constructor.nestedsource.source.Song) ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Label(org.mapstruct.ap.test.constructor.nestedsource.source.Label) Studio(org.mapstruct.ap.test.constructor.nestedsource.source.Studio) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)22 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)19 WithClasses (org.mapstruct.ap.testutil.WithClasses)16 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)11 Chart (org.mapstruct.ap.test.nestedsourceproperties.source.Chart)10 Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)5 Test (org.junit.Test)4 Chart (org.mapstruct.ap.test.constructor.nestedsource.source.Chart)4 BaseChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry)4 BaseChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry)3 Artist (org.mapstruct.ap.test.constructor.nestedsource.source.Artist)2 Label (org.mapstruct.ap.test.constructor.nestedsource.source.Label)2 Studio (org.mapstruct.ap.test.constructor.nestedsource.source.Studio)2 Artist (org.mapstruct.ap.test.nestedsourceproperties.source.Artist)2 Label (org.mapstruct.ap.test.nestedsourceproperties.source.Label)2 Studio (org.mapstruct.ap.test.nestedsourceproperties.source.Studio)2 ChartEntryComposed (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryComposed)1 ChartEntryWithBase (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryWithBase)1 ChartEntryWithMapping (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryWithMapping)1