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