Search in sources :

Example 1 with Chart

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

the class NestedTargetPropertiesTest method shouldMapNestedTarget.

@Test
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) Test(org.junit.Test)

Example 2 with Chart

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

the class NestedTargetPropertiesTest method shouldReverseNestedTarget.

@Test
public void shouldReverseNestedTarget() {
    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 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.nestedsourceproperties._target.ChartEntry) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) Test(org.junit.Test)

Example 3 with Chart

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

the class ChartEntryToArtistImpl method map.

@Override
public Chart map(ChartEntry chartEntry1, ChartEntry chartEntry2) {
    if (chartEntry1 == null && chartEntry2 == null) {
        return null;
    }
    Chart chart = new Chart();
    if (chartEntry1 != null) {
        if (chart.getSong() == null) {
            chart.setSong(new Song());
        }
        chartEntryToSong1(chartEntry1, chart.getSong());
    }
    if (chartEntry2 != null) {
        if (chart.getSong() == null) {
            chart.setSong(new Song());
        }
        chartEntryToSong2(chartEntry2, chart.getSong());
        chart.setName(chartEntry2.getChartName());
    }
    return chart;
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart)

Example 4 with Chart

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

the class NestedSourcePropertiesTest method shouldUseAddAsTargetAccessor.

@ProcessorTest
@WithClasses({ ArtistToChartEntryAdder.class, ChartPositions.class, AdderUsageObserver.class })
public void shouldUseAddAsTargetAccessor() {
    AdderUsageObserver.setUsed(false);
    Song song = new Song();
    song.setPositions(Arrays.asList(3, 5));
    Chart chart = new Chart();
    chart.setSong(song);
    ChartPositions positions = ArtistToChartEntryAdder.MAPPER.map(chart);
    assertThat(positions).isNotNull();
    assertThat(positions.getPositions()).containsExactly(3L, 5L);
    assertThat(AdderUsageObserver.isUsed()).isTrue();
}
Also used : Song(org.mapstruct.ap.test.nestedsourceproperties.source.Song) ChartPositions(org.mapstruct.ap.test.nestedsourceproperties._target.ChartPositions) Chart(org.mapstruct.ap.test.nestedsourceproperties.source.Chart) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 5 with Chart

use of org.mapstruct.ap.test.nestedsourceproperties.source.Chart 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)

Aggregations

Chart (org.mapstruct.ap.test.nestedsourceproperties.source.Chart)13 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)10 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)8 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)6 Test (org.junit.Test)4 WithClasses (org.mapstruct.ap.testutil.WithClasses)4 ChartPositions (org.mapstruct.ap.test.nestedsourceproperties._target.ChartPositions)2 Artist (org.mapstruct.ap.test.nestedsourceproperties.source.Artist)1 Label (org.mapstruct.ap.test.nestedsourceproperties.source.Label)1 Studio (org.mapstruct.ap.test.nestedsourceproperties.source.Studio)1