mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
Java API update for 2.0 release.
This commit is contained in:
1 parent
eb843caccc
commit
8eb9cdc67e
20 files changed
+2185
-26
No files matched your search
@@ -0,0 +1,166 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.cluster.Cluster;
|
||||
import org.opennebula.client.cluster.ClusterPool;
|
||||
import org.opennebula.client.host.Host;
|
||||
|
||||
|
||||
public class ClusterTest
|
||||
{
|
||||
|
||||
private static Cluster cluster;
|
||||
private static ClusterPool clusterPool;
|
||||
|
||||
private static Host host;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static OneResponse res;
|
||||
private static String name = "new_test_cluster";
|
||||
private static int hid = -1;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
clusterPool = new ClusterPool(client);
|
||||
|
||||
res = Host.allocate(client, "new_test_host",
|
||||
"im_dummy", "vmm_dummy", "tm_dummy");
|
||||
try{
|
||||
hid = Integer.parseInt( res.getMessage() );
|
||||
}catch(NumberFormatException e)
|
||||
{
|
||||
System.err.println("Test initilization failed (setUpBeforeClass).");
|
||||
}
|
||||
host = new Host(hid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = Cluster.allocate(client, name);
|
||||
|
||||
int clid = Integer.parseInt(res.getMessage());
|
||||
cluster = new Cluster(clid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
cluster.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
String allocate_name = "allocation_test";
|
||||
res = Cluster.allocate(client, allocate_name);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
clusterPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(Cluster c : clusterPool)
|
||||
{
|
||||
found = found || c.getName().equals(allocate_name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = cluster.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( cluster.getId().equals("1") );
|
||||
// assertTrue( cluster.id() == 1 );
|
||||
assertTrue( cluster.getName().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addHost()
|
||||
{
|
||||
res = cluster.add(hid);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( host.getCluster().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeHost()
|
||||
{
|
||||
assertTrue( hid > -1 );
|
||||
|
||||
res = cluster.remove(hid);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( host.getCluster().equals("default") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = cluster.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( cluster.xpath("ID").equals("1") );
|
||||
assertTrue( cluster.xpath("NAME").equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = cluster.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = cluster.info();
|
||||
assertTrue( res.isError() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.host.Host;
|
||||
import org.opennebula.client.host.HostPool;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class HostTest
|
||||
{
|
||||
class HostXML extends Host
|
||||
{
|
||||
public HostXML(Node node, Client client){ super(node, client); }
|
||||
}
|
||||
|
||||
private static Host host;
|
||||
private static HostPool hostPool;
|
||||
private static Client client;
|
||||
private OneResponse res;
|
||||
private static String name = "new_test_host";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
hostPool = new HostPool(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "tm_dummy");
|
||||
|
||||
int hid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
||||
host = new Host(hid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
host.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
String name = "allocate_test";
|
||||
|
||||
res = Host.allocate(client, name, "im_dummy", "vmm_dummy", "tm_dummy");
|
||||
assertTrue( !res.isError() );
|
||||
// assertTrue( res.getMessage().equals("0") );
|
||||
|
||||
hostPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(Host h : hostPool)
|
||||
{
|
||||
found = found || h.getName().equals(name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( host.getId().equals("0") );
|
||||
assertTrue( host.id() >= 0 );
|
||||
|
||||
assertTrue( host.shortStateStr().equals("on") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enable()
|
||||
{
|
||||
res = host.enable();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
host.info();
|
||||
assertTrue( host.isEnabled() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disable()
|
||||
{
|
||||
res = host.disable();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
host.info();
|
||||
assertTrue( !host.isEnabled() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
String name = host.getName();
|
||||
|
||||
res = host.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = host.info();
|
||||
assertTrue( res.isError() );
|
||||
|
||||
res = hostPool.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
boolean found = false;
|
||||
for(Host h : hostPool)
|
||||
{
|
||||
found = found || h.getName().equals(name);
|
||||
}
|
||||
|
||||
assertTrue( !found );
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
DocumentBuilder builder;
|
||||
Document doc;
|
||||
Element xml;
|
||||
|
||||
try
|
||||
{
|
||||
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
|
||||
doc = builder.parse( new File("./fixtures/host.xml") );
|
||||
xml = doc.getDocumentElement();
|
||||
|
||||
host = new HostXML(xml, client);
|
||||
|
||||
assertTrue( host.xpath("ID").equals("7") );
|
||||
assertTrue( host.xpath("NAME").equals("dummyhost") );
|
||||
assertTrue( host.xpath("STATE").equals("2") );
|
||||
assertTrue( host.xpath("IM_MAD").equals("im_dummy") );
|
||||
assertTrue( host.xpath("LAST_MON_TIME").equals("1277733596") );
|
||||
assertTrue( host.xpath("HOST_SHARE/MEM_USAGE").equals("1572864") );
|
||||
assertTrue( host.xpath("HOST_SHARE/CPU_USAGE").equals("300") );
|
||||
assertTrue( host.xpath("HOST_SHARE/FREE_CPU").equals("800") );
|
||||
assertTrue( host.xpath("HOST_SHARE/RUNNING_VMS").equals("3") );
|
||||
assertTrue( host.xpath("TEMPLATE/CPUSPEED").equals("2.2GHz") );
|
||||
assertTrue( host.xpath("TEMPLATE/HYPERVISOR").equals("dummy") );
|
||||
assertTrue( host.xpath("TEMPLATE/TOTALMEMORY").equals("16777216") );
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.image.*;
|
||||
|
||||
|
||||
|
||||
public class ImageTest
|
||||
{
|
||||
|
||||
private static Image image;
|
||||
private static ImagePool imagePool;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static OneResponse res;
|
||||
private static String name = "new_test_img";
|
||||
|
||||
|
||||
private static String template =
|
||||
"NAME = \"" + name + "\"\n" +
|
||||
"ATT1 = \"val1\"";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
imagePool = new ImagePool(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = Image.allocate(client, template);
|
||||
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
image = new Image(imgid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
image.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
image.delete();
|
||||
|
||||
res = Image.allocate(client, template);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
int imgid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
image = new Image(imgid, client);
|
||||
|
||||
|
||||
imagePool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(Image img : imagePool)
|
||||
{
|
||||
found = found || img.getName().equals(name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void info()
|
||||
{
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( image.getId().equals("0") );
|
||||
// assertTrue( image.id() == 0 );
|
||||
assertTrue( image.getName().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
// Update an existing att.
|
||||
res = image.update("ATT1", "new_val_1");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals("new_val_1") );
|
||||
|
||||
// Create a new att.
|
||||
res = image.update("ATT2", "new_val_2");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals("new_val_2") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rmattr()
|
||||
{
|
||||
res = image.rmattr("ATT1");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( image.xpath("ATT1").equals("") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enable()
|
||||
{
|
||||
res = image.enable();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( image.isEnabled() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disable()
|
||||
{
|
||||
res = image.disable();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( !image.isEnabled() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publish()
|
||||
{
|
||||
res = image.publish();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( image.isPublic() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpublish()
|
||||
{
|
||||
res = image.unpublish();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
image.info();
|
||||
assertTrue( !image.isPublic() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( image.xpath("ID").equals("0") );
|
||||
assertTrue( image.xpath("NAME").equals(name) );
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void delete()
|
||||
{
|
||||
res = image.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( res.isError() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
|
||||
public class SessionTest {
|
||||
|
||||
@Test
|
||||
public void createSession()
|
||||
{
|
||||
Client oneClient = null;
|
||||
try
|
||||
{
|
||||
oneClient = new Client();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
assertNotNull(oneClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrong_token()
|
||||
{
|
||||
Client oneClient = null;
|
||||
|
||||
try
|
||||
{
|
||||
// The secret string should be user:password. The url is null, so it
|
||||
// will be set to default.
|
||||
oneClient = new Client("wrong_password_token",null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
assertNull("Client should complain about the wrong token", oneClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrong_url()
|
||||
{
|
||||
Client oneClient = null;
|
||||
try
|
||||
{
|
||||
// The HTTP is misspelled
|
||||
oneClient = new Client(null,"HTP://localhost:2633/RPC2");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
assertNull("Client should complain about misspelled url", oneClient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.user.User;
|
||||
import org.opennebula.client.user.UserPool;
|
||||
|
||||
public class UserTest
|
||||
{
|
||||
|
||||
private static User user;
|
||||
private static UserPool userPool;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static OneResponse res;
|
||||
private static String name = "new_test_user";
|
||||
private static String password = "new_test_password";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
userPool = new UserPool(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = User.allocate(client, name, password);
|
||||
|
||||
int uid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
user = new User(uid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
user.delete();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
userPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(User u : userPool)
|
||||
{
|
||||
found = found || u.getName().equals(name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = user.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
assertTrue( user.id() >= 0 );
|
||||
assertTrue( user.getName().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = user.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
assertTrue( user.xpath("NAME").equals(name) );
|
||||
assertTrue( user.xpath("ENABLED").equals("True") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = user.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
assertTrue( user.isEnabled() );
|
||||
|
||||
res = user.delete();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
|
||||
res = user.info();
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
assertTrue( !user.isEnabled() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.host.Host;
|
||||
import org.opennebula.client.vm.VirtualMachine;
|
||||
import org.opennebula.client.vm.VirtualMachinePool;
|
||||
|
||||
|
||||
public class VirtualMachineTest
|
||||
{
|
||||
|
||||
private static VirtualMachine vm;
|
||||
private static VirtualMachinePool vmPool;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static int hid_A, hid_B;
|
||||
|
||||
private static OneResponse res;
|
||||
private static String name = "new_test_machine";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
vmPool = new VirtualMachinePool(client);
|
||||
|
||||
|
||||
res = Host.allocate(client, "host_A",
|
||||
"im_dummy", "vmm_dummy", "tm_dummy");
|
||||
hid_A = Integer.parseInt( res.getMessage() );
|
||||
|
||||
res = Host.allocate(client, "host_B",
|
||||
"im_dummy", "vmm_dummy", "tm_dummy");
|
||||
hid_B = Integer.parseInt( res.getMessage() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
String template = "NAME = " + name + "\n"+
|
||||
"MEMORY = 512\n" +
|
||||
"CONTEXT = [DNS = 192.169.1.4]";
|
||||
|
||||
res = VirtualMachine.allocate(client, template);
|
||||
int vmid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
||||
|
||||
vm = new VirtualMachine(vmid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
vm.finalizeVM();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
// String template = "NAME = " + name + "\n"+
|
||||
// "MEMORY = 512\n" +
|
||||
// "CONTEXT = [DNS = 192.169.1.4]";
|
||||
//
|
||||
// res = VirtualMachine.allocate(client, template);
|
||||
// assertTrue( !res.isError() );
|
||||
// assertTrue( res.getMessage().equals("0") );
|
||||
|
||||
vmPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(VirtualMachine vm : vmPool)
|
||||
{
|
||||
found = found || vm.getName().equals(name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = vm.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( vm.getId().equals("0") );
|
||||
// assertTrue( vm.id() == 0 );
|
||||
assertTrue( vm.getName().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hold()
|
||||
{
|
||||
res = vm.hold();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void release()
|
||||
{
|
||||
vm.hold();
|
||||
|
||||
res = vm.release();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deploy()
|
||||
{
|
||||
res = vm.deploy(hid_A);
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.migrate(hid_B);
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void liveMigrate()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.liveMigrate(hid_B);
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shutdown()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.shutdown();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cancel()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.cancel();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stop()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.stop();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suspend()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.suspend();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resume()
|
||||
{
|
||||
vm.deploy(hid_A);
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
vm.suspend();
|
||||
try{ Thread.sleep(5000); } catch (Exception e){}
|
||||
|
||||
res = vm.resume();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void finalize()
|
||||
{
|
||||
res = vm.finalizeVM();
|
||||
assertTrue( !res.isError() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restart()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = vm.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( vm.xpath("NAME").equals(name) );
|
||||
assertTrue( vm.xpath("TEMPLATE/MEMORY").equals("512") );
|
||||
// assertTrue( vm.xpath("ID").equals("0") );
|
||||
assertTrue( vm.xpath("TEMPLATE/MEMORY").equals("512") );
|
||||
assertTrue( vm.xpath("TEMPLATE/CONTEXT/DNS").equals("192.169.1.4") );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.vnet.VirtualNetwork;
|
||||
import org.opennebula.client.vnet.VirtualNetworkPool;
|
||||
|
||||
public class VirtualNetworkTest
|
||||
{
|
||||
|
||||
private static VirtualNetwork vnet;
|
||||
private static VirtualNetworkPool vnetPool;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static OneResponse res;
|
||||
private static String name = "new_test_vnet";
|
||||
|
||||
|
||||
private static String template =
|
||||
"NAME = " + name + "\n"+
|
||||
"TYPE = RANGED\n" +
|
||||
"PUBLIC = NO\n" +
|
||||
"BRIDGE = vbr0\n" +
|
||||
"NETWORK_SIZE = C\n" +
|
||||
"NETWORK_ADDRESS = 192.168.0.0\n";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
vnetPool = new VirtualNetworkPool(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = VirtualNetwork.allocate(client, template);
|
||||
|
||||
int vnid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
|
||||
vnet = new VirtualNetwork(vnid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
vnet.delete();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
// String template = "NAME = " + name + "\n"+
|
||||
// "TYPE = RANGED\n" +
|
||||
// "PUBLIC = NO\n" +
|
||||
// "BRIDGE = vbr0\n" +
|
||||
// "NETWORK_SIZE = C\n" +
|
||||
// "NETWORK_ADDRESS = 192.168.0.0\n";
|
||||
//
|
||||
// res = VirtualNetwork.allocate(client, template);
|
||||
// assertTrue( !res.isError() );
|
||||
// assertTrue( res.getMessage().equals("0") );
|
||||
|
||||
vnetPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(VirtualNetwork vn : vnetPool)
|
||||
{
|
||||
found = found || vn.getName().equals(name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = vnet.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( vnet.getId().equals("0") );
|
||||
// assertTrue( vnet.id() == 0 );
|
||||
assertTrue( vnet.getName().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = vnet.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( vnet.xpath("ID").equals("0") );
|
||||
assertTrue( vnet.xpath("NAME").equals(name) );
|
||||
assertTrue( vnet.xpath("BRIDGE").equals("vbr0") );
|
||||
assertTrue( vnet.xpath("TEMPLATE/NETWORK_ADDRESS").equals("192.168.0.0") );
|
||||
assertTrue( vnet.xpath("TEMPLATE/TYPE").equals("RANGED") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = vnet.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = vnet.info();
|
||||
assertTrue( res.isError() );
|
||||
}
|
||||
}
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
./test.sh ClusterTest
|
||||
./test.sh HostTest
|
||||
./test.sh ImageTest
|
||||
./test.sh SessionTest
|
||||
./test.sh UserTest
|
||||
./test.sh VirtualMachineTest
|
||||
./test.sh VirtualNetworkTest
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# Usage: test.sh <Test_name>
|
||||
# For instance: test.sh ImageTest
|
||||
|
||||
JUNIT_JAR="/usr/share/java/junit4.jar"
|
||||
ONEDB="$ONE_LOCATION/var/one.db"
|
||||
|
||||
|
||||
oned
|
||||
sleep 4s;
|
||||
|
||||
java -cp ../lib/*:../jar/*:$JUNIT_JAR:. org.junit.runner.JUnitCore $1
|
||||
|
||||
pkill oned;
|
||||
sleep 4s;
|
||||
pkill -9 oned;
|
||||
rm $ONEDB
|
||||
Reference in new issue
Block a user