mirror of https://github.com/apache/cloudstack.git
Merge pull request #944 from rafaelweingartner/lrg-cs-hackday-012
Create test cases to getPatchFilePath method and class names changed In this commit we created tests cases for the respective classes in package com.cloud.hypervisor.xenserver.resource. We added test cases to check the implementation of com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.getPatchFiles. Therefore, we test in a more comprehensive way the tests that already exist to check the code of com.cloud.hypervisor.xenserver.resource.CitrixResourceBase.getPatchFilePath. We added a new abstract class, called com.cloud.hypervisor.xenserver.resource.CitrixResourceBaseTest.java This class has two tests methods: * com.cloud.hypervisor.xenserver.resource.CitrixResourceBaseTest.testGetPathFilesExeption(CitrixResourceBase), this method tests if the getPatchFilePath() method throws the com.cloud.utils.exception.CloudRuntimeException.CloudRuntimeException when the com.cloud.utils.script.Script.findScript(String, String) return a null value; * com.cloud.hypervisor.xenserver.resource.CitrixResourceBaseTest.testGetPathFilesListReturned(CitrixResourceBase), this method tests the correct return value from getPatchFilePath() method, basically, verify if the returned list contain the file with the same absolute path that was retrieved from the findScript method. We also changed the name of those test classes, the change was basically remove the Path word from the name of classes. * pr/944: created tests cases for method "citrixResourceBase.getPatchFiles" Signed-off-by: Remi Bergsma <github@remi.nl>
This commit is contained in:
commit
6d558c0201
|
|
@ -2869,7 +2869,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
}
|
||||
}
|
||||
|
||||
private List<File> getPatchFiles() {
|
||||
protected List<File> getPatchFiles() {
|
||||
String patch = getPatchFilePath();
|
||||
String patchfilePath = Script.findScript("", patch);
|
||||
if (patchfilePath == null) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright 2015 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.cloud.hypervisor.xenserver.resource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.mockito.Mockito;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public abstract class CitrixResourceBaseTest {
|
||||
|
||||
public void testGetPathFilesExeption(CitrixResourceBase citrixResourceBase) {
|
||||
String patch = citrixResourceBase.getPatchFilePath();
|
||||
|
||||
PowerMockito.mockStatic(Script.class);
|
||||
Mockito.when(Script.findScript("", patch)).thenReturn(null);
|
||||
|
||||
citrixResourceBase.getPatchFiles();
|
||||
|
||||
}
|
||||
|
||||
public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase) {
|
||||
String patch = citrixResourceBase.getPatchFilePath();
|
||||
|
||||
PowerMockito.mockStatic(Script.class);
|
||||
Mockito.when(Script.findScript("", patch)).thenReturn(patch);
|
||||
|
||||
File expected = new File(patch);
|
||||
String pathExpected = expected.getAbsolutePath();
|
||||
|
||||
List<File> files = citrixResourceBase.getPatchFiles();
|
||||
String receivedPath = files.get(0).getAbsolutePath();
|
||||
Assert.assertEquals(receivedPath, pathExpected);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XcpOssResourcePathTest {
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class XcpOssResourceTest extends CitrixResourceBaseTest{
|
||||
|
||||
private XcpOssResource xcpOssResource = new XcpOssResource();
|
||||
|
||||
|
|
@ -29,4 +35,16 @@ public class XcpOssResourcePathTest {
|
|||
|
||||
Assert.assertEquals(patch, patchFilePath);
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFiles(){
|
||||
testGetPathFilesExeption(xcpOssResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFilesListReturned(){
|
||||
testGetPathFilesListReturned(xcpOssResource);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,15 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XcpServerResourcePathTest {
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class XcpServerResourceTest extends CitrixResourceBaseTest{
|
||||
|
||||
private XcpServerResource xcpServerResource = new XcpServerResource();
|
||||
|
||||
|
|
@ -29,4 +36,16 @@ public class XcpServerResourcePathTest {
|
|||
|
||||
Assert.assertEquals(patch, patchFilePath);
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFilesExeption(){
|
||||
testGetPathFilesExeption(xcpServerResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFilesListReturned(){
|
||||
testGetPathFilesListReturned(xcpServerResource);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XenServer56FP1ResourcePathTest {
|
||||
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();
|
||||
|
||||
|
|
@ -29,4 +35,14 @@ public class XenServer56FP1ResourcePathTest {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XenServer56ResourcePathTest {
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class XenServer56ResourceTest extends CitrixResourceBaseTest {
|
||||
|
||||
private XenServer56Resource xenServer56Resource = new XenServer56Resource();
|
||||
|
||||
|
|
@ -29,4 +35,15 @@ public class XenServer56ResourcePathTest {
|
|||
|
||||
Assert.assertEquals(patch, patchFilePath);
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFiles(){
|
||||
testGetPathFilesExeption(xenServer56Resource);
|
||||
}
|
||||
@Test
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFilesListReturned(){
|
||||
testGetPathFilesListReturned(xenServer56Resource);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XenServer56SP2ResourcePathTest {
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class XenServer56SP2ResourceTest extends CitrixResourceBaseTest{
|
||||
|
||||
private XenServer56SP2Resource xenServer56SP2Resource = new XenServer56SP2Resource();
|
||||
|
||||
|
|
@ -29,4 +35,14 @@ public class XenServer56SP2ResourcePathTest {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XenServer600ResourcePathTest {
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class XenServer600ResourceTest extends CitrixResourceBaseTest{
|
||||
|
||||
private XenServer600Resource xenServer600Resource = new XenServer600Resource();
|
||||
|
||||
|
|
@ -29,4 +35,14 @@ public class XenServer600ResourcePathTest {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XenServer625ResourcePathTest {
|
||||
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();
|
||||
|
||||
|
|
@ -29,4 +35,14 @@ public class XenServer625ResourcePathTest {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,14 @@ package com.cloud.hypervisor.xenserver.resource;
|
|||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
public class XenServer650ResourcePathTest {
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class XenServer650ResourceTest extends CitrixResourceBaseTest{
|
||||
|
||||
private XenServer650Resource xenServer650Resource = new XenServer650Resource();
|
||||
|
||||
|
|
@ -29,4 +35,15 @@ public class XenServer650ResourcePathTest {
|
|||
|
||||
Assert.assertEquals(patch, patchFilePath);
|
||||
}
|
||||
|
||||
@Test(expected = CloudRuntimeException.class)
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFiles(){
|
||||
testGetPathFilesExeption(xenServer650Resource);
|
||||
}
|
||||
@Test
|
||||
@PrepareForTest(Script.class )
|
||||
public void testGetFilesListReturned(){
|
||||
testGetPathFilesListReturned(xenServer650Resource);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue