package tests; import static org.junit.Assert.*; import org.junit.Test; import models.algebra.Variable; import models.dataConstraintModel.*; public class DataConstraintModelTest { @Test public void test() { // Construct a data constraint architecture model. DataConstraintModel model = new DataConstraintModel(); ResourcePath customers = new ResourcePath("customers"); // "customers" ResourcePath customer = new ResourcePath(customers, new Variable("uid")); // "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")); // "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); assertEquals(customer_off.getPathParams().get(0), cio_setCustomerOff.getSelectors().iterator().next().getExpression()); 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); assertEquals(company_add.getPathParams().get(0), cio_setCompanyAdd.getSelectors().iterator().next().getExpression()); 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); assertEquals(customer_off.getPathParams().get(0), c.getSelectors().iterator().next().getExpression()); assertEquals(customer_add.getPathParams().get(0), c.getSelectors().iterator().next().getExpression()); assertEquals(company_add.getPathParams().get(0), new Variable("cid")); model.addInputChannel(cio_setCustomerOff); model.addInputChannel(cio_setCompanyAdd); model.addChannel(c); // Check the model. assertEquals(3, model.getResourcePaths().size()); assertEquals(7, model.getResourceHierarchies().size()); assertEquals(2, model.getInputChannels().size()); assertEquals(1, model.getChannels().size()); } }