Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / tests / DataConstraintModelTest.java
package tests;

import static org.junit.Assert.*;

import org.junit.Test;

import models.dataConstraintModel.*;

public class DataConstraintModelTest {

	@Test
	public void test() {
		// Construct a data constraint architecture model.
		DataConstraintModel model = new DataConstraintModel();
		ResourcePath customers = model.createResourcePath(null, "customers");			// "customers"
		ResourcePath customer = model.createResourcePath(customers, "{customer_id}");	// "customers.{customer_id}"
		ResourcePath customer_off = model.createResourcePath(customer, "off");			// "customers.{customer_id}.off"
		ResourcePath customer_add = model.createResourcePath(customer, "add");			// "customers.{customer_id}.add"
		ResourcePath companies = model.createResourcePath(null, "companies");			// "companies"
		ResourcePath company = model.createResourcePath(companies, "{company_id}");		// "companies.{company_id}"
		ResourcePath company_add = model.createResourcePath(companies, "add");			// "companies.{company_id}.add"
		
		Channel gin_1 = new Channel("gin_1");	// set customer's office
		GroupSelector x1 = new GroupSelector();
		ChannelMember customer_off_1 = new ChannelMember(customer_off);
		customer_off_1.addPathParam(x1);
		gin_1.addChannelMember(customer_off_1);
		assertEquals(customer_off.getNumberOfParameters(), customer_off_1.getPathParams().size());
		
		Channel gin_2 = new Channel("gin_2");	// set companie's address
		GroupSelector x2 = new GroupSelector();
		ChannelMember company_add_1 = new ChannelMember(company_add);
		company_add_1.addPathParam(x2);
		gin_2.addChannelMember(company_add_1);		
		assertEquals(company_add.getNumberOfParameters(), company_add_1.getPathParams().size());
		
		Channel g = new Channel("g");		// update customer's address
		GroupSelector x3 = new GroupSelector();
		ChannelSelector y = new ChannelSelector();
		ChannelMember customer_off_2 = new ChannelMember(customer_off);
		ChannelMember company_add_2 = new ChannelMember(company_add);
		ChannelMember customer_add_2 = new ChannelMember(customer_add);
		customer_off_2.addPathParam(x3);
		company_add_2.addPathParam(y);
		customer_add_2.addPathParam(x3);
		g.addChannelMember(customer_off_2);
		g.addChannelMember(customer_add_2);
		g.addChannelMember(company_add_2);
		assertEquals(customer_off.getNumberOfParameters(), customer_off_2.getPathParams().size());
		assertEquals(customer_add.getNumberOfParameters(), customer_add_2.getPathParams().size());
		assertEquals(company_add.getNumberOfParameters(), company_add_2.getPathParams().size());
		
		model.addIOChannel(gin_1);
		model.addIOChannel(gin_2);
		model.addChannel(g);
		
		// Check the model.
		assertEquals(3, model.getResourcePaths().size());
		assertEquals(2, model.getIOChannels().size());
		assertEquals(1, model.getChannels().size());
	}

}