下面列出了org.springframework.context.support.ClassPathXmlApplicationContext#setId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testLayerTreeCheck() throws Exception {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/testdata/beanContext.xml " +
"/org/geomajas/testdata/layerBeans.xml " +
"/org/geomajas/internal/configuration/layerTreeInvalid.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
Assert.assertTrue(bce.getCause().getMessage().startsWith(
"A LayerTreeNodeInfo object can only reference layers which are part of the map, layer "));
}
}
@Test
public void testNullTileWidth() throws Exception {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/internal/configuration/RasterLayerZeroTileWidth.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
assertThat(bce.getCause().getCause().getMessage()).startsWith(
"Layer layerOsm is not correctly configured: tileWidth should not be zero.");
}
}
@Test
public void testNullTileHeight() throws Exception {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/internal/configuration/RasterLayerZeroTileHeight.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
assertThat(bce.getCause().getCause().getMessage()).startsWith(
"Layer layerOsm is not correctly configured: tileHeight should not be zero.");
}
}
@Test
public void testAttributeInvalidNameCheck() {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/testdata/beanContext.xml " +
"/org/geomajas/testdata/layerBeans.xml " +
"/org/geomajas/internal/configuration/layerBeansInvalid.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
assertThat(bce.getCause().getCause().getMessage()).startsWith(
"Invalid attribute name manyToOne.stringAttr in layer beans.");
}
}
@Test
public void testDuplicateAttribute() {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/internal/configuration/layerBeansDuplicateAttribute.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
assertThat(bce.getCause().getCause().getMessage()).startsWith(
"Duplicate attribute name stringAttr in layer beans, path .");
}
}
@Test
public void testDuplicateAttributeInOneToMany() {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/internal/configuration/layerBeansDuplicateAttrOneToMany.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
assertThat(bce.getCause().getCause().getMessage()).startsWith(
"Duplicate attribute name stringAttr in layer beans, path /oneToManyAttr.");
}
}
@Test
public void testDuplicateAttributeInManyToOne() {
try {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml " +
"/org/geomajas/internal/configuration/layerBeansDuplicateAttrManyToOne.xml " +
"");
context.refresh();
Assert.fail("Context initialization should have failed.");
} catch (BeanCreationException bce) {
assertThat(bce.getCause().getCause().getMessage()).startsWith(
"Duplicate attribute name stringAttr in layer beans, path /manyToOneAttr.");
}
}
@Test
public void testDefaultStyle() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml "+
"/org/geomajas/internal/configuration/layerDefaultStyle.xml ");
context.refresh();
VectorLayer layerDefaultStyle = (VectorLayer)context.getBean("layerDefaultStyle");
List<NamedStyleInfo> styles = layerDefaultStyle.getLayerInfo().getNamedStyleInfos();
Assert.assertEquals(1, styles.size());
NamedStyleInfo defaultStyle = styles.get(0);
Assert.assertEquals(NamedStyleInfo.DEFAULT_NAME, defaultStyle.getName());
Assert.assertEquals(LabelStyleInfo.ATTRIBUTE_NAME_ID, defaultStyle.getLabelStyle().getLabelAttributeName());
}
@Test
public void testUserStyle() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation(
"/org/geomajas/spring/geomajasContext.xml "+
"/org/geomajas/internal/configuration/layerDefaultStyle.xml ");
context.refresh();
VectorLayer layerDefaultStyle = (VectorLayer)context.getBean("layerDefaultStyle");
List<NamedStyleInfo> styles = layerDefaultStyle.getLayerInfo().getNamedStyleInfos();
Assert.assertEquals(1, styles.size());
NamedStyleInfo defaultStyle = styles.get(0);
UserStyleInfo userStyle = defaultStyle.getUserStyle();
List<RuleInfo> rules = userStyle.getFeatureTypeStyleList().get(0).getRuleList();
Assert.assertEquals(1, rules.size());
Assert.assertEquals(null, rules.get(0).getName());
}
@Test
public void testLogging() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setId("test");
context.setDisplayName("test");
context.setConfigLocation("/org/geomajas/spring/geomajasContext.xml ");
context.refresh();
Assert.assertSame(Logging.GEOTOOLS.getLoggerFactory(), Slf4jLoggerFactory.getInstance());
}