Remove test cases duplicated code.

This commit is contained in:
weingartner 2016-04-10 18:06:12 -03:00
parent 935113fbd3
commit 8355b586a0
9 changed files with 106 additions and 185 deletions

View File

@ -19,14 +19,22 @@ import java.io.File;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import com.cloud.utils.script.Script;
public abstract class CitrixResourceBaseTest {
public class CitrixResourceBaseTest {
public void testGetPathFilesExeption(CitrixResourceBase citrixResourceBase) {
protected CitrixResourceBase citrixResourceBase = new CitrixResourceBase() {
@Override
protected String getPatchFilePath() {
return null;
}
};
public void testGetPathFilesExeption() {
String patch = citrixResourceBase.getPatchFilePath();
PowerMockito.mockStatic(Script.class);
@ -36,7 +44,7 @@ public abstract class CitrixResourceBaseTest {
}
public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase) {
public void testGetPathFilesListReturned() {
String patch = citrixResourceBase.getPatchFilePath();
PowerMockito.mockStatic(Script.class);
@ -50,7 +58,8 @@ public abstract class CitrixResourceBaseTest {
Assert.assertEquals(receivedPath, pathExpected);
}
public void testGetGuestOsTypeNull(CitrixResourceBase citrixResourceBase) {
@Test
public void testGetGuestOsTypeNull() {
String platformEmulator = null;
String expected = "Other install media";
@ -58,7 +67,8 @@ public abstract class CitrixResourceBaseTest {
Assert.assertEquals(expected, guestOsType);
}
public void testGetGuestOsTypeEmpty(CitrixResourceBase citrixResourceBase) {
@Test
public void testGetGuestOsTypeEmpty() {
String platformEmulator = "";
String expected = "Other install media";
@ -66,7 +76,8 @@ public abstract class CitrixResourceBaseTest {
Assert.assertEquals(expected, guestOsType);
}
public void testGetGuestOsTypeBlank(CitrixResourceBase citrixResourceBase) {
@Test
public void testGetGuestOsTypeBlank() {
String platformEmulator = " ";
String expected = "Other install media";
@ -74,7 +85,8 @@ public abstract class CitrixResourceBaseTest {
Assert.assertEquals(expected, guestOsType);
}
public void testGetGuestOsTypeOther(CitrixResourceBase citrixResourceBase) {
@Test
public void testGetGuestOsTypeOther() {
String platformEmulator = "My Own Linux Distribution Y.M (64-bit)";
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,11 +27,14 @@ import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XcpOssResourceTest extends CitrixResourceBaseTest{
private XcpOssResource xcpOssResource = new XcpOssResource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XcpOssResource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xcpOssResource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
Assert.assertEquals(patch, patchFilePath);
@ -39,29 +43,12 @@ public class XcpOssResourceTest extends CitrixResourceBaseTest{
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xcpOssResource);
testGetPathFilesExeption();
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xcpOssResource);
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xcpOssResource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xcpOssResource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xcpOssResource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xcpOssResource);
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -27,11 +28,14 @@ import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XcpServerResourceTest extends CitrixResourceBaseTest{
private XcpServerResource xcpServerResource = new XcpServerResource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XcpServerResource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xcpServerResource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xcpserver/patch";
Assert.assertEquals(patch, patchFilePath);
@ -40,29 +44,12 @@ public class XcpServerResourceTest extends CitrixResourceBaseTest{
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFilesExeption(){
testGetPathFilesExeption(xcpServerResource);
testGetPathFilesExeption();
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xcpServerResource);
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xcpServerResource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xcpServerResource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xcpServerResource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xcpServerResource);
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -23,43 +24,32 @@ import org.powermock.modules.junit4.PowerMockRunner;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XenServer56FP1ResourceTest extends CitrixResourceBaseTest{
private XenServer56FP1Resource xenServer56FP1Resource = new XenServer56FP1Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer56FP1Resource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xenServer56FP1Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
Assert.assertEquals(patch, patchFilePath);
}
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer56FP1Resource);
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer56FP1Resource);
testGetPathFilesExeption();
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xenServer56FP1Resource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xenServer56FP1Resource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xenServer56FP1Resource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xenServer56FP1Resource);
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,11 +27,14 @@ import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XenServer56ResourceTest extends CitrixResourceBaseTest {
private XenServer56Resource xenServer56Resource = new XenServer56Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer56Resource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xenServer56Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56/patch";
Assert.assertEquals(patch, patchFilePath);
@ -39,28 +43,12 @@ public class XenServer56ResourceTest extends CitrixResourceBaseTest {
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer56Resource);
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer56Resource);
testGetPathFilesExeption();
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xenServer56Resource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xenServer56Resource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xenServer56Resource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xenServer56Resource);
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,40 +27,28 @@ import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XenServer56SP2ResourceTest extends CitrixResourceBaseTest{
private XenServer56SP2Resource xenServer56SP2Resource = new XenServer56SP2Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer56SP2Resource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xenServer56SP2Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";
Assert.assertEquals(patch, patchFilePath);
}
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer56SP2Resource);
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer56SP2Resource);
testGetPathFilesExeption();
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xenServer56SP2Resource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xenServer56SP2Resource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xenServer56SP2Resource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xenServer56SP2Resource);
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,40 +27,29 @@ import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XenServer600ResourceTest extends CitrixResourceBaseTest{
private XenServer600Resource xenServer600Resource = new XenServer600Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer600Resource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xenServer600Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver60/patch";
Assert.assertEquals(patch, patchFilePath);
}
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer600Resource);
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer600Resource);
testGetPathFilesExeption();
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xenServer600Resource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xenServer600Resource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xenServer600Resource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xenServer600Resource);
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -23,43 +24,32 @@ import org.powermock.modules.junit4.PowerMockRunner;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XenServer625ResourceTest extends CitrixResourceBaseTest{
private Xenserver625Resource xenServer625Resource = new Xenserver625Resource();
@RunWith(PowerMockRunner.class)
public class XenServer625ResourceTest extends CitrixResourceBaseTest {
@Before
public void beforeTest() {
super.citrixResourceBase = new Xenserver625Resource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xenServer625Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver62/patch";
Assert.assertEquals(patch, patchFilePath);
}
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer625Resource);
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer625Resource);
@PrepareForTest(Script.class)
public void testGetFiles() {
testGetPathFilesExeption();
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xenServer625Resource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xenServer625Resource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xenServer625Resource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xenServer625Resource);
@PrepareForTest(Script.class)
public void testGetFilesListReturned() {
testGetPathFilesListReturned();
}
}

View File

@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -26,11 +27,14 @@ import com.cloud.utils.script.Script;
@RunWith(PowerMockRunner.class)
public class XenServer650ResourceTest extends CitrixResourceBaseTest{
private XenServer650Resource xenServer650Resource = new XenServer650Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer650Resource();
}
@Test
public void testPatchFilePath() {
String patchFilePath = xenServer650Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver65/patch";
Assert.assertEquals(patch, patchFilePath);
@ -39,28 +43,12 @@ public class XenServer650ResourceTest extends CitrixResourceBaseTest{
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer650Resource);
}
@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer650Resource);
testGetPathFilesExeption();
}
@Test
public void testGetOsTypeNull() {
testGetGuestOsTypeNull(xenServer650Resource);
}
@Test
public void testGetOsTypeEmpty() {
testGetGuestOsTypeEmpty(xenServer650Resource);
}
@Test
public void testGetOsTypeBlank() {
testGetGuestOsTypeBlank(xenServer650Resource);
}
@Test
public void testGetOsTypeOther() {
testGetGuestOsTypeOther(xenServer650Resource);
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned();
}
}