Search in sources :

Example 1 with AnnotationConfigEmbeddedWebApplicationContext

use of org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext in project Activiti by Activiti.

the class EndpointAutoConfigurationTest method mvcEndpoint.

@Test
public void mvcEndpoint() throws Throwable {
    AnnotationConfigEmbeddedWebApplicationContext applicationContext = new AnnotationConfigEmbeddedWebApplicationContext(CallbackEmbeddedContainerCustomizer.class, EmbeddedContainerConfiguration.class, EndpointConfiguration.class);
    ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);
    org.junit.Assert.assertNotNull("the processEngine should not be null", processEngine);
    ProcessEngineEndpoint processEngineEndpoint = applicationContext.getBean(ProcessEngineEndpoint.class);
    org.junit.Assert.assertNotNull("the processEngineEndpoint should not be null", processEngineEndpoint);
    RestTemplate restTemplate = applicationContext.getBean(RestTemplate.class);
    ResponseEntity<Map> mapResponseEntity = restTemplate.getForEntity("http://localhost:9091/activiti/", Map.class);
    Map map = mapResponseEntity.getBody();
    String[] criticalKeys = { "completedTaskCount", "openTaskCount", "cachedProcessDefinitionCount" };
    Map<?, ?> invokedResults = processEngineEndpoint.invoke();
    for (String k : criticalKeys) {
        org.junit.Assert.assertTrue(map.containsKey(k));
        org.junit.Assert.assertEquals(((Number) map.get(k)).longValue(), ((Number) invokedResults.get(k)).longValue());
    }
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ProcessEngineEndpoint(org.activiti.spring.boot.actuate.endpoint.ProcessEngineEndpoint) Map(java.util.Map) AnnotationConfigEmbeddedWebApplicationContext(org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext) ProcessEngine(org.activiti.engine.ProcessEngine) Test(org.junit.Test)

Example 2 with AnnotationConfigEmbeddedWebApplicationContext

use of org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext in project Activiti by Activiti.

the class RestApiAutoConfigurationTest method testRestApiIntegration.

@Test
public void testRestApiIntegration() throws Throwable {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    this.context.register(BaseConfiguration.class);
    this.context.refresh();
    RestTemplate restTemplate = this.context.getBean(RestTemplate.class);
    String authenticationChallenge = "http://localhost:" + this.context.getEmbeddedServletContainer().getPort() + "/repository/process-definitions";
    final AtomicBoolean received401 = new AtomicBoolean();
    received401.set(false);
    restTemplate.setErrorHandler(new ResponseErrorHandler() {

        @Override
        public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
            return true;
        }

        @Override
        public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
            if (clientHttpResponse.getStatusCode().equals(HttpStatus.UNAUTHORIZED))
                received401.set(true);
        }
    });
    ResponseEntity<String> response = restTemplate.getForEntity(authenticationChallenge, String.class);
    org.junit.Assert.assertTrue(received401.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResponseErrorHandler(org.springframework.web.client.ResponseErrorHandler) RestTemplate(org.springframework.web.client.RestTemplate) IOException(java.io.IOException) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) AnnotationConfigEmbeddedWebApplicationContext(org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext) Test(org.junit.Test)

Example 3 with AnnotationConfigEmbeddedWebApplicationContext

use of org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext in project java-chassis by ServiceComb.

the class CseSpringApplicationRunListener method contextLoaded.

@Override
public void contextLoaded(ConfigurableApplicationContext context) {
    if (!(context instanceof AnnotationConfigEmbeddedWebApplicationContext)) {
        return;
    }
    LOGGER.info("Initializing the CSE...");
    try {
        XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) context.getBeanFactory());
        beanDefinitionReader.loadBeanDefinitions(BeanUtils.DEFAULT_BEAN_RESOURCE);
    } catch (Throwable e) {
        LOGGER.error("Error to initialize CSE...", e);
        throw new Error(e);
    }
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) AnnotationConfigEmbeddedWebApplicationContext(org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext)

Aggregations

AnnotationConfigEmbeddedWebApplicationContext (org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext)3 Test (org.junit.Test)2 RestTemplate (org.springframework.web.client.RestTemplate)2 IOException (java.io.IOException)1 Map (java.util.Map)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 ProcessEngineEndpoint (org.activiti.spring.boot.actuate.endpoint.ProcessEngineEndpoint)1 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 ResponseErrorHandler (org.springframework.web.client.ResponseErrorHandler)1