IndexConverter extends ConfigurationConverter<Index, RegionConfig.Index> { @Override protected RegionConfig.Index fromNonNullConfigObject(Index index) { RegionConfig.Index regionConfigIndex = new RegionConfig.Index(); regionConfigIndex.setName(index.getName()); regionConfigIndex.setFromClause(index.getRegionPath()); regionConfigIndex.setExpression(index.getExpression()); if (index.getIndexType() == IndexType.KEY) { regionConfigIndex.setKeyIndex(true); } else if (index.getIndexType() == IndexType.HASH_DEPRECATED) { regionConfigIndex.setType(HASH); } else { regionConfigIndex.setType(RANGE); } return regionConfigIndex; }    }
@Test public void fromNonNullConfigObject_copiesSimpleProperties() { Index index = new Index(); index.setExpression("index expression"); index.setName("index name"); index.setRegionPath("index region path"); RegionConfig.Index regionConfigIndex = indexConverter.fromNonNullConfigObject(index); assertSoftly(softly -> { softly.assertThat(regionConfigIndex.getExpression()) .isEqualTo(index.getExpression()); softly.assertThat(regionConfigIndex.getName()) .isEqualTo(index.getName()); softly.assertThat(regionConfigIndex.getFromClause()) .isEqualTo(index.getRegionPath()); }); }
@Test public void fromNonNullConfigObject_mapsFunctionalIndexTypeToRangeIndexType() { Index index = new Index(); index.setIndexType(RANGE); RegionConfig.Index regionConfigIndex = indexConverter.fromNonNullConfigObject(index); assertSoftly(softly -> { softly.assertThat(regionConfigIndex.getType()) .as("type") .isEqualTo("range"); softly.assertThat(regionConfigIndex.isKeyIndex()) .as("is key index") .isFalse(); }); }
@Test public void fromNonNullConfigObject_mapsPrimaryKeyIndexTypeToKeyIndexType() { Index index = new Index(); index.setIndexType(KEY); RegionConfig.Index regionConfigIndex = indexConverter.fromNonNullConfigObject(index); assertSoftly(softly -> { softly.assertThat(regionConfigIndex.getType()) .as("type") .isEqualTo("key"); softly.assertThat(regionConfigIndex.isKeyIndex()) .as("is key index") .isTrue(); }); }
@Test public void fromNonNullConfigObject_mapsHashDeprecatedIndexTypeToHashIndexType() { Index index = new Index(); index.setIndexType(HASH_DEPRECATED); RegionConfig.Index regionConfigIndex = indexConverter.fromNonNullConfigObject(index); assertSoftly(softly -> { softly.assertThat(regionConfigIndex.getType()) .as("type") .isEqualTo("hash"); softly.assertThat(regionConfigIndex.isKeyIndex()) .as("is key index") .isFalse(); }); }