@Override public void validate(RegionConfig config) throws IllegalArgumentException { if (config.getName() == null) { throw new IllegalArgumentException("Name of the region has to be specified."); } if (config.getType() == null) { config.setType(DEFAULT_REGION_TYPE); } } }
@Test public void defaultsTypeToPartitioned() { config.setName("regionName"); validator.validate(config); assertThat(config.getType()).isEqualTo("PARTITION"); }
@Test public void noChangesWhenTypeIsSet() { config.setName("regionName"); config.setType("REPLICATE"); validator.validate(config); assertThat(config.getType()).isEqualTo("REPLICATE"); }
@Test public void correctJsonAndXml() throws Exception { String json = "{\"name\":\"test\", \"type\":\"REPLICATE\"}"; ObjectMapper mapper = new ObjectMapper(); regionConfig = mapper.readValue(json, RegionConfig.class); assertThat(regionConfig.getName()).isEqualTo("test"); assertThat(regionConfig.getType()).isEqualTo("REPLICATE"); String json2 = mapper.writeValueAsString(regionConfig); assertThat(json2).contains("\"type\":\"REPLICATE\""); assertThat(json2).contains("\"id\":\"test\""); CacheConfig cacheConfig = new CacheConfig(); cacheConfig.getRegions().add(regionConfig); String xml = service.marshall(cacheConfig); assertThat(xml).contains("<region name=\"test\" refid=\"REPLICATE\""); } }