Raise JUnit coverage asdctool
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / migration / resolver / SpringBeansMigrationResolverTest.java
index 636b1c6..47bf9c9 100644 (file)
@@ -15,74 +15,78 @@ import org.openecomp.sdc.asdctool.migration.core.DBVersion;
 import org.openecomp.sdc.asdctool.migration.core.task.IMigrationStage;
 import org.openecomp.sdc.asdctool.migration.core.task.Migration;
 import org.openecomp.sdc.asdctool.migration.core.task.MigrationResult;
+import org.openecomp.sdc.asdctool.migration.dao.MigrationTasksDao;
 import org.openecomp.sdc.asdctool.migration.service.SdcRepoService;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 public class SpringBeansMigrationResolverTest {
 
-    @InjectMocks
-    private SpringBeansMigrationResolver testInstance;
+       @InjectMocks
+       private SpringBeansMigrationResolver testInstance;
 
-    @Mock
-    private SdcRepoService sdcRepoServiceMock;
+       @Mock
+       private SdcRepoService sdcRepoServiceMock;
 
-    private List<Migration> migrations = Arrays.asList(createMigration("1710.1"), createMigration("1710.22"), createMigration("1707.12"), createMigration("1710.3"));
+       private List<Migration> migrations = Arrays.asList(createMigration("1710.1"), createMigration("1710.22"),
+                       createMigration("1707.12"), createMigration("1710.3"));
 
-
-    @BeforeMethod
+       @BeforeMethod
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-        testInstance.setMigrations(migrations);
-    }
+               MockitoAnnotations.initMocks(this);
+               testInstance.setMigrations(migrations);
+       }
 
-    @Test
+       @Test
     public void testResolveMigrations_getMigrationsWithVersionGreaterThanLatest() {
-        when(sdcRepoServiceMock.getLatestDBVersion()).thenReturn(DBVersion.fromString("1710.2"));
-        testInstance.setPostMigrations(Collections.emptyList());
-        List<IMigrationStage> resolvedMigrations = testInstance.resolveMigrations();
-        assertEquals(resolvedMigrations.size(), 2);
-        assertEquals(resolvedMigrations.get(0).getVersion(), DBVersion.fromString("1710.3"));
-        assertEquals(resolvedMigrations.get(1).getVersion(), DBVersion.fromString("1710.22"));
-    }
-
-    @Test
+               when(sdcRepoServiceMock.getLatestDBVersion()).thenReturn(DBVersion.fromString("1710.2"));
+               testInstance.setPostMigrations(Collections.emptyList());
+               List<IMigrationStage> resolvedMigrations = testInstance.resolveMigrations();
+               assertEquals(resolvedMigrations.size(), 2);
+               assertEquals(resolvedMigrations.get(0).getVersion(), DBVersion.fromString("1710.3"));
+               assertEquals(resolvedMigrations.get(1).getVersion(), DBVersion.fromString("1710.22"));
+       }
+
+       @Test
     public void testResolveMigration_noLatestVersionForCurrentMajorVersion() {
-        when(sdcRepoServiceMock.getLatestDBVersion()).thenReturn(DBVersion.fromString("1710.-1"));
-        testInstance.setPostMigrations(Collections.emptyList());
-        List<IMigrationStage> resolvedMigrations = testInstance.resolveMigrations();
-        assertEquals(resolvedMigrations.size(), 3);
-        assertEquals(resolvedMigrations.get(0).getVersion(), DBVersion.fromString("1710.1"));
-        assertEquals(resolvedMigrations.get(1).getVersion(), DBVersion.fromString("1710.3"));
-        assertEquals(resolvedMigrations.get(2).getVersion(), DBVersion.fromString("1710.22"));
-    }
-
-    @Test
+               when(sdcRepoServiceMock.getLatestDBVersion()).thenReturn(DBVersion.fromString("1710.-1"));
+               testInstance.setPostMigrations(Collections.emptyList());
+               List<IMigrationStage> resolvedMigrations = testInstance.resolveMigrations();
+               assertEquals(resolvedMigrations.size(), 3);
+               assertEquals(resolvedMigrations.get(0).getVersion(), DBVersion.fromString("1710.1"));
+               assertEquals(resolvedMigrations.get(1).getVersion(), DBVersion.fromString("1710.3"));
+               assertEquals(resolvedMigrations.get(2).getVersion(), DBVersion.fromString("1710.22"));
+       }
+
+       @Test
     public void testResolveMigrations_emptyMigrationsList() {
-        testInstance.setMigrations(Collections.emptyList());
-        testInstance.setPostMigrations(Collections.emptyList());
-        when(sdcRepoServiceMock.getLatestDBVersion()).thenReturn(DBVersion.fromString("1710.-1"));
-        List<IMigrationStage> resolvedMigrations = testInstance.resolveMigrations();
-        assertTrue(resolvedMigrations.isEmpty());
-    }
-
-    private Migration createMigration(String version) {
-        return new Migration() {
-            @Override
-            public String description() {
-                return null;
-            }
-
-            @Override
-            public DBVersion getVersion() {
-                return DBVersion.fromString(version);
-            }
-
-            @Override
-            public MigrationResult migrate() {
-                return null;
-            }
-        };
-    }
-
+               testInstance.setMigrations(Collections.emptyList());
+               testInstance.setPostMigrations(Collections.emptyList());
+               when(sdcRepoServiceMock.getLatestDBVersion()).thenReturn(DBVersion.fromString("1710.-1"));
+               List<IMigrationStage> resolvedMigrations = testInstance.resolveMigrations();
+               assertTrue(resolvedMigrations.isEmpty());
+       }
+
+       private Migration createMigration(String version) {
+               return new Migration() {
+                       @Override
+                       public String description() {
+                               return null;
+                       }
+
+                       @Override
+                       public DBVersion getVersion() {
+                               return DBVersion.fromString(version);
+                       }
+
+                       @Override
+                       public MigrationResult migrate() {
+                               return null;
+                       }
+               };
+       }
+
+       private SpringBeansMigrationResolver createTestSubject() {
+               return new SpringBeansMigrationResolver(null, null, new SdcRepoService(new MigrationTasksDao()));
+       }
 }