-2

Trying to use Junit tests to generate documentation using Spring Rest Docs, but I'm getting these errors which I can't identify where it's coming from. I'm a junior developer so inexperience may be part of it.

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener.prepareTestInstance(SpringBootDependencyInjectionTestExecutionListener.java:47)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ALC012Client' defined in URL [jar:file:/C:/ProgramData/Maven/.m2/repository/com/jbhunt/order/lib_ordermanagement_alc012/2.0.2/lib_ordermanagement_alc012-2.0.2.jar!/com/jbhunt/ordermanagement/order/alc012/client/ALC012Client.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servicePortConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servicePortConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
Caused by: java.lang.IllegalArgumentException
    at com.sun.xml.ws.client.RequestContext.setEndPointAddressString(RequestContext.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jvnet.ws.message.BasePropertySet$MethodAccessor.set(BasePropertySet.java:249)
    at org.jvnet.ws.message.BasePropertySet$MapView.put(BasePropertySet.java:325)
    at org.jvnet.ws.message.BasePropertySet$MapView.put(BasePropertySet.java:280)
    at org.jvnet.ws.message.BaseDistributedPropertySet$DistributedMapView.put(BaseDistributedPropertySet.java:250)
    at org.jvnet.ws.message.BaseDistributedPropertySet$DistributedMapView.put(BaseDistributedPropertySet.java:212)
    at com.jbhunt.ordermanagement.order.alc012.configuration.ServicePortConfiguration.oec170Port(ServicePortConfiguration.java:45)
    at com.jbhunt.ordermanagement.order.alc012.configuration.ServicePortConfigurationinitServicePortConfiguration(ServicePortConfiguration.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134)
    ... 182 more

I can't show too much code because it's company code but here are the annotations and a little bit of code. I'm mainly just trying to locate where the problem might be coming from.

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@Transactional
public class DocumentControllerTest {

@Autowired
    PIDCredentials pidCredentials;

    @MockBean
    EOIClient eooiClient;

    @MockBean
    private DocumentService documentService;

    @Autowired
    private WebApplicationContext webApplicationContext;

    @Rule
    public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("target/generated-snippets");

    @Autowired
    private ObjectMapper objectMapper = new ObjectMapper();

    private MockMvc mockMvc;

    private RestDocumentationResultHandler documentResultHandler;


    @Test
    public void testfindallDocumentClasses() throws Exception {
        Map<String, String> documentListDTO = null;
        Mockito.when(documentService.findAllDocumentClasses()).thenReturn(documentListDTO);
        this.mockMvc.perform(get("/search/findalldocumentclasses")
                .accept(MediaType.APPLICATION_JSON)
                .contentType(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andDo(document("find-all-document-classes"));
    }

}
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
Sathle
  • 1
  • 1
  • 2
  • So i managed to fix the issue and now it's saying I'm passing 0 to setMaxTotal in the PoolingHttpClientConnectionManager (from apache) and that I can't do that. – Sathle Apr 18 '19 at 22:15

1 Answers1

1

Try to mvn clean package and mvn clean install, because it seem something when try to deploy your code.