package au.gov.ga.geodesy.domain.service;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.junit.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.Test;

import au.gov.ga.geodesy.domain.model.sitelog.SiteLogRepository;
import au.gov.ga.geodesy.port.InvalidSiteLogException;
import au.gov.ga.geodesy.port.SiteLogReader;
import au.gov.ga.geodesy.port.adapter.sopac.SopacSiteLogReader;
import au.gov.ga.geodesy.support.spring.IntegrationTestConfig;

@Transactional("geodesyTransactionManager")
public class MultipleSitesTest extends IntegrationTestConfig {

	private static final String scenarioDirName = "src/test/resources/multiple-sites/";

	@Autowired
	private IgsSiteLogService siteLogService;

	@Autowired
	private SiteLogRepository siteLogs;

	private int numberOfSites;

	/**
	 * Each siteLog file must have a unique getSiteIdentification.
	 * @param scenarioDirName
	 * @throws InvalidSiteLogException
	 * @throws IOException
	 */
	private void executeSiteLogScenario(String scenarioDirName) throws IOException, InvalidSiteLogException {
		File[] siteLogFiles = new File(scenarioDirName).listFiles((File dir, String f) -> {
			return f.endsWith(".xml");
		});
		numberOfSites = siteLogFiles.length;
		for (File f : siteLogFiles) {
            SiteLogReader input = new SopacSiteLogReader(new FileReader(f));
			siteLogService.upload(input.getSiteLog());
		}
	}

	@Test
	@Rollback(false)
	public void checkSetupId() throws Exception {
		Assert.assertEquals(0, siteLogs.count());
		executeSiteLogScenario(scenarioDirName);
		Assert.assertEquals(numberOfSites, siteLogs.count());
	}
}

@@ -757,17 +757,20 @@
 nfig %7B%0A%0A
-%09
+    
 private 
@@ -846,17 +846,20 @@
 tes/%22;%0A%0A
-%09
+    
 @Autowir
@@ -853,33 +853,36 @@
 %0A    @Autowired%0A
-%09
+    
 private IgsSiteL
@@ -908,17 +908,20 @@
 rvice;%0A%0A
-%09
+    
 @Autowir
@@ -923,17 +923,20 @@
 towired%0A
-%09
+    
 private 
@@ -964,17 +964,20 @@
 eLogs;%0A%0A
-%09
+    
 private 
@@ -1000,14 +1000,20 @@
 s;%0A%0A
-%09/**%0A%09
+    /**%0A    
  * E
@@ -1071,17 +1071,20 @@
 cation.%0A
-%09
+    
  * @para
@@ -1101,17 +1101,20 @@
 DirName%0A
-%09
+    
  * @thro
@@ -1140,17 +1140,20 @@
 ception%0A
-%09
+    
  * @thro
@@ -1171,14 +1171,20 @@
 ion%0A
-%09 */%0A%09
+     */%0A    
 priv
@@ -1285,18 +1285,24 @@
 ption %7B%0A
-%09%09
+        
 File%5B%5D s
@@ -1377,19 +1377,28 @@
 f) -%3E %7B%0A
-%09%09%09
+            
 return f
@@ -1420,16 +1420,28 @@
 %22);%0A
-%09%09%7D);%0A%09%09
+        %7D);%0A        
 numb
@@ -1473,18 +1473,24 @@
 length;%0A
-%09%09
+        
 for (Fil
@@ -1592,11 +1592,20 @@
 ));%0A
-%09%09%09
+            
 site
@@ -1647,24 +1647,39 @@
 ));%0A
-%09%09%7D%0A%09%7D%0A%0A%09
+        %7D%0A    %7D%0A%0A    
 @Test%0A
-%09
+    
 @Rol
@@ -1691,17 +1691,20 @@
 (false)%0A
-%09
+    
 public v
@@ -1741,18 +1741,24 @@
 ption %7B%0A
-%09%09
+        
 Assert.a
@@ -1791,18 +1791,24 @@
 unt());%0A
-%09%09
+        
 executeS
@@ -1844,10 +1844,16 @@
 e);%0A
-%09%09
+        
 Asse
@@ -1906,9 +1906,12 @@
 ));%0A
-%09
+    
 %7D%0A%7D%0A

Remove tabs