Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / tests / DataTransferModelTest.java
  1. package tests;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import org.junit.Test;
  6.  
  7. import models.*;
  8. import models.algebra.Variable;
  9. import models.dataConstraintModel.*;
  10. import models.dataFlowModel.*;
  11.  
  12. public class DataTransferModelTest {
  13.  
  14. @Test
  15. public void test() {
  16. // Construct a data-flow architecture model.
  17. DataTransferModel model = new DataTransferModel();
  18. ResourcePath customers = new ResourcePath("customers"); // "customers"
  19. ResourcePath customer = new ResourcePath(customers, new Variable("uid")); // "customers.{uid}"
  20. ResourcePath customer_off = new ResourcePath(customer, "off"); // "customers.{uid}.off"
  21. ResourcePath customer_add = new ResourcePath(customer, "add"); // "customers.{uid}.add"
  22. ResourcePath companies = new ResourcePath("companies"); // "companies"
  23. ResourcePath company = new ResourcePath(companies, new Variable("cid")); // "companies.{cid}"
  24. ResourcePath company_add = new ResourcePath(company, "add"); // "companies.{cid}.add"
  25. model.addResourcePath(customer_off);
  26. model.addResourcePath(customer_add);
  27. model.addResourcePath(company_add);
  28. // === cio_setCustomerOff(uid) ===
  29. //
  30. // out customers.{uid}.off(c, set(x)) = x
  31. //
  32. DataTransferChannel cio_setCustomerOff = new DataTransferChannel("CIO_SetCustomerOff", new Variable("uid")); // set customer's office (an input channel)
  33. ChannelMember customer_off_1 = new ChannelMember(customer_off);
  34. cio_setCustomerOff.addChannelMemberAsOutput(customer_off_1);
  35. assertEquals(customer_off.getPathParams().get(0), cio_setCustomerOff.getSelectors().iterator().next().getExpression());
  36. // === cio_setCompanyAdd(cid) ===
  37. //
  38. // out companies.{cid}.add(a, set(y)) = y
  39. //
  40. DataTransferChannel cio_setCompanyAdd = new DataTransferChannel("CIO_SetCompanyAdd", new Variable("cid")); // set companie's address (an input channel)
  41. ChannelMember company_add_1 = new ChannelMember(company_add);
  42. cio_setCompanyAdd.addChannelMemberAsOutput(company_add_1);
  43. assertEquals(company_add.getPathParams().get(0), cio_setCompanyAdd.getSelectors().iterator().next().getExpression());
  44. // === c ===
  45. //
  46. // in customers.{uid}.off( c, update(cid, a2)) = cid
  47. // in companies.{cid}.add( a, update(cid, a2)) = a2
  48. // out customers.{uid}.add(b, update(cid, a2)) = a2
  49. //
  50. DataTransferChannel c = new DataTransferChannel("c", new Variable("uid")); // update customer's address
  51. ChannelMember customer_off_2 = new ChannelMember(customer_off);
  52. ChannelMember company_add_2 = new ChannelMember(company_add);
  53. ChannelMember customer_add_2 = new ChannelMember(customer_add);
  54. c.addChannelMemberAsInput(customer_off_2);
  55. c.addChannelMemberAsInput(company_add_2);
  56. c.addChannelMemberAsOutput(customer_add_2);
  57. assertEquals(customer_off.getPathParams().get(0), c.getSelectors().iterator().next().getExpression());
  58. assertEquals(customer_add.getPathParams().get(0), c.getSelectors().iterator().next().getExpression());
  59. assertEquals(company_add.getPathParams().get(0), new Variable("cid"));
  60. // Construct a data-flow architecture model.
  61. model.addIOChannel(cio_setCustomerOff);
  62. model.addIOChannel(cio_setCompanyAdd);
  63. model.addChannel(c);
  64. // Check the model.
  65. assertEquals(3, model.getResourcePaths().size());
  66. assertEquals(7, model.getResourceHierarchies().size());
  67. assertEquals(2, model.getIOChannels().size());
  68. assertEquals(1, model.getChannels().size());
  69. // Extract the resource dependency graph.
  70. DataFlowGraph resourceDependencyGraph = model.getDataFlowGraph();
  71. // Check the graph.
  72. assertEquals(7, resourceDependencyGraph.getResourceNodes().size());
  73. assertEquals(3, resourceDependencyGraph.getChannelNodes().size());
  74. assertEquals(5, resourceDependencyGraph.getEdges().size());
  75. for (Edge e: resourceDependencyGraph.getEdges()) {
  76. System.out.println(e.getSource() + "-(" + e + ")->" + e.getDestination());
  77. }
  78. }
  79.  
  80. }