forked from slemesle/selma
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the generated mapper is an application-scoped CDI bean and can be
retrieved via @Inject
- Loading branch information
1 parent
ed47d9a
commit 009cc90
Showing
7 changed files
with
172 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
processor/src/test/java/fr/xebia/extras/selma/it/inject/AddressMapperCDI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2013 Séven Le Mesle | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package fr.xebia.extras.selma.it.inject; | ||
|
||
import fr.xebia.extras.selma.IoC; | ||
import fr.xebia.extras.selma.Mapper; | ||
import fr.xebia.extras.selma.beans.AddressIn; | ||
import fr.xebia.extras.selma.beans.AddressOut; | ||
|
||
/** | ||
* Created by slemesle on 25/03/15. | ||
*/ | ||
@Mapper(withIgnoreFields = "extras", withCustom = CustomImmutableMapperClass.class, withFactories = BeanFactoryClass.class, withIoC = IoC.CDI, withFinalMappers = false) | ||
public interface AddressMapperCDI { | ||
|
||
AddressOut asAddressOut(AddressIn in); | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
processor/src/test/java/fr/xebia/extras/selma/it/inject/CustomMapperUsingCdiIoCIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2013 Séven Le Mesle | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package fr.xebia.extras.selma.it.inject; | ||
|
||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
import org.apache.webbeans.config.WebBeansContext; | ||
import org.apache.webbeans.spi.ContainerLifecycle; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import fr.xebia.extras.selma.beans.AddressIn; | ||
import fr.xebia.extras.selma.beans.AddressOut; | ||
import fr.xebia.extras.selma.beans.CityIn; | ||
import fr.xebia.extras.selma.it.custom.mapper.CustomImmutableMapper; | ||
import fr.xebia.extras.selma.it.utils.Compile; | ||
import fr.xebia.extras.selma.it.utils.IntegrationTestBase; | ||
|
||
@Compile(withClasses = { AddressMapperCDI.class, CustomImmutableMapperClass.class, BeanFactoryClass.class }) | ||
public class CustomMapperUsingCdiIoCIT extends IntegrationTestBase { | ||
|
||
@Test | ||
public void given_custom_as_selma_mapper_should_map_bean_with_it() | ||
throws IllegalAccessException, InstantiationException, ClassNotFoundException { | ||
|
||
final WebBeansContext currentInstance = WebBeansContext.currentInstance(); | ||
|
||
final ContainerLifecycle container = currentInstance.getService(ContainerLifecycle.class); | ||
|
||
container.startApplication(null); | ||
|
||
final BeanManager beanManager = container.getBeanManager(); | ||
|
||
final Set<Bean<?>> beans = beanManager.getBeans(AddressMapperCDI.class); | ||
|
||
final Iterator<Bean<?>> iterator = beans.iterator(); | ||
final Bean<?> bean = iterator.next(); | ||
final Object create = bean.create(null); | ||
final AddressMapperCDI addressMapper = (AddressMapperCDI) create; | ||
|
||
final AddressIn addressIn = new AddressIn(); | ||
addressIn.setCity(new CityIn()); | ||
addressIn.getCity().setCapital(true); | ||
addressIn.getCity().setName("Paris"); | ||
addressIn.getCity().setPopulation(3 * 1000 * 1000); | ||
addressIn.setPrincipal(true); | ||
addressIn.setNumber(55); | ||
addressIn.setStreet("rue de la truanderie"); | ||
addressIn.setExtras(Arrays.asList("titi", "toto")); | ||
|
||
final AddressOut res = addressMapper.asAddressOut(addressIn); | ||
|
||
Assert.assertNotNull(res); | ||
|
||
Assert.assertEquals(addressIn.getStreet(), res.getStreet()); | ||
Assert.assertEquals(addressIn.getNumber(), res.getNumber()); | ||
Assert.assertNull(res.getExtras()); | ||
|
||
Assert.assertEquals(addressIn.getCity().getName() + CustomImmutableMapper.IMMUTABLY_MAPPED, res.getCity().getName()); | ||
Assert.assertEquals(addressIn.getCity().getPopulation() + CustomImmutableMapper.POPULATION_INC, res.getCity().getPopulation()); | ||
Assert.assertEquals(addressIn.getCity().isCapital(), res.getCity().isCapital()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,5 @@ | |
* Created by slemesle on 27/03/15. | ||
*/ | ||
public enum IoC { | ||
NO, SPRING | ||
NO, SPRING, CDI | ||
} |