MetadataSyncDelegate { public boolean shouldStopSync( String metadataVersionSnapshot ) { SystemInfo systemInfo = systemService.getSystemInfo(); String systemVersion = systemInfo.getVersion(); if ( StringUtils.isEmpty( systemVersion ) || !metadataSystemSettingService.getStopMetadataSyncSetting() ) { return false; } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( metadataVersionSnapshot.getBytes( StandardCharsets.UTF_8 ) ); String remoteVersion = ""; try { JsonNode systemObject = renderService.getSystemObject( byteArrayInputStream, RenderFormat.JSON ); if ( systemObject == null ) { return false; } remoteVersion = systemObject.get( "version" ).textValue(); if ( StringUtils.isEmpty( remoteVersion ) ) { return false; } } catch ( IOException e ) { log.error( "Exception occurred when parsing the metadata snapshot" + e.getMessage() ); } return !systemVersion.trim().equals( remoteVersion.trim() ); }  boolean shouldStopSync( String metadataVersionSnapshot );  }
@Test public void testShouldVerifyIfStopSyncReturnFalseIfNoSystemVersionInLocal() { String versionSnapshot = "{\"system:\": {\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}"; SystemInfo systemInfo = new SystemInfo(); when ( systemService.getSystemInfo() ).thenReturn( systemInfo ); boolean shouldStopSync = metadataSyncDelegate.shouldStopSync( versionSnapshot ); assertFalse(shouldStopSync); }
@Test public void testShouldVerifyIfStopSyncReturnFalseIfNoSystemVersionInRemote() throws IOException { String versionSnapshot = "{\"system:\": {\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}"; SystemInfo systemInfo = new SystemInfo(); systemInfo.setVersion( "2.26" ); when ( systemService.getSystemInfo() ).thenReturn( systemInfo ); boolean shouldStopSync = metadataSyncDelegate.shouldStopSync( versionSnapshot ); assertFalse(shouldStopSync); }
@Test public void testShouldVerifyIfStopSyncReturnTrueIfDHISVersionMismatch() throws IOException { String versionSnapshot = "{\"system:\": {\"date\":\"2016-06-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\"," + "\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}"; String systemNodeString = "{\"date\":\"2016-06-24T05:27:25.128+0000\", \"version\": \"2.26\"}"; SystemInfo systemInfo = new SystemInfo(); systemInfo.setVersion( "2.25" ); when( systemService.getSystemInfo() ).thenReturn( systemInfo ); when( metadataSystemSettingService.getStopMetadataSyncSetting() ).thenReturn( true ); ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree( systemNodeString ); when( renderService.getSystemObject( any( ByteArrayInputStream.class), eq( RenderFormat.JSON ) ) ).thenReturn( jsonNode); boolean shouldStopSync = metadataSyncDelegate.shouldStopSync( versionSnapshot ); assertTrue(shouldStopSync); }
@Test public void testShouldVerifyIfStopSyncReturnFalseIfDHISVersionSame() throws IOException { String versionSnapshot = "{\"system:\": {\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}"; String systemNodeString = "{\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}"; SystemInfo systemInfo = new SystemInfo(); systemInfo.setVersion( "2.26" ); when( systemService.getSystemInfo() ).thenReturn( systemInfo ); when( metadataSystemSettingService.getStopMetadataSyncSetting() ).thenReturn( true ); ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree( systemNodeString ); when( renderService.getSystemObject(any( ByteArrayInputStream.class), eq( RenderFormat.JSON ) ) ).thenReturn( jsonNode); boolean shouldStopSync = metadataSyncDelegate.shouldStopSync( versionSnapshot ); assertFalse(shouldStopSync); }
@Test public void testShouldVerifyIfStopSyncReturnFalseIfStopSyncIsNotSet() { String versionSnapshot = "{\"system:\": {\"date\":\"2016-05-24T05:27:25.128+0000\", \"version\": \"2.26\"}, \"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}"; SystemInfo systemInfo = new SystemInfo(); systemInfo.setVersion( "2.26" ); when( systemService.getSystemInfo() ).thenReturn( systemInfo ); when( metadataSystemSettingService.getStopMetadataSyncSetting() ).thenReturn( false ); boolean shouldStopSync = metadataSyncDelegate.shouldStopSync( versionSnapshot ); assertFalse(shouldStopSync); }