Search in sources :

Example 6 with ChartEntry

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

the class NestedProductPropertiesConstructorTest method shouldMapNestedTarget.

@ProcessorTest
public void shouldMapNestedTarget() {
    ChartEntry chartEntry = new ChartEntry("US Billboard Hot Rock Songs", "Purple Rain", "Prince", "Live, First Avenue, Minneapolis", "Minneapolis", 1);
    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.constructor.nestedsource._target.ChartEntry) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 7 with ChartEntry

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

the class NestedProductPropertiesConstructorTest method shouldReverseNestedTarget.

@ProcessorTest
public void shouldReverseNestedTarget() {
    ChartEntry chartEntry = new ChartEntry("US Billboard Hot Rock Songs", "Purple Rain", "Prince", "Live, First Avenue, Minneapolis", "Minneapolis", 1);
    Chart chart = ChartEntryToArtist.MAPPER.map(chartEntry);
    ChartEntry result = ChartEntryToArtist.MAPPER.map(chart);
    assertThat(result).isNotNull();
    assertThat(result.getArtistName()).isEqualTo("Prince");
    assertThat(result.getChartName()).isEqualTo("US Billboard Hot Rock Songs");
    assertThat(result.getCity()).isEqualTo("Minneapolis");
    assertThat(result.getPosition()).isEqualTo(1);
    assertThat(result.getRecordedAt()).isEqualTo("Live, First Avenue, Minneapolis");
    assertThat(result.getSongTitle()).isEqualTo("Purple Rain");
}
Also used : ChartEntry(org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry) Chart(org.mapstruct.ap.test.constructor.nestedsource.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 8 with ChartEntry

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

the class ReversingNestedSourcePropertiesTest method shouldIgnoreEverytingBelowArtist.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithIgnoresReverse.class })
public void shouldIgnoreEverytingBelowArtist() {
    Song song1 = prepareSong();
    ChartEntry chartEntry = ArtistToChartEntryWithIgnoresReverse.MAPPER.mapForward(song1);
    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");
    // and now in reverse
    Song song2 = ArtistToChartEntryWithIgnoresReverse.MAPPER.mapReverse(chartEntry);
    assertThat(song2).isNotNull();
    assertThat(song2.getArtist()).isNull();
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) BaseChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 9 with ChartEntry

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

the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedReverseWithFactory.

@ProcessorTest
@WithClasses({ ArtistToChartEntryWithFactoryReverse.class, SourceDtoFactory.class })
public void shouldGenerateNestedReverseWithFactory() {
    Song song1 = prepareSong();
    ChartEntry chartEntry = ArtistToChartEntryWithFactoryReverse.MAPPER.mapForward(song1);
    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");
    // and now in reverse
    Song song2 = ArtistToChartEntryWithFactoryReverse.MAPPER.mapReverse(chartEntry);
    assertThat(song2).isNotNull();
    assertThat(song2.getArtist()).isNotNull();
    assertThat(song2.getArtist().getName()).isEqualTo("The Beatles");
    assertThat(song2.getArtist().getLabel()).isNotNull();
    assertThat(song2.getArtist().getLabel().getName()).isNull();
    assertThat(song2.getArtist().getLabel().getStudio()).isNotNull();
    assertThat(song2.getArtist().getLabel().getStudio().getCity()).isEqualTo("London");
    assertThat(song2.getArtist().getLabel().getStudio().getName()).isEqualTo("Abbey Road");
    assertThat(SourceDtoFactory.isCreateSongCalled()).isTrue();
    assertThat(SourceDtoFactory.isCreateStudioCalled()).isTrue();
    assertThat(SourceDtoFactory.isCreateLabelCalled()).isTrue();
    assertThat(SourceDtoFactory.isCreateArtistCalled()).isTrue();
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry) BaseChartEntry(org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 10 with ChartEntry

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

the class ReversingNestedSourcePropertiesTest method shouldGenerateNestedComposedReverse.

@ProcessorTest
@WithClasses({ ArtistToChartEntryComposedReverse.class, ChartEntryComposed.class, ChartEntryLabel.class })
public void shouldGenerateNestedComposedReverse() {
    Song song1 = prepareSong();
    ChartEntryComposed chartEntry = ArtistToChartEntryComposedReverse.MAPPER.mapForward(song1);
    assertThat(chartEntry).isNotNull();
    assertThat(chartEntry.getArtistName()).isEqualTo("The Beatles");
    assertThat(chartEntry.getChartName()).isNull();
    assertThat(chartEntry.getLabel().getName()).isEqualTo("EMY");
    assertThat(chartEntry.getLabel().getCity()).isEqualTo("London");
    assertThat(chartEntry.getLabel().getRecordedAt()).isEqualTo("Abbey Road");
    assertThat(chartEntry.getPosition()).isEqualTo(0);
    assertThat(chartEntry.getSongTitle()).isEqualTo("A Hard Day's Night");
    // and now in reverse
    Song song2 = ArtistToChartEntryComposedReverse.MAPPER.mapReverse(chartEntry);
    assertThat(song2).isNotNull();
    assertThat(song2.getArtist()).isNotNull();
    assertThat(song2.getArtist().getName()).isEqualTo("The Beatles");
    assertThat(song2.getArtist().getLabel()).isNotNull();
    assertThat(song2.getArtist().getLabel().getName()).isEqualTo("EMY");
    assertThat(song2.getArtist().getLabel().getStudio()).isNotNull();
    assertThat(song2.getArtist().getLabel().getStudio().getCity()).isEqualTo("London");
    assertThat(song2.getArtist().getLabel().getStudio().getName()).isEqualTo("Abbey Road");
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartEntryComposed(org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryComposed) 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