package org.zstack.test.network;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zstack.core.componentloader.ComponentLoader;
import org.zstack.core.db.DatabaseFacade;
import org.zstack.header.network.l2.L2NetworkInventory;
import org.zstack.header.network.l3.L3NetworkInventory;
import org.zstack.header.zone.ZoneInventory;
import org.zstack.test.*;
import org.zstack.utils.CollectionUtils;
import org.zstack.utils.function.Function;
import java.util.List;
public class TestListL3Network {
Api api;
ComponentLoader loader;
DatabaseFacade dbf;
@Before
public void setUp() throws Exception {
DBUtil.reDeployDB();
BeanConstructor con = new WebBeanConstructor();
/* This loads spring application context */
loader = con.addXml("PortalForUnitTest.xml").addXml("ZoneManager.xml").addXml("NetworkManager.xml").addXml("AccountManager.xml").build();
dbf = loader.getComponent(DatabaseFacade.class);
api = new Api();
api.startServer();
}
@After
public void tearDown() throws Exception {
api.stopServer();
}
@Test
public void test() throws ApiSenderException {
int testNum = 10;
ZoneInventory zone = api.createZones(1).get(0);
L2NetworkInventory linv = api.createNoVlanL2Network(zone.getUuid(), "eth0");
for (int i = 0; i < testNum; i++) {
api.createL3BasicNetwork(linv.getUuid());
}
List<L3NetworkInventory> iinvs = api.listL3Network(null);
Assert.assertEquals(testNum, iinvs.size());
List<String> uuids = CollectionUtils.transformToList(iinvs, new Function<String, L3NetworkInventory>() {
@Override
public String call(L3NetworkInventory arg) {
return arg.getUuid();
}
});
iinvs = api.listL3Network(uuids);
for (int i = 0; i < testNum; i++) {
Assert.assertEquals(uuids.get(i), iinvs.get(i).getUuid());
}
}
}