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());
}
}
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());
}
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);
}
}
Aggregations