Search in sources :

Example 1 with SpringContextInstallStage

use of com.alipay.sofa.isle.stage.SpringContextInstallStage in project sofa-boot by alipay.

the class DeploymentExceptionTest method test.

@Test(expected = DeploymentException.class)
public void test() throws Exception {
    // create ApplicationRuntimeModel with dependency problem
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName("testCase");
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
    Properties props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.test");
    props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.dependency");
    URL fileUrl = new URL("file:/demo/path/isle-module.config");
    application.addDeployment(DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader()));
    // mock ApplicationContext
    AbstractApplicationContext applicationContext = mock(AbstractApplicationContext.class);
    when(applicationContext.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class)).thenReturn(application);
    ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
    when(applicationContext.getEnvironment()).thenReturn(environment);
    when(environment.getProperty(SofaBootConstants.APP_NAME_KEY)).thenReturn("testCase");
    new SpringContextInstallStage(applicationContext, new SofaModuleProperties()).process();
}
Also used : DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringContextInstallStage(com.alipay.sofa.isle.stage.SpringContextInstallStage) DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) URL(java.net.URL) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Test(org.junit.Test)

Example 2 with SpringContextInstallStage

use of com.alipay.sofa.isle.stage.SpringContextInstallStage in project sofa-boot by sofastack.

the class DeploymentExceptionTest method test.

@Test(expected = DeploymentException.class)
public void test() throws Exception {
    // create ApplicationRuntimeModel with dependency problem
    ApplicationRuntimeModel application = new ApplicationRuntimeModel();
    application.setAppName("testCase");
    application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
    DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
    Properties props = new Properties();
    props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.test");
    props.setProperty(SofaBootConstants.REQUIRE_MODULE, "com.alipay.dependency");
    URL fileUrl = new URL("file:/demo/path/isle-module.config");
    application.addDeployment(DeploymentBuilder.build(fileUrl, props, deploymentDescriptorConfiguration, ApplicationRuntimeModelTest.class.getClassLoader()));
    // mock ApplicationContext
    AbstractApplicationContext applicationContext = mock(AbstractApplicationContext.class);
    when(applicationContext.getBean(SofaBootConstants.APPLICATION, ApplicationRuntimeModel.class)).thenReturn(application);
    ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
    when(applicationContext.getEnvironment()).thenReturn(environment);
    when(environment.getProperty(SofaBootConstants.APP_NAME_KEY)).thenReturn("testCase");
    new SpringContextInstallStage(applicationContext, new SofaModuleProperties()).process();
}
Also used : DeploymentDescriptorConfiguration(com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringContextInstallStage(com.alipay.sofa.isle.stage.SpringContextInstallStage) DefaultModuleDeploymentValidator(com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Properties(java.util.Properties) URL(java.net.URL) ApplicationRuntimeModel(com.alipay.sofa.isle.ApplicationRuntimeModel) SofaModuleProperties(com.alipay.sofa.isle.spring.config.SofaModuleProperties) Test(org.junit.Test)

Aggregations

ApplicationRuntimeModel (com.alipay.sofa.isle.ApplicationRuntimeModel)2 DeploymentDescriptorConfiguration (com.alipay.sofa.isle.deployment.DeploymentDescriptorConfiguration)2 DefaultModuleDeploymentValidator (com.alipay.sofa.isle.deployment.impl.DefaultModuleDeploymentValidator)2 SofaModuleProperties (com.alipay.sofa.isle.spring.config.SofaModuleProperties)2 SpringContextInstallStage (com.alipay.sofa.isle.stage.SpringContextInstallStage)2 URL (java.net.URL)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2