package tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import models.algebra.Variable;
import models.dataConstraintModel.Channel;
import models.dataConstraintModel.ChannelMember;
import models.dataConstraintModel.DataConstraintModel;
import models.dataConstraintModel.ResourcePath;
import models.dataFlowModel.DataTransferModel;
import simulator.Resource;
import simulator.Simulator;
import simulator.SystemState;
import simulator.states.MapResourceState;
public class SimulatorTest {
@Test
public void test() {
// Construct a data transfer architecture model.
DataTransferModel model = new DataTransferModel();
ResourcePath customers = new ResourcePath("customers"); // "customers"
ResourcePath customer = new ResourcePath(customers,
new Variable("uid", DataConstraintModel.typeString)); // "customers.{uid}"
ResourcePath customer_off = new ResourcePath(customer, "off"); // "customers.{uid}.off"
ResourcePath customer_add = new ResourcePath(customer, "add"); // "customers.{uid}.add"
ResourcePath companies = new ResourcePath("companies"); // "companies"
ResourcePath company = new ResourcePath(companies,
new Variable("cid", DataConstraintModel.typeString)); // "companies.{cid}"
ResourcePath company_add = new ResourcePath(company, "add"); // "companies.{cid}.add"
model.addResourcePath(customer_off);
model.addResourcePath(customer_add);
model.addResourcePath(company_add);
Channel cio_setCustomerOff = new Channel("CIO_SetCustomerOff", new Variable("uid")); // set customer's office
ChannelMember customer_off_1 = new ChannelMember(customer_off);
cio_setCustomerOff.addChannelMember(customer_off_1);
Channel cio_setCompanyAdd = new Channel("CIO_SetCompanyAdd", new Variable("cid")); // set companie's address
ChannelMember company_add_1 = new ChannelMember(company_add);
cio_setCompanyAdd.addChannelMember(company_add_1);
Channel c = new Channel("c", new Variable("uid")); // update customer's address
ChannelMember customer_off_2 = new ChannelMember(customer_off);
ChannelMember company_add_2 = new ChannelMember(company_add);
ChannelMember customer_add_2 = new ChannelMember(customer_add);
c.addChannelMember(customer_off_2);
c.addChannelMember(company_add_2);
c.addChannelMember(customer_add_2);
model.addIOChannel(cio_setCustomerOff);
model.addIOChannel(cio_setCompanyAdd);
model.addChannel(c);
Simulator simulator = new Simulator(model);
SystemState initialState = simulator.init();
assertEquals(2, initialState.getRootResources().size());
for (Resource rootRes: initialState.getRootResources()) {
System.out.println(rootRes.getResourceHierarchy().getResourceName());
assertTrue(rootRes.getState() instanceof MapResourceState);
assertEquals(0, rootRes.getChildren().size());
assertEquals(0, ((MapResourceState) rootRes.getState()).getChildStates().size());
}
}
}