joinfaces-bean-test

Demonstrates a way to create an JSF bean integration test

Лицензия

Лицензия

Группа

Группа

de.larmic
Идентификатор

Идентификатор

joinfaces-bean-test
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

joinfaces-bean-test
Demonstrates a way to create an JSF bean integration test
Ссылка на сайт

Ссылка на сайт

https://github.com/larmic/joinfaces-bean-test
Система контроля версий

Система контроля версий

https://github.com/larmic/joinfaces-bean-test

Скачать joinfaces-bean-test

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/de.larmic/joinfaces-bean-test/ -->
<dependency>
    <groupId>de.larmic</groupId>
    <artifactId>joinfaces-bean-test</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.larmic/joinfaces-bean-test/
implementation 'de.larmic:joinfaces-bean-test:1.0.0'
// https://jarcasting.com/artifacts/de.larmic/joinfaces-bean-test/
implementation ("de.larmic:joinfaces-bean-test:1.0.0")
'de.larmic:joinfaces-bean-test:jar:1.0.0'
<dependency org="de.larmic" name="joinfaces-bean-test" rev="1.0.0">
  <artifact name="joinfaces-bean-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.larmic', module='joinfaces-bean-test', version='1.0.0')
)
libraryDependencies += "de.larmic" % "joinfaces-bean-test" % "1.0.0"
[de.larmic/joinfaces-bean-test "1.0.0"]

Зависимости

provided (4)

Идентификатор библиотеки Тип Версия
org.joinfaces : jsf-spring-boot-starter jar 4.0.1
org.springframework.boot : spring-boot-starter-web jar 2.1.1.RELEASE
javax.enterprise : cdi-api jar 2.0
org.springframework.boot : spring-boot-starter-test jar 2.1.1.RELEASE

Модули Проекта

Данный проект не имеет модулей.

JSF Bean testing using JoinFaces and SpringBoot

Build Status Coverage Status License

This is a simple demo to demonstrate how to test a jsf scoped bean in Spring Boot context using JoinsFaces.

This code is inspired by some commercial project commits of @DEXRAY and updated by @larmic and @renepa

Usage

Dependency is available in maven central repository. Just add to your pom.xml

<dependency>
   <groupId>de.larmic</groupId>
   <artifactId>joinfaces-bean-test</artifactId>
   <version>1.0</version>
   <scope>test</scope>
</dependency>

Compatibility list

Version Spring Boot JoinFaces
<= 0.3 1.5.x 2.3.x
0.4 2.0.x 3.0.0.RC1
0.6 2.0.x 3.0.x
0.7 2.0.x 3.1.x
>= 0.8 2.0.x 3.2.x
1.0 2.1.x 4.x.x

Example

@Named
@RequestScoped
public class ContractsBean {

    private String customerNumber;

    @PostConstruct
    public void init() {
        customerNumber = FacesContext.getCurrentInstance()
                .getExternalContext()
                .getRequestParameterMap()
                .get("customerNumber");

    }

    public String getCustomerNumber() {
        return customerNumber;
    }
}

This simple bean reads url query parameter customerNumber. Using JoinFaces and SpringBoot this bean is not testable by default injection into a test class.

This demo allows following integration test:

@RunWith(SpringRunner.class)
@ContextConfiguration(initializers = {FacesContextMockApplicationContextInitializer.class})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class ContractsBeanTest {
    
    @Autowired
    private ApplicationContext context;

    @Test
    public void testCreateRequestScopedBeanWithCustomerNumberIsSet() {
        final ContractsBean bean = new JsfSpringBeanBuilder(context)
                .withExternalParameter("customerNumber", "unit-test-customer-number")
                .build(ContractsBean.class);

        assertThat(bean.getCustomerNumber()).isEqualTo("unit-test-customer-number");
    }

    @Test
    public void testCreateRequestScopedBeanWithCustomerNumberIsNull() {
        final ContractsBean bean = new JsfSpringBeanBuilder(context)
                .build(ContractsBean.class);

        assertThat(bean.getCustomerNumber()).isNull();
    }
}

Версии библиотеки

Версия
1.0.0
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.2.ALPHA5