Skip to content

AlreadyBuiltException when generating integration tests for UserController #2577

Closed
@IlyaMuravjov

Description

@IlyaMuravjov

Description

One failing test expecting AlreadyBuiltException is generated for UserController.getByUsername()

To Reproduce

Generate integration tests for UserController.getByUsername() in Medical-Web-App project (after starting all docker containers as described in the project README).

Expected behavior

Some successful tests are generated.

Actual behavior

No successful tests are generated, one failing test is generated that is in fact passes.

Visual proofs (screenshots, logs, images)

@Test
@DisplayName("getByUsername: username = '#$\\\"'', role = 'pty[m\u00AAe' (mutated from 'ptym\u00AAe') -> throw BeanCreationException")
public void testGetByUsernameThrowsBCEWithNonEmptyStrings() throws Exception {
   User user = new User();
   entityManager.persist(user);
   entityManager.flush();
   UriComponentsBuilder uriComponentsBuilder = fromPath("/api/search/username/{username}/{role}");
   Map uriVariables = new HashMap();
   uriVariables.put("username", "#$\\\"'");
   uriVariables.put("role", "pty[m\u00AAe");
   UriComponentsBuilder uriComponentsBuilder1 = uriComponentsBuilder.uriVariables(uriVariables);
   String urlTemplate = uriComponentsBuilder1.toUriString();
   Object[] uriVars = {};
   MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(urlTemplate, uriVars);
  
   /* This test fails because method [org.springframework.test.web.servlet.MockMvc.perform] produces [org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built; nested exception is java.lang.RuntimeException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is org.springframework.security.config.annotation.AlreadyBuiltException: This object has already been built]
       org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
       org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
       org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
       org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
       org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
       org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
       org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
       org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1160)
       org.springframework.security.test.web.support.WebTestUtils.getSpringSecurityFilterChain(WebTestUtils.java:145)
       org.springframework.security.test.web.support.WebTestUtils.findFilter(WebTestUtils.java:117)
       org.springframework.security.test.web.support.WebTestUtils.getSecurityContextRepository(WebTestUtils.java:63)
       org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors$SecurityContextRequestPostProcessorSupport.save(SecurityMockMvcRequestPostProcessors.java:725)
       org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors$TestSecurityContextHolderPostProcessor.postProcessRequest(SecurityMockMvcRequestPostProcessors.java:805)
       org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.postProcessRequest(MockHttpServletRequestBuilder.java:843)
       org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:189) */
   mockMvc.perform(mockHttpServletRequestBuilder);
}

Metadata

Metadata

Assignees

Labels

comp-instrumented-processIssue is related to Instrumented processcomp-springIssue is related to Spring projects supportctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions