DiskStoreConverter extends ConfigurationConverter<DiskStore, DiskStoreType> { @Override protected DiskStoreType fromNonNullConfigObject(DiskStore configObject) { DiskStoreType diskStoreType = new DiskStoreType(); diskStoreType.setName(configObject.getName()); if (configObject.isAllowForceCompaction() != null) { diskStoreType.setAllowForceCompaction(configObject.isAllowForceCompaction()); } if (configObject.isAutoCompact() != null) { diskStoreType.setAutoCompact(configObject.isAutoCompact()); } if (configObject.getCompactionThreshold() != null) { diskStoreType.setCompactionThreshold(configObject.getCompactionThreshold().toString()); } if (configObject.getDiskUsageCriticalPercentage() != null) { diskStoreType .setDiskUsageCriticalPercentage(configObject.getDiskUsageCriticalPercentage().toString()); } if (configObject.getDiskUsageWarningPercentage() != null) { diskStoreType .setDiskUsageWarningPercentage(configObject.getDiskUsageWarningPercentage().toString()); } if (configObject.getMaxOplogSizeInBytes() != null) { diskStoreType.setMaxOplogSize(configObject.getMaxOplogSizeInBytes().toString()); } if (configObject.getQueueSize() != null) { diskStoreType.setQueueSize(configObject.getQueueSize().toString()); } if (configObject.getTimeInterval() != null) { diskStoreType.setTimeInterval(configObject.getTimeInterval().toString()); } if (configObject.getWriteBufferSize() != null) { diskStoreType.setWriteBufferSize(configObject.getWriteBufferSize().toString()); } diskStoreType.setDiskDirs(configObject.getDirectories().stream().map(diskDir -> { DiskDirType diskDirType = new DiskDirType(); diskDirType.setContent(diskDir.getName()); if (diskDir.getDirSize() != null) { diskDirType.setDirSize(diskDir.getDirSize().toString()); } return diskDirType; }).collect(Collectors.toList())); return diskStoreType; }    }
@Test public void fromNonNullConfigObjectCopiesPropertiesCorrectly() { DiskStore config = new DiskStore(); config.setName("name"); config.setAllowForceCompaction(false); config.setAutoCompact(false); config.setCompactionThreshold(50); config.setDiskUsageCriticalPercentage(80F); config.setDiskUsageWarningPercentage(70F); config.setMaxOplogSizeInBytes(10L); config.setQueueSize(5); config.setTimeInterval(1L); config.setWriteBufferSize(1); ArrayList<DiskDir> directories = new ArrayList<>(); directories.add(new DiskDir("directoryName", 1)); config.setDirectories(directories); DiskStoreType diskStoreType = diskStoreConverter.fromNonNullConfigObject(config); assertSoftly(softly -> { softly.assertThat(diskStoreType.isAllowForceCompaction()) .isEqualTo(config.isAllowForceCompaction()); softly.assertThat(diskStoreType.isAutoCompact()) .isEqualTo(config.isAutoCompact()); softly.assertThat(diskStoreType.getCompactionThreshold()) .isEqualTo(config.getCompactionThreshold().toString()); softly.assertThat(diskStoreType.getDiskUsageCriticalPercentage()) .isEqualTo(config.getDiskUsageCriticalPercentage().toString()); softly.assertThat(diskStoreType.getDiskUsageWarningPercentage()) .isEqualTo(config.getDiskUsageWarningPercentage().toString()); softly.assertThat(diskStoreType.getMaxOplogSize()) .isEqualTo(config.getMaxOplogSizeInBytes().toString()); softly.assertThat(diskStoreType.getQueueSize()) .isEqualTo(config.getQueueSize().toString()); softly.assertThat(diskStoreType.getTimeInterval()) .isEqualTo(config.getTimeInterval().toString()); softly.assertThat(diskStoreType.getWriteBufferSize()) .isEqualTo(config.getWriteBufferSize().toString()); softly.assertThat(diskStoreType.getDiskDirs().size()) .isEqualTo(config.getDirectories().size()); }); }