How to use Consumer method of mock.contract.Consumer class

Best Karate code snippet using mock.contract.Consumer.Consumer

Source:ContractRegistryTests.java Github

copy

Full Screen

...191 componentMock = new ComponentMock("Component 1");192193 ConnectorMock consumerMock;194 consumerMock =195 new ConnectorMock("Consumer 1", componentMock, ConnectorType.CONSUMER);196197 Contract contract;198 contract = this.createTestContract(TEST_CONTRACT_01);199200 ResourceManagerMock resourceManagerMock;201 resourceManagerMock = new ResourceManagerMock();202 ContractRegistry contractRegistry;203 contractRegistry =204 new ContractRegistry(resourceManagerMock, triggerRegistry);205206 /* Add the contract. */207 try {208 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,209 consumerMock, Role.CONSUMER);210 }211212 catch (TreatyException e) {213 fail("Unexpected TreatyException: " + e.getMessage());214 }215 // end catch.216217 assertFalse(contractRegistry.getContracts(consumerMock, Role.LEGISLATOR)218 .contains(contract));219 /* The registry should know the contract. */220 assertTrue(contractRegistry.getContracts(consumerMock, Role.CONSUMER)221 .contains(contract));222 /* The contract should have constraints. */223 assertFalse(contractRegistry.getContracts(consumerMock, Role.CONSUMER)224 .iterator().next().getConstraints().isEmpty());225 assertFalse(contractRegistry.getContracts(consumerMock, Role.SUPPLIER)226 .contains(contract));227228 /* The consumer should be set as consumer of the contract. */229 assertEquals(consumerMock, contractRegistry.getContracts(consumerMock,230 Role.CONSUMER).iterator().next().getConsumer());231232 /* Remove the contract. */233 try {234 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,235 consumerMock, Role.CONSUMER);236 }237238 catch (TreatyException e) {239 fail("Unexpected TreatyException: " + e.getMessage());240 }241 // end catch.242243 assertEquals(0, contractRegistry244 .getContracts(consumerMock, Role.LEGISLATOR).size());245 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.CONSUMER)246 .size());247 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.SUPPLIER)248 .size());249 }250251 /**252 * <p>253 * Tests the method254 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}255 * by adding a {@link Role#CONSUMER} {@link Contract} with an256 * {@link ConnectorType#SUPPLIER} to the {@link ContractRegistry}.257 * </p>258 */259 @Test260 public void testUpdateRegistry03() {261262 ComponentMock componentMock;263 componentMock = new ComponentMock("Component 1");264265 ConnectorMock supplierMock;266 supplierMock =267 new ConnectorMock("Supplier 1", componentMock, ConnectorType.SUPPLIER);268269 Contract contract;270 contract = this.createTestContract(TEST_CONTRACT_01);271272 ResourceManagerMock resourceManagerMock;273 resourceManagerMock = new ResourceManagerMock();274 ContractRegistry contractRegistry;275 contractRegistry =276 new ContractRegistry(resourceManagerMock, triggerRegistry);277278 /* Add the contract. */279 try {280 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,281 supplierMock, Role.CONSUMER);282 fail("Expected TreatyException was not thrown.");283 }284285 catch (TreatyException e) {286 /* Expected exception. */287 }288 // end catch.289 }290291 /**292 * <p>293 * Tests the method294 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}295 * by adding and removing a {@link Role#SUPPLIER} {@link Contract} to the296 * {@link ContractRegistry}.297 * </p>298 */299 @Test300 public void testUpdateRegistry04() {301302 ComponentMock componentMock;303 componentMock = new ComponentMock("Component 1");304305 ConnectorMock supplierMock;306 supplierMock =307 new ConnectorMock("Supplier 1", componentMock, ConnectorType.SUPPLIER);308309 Contract contract;310 contract = this.createTestContract(TEST_CONTRACT_01);311312 ResourceManagerMock resourceManagerMock;313 resourceManagerMock = new ResourceManagerMock();314 ContractRegistry contractRegistry;315 contractRegistry =316 new ContractRegistry(resourceManagerMock, triggerRegistry);317318 /* Add the contract. */319 try {320 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,321 supplierMock, Role.SUPPLIER);322 }323324 catch (TreatyException e) {325 fail("Unexpected TreatyException: " + e.getMessage());326 }327 // end catch.328329 assertFalse(contractRegistry.getContracts(supplierMock, Role.LEGISLATOR)330 .contains(contract));331 assertFalse(contractRegistry.getContracts(supplierMock, Role.CONSUMER)332 .contains(contract));333 /* The registry should know the contract. */334 assertTrue(contractRegistry.getContracts(supplierMock, Role.SUPPLIER)335 .contains(contract));336 /* The contract should have constraints. */337 assertFalse(contractRegistry.getContracts(supplierMock, Role.SUPPLIER)338 .iterator().next().getConstraints().isEmpty());339340 /* The supplier should be set as supplier of the contract. */341 assertEquals(supplierMock, contractRegistry.getContracts(supplierMock,342 Role.SUPPLIER).iterator().next().getSupplier());343344 /* Remove the contract. */345 try {346 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,347 supplierMock, Role.SUPPLIER);348 }349350 catch (TreatyException e) {351 fail("Unexpected TreatyException: " + e.getMessage());352 }353 // end catch.354355 assertEquals(0, contractRegistry356 .getContracts(supplierMock, Role.LEGISLATOR).size());357 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.CONSUMER)358 .size());359 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.SUPPLIER)360 .size());361 }362363 /**364 * <p>365 * Tests the method366 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}367 * by adding a {@link Role#SUPPLIER} {@link Contract} with an368 * {@link ConnectorType#CONSUMER} to the {@link ContractRegistry}.369 * </p>370 */371 @Test372 public void testUpdateRegistry05() {373374 ComponentMock componentMock;375 componentMock = new ComponentMock("Component 1");376377 ConnectorMock consumerMock;378 consumerMock =379 new ConnectorMock("Consumer 1", componentMock, ConnectorType.CONSUMER);380381 Contract contract;382 contract = this.createTestContract(TEST_CONTRACT_01);383384 ResourceManagerMock resourceManagerMock;385 resourceManagerMock = new ResourceManagerMock();386 ContractRegistry contractRegistry;387 contractRegistry =388 new ContractRegistry(resourceManagerMock, triggerRegistry);389390 /* Add the contract. */391 try {392 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,393 consumerMock, Role.SUPPLIER);394 fail("Expected TreatyException was not thrown.");395 }396397 catch (TreatyException e) {398 /* Expected exception. */399 }400 // end catch.401 }402403 /**404 * <p>405 * Tests the method406 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}407 * by adding and removing a {@link Role#LEGISLATOR} and a408 * {@link Role#CONSUMER} {@link Contract} to the {@link ContractRegistry}.409 * </p>410 */411 @Test412 public void testUpdateRegistry06() {413414 ComponentMock componentMock;415 componentMock = new ComponentMock("Component 1");416417 ConnectorMock legistlatorMock;418 legistlatorMock =419 new ConnectorMock("Legislator 1", componentMock, ConnectorType.SUPPLIER);420421 ConnectorMock consumerMock;422 consumerMock =423 new ConnectorMock("Consumer 1", componentMock, ConnectorType.CONSUMER);424425 Contract contract;426 contract = this.createTestContract(TEST_CONTRACT_01);427428 ResourceManagerMock resourceManagerMock;429 resourceManagerMock = new ResourceManagerMock();430 ContractRegistry contractRegistry;431 contractRegistry =432 new ContractRegistry(resourceManagerMock, triggerRegistry);433434 /* Add the legislator contract and the consumer contract. */435 try {436 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,437 legistlatorMock, Role.LEGISLATOR);438 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,439 consumerMock, Role.CONSUMER);440 }441442 catch (TreatyException e) {443 fail("Unexpected TreatyException: " + e.getMessage());444 }445 // end catch.446447 /* The registry should know the contract. */448 assertTrue(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)449 .contains(contract));450 /* The contract should have constraints. */451 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)452 .iterator().next().getConstraints().isEmpty());453454 assertFalse(contractRegistry.getContracts(consumerMock, Role.LEGISLATOR)455 .contains(contract));456457 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.CONSUMER)458 .contains(contract));459460 /*461 * The consumer's contract should have the legislator's contract as462 * definition.463 */464 assertEquals(contract, contractRegistry.getContracts(consumerMock,465 Role.CONSUMER).iterator().next().getDefinition());466467 /* The consumer's contract should have constraints. */468 assertFalse(contractRegistry.getContracts(consumerMock, Role.CONSUMER)469 .iterator().next().getConstraints().isEmpty());470471 /* Remove the contracts. */472 try {473 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,474 legistlatorMock, Role.LEGISLATOR);475 }476477 catch (TreatyException e) {478 fail("Unexpected TreatyException: " + e.getMessage());479 }480 // end catch.481482 assertEquals(0, contractRegistry.getContracts(legistlatorMock,483 Role.LEGISLATOR).size());484 assertEquals(0, contractRegistry.getContracts(legistlatorMock,485 Role.CONSUMER).size());486 assertEquals(0, contractRegistry.getContracts(legistlatorMock,487 Role.SUPPLIER).size());488489 assertEquals(0, contractRegistry490 .getContracts(consumerMock, Role.LEGISLATOR).size());491 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.CONSUMER)492 .size());493 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.SUPPLIER)494 .size());495 }496497 /**498 * <p>499 * Tests the method500 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}501 * by adding and removing a {@link Role#LEGISLATOR} and a502 * {@link Role#SUPPLIER} {@link Contract} to the {@link ContractRegistry}.503 * </p>504 */505 @Test506 public void testUpdateRegistry07() {507508 ComponentMock componentMock;509 componentMock = new ComponentMock("Component 1");510511 ConnectorMock legistlatorMock;512 legistlatorMock =513 new ConnectorMock("Legislator 1", componentMock, ConnectorType.SUPPLIER);514515 ConnectorMock supplierMock;516 supplierMock =517 new ConnectorMock("Supplier 1", componentMock, ConnectorType.SUPPLIER);518519 Contract contract;520 contract = this.createTestContract(TEST_CONTRACT_01);521522 ResourceManagerMock resourceManagerMock;523 resourceManagerMock = new ResourceManagerMock();524 ContractRegistry contractRegistry;525 contractRegistry =526 new ContractRegistry(resourceManagerMock, triggerRegistry);527528 /* Add the legislator contract and the supplier contract. */529 try {530 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,531 legistlatorMock, Role.LEGISLATOR);532 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,533 supplierMock, Role.SUPPLIER);534 }535536 catch (TreatyException e) {537 fail("Unexpected TreatyException: " + e.getMessage());538 }539 // end catch.540541 assertTrue(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)542 .contains(contract));543 assertFalse(contractRegistry.getContracts(supplierMock, Role.LEGISLATOR)544 .contains(contract));545 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.CONSUMER)546 .contains(contract));547548 /*549 * The supplier's contract should have the legislator's contract as550 * definition.551 */552 assertEquals(contract, contractRegistry.getContracts(supplierMock,553 Role.SUPPLIER).iterator().next().getDefinition());554555 /* The supplier's contract should have constraints. */556 assertFalse(contractRegistry.getContracts(supplierMock, Role.SUPPLIER)557 .iterator().next().getConstraints().isEmpty());558559 /* Remove the contracts. */560 try {561 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,562 legistlatorMock, Role.LEGISLATOR);563 }564565 catch (TreatyException e) {566 fail("Unexpected TreatyException: " + e.getMessage());567 }568 // end catch.569570 assertEquals(0, contractRegistry.getContracts(legistlatorMock,571 Role.LEGISLATOR).size());572 assertEquals(0, contractRegistry.getContracts(legistlatorMock,573 Role.CONSUMER).size());574 assertEquals(0, contractRegistry.getContracts(legistlatorMock,575 Role.SUPPLIER).size());576577 assertEquals(0, contractRegistry578 .getContracts(supplierMock, Role.LEGISLATOR).size());579 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.CONSUMER)580 .size());581 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.SUPPLIER)582 .size());583 }584585 /**586 * <p>587 * Tests the method588 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}589 * by adding and removing a {@link Role#LEGISLATOR}, a {@link Role#CONSUMER}590 * and a {@link Role#SUPPLIER} {@link Contract} to the591 * {@link ContractRegistry}.592 * </p>593 */594 @Test595 public void testUpdateRegistry08() {596597 ComponentMock componentMock;598 componentMock = new ComponentMock("Component 1");599600 ConnectorMock legistlatorMock;601 legistlatorMock =602 new ConnectorMock("Legislator 1", componentMock, ConnectorType.SUPPLIER);603604 ConnectorMock consumerMock;605 consumerMock =606 new ConnectorMock("Consumer 1", componentMock, ConnectorType.CONSUMER);607608 ConnectorMock supplierMock;609 supplierMock =610 new ConnectorMock("Supplier 1", componentMock, ConnectorType.SUPPLIER);611612 Contract contract;613 contract = this.createTestContract(TEST_CONTRACT_01);614615 ResourceManagerMock resourceManagerMock;616 resourceManagerMock = new ResourceManagerMock();617 ContractRegistry contractRegistry;618 contractRegistry =619 new ContractRegistry(resourceManagerMock, triggerRegistry);620621 /*622 * Add the legislator contract, the consumer contract and the supplier623 * contract.624 */625 try {626 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,627 legistlatorMock, Role.LEGISLATOR);628 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,629 consumerMock, Role.CONSUMER);630 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry631 .getContracts(consumerMock, Role.CONSUMER).iterator().next(),632 supplierMock, Role.SUPPLIER);633 }634635 catch (TreatyException e) {636 fail("Unexpected TreatyException: " + e.getMessage());637 }638 // end catch.639640 assertTrue(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)641 .contains(contract));642 assertFalse(contractRegistry.getContracts(consumerMock, Role.LEGISLATOR)643 .contains(contract));644 assertFalse(contractRegistry.getContracts(supplierMock, Role.LEGISLATOR)645 .contains(contract));646 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.CONSUMER)647 .contains(contract));648649 /*650 * The consumer's contract should have the legislator's contract as651 * definition.652 */653 assertEquals(contract, contractRegistry.getContracts(consumerMock,654 Role.CONSUMER).iterator().next().getDefinition());655656 /* The consumer's contract should have constraints. */657 assertFalse(contractRegistry.getContracts(consumerMock, Role.CONSUMER)658 .iterator().next().getConstraints().isEmpty());659660 /*661 * The supplier's contract should have the consumer's contract as662 * definition.663 */664 assertEquals(contractRegistry.getContracts(consumerMock, Role.CONSUMER)665 .iterator().next(), contractRegistry.getContracts(supplierMock,666 Role.SUPPLIER).iterator().next().getDefinition());667668 /* The supplier's contract should have constraints. */669 assertFalse(contractRegistry.getContracts(supplierMock, Role.SUPPLIER)670 .iterator().next().getConstraints().isEmpty());671672 /* Remove the contracts. */673 try {674 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,675 legistlatorMock, Role.LEGISLATOR);676 }677678 catch (TreatyException e) {679 fail("Unexpected TreatyException: " + e.getMessage());680 }681 // end catch.682683 assertEquals(0, contractRegistry.getContracts(legistlatorMock,684 Role.LEGISLATOR).size());685 assertEquals(0, contractRegistry.getContracts(legistlatorMock,686 Role.CONSUMER).size());687 assertEquals(0, contractRegistry.getContracts(legistlatorMock,688 Role.SUPPLIER).size());689690 assertEquals(0, contractRegistry691 .getContracts(consumerMock, Role.LEGISLATOR).size());692 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.CONSUMER)693 .size());694 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.SUPPLIER)695 .size());696697 assertEquals(0, contractRegistry698 .getContracts(supplierMock, Role.LEGISLATOR).size());699 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.CONSUMER)700 .size());701 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.SUPPLIER)702 .size());703 }704705 /**706 * <p>707 * Tests the method708 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}709 * by adding and removing a {@link Role#LEGISLATOR}, a {@link Role#CONSUMER}710 * and a {@link Role#SUPPLIER} {@link Contract} to the711 * {@link ContractRegistry}.712 * </p>713 */714 @Test715 public void testUpdateRegistry09() {716717 ComponentMock componentMock;718 componentMock = new ComponentMock("Component 1");719720 ConnectorMock legistlatorMock;721 legistlatorMock =722 new ConnectorMock("Legislator 1", componentMock, ConnectorType.SUPPLIER);723724 ConnectorMock consumerMock;725 consumerMock =726 new ConnectorMock("Consumer 1", componentMock, ConnectorType.CONSUMER);727728 ConnectorMock supplierMock;729 supplierMock =730 new ConnectorMock("Supplier 1", componentMock, ConnectorType.SUPPLIER);731732 Contract contract;733 contract = this.createTestContract(TEST_CONTRACT_01);734735 ResourceManagerMock resourceManagerMock;736 resourceManagerMock = new ResourceManagerMock();737 ContractRegistry contractRegistry;738 contractRegistry =739 new ContractRegistry(resourceManagerMock, triggerRegistry);740741 /*742 * Add the legislator contract, the consumer contract and the supplier743 * contract.744 */745 try {746 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,747 legistlatorMock, Role.LEGISLATOR);748 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,749 supplierMock, Role.SUPPLIER);750 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry751 .getContracts(supplierMock, Role.SUPPLIER).iterator().next(),752 consumerMock, Role.CONSUMER);753 }754755 catch (TreatyException e) {756 fail("Unexpected TreatyException: " + e.getMessage());757 }758 // end catch.759760 assertTrue(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)761 .contains(contract));762 assertFalse(contractRegistry.getContracts(consumerMock, Role.LEGISLATOR)763 .contains(contract));764 assertFalse(contractRegistry.getContracts(supplierMock, Role.LEGISLATOR)765 .contains(contract));766 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.SUPPLIER)767 .contains(contract));768769 /*770 * The supplier's contract should have the legislator's contract as771 * definition.772 */773 assertEquals(contract, contractRegistry.getContracts(supplierMock,774 Role.SUPPLIER).iterator().next().getDefinition());775776 /* The supplier's contract should have constraints. */777 assertFalse(contractRegistry.getContracts(supplierMock, Role.SUPPLIER)778 .iterator().next().getConstraints().isEmpty());779780 /*781 * The consumer's contract should have the supplier's contract as782 * definition.783 */784 assertEquals(contractRegistry.getContracts(supplierMock, Role.SUPPLIER)785 .iterator().next(), contractRegistry.getContracts(consumerMock,786 Role.CONSUMER).iterator().next().getDefinition());787788 /* The consumer's contract should have constraints. */789 assertFalse(contractRegistry.getContracts(consumerMock, Role.CONSUMER)790 .iterator().next().getConstraints().isEmpty());791792 /* Remove the contracts. */793 try {794 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,795 legistlatorMock, Role.LEGISLATOR);796 }797798 catch (TreatyException e) {799 fail("Unexpected TreatyException: " + e.getMessage());800 }801 // end catch.802803 assertEquals(0, contractRegistry.getContracts(legistlatorMock,804 Role.LEGISLATOR).size());805 assertEquals(0, contractRegistry.getContracts(legistlatorMock,806 Role.CONSUMER).size());807 assertEquals(0, contractRegistry.getContracts(legistlatorMock,808 Role.SUPPLIER).size());809810 assertEquals(0, contractRegistry811 .getContracts(consumerMock, Role.LEGISLATOR).size());812 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.CONSUMER)813 .size());814 assertEquals(0, contractRegistry.getContracts(consumerMock, Role.SUPPLIER)815 .size());816817 assertEquals(0, contractRegistry818 .getContracts(supplierMock, Role.LEGISLATOR).size());819 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.CONSUMER)820 .size());821 assertEquals(0, contractRegistry.getContracts(supplierMock, Role.SUPPLIER)822 .size());823 }824825 /**826 * <p>827 * Tests the method828 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}829 * .830 * </p>831 */832 @Test833 public void testGetAffectedContracts01() throws TreatyException {834835 ComponentMock consumerComponentMock;836 consumerComponentMock = new ComponentMock("Consumer Component 1");837838 ComponentMock supplier1ComponentMock;839 supplier1ComponentMock = new ComponentMock("Supplier Component 1");840841 ComponentMock supplier2ComponentMock;842 supplier2ComponentMock = new ComponentMock("Supplier Component 2");843844 ConnectorMock consumerMock;845 consumerMock =846 new ConnectorMock("Consumer 1", consumerComponentMock,847 ConnectorType.CONSUMER);848849 ConnectorMock supplierMock1;850 supplierMock1 =851 new ConnectorMock("Supplier 1", supplier1ComponentMock,852 ConnectorType.SUPPLIER);853854 ConnectorMock supplierMock2;855 supplierMock2 =856 new ConnectorMock("Supplier 2", supplier2ComponentMock,857 ConnectorType.SUPPLIER);858859 Contract contract;860 contract = this.createTestContract(TEST_CONTRACT_01);861862 ResourceManagerMock resourceManagerMock;863 resourceManagerMock = new ResourceManagerMock();864 ContractRegistry contractRegistry;865 contractRegistry =866 new ContractRegistry(resourceManagerMock, triggerRegistry);867868 /* Add the consumer contract. */869 try {870 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,871 consumerMock, Role.CONSUMER);872 }873874 catch (TreatyException e) {875 fail("Unexpected TreatyException: " + e.getMessage());876 }877 // end catch.878879 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,880 consumerComponentMock).size());881 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,882 supplier1ComponentMock).size());883 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,884 supplier2ComponentMock).size());885886 /* Add a supplier contract. */887 try {888 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,889 supplierMock1, Role.SUPPLIER);890 }891892 catch (TreatyException e) {893 fail("Unexpected TreatyException: " + e.getMessage());894 }895 // end catch.896897 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,898 consumerComponentMock).size());899 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,900 supplier1ComponentMock).size());901 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,902 supplier2ComponentMock).size());903904 /* Add a supplier contract. */905 try {906 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,907 supplierMock2, Role.SUPPLIER);908 }909910 catch (TreatyException e) {911 fail("Unexpected TreatyException: " + e.getMessage());912 }913 // end catch.914915 assertEquals(2, contractRegistry.getAffectedContracts(trigger1,916 consumerComponentMock).size());917 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,918 supplier1ComponentMock).size());919 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,920 supplier2ComponentMock).size());921 }922923 /**924 * <p>925 * Tests the method926 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}927 * .928 * </p>929 */930 @Test931 public void testGetAffectedContracts02() throws TreatyException {932933 ComponentMock consumer1ComponentMock;934 consumer1ComponentMock = new ComponentMock("Consumer Component 1");935936 ComponentMock consumer2ComponentMock;937 consumer2ComponentMock = new ComponentMock("Consumer Component 2");938939 ComponentMock supplier1ComponentMock;940 supplier1ComponentMock = new ComponentMock("Supplier Component 1");941942 ConnectorMock consumerMock1;943 consumerMock1 =944 new ConnectorMock("Consumer 1", consumer1ComponentMock,945 ConnectorType.CONSUMER);946947 ConnectorMock consumerMock2;948 consumerMock2 =949 new ConnectorMock("Consumer 2", consumer2ComponentMock,950 ConnectorType.CONSUMER);951952 ConnectorMock supplierMock1;953 supplierMock1 =954 new ConnectorMock("Supplier 1", supplier1ComponentMock,955 ConnectorType.SUPPLIER);956957 Contract contract;958 contract = this.createTestContract(TEST_CONTRACT_01);959960 ResourceManagerMock resourceManagerMock;961 resourceManagerMock = new ResourceManagerMock();962 ContractRegistry contractRegistry;963 contractRegistry =964 new ContractRegistry(resourceManagerMock, triggerRegistry);965966 /* Add the supplier contract. */967 try {968 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,969 supplierMock1, Role.SUPPLIER);970 }971972 catch (TreatyException e) {973 fail("Unexpected TreatyException: " + e.getMessage());974 }975 // end catch.976977 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,978 consumer1ComponentMock).size());979 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,980 supplier1ComponentMock).size());981 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,982 consumer2ComponentMock).size());983984 /* Add a consumer contract. */985 try {986 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,987 consumerMock1, Role.CONSUMER);988 }989990 catch (TreatyException e) {991 fail("Unexpected TreatyException: " + e.getMessage());992 }993 // end catch.994995 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,996 consumer1ComponentMock).size());997 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,998 supplier1ComponentMock).size());999 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1000 consumer2ComponentMock).size());10011002 /* Add a consumer contract. */1003 try {1004 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1005 consumerMock2, Role.CONSUMER);1006 }10071008 catch (TreatyException e) {1009 fail("Unexpected TreatyException: " + e.getMessage());1010 }1011 // end catch.10121013 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1014 consumer1ComponentMock).size());1015 assertEquals(2, contractRegistry.getAffectedContracts(trigger1,1016 supplier1ComponentMock).size());1017 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1018 consumer2ComponentMock).size());1019 }10201021 /**1022 * <p>1023 * Tests the method1024 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}1025 * .1026 * </p>1027 */1028 @Test1029 public void testGetAffectedContracts03() throws TreatyException {10301031 ComponentMock legislator1ComponentMock;1032 legislator1ComponentMock = new ComponentMock("Legislator Component 1");10331034 ComponentMock consumer1ComponentMock;1035 consumer1ComponentMock = new ComponentMock("Consumer Component 1");10361037 ComponentMock supplier1ComponentMock;1038 supplier1ComponentMock = new ComponentMock("Supplier Component 1");10391040 ComponentMock supplier2ComponentMock;1041 supplier2ComponentMock = new ComponentMock("Supplier Component 2");10421043 ConnectorMock legislator1Mock;1044 legislator1Mock =1045 new ConnectorMock("Legislator 1", legislator1ComponentMock,1046 ConnectorType.CONSUMER);10471048 ConnectorMock consumer1Mock;1049 consumer1Mock =1050 new ConnectorMock("Consumer 1", consumer1ComponentMock,1051 ConnectorType.CONSUMER);10521053 ConnectorMock supplierMock1;1054 supplierMock1 =1055 new ConnectorMock("Supplier 1", supplier1ComponentMock,1056 ConnectorType.SUPPLIER);10571058 ConnectorMock supplierMock2;1059 supplierMock2 =1060 new ConnectorMock("Supplier 2", supplier2ComponentMock,1061 ConnectorType.SUPPLIER);10621063 Contract contract;1064 contract = this.createTestContract(TEST_CONTRACT_01);10651066 ResourceManagerMock resourceManagerMock;1067 resourceManagerMock = new ResourceManagerMock();1068 ContractRegistry contractRegistry;1069 contractRegistry =1070 new ContractRegistry(resourceManagerMock, triggerRegistry);10711072 /* Add the legislator contract. */1073 try {1074 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1075 legislator1Mock, Role.LEGISLATOR);1076 }10771078 catch (TreatyException e) {1079 fail("Unexpected TreatyException: " + e.getMessage());1080 }1081 // end catch.10821083 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1084 legislator1ComponentMock).size());1085 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1086 consumer1ComponentMock).size());1087 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1088 supplier1ComponentMock).size());1089 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1090 supplier2ComponentMock).size());10911092 /* Add the consumer contract. */1093 try {1094 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1095 consumer1Mock, Role.CONSUMER);1096 }10971098 catch (TreatyException e) {1099 fail("Unexpected TreatyException: " + e.getMessage());1100 }1101 // end catch.11021103 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1104 legislator1ComponentMock).size());1105 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1106 consumer1ComponentMock).size());1107 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1108 supplier1ComponentMock).size());1109 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1110 supplier2ComponentMock).size());11111112 /* Add a supplier contract. */1113 try {1114 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry1115 .getContracts(consumer1Mock, Role.CONSUMER).iterator().next(),1116 supplierMock1, Role.SUPPLIER);1117 }11181119 catch (TreatyException e) {1120 fail("Unexpected TreatyException: " + e.getMessage());1121 }1122 // end catch.11231124 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1125 legislator1ComponentMock).size());1126 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1127 consumer1ComponentMock).size());1128 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1129 supplier1ComponentMock).size());1130 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1131 supplier2ComponentMock).size());11321133 /* Add a supplier contract. */1134 try {1135 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry1136 .getContracts(consumer1Mock, Role.CONSUMER).iterator().next(),1137 supplierMock2, Role.SUPPLIER);1138 }11391140 catch (TreatyException e) {1141 fail("Unexpected TreatyException: " + e.getMessage());1142 }1143 // end catch.11441145 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1146 legislator1ComponentMock).size());1147 assertEquals(2, contractRegistry.getAffectedContracts(trigger1,1148 consumer1ComponentMock).size());1149 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1150 supplier1ComponentMock).size());1151 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1152 supplier2ComponentMock).size());1153 }11541155 /**1156 * <p>1157 * Tests the method1158 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}1159 * .1160 * </p>1161 */1162 @Test1163 public void testGetAffectedContracts04() throws TreatyException {11641165 ComponentMock legislator1ComponentMock;1166 legislator1ComponentMock = new ComponentMock("Legislator Component 1");11671168 ComponentMock consumer1ComponentMock;1169 consumer1ComponentMock = new ComponentMock("Consumer Component 1");11701171 ComponentMock consumer2ComponentMock;1172 consumer2ComponentMock = new ComponentMock("Consumer Component 2");11731174 ComponentMock supplier1ComponentMock;1175 supplier1ComponentMock = new ComponentMock("Supplier Component 1");11761177 ConnectorMock legislator1Mock;1178 legislator1Mock =1179 new ConnectorMock("Legislator 1", legislator1ComponentMock,1180 ConnectorType.CONSUMER);11811182 ConnectorMock consumerMock1;1183 consumerMock1 =1184 new ConnectorMock("Consumer 1", consumer1ComponentMock,1185 ConnectorType.CONSUMER);11861187 ConnectorMock consumerMock2;1188 consumerMock2 =1189 new ConnectorMock("Consumer 2", consumer2ComponentMock,1190 ConnectorType.CONSUMER);11911192 ConnectorMock supplierMock1;1193 supplierMock1 =1194 new ConnectorMock("Supplier 1", supplier1ComponentMock,1195 ConnectorType.SUPPLIER);11961197 Contract contract;1198 contract = this.createTestContract(TEST_CONTRACT_01);11991200 ResourceManagerMock resourceManagerMock;1201 resourceManagerMock = new ResourceManagerMock();1202 ContractRegistry contractRegistry;1203 contractRegistry =1204 new ContractRegistry(resourceManagerMock, triggerRegistry);12051206 /* Add the legislator contract. */1207 try {1208 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1209 legislator1Mock, Role.LEGISLATOR);1210 }12111212 catch (TreatyException e) {1213 fail("Unexpected TreatyException: " + e.getMessage());1214 }1215 // end catch.12161217 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1218 legislator1ComponentMock).size());1219 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1220 supplier1ComponentMock).size());1221 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1222 consumer1ComponentMock).size());1223 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1224 consumer2ComponentMock).size());12251226 /* Add the supplier contract. */1227 try {1228 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1229 supplierMock1, Role.SUPPLIER);1230 }12311232 catch (TreatyException e) {1233 fail("Unexpected TreatyException: " + e.getMessage());1234 }1235 // end catch.12361237 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1238 legislator1ComponentMock).size());1239 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1240 supplier1ComponentMock).size());1241 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1242 consumer1ComponentMock).size());1243 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1244 consumer2ComponentMock).size());12451246 /* Add a consumer contract. */1247 try {1248 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry1249 .getContracts(supplierMock1, Role.SUPPLIER).iterator().next(),1250 consumerMock1, Role.CONSUMER);1251 }12521253 catch (TreatyException e) {1254 fail("Unexpected TreatyException: " + e.getMessage());1255 }1256 // end catch.12571258 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1259 legislator1ComponentMock).size());1260 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1261 supplier1ComponentMock).size());1262 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1263 consumer1ComponentMock).size());1264 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1265 consumer2ComponentMock).size());12661267 /* Add a consumer contract. */1268 try {1269 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry1270 .getContracts(supplierMock1, Role.SUPPLIER).iterator().next(),1271 consumerMock2, Role.CONSUMER);1272 }12731274 catch (TreatyException e) {1275 fail("Unexpected TreatyException: " + e.getMessage());1276 }1277 // end catch.12781279 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1280 legislator1ComponentMock).size());1281 assertEquals(2, contractRegistry.getAffectedContracts(trigger1,1282 supplier1ComponentMock).size());1283 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1284 consumer1ComponentMock).size());1285 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1286 consumer2ComponentMock).size());1287 }12881289 /**1290 * <p>1291 * Tests the method1292 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}1293 * .1294 * </p>1295 */1296 @Test1297 public void testGetAffectedContracts05() throws TreatyException {12981299 ComponentMock consumerComponentMock;1300 consumerComponentMock = new ComponentMock("Consumer Component 1");13011302 ComponentMock supplier1ComponentMock;1303 supplier1ComponentMock = new ComponentMock("Supplier Component 1");13041305 ComponentMock supplier2ComponentMock;1306 supplier2ComponentMock = new ComponentMock("Supplier Component 2");13071308 ConnectorMock consumerMock;1309 consumerMock =1310 new ConnectorMock("Consumer 1", consumerComponentMock,1311 ConnectorType.CONSUMER);13121313 ConnectorMock supplierMock1;1314 supplierMock1 =1315 new ConnectorMock("Supplier 1", supplier1ComponentMock,1316 ConnectorType.SUPPLIER);13171318 ConnectorMock supplierMock2;1319 supplierMock2 =1320 new ConnectorMock("Supplier 2", supplier2ComponentMock,1321 ConnectorType.SUPPLIER);13221323 Contract contract;1324 contract = this.createTestContract(TEST_CONTRACT_01);13251326 ResourceManagerMock resourceManagerMock;1327 resourceManagerMock = new ResourceManagerMock();1328 ContractRegistry contractRegistry;1329 contractRegistry =1330 new ContractRegistry(resourceManagerMock, triggerRegistry);13311332 /* Add the consumer contract. */1333 try {1334 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1335 consumerMock, Role.CONSUMER);1336 }13371338 catch (TreatyException e) {1339 fail("Unexpected TreatyException: " + e.getMessage());1340 }1341 // end catch.13421343 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1344 consumerComponentMock).size());1345 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1346 supplier1ComponentMock).size());1347 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1348 supplier2ComponentMock).size());1349 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1350 consumerComponentMock).size());1351 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1352 supplier1ComponentMock).size());1353 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1354 supplier2ComponentMock).size());13551356 /* Add a supplier contract. */1357 try {1358 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1359 supplierMock1, Role.SUPPLIER);1360 }13611362 catch (TreatyException e) {1363 fail("Unexpected TreatyException: " + e.getMessage());1364 }1365 // end catch.13661367 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1368 consumerComponentMock).size());1369 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1370 supplier1ComponentMock).size());1371 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1372 supplier2ComponentMock).size());1373 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1374 consumerComponentMock).size());1375 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1376 supplier1ComponentMock).size());1377 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1378 supplier2ComponentMock).size());13791380 /* Add a supplier contract. */1381 try {1382 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1383 supplierMock2, Role.SUPPLIER);1384 }13851386 catch (TreatyException e) {1387 fail("Unexpected TreatyException: " + e.getMessage());1388 }1389 // end catch.13901391 assertEquals(2, contractRegistry.getAffectedContracts(trigger1,1392 consumerComponentMock).size());1393 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1394 supplier1ComponentMock).size());1395 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1396 supplier2ComponentMock).size());1397 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1398 consumerComponentMock).size());1399 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1400 supplier1ComponentMock).size());1401 assertEquals(0, contractRegistry.getAffectedContracts(trigger2,1402 supplier2ComponentMock).size());1403 }14041405 /**1406 * <p>1407 * Tests the method1408 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}1409 * .1410 * </p>1411 * 1412 * <p>1413 * Tests the method using a trigger that is defined as default trigger and1414 * thus must not be defined in the {@link Contract}.1415 * </p>1416 */1417 @Test1418 public void testGetAffectedContracts06() throws TreatyException {14191420 ComponentMock consumerComponentMock;1421 consumerComponentMock = new ComponentMock("Consumer Component 1");14221423 ComponentMock supplier1ComponentMock;1424 supplier1ComponentMock = new ComponentMock("Supplier Component 1");14251426 ComponentMock supplier2ComponentMock;1427 supplier2ComponentMock = new ComponentMock("Supplier Component 2");14281429 ConnectorMock consumerMock;1430 consumerMock =1431 new ConnectorMock("Consumer 1", consumerComponentMock,1432 ConnectorType.CONSUMER);14331434 ConnectorMock supplierMock1;1435 supplierMock1 =1436 new ConnectorMock("Supplier 1", supplier1ComponentMock,1437 ConnectorType.SUPPLIER);14381439 ConnectorMock supplierMock2;1440 supplierMock2 =1441 new ConnectorMock("Supplier 2", supplier2ComponentMock,1442 ConnectorType.SUPPLIER);14431444 Contract contract;1445 contract = this.createTestContract(TEST_CONTRACT_01);14461447 ResourceManagerMock resourceManagerMock;1448 resourceManagerMock = new ResourceManagerMock();1449 ContractRegistry contractRegistry;1450 contractRegistry =1451 new ContractRegistry(resourceManagerMock, triggerRegistry);14521453 /* Add the consumer contract. */1454 try {1455 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1456 consumerMock, Role.CONSUMER);1457 }14581459 catch (TreatyException e) {1460 fail("Unexpected TreatyException: " + e.getMessage());1461 }1462 // end catch.14631464 assertEquals(0, contractRegistry.getAffectedContracts(defaultTrigger,1465 consumerComponentMock).size());1466 assertEquals(0, contractRegistry.getAffectedContracts(defaultTrigger,1467 supplier1ComponentMock).size());1468 assertEquals(0, contractRegistry.getAffectedContracts(defaultTrigger,1469 supplier2ComponentMock).size());14701471 /* Add a supplier contract. */1472 try {1473 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1474 supplierMock1, Role.SUPPLIER);1475 }14761477 catch (TreatyException e) {1478 fail("Unexpected TreatyException: " + e.getMessage());1479 }1480 // end catch.14811482 assertEquals(1, contractRegistry.getAffectedContracts(defaultTrigger,1483 consumerComponentMock).size());1484 assertEquals(1, contractRegistry.getAffectedContracts(defaultTrigger,1485 supplier1ComponentMock).size());1486 assertEquals(0, contractRegistry.getAffectedContracts(defaultTrigger,1487 supplier2ComponentMock).size());14881489 /* Add a supplier contract. */1490 try {1491 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1492 supplierMock2, Role.SUPPLIER);1493 }14941495 catch (TreatyException e) {1496 fail("Unexpected TreatyException: " + e.getMessage());1497 }1498 // end catch.14991500 assertEquals(2, contractRegistry.getAffectedContracts(defaultTrigger,1501 consumerComponentMock).size());1502 assertEquals(1, contractRegistry.getAffectedContracts(defaultTrigger,1503 supplier1ComponentMock).size());1504 assertEquals(1, contractRegistry.getAffectedContracts(defaultTrigger,1505 supplier2ComponentMock).size());1506 }15071508 /**1509 * <p>1510 * Tests the method1511 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}1512 * .1513 * </p>1514 * 1515 * <p>1516 * Tests the method using a trigger that is not defined in the1517 * {@link Contract} but has a super trigger that is defined in the1518 * {@link Contract}.1519 * </p>1520 */1521 @Test1522 public void testGetAffectedContracts07() throws TreatyException {15231524 ComponentMock consumerComponentMock;1525 consumerComponentMock = new ComponentMock("Consumer Component 1");15261527 ComponentMock supplier1ComponentMock;1528 supplier1ComponentMock = new ComponentMock("Supplier Component 1");15291530 ComponentMock supplier2ComponentMock;1531 supplier2ComponentMock = new ComponentMock("Supplier Component 2");15321533 ConnectorMock consumerMock;1534 consumerMock =1535 new ConnectorMock("Consumer 1", consumerComponentMock,1536 ConnectorType.CONSUMER);15371538 ConnectorMock supplierMock1;1539 supplierMock1 =1540 new ConnectorMock("Supplier 1", supplier1ComponentMock,1541 ConnectorType.SUPPLIER);15421543 ConnectorMock supplierMock2;1544 supplierMock2 =1545 new ConnectorMock("Supplier 2", supplier2ComponentMock,1546 ConnectorType.SUPPLIER);15471548 Contract contract;1549 contract = this.createTestContract(TEST_CONTRACT_02);15501551 ResourceManagerMock resourceManagerMock;1552 resourceManagerMock = new ResourceManagerMock();1553 ContractRegistry contractRegistry;1554 contractRegistry =1555 new ContractRegistry(resourceManagerMock, triggerRegistry);15561557 /* Add the consumer contract. */1558 try {1559 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1560 consumerMock, Role.CONSUMER);1561 }15621563 catch (TreatyException e) {1564 fail("Unexpected TreatyException: " + e.getMessage());1565 }1566 // end catch.15671568 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1569 consumerComponentMock).size());1570 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1571 supplier1ComponentMock).size());1572 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1573 supplier2ComponentMock).size());15741575 /* Add a supplier contract. */1576 try {1577 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1578 supplierMock1, Role.SUPPLIER);1579 }15801581 catch (TreatyException e) {1582 fail("Unexpected TreatyException: " + e.getMessage());1583 }1584 // end catch.15851586 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1587 consumerComponentMock).size());1588 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1589 supplier1ComponentMock).size());1590 assertEquals(0, contractRegistry.getAffectedContracts(trigger1,1591 supplier2ComponentMock).size());15921593 /* Add a supplier contract. */1594 try {1595 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1596 supplierMock2, Role.SUPPLIER);1597 }15981599 catch (TreatyException e) {1600 fail("Unexpected TreatyException: " + e.getMessage());1601 }1602 // end catch.16031604 assertEquals(2, contractRegistry.getAffectedContracts(trigger1,1605 consumerComponentMock).size());1606 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1607 supplier1ComponentMock).size());1608 assertEquals(1, contractRegistry.getAffectedContracts(trigger1,1609 supplier2ComponentMock).size());1610 }16111612 /**1613 * <p>1614 * Tests the method1615 * {@link ContractRegistry#getAffectedContracts(net.java.treaty.event.LifeCycleEvent)}1616 * .1617 * </p>1618 * 1619 * <p>1620 * Tests the method using a trigger that is not defined in the1621 * {@link Contract} but is a super trigger of the trigger that is defined in1622 * the {@link Contract}.1623 * </p>1624 */1625 @Test1626 public void testGetAffectedContracts08() throws TreatyException {16271628 ComponentMock consumerComponentMock;1629 consumerComponentMock = new ComponentMock("Consumer Component 1");16301631 ComponentMock supplier1ComponentMock;1632 supplier1ComponentMock = new ComponentMock("Supplier Component 1");16331634 ComponentMock supplier2ComponentMock;1635 supplier2ComponentMock = new ComponentMock("Supplier Component 2");16361637 ConnectorMock consumerMock;1638 consumerMock =1639 new ConnectorMock("Consumer 1", consumerComponentMock,1640 ConnectorType.CONSUMER);16411642 ConnectorMock supplierMock1;1643 supplierMock1 =1644 new ConnectorMock("Supplier 1", supplier1ComponentMock,1645 ConnectorType.SUPPLIER);16461647 ConnectorMock supplierMock2;1648 supplierMock2 =1649 new ConnectorMock("Supplier 2", supplier2ComponentMock,1650 ConnectorType.SUPPLIER);16511652 Contract contract;1653 contract = this.createTestContract(TEST_CONTRACT_01); ...

Full Screen

Full Screen

Source:ContractNegotiationIntegrationTest.java Github

copy

Full Screen

...259 consumerNegotiationId = null;260 // Create an initial contract offer and two counter offers261 ContractOffer initialOffer = getContractOffer();262 ContractOffer counterOffer = getCounterOffer();263 ContractOffer consumerCounterOffer = getConsumerCounterOffer();264 // Mock validation of initial offer on provider side => counter offer265 when(validationService.validate(token, initialOffer)).thenReturn(Result.success(null));266 //Mock validation of counter offer on consumer side => counter offer267 when(validationService.validate(token, counterOffer, initialOffer)).thenReturn(Result.success(null));268 //Mock validation of second counter offer on provider side => accept269 when(validationService.validate(token, consumerCounterOffer, counterOffer)).thenReturn(Result.success(null));270 // Mock validation of agreement on consumer side271 when(validationService.validate(eq(token), any(ContractAgreement.class),272 eq(consumerCounterOffer))).thenReturn(true);273 // Create and register listeners for provider and consumer274 providerObservable.registerListener(negotiationListenerMock);275 consumerObservable.registerListener(negotiationListenerMock);276 // Start provider and consumer negotiation managers277 providerManager.start();278 consumerManager.start();279 // Create an initial request and trigger consumer manager280 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()281 .connectorId("connectorId")282 .connectorAddress("connectorAddress")283 .contractOffer(initialOffer)284 .protocol("protocol")285 .build();286 consumerManager.initiate(request);287 // Wait for negotiation to finish with time out at 15 seconds288 await().atMost(DEFAULT_TEST_TIMEOUT)289 .pollInterval(DEFAULT_POLL_INTERVAL)290 .untilAsserted(() -> {291 var consumerNegotiation = consumerStore.find(consumerNegotiationId);292 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);293 // Assert that provider and consumer have the same number of offers stored294 assertNegotiations(consumerNegotiation, providerNegotiation, 3);295 // Assert that initial offer is the same296 assertThat(consumerNegotiation.getContractOffers().get(0)).isEqualTo(providerNegotiation.getContractOffers().get(0));297 // Assert that first counter offer is the same298 assertThat(consumerNegotiation.getContractOffers().get(1)).isEqualTo(providerNegotiation.getContractOffers().get(1));299 // Assert that second counter offer is the same300 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());301 // Assert that same agreement is stored on both sides302 assertThat(consumerNegotiation.getContractAgreement()).isNotNull();303 assertThat(consumerNegotiation.getContractAgreement()).isEqualTo(providerNegotiation.getContractAgreement());304 verify(validationService, atLeastOnce()).validate(token, initialOffer);305 verify(validationService, atLeastOnce()).validate(token, counterOffer, initialOffer);306 verify(validationService, atLeastOnce()).validate(token, consumerCounterOffer, counterOffer);307 verify(validationService, atLeastOnce()).validate(eq(token), any(ContractAgreement.class), eq(consumerCounterOffer));308 verify(negotiationListenerMock, times(2)).preConfirmed(any());309 });310 // Stop provider and consumer negotiation managers311 providerManager.stop();312 consumerManager.stop();313 }314 @Test315 @Disabled316 void testNegotiation_consumerCounterOfferDeclined() {317 consumerNegotiationId = null;318 // Create an initial contract offer and two counter offers319 ContractOffer initialOffer = getContractOffer();320 ContractOffer counterOffer = getCounterOffer();321 ContractOffer consumerCounterOffer = getConsumerCounterOffer();322 // Mock validation of initial offer on provider side => counter offer323 when(validationService.validate(token, initialOffer)).thenReturn(Result.success(null));324 //Mock validation of counter offer on consumer side => counter offer325 when(validationService.validate(token, counterOffer, initialOffer)).thenReturn(Result.success(null));326 //Mock validation of second counter offer on provider side => decline327 when(validationService.validate(token, consumerCounterOffer, counterOffer)).thenReturn(Result.success(null));328 // Create and register listeners for provider and consumer329 providerObservable.registerListener(negotiationListenerMock);330 consumerObservable.registerListener(negotiationListenerMock);331 // Start provider and consumer negotiation managers332 providerManager.start();333 consumerManager.start();334 // Create an initial request and trigger consumer manager335 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()...

Full Screen

Full Screen

Source:TriggeredVerifierTest.java Github

copy

Full Screen

1/*2 * Copyright (C) 2009 Jens Dietrich3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 * Unless required by applicable law or agreed to in writing, software distributed under the License 7 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 8 * See the License for the specific language governing permissions and limitations under the License. 9 */1011package test.net.java.treaty.trigger.verification;1213import static org.junit.Assert.assertFalse;14import static org.junit.Assert.assertNull;15import static org.junit.Assert.assertTrue;16import static org.junit.Assert.fail;1718import java.io.File;19import java.io.IOException;20import java.net.URI;21import java.net.URISyntaxException;22import java.net.URL;23import java.util.Set;2425import net.java.treaty.Component;26import net.java.treaty.Connector;27import net.java.treaty.ConnectorType;28import net.java.treaty.Contract;29import net.java.treaty.ContractReader;30import net.java.treaty.Role;31import net.java.treaty.TreatyException;32import net.java.treaty.contractregistry.ContractRegistry;33import net.java.treaty.contractregistry.ContractRegistry.UpdateType;34import net.java.treaty.trigger.AbstractTriggerVocabulary;35import net.java.treaty.trigger.TriggerRegistry;36import net.java.treaty.trigger.verification.AbstractTriggeredVerifier;37import net.java.treaty.trigger.verification.TriggeredVerifierListener;38import net.java.treaty.xml.XMLContractReader;3940import org.junit.Test;4142import test.net.java.treaty.contractregistry.VocabularyMock;43import test.net.java.treaty.mocks.ComponentMock;44import test.net.java.treaty.mocks.ConnectorMock;45import test.net.java.treaty.mocks.ResourceManagerMock;46import test.net.java.treaty.mocks.TriggerVocabularyMock;47import test.net.java.treaty.mocks.TriggeredVerifierMock;4849/**50 * <p>51 * Test cases to test the class {@link AbstractTriggeredVerifier}.52 * </p>53 * 54 * @author Claas Wilke55 */56public class TriggeredVerifierTest implements TriggeredVerifierListener {5758 /** The location of the {@link Contract} files used for testing. */59 private static final String TEST_CONTRACT_LOCATION =60 "tests/test/net/java/treaty/mocks/";6162 /** The name of a {@link Contract} file used for testing. */63 private static final String TEST_CONTRACT_1 =64 TEST_CONTRACT_LOCATION + "test04.contract";6566 /** The name of a {@link Contract} file used for testing. */67 private static final String TEST_CONTRACT_2 =68 TEST_CONTRACT_LOCATION + "test05.contract";6970 /** The name of a {@link Contract} file used for testing. */71 private static final String TEST_CONTRACT_3 =72 TEST_CONTRACT_LOCATION + "test06.contract";7374 /** The maximum loops to wait for a verification result. */75 private static final int WAIT_TOTAL_LOOPS = 20;7677 /** The time to wait in a loop. */78 private static final long WAIT_PAUSE_LENGTH = 50;7980 /** Contains the verification result used during testing. */81 private Boolean verificationResult;8283 /*84 * (non-Javadoc)85 * @see86 * net.java.treaty.event.verification.TriggeredVerifierListener#verificationFailed87 * (java.net.URI, net.java.treaty.Contract)88 */89 public void verificationFailed(URI triggerType, Contract contrac) {9091 this.verificationResult = false;92 }9394 /*95 * (non-Javadoc)96 * @seenet.java.treaty.event.verification.TriggeredVerifierListener#97 * verificationSucceeded(java.net.URI, net.java.treaty.Contract)98 */99 public void verificationSucceeded(URI triggerType, Contract contrac) {100101 this.verificationResult = true;102 }103104 /**105 * <p>106 * A test case testing the Triggered Verification of the107 * {@link AbstractTriggeredVerifier}.108 * </p>109 * 110 * @throws TreatyException111 * If thrown, the test case fails.112 * @throws URISyntaxException113 * If thrown, the test case fails.114 */115 @Test116 public void testVerification01() throws TreatyException, URISyntaxException {117118 /* Prepare test data. */119 TriggerRegistry triggerRegistry;120 triggerRegistry = new TriggerRegistry();121122 ContractRegistry contractRegistry;123 contractRegistry =124 new ContractRegistry(new ResourceManagerMock(), triggerRegistry);125126 Component consumerComponent;127 consumerComponent = new ComponentMock("consumercomponent");128129 Connector consumer;130 consumer =131 new ConnectorMock("consumercomponent.consumer", consumerComponent,132 ConnectorType.CONSUMER);133134 Component supplierComponent;135 supplierComponent = new ComponentMock("suppliercomponent");136137 Connector supplier;138 supplier =139 new ConnectorMock("suppliercomponent.supplier", supplierComponent,140 ConnectorType.SUPPLIER);141142 Contract contract;143 contract = this.createTestContract(TEST_CONTRACT_1);144145 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,146 consumer, Role.CONSUMER);147 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry148 .getContracts(consumer, Role.CONSUMER).iterator().next(), supplier,149 Role.SUPPLIER);150151 /* Create the verifier. */152 AbstractTriggeredVerifier triggeredVerifier;153 triggeredVerifier = new TriggeredVerifierMock();154155 /* Register as listener. */156 triggeredVerifier.addListener(this);157158 /* Reset the verification result. */159 this.verificationResult = null;160161 /* Trigger verification. */162 URI triggerType;163 triggerType = new URI(TriggerVocabularyMock.NAME_TRIGGER_1);164165 AbstractTriggerVocabulary triggerVocabulary;166 triggerVocabulary = new TriggerVocabularyMock();167 triggerVocabulary.addEventListener(triggeredVerifier);168 triggerRegistry.addTriggerVocabulary(triggerVocabulary);169170 Set<Contract> contracts;171 contracts =172 contractRegistry.getAffectedContracts(triggerType, consumerComponent);173174 triggerVocabulary.notifyEventListners(triggerType, contracts);175176 /* Wait for result. */177 int loops;178 loops = 0;179180 while (verificationResult == null) {181 /* Wait some time to improve CPU performance. */182 try {183 Thread.sleep(WAIT_PAUSE_LENGTH);184 }185186 catch (InterruptedException e) {187 fail("Cannot ensure that testcase behaves determinisitc. Test failed.");188 }189 // end catch.190191 loops++;192 if (loops > WAIT_TOTAL_LOOPS) {193 fail("Verification result was not available.");194 }195 // no else.196 }197198 /* Result should be positive. */199 assertTrue(this.verificationResult);200201 /* Unregister as listener. */202 triggeredVerifier.removeListener(this);203 }204205 /**206 * <p>207 * A test case testing the Triggered Verification of the208 * {@link AbstractTriggeredVerifier}.209 * </p>210 * 211 * @throws TreatyException212 * If thrown, the test case fails.213 * @throws URISyntaxException214 * If thrown, the test case fails.215 */216 @Test217 public void testVerification02() throws TreatyException, URISyntaxException {218219 /* Prepare test data. */220 TriggerRegistry triggerRegistry;221 triggerRegistry = new TriggerRegistry();222223 ContractRegistry contractRegistry;224 contractRegistry =225 new ContractRegistry(new ResourceManagerMock(), triggerRegistry);226227 Component consumerComponent;228 consumerComponent = new ComponentMock("consumercomponent");229230 Connector consumer;231 consumer =232 new ConnectorMock("consumercomponent.consumer", consumerComponent,233 ConnectorType.CONSUMER);234235 Component supplierComponent;236 supplierComponent = new ComponentMock("suppliercomponent");237238 Connector supplier;239 supplier =240 new ConnectorMock("suppliercomponent.supplier", supplierComponent,241 ConnectorType.SUPPLIER);242243 Contract contract;244 contract = this.createTestContract(TEST_CONTRACT_2);245246 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,247 consumer, Role.CONSUMER);248 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry249 .getContracts(consumer, Role.CONSUMER).iterator().next(), supplier,250 Role.SUPPLIER);251252 /* Create the verifier. */253 AbstractTriggeredVerifier triggeredVerifier;254 triggeredVerifier = new TriggeredVerifierMock();255256 /* Register as listener. */257 triggeredVerifier.addListener(this);258259 /* Reset the verification result. */260 this.verificationResult = null;261262 /* Trigger verification. */263 URI triggerType;264 triggerType = new URI(TriggerVocabularyMock.NAME_TRIGGER_2);265266 AbstractTriggerVocabulary triggerVocabulary;267 triggerVocabulary = new TriggerVocabularyMock();268 triggerVocabulary.addEventListener(triggeredVerifier);269 triggerRegistry.addTriggerVocabulary(triggerVocabulary);270271 Set<Contract> contracts;272 contracts =273 contractRegistry.getAffectedContracts(triggerType, consumerComponent);274275 triggerVocabulary.notifyEventListners(triggerType, contracts);276277 /* Wait for result. */278 int loops;279 loops = 0;280281 while (verificationResult == null) {282 /* Wait some time to improve CPU performance. */283 try {284 Thread.sleep(WAIT_PAUSE_LENGTH);285 }286287 catch (InterruptedException e) {288 fail("Cannot ensure that testcase behaves determinisitc. Test failed.");289 }290 // end catch.291292 loops++;293 if (loops > WAIT_TOTAL_LOOPS) {294 fail("Verification result was not available.");295 }296 // no else.297 }298299 /* Result should be negative. */300 assertFalse(this.verificationResult);301302 /* Unregister as listener. */303 triggeredVerifier.removeListener(this);304 }305306 /**307 * <p>308 * A test case testing the Triggered Verification of the309 * {@link AbstractTriggeredVerifier} with a super trigger defined in a310 * {@link Contract}.311 * </p>312 * 313 * @throws TreatyException314 * If thrown, the test case fails.315 * @throws URISyntaxException316 * If thrown, the test case fails.317 */318 @Test319 public void testVerification03() throws TreatyException, URISyntaxException {320321 /* Prepare test data. */322 TriggerRegistry triggerRegistry;323 triggerRegistry = new TriggerRegistry();324325 ContractRegistry contractRegistry;326 contractRegistry =327 new ContractRegistry(new ResourceManagerMock(), triggerRegistry);328329 Component consumerComponent;330 consumerComponent = new ComponentMock("consumercomponent");331332 Connector consumer;333 consumer =334 new ConnectorMock("consumercomponent.consumer", consumerComponent,335 ConnectorType.CONSUMER);336337 Component supplierComponent;338 supplierComponent = new ComponentMock("suppliercomponent");339340 Connector supplier;341 supplier =342 new ConnectorMock("suppliercomponent.supplier", supplierComponent,343 ConnectorType.SUPPLIER);344345 Contract contract;346 contract = this.createTestContract(TEST_CONTRACT_3);347348 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,349 consumer, Role.CONSUMER);350 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry351 .getContracts(consumer, Role.CONSUMER).iterator().next(), supplier,352 Role.SUPPLIER);353354 /* Create the verifier. */355 AbstractTriggeredVerifier triggeredVerifier;356 triggeredVerifier = new TriggeredVerifierMock();357358 /* Register as listener. */359 triggeredVerifier.addListener(this);360361 /* Reset the verification result. */362 this.verificationResult = null;363364 /* Trigger verification. */365 URI triggerType;366 triggerType = new URI(TriggerVocabularyMock.NAME_PARENT_TRIGGER_1);367368 AbstractTriggerVocabulary triggerVocabulary;369 triggerVocabulary = new TriggerVocabularyMock();370 triggerVocabulary.addEventListener(triggeredVerifier);371 triggerRegistry.addTriggerVocabulary(triggerVocabulary);372373 Set<Contract> contracts;374 contracts =375 contractRegistry.getAffectedContracts(triggerType, consumerComponent);376377 triggerVocabulary.notifyEventListners(triggerType, contracts);378379 /* Wait for result. */380 int loops;381 loops = 0;382383 while (verificationResult == null) {384 /* Wait some time to improve CPU performance. */385 try {386 Thread.sleep(WAIT_PAUSE_LENGTH);387 }388389 catch (InterruptedException e) {390 fail("Cannot ensure that testcase behaves determinisitc. Test failed.");391 }392 // end catch.393394 loops++;395 if (loops > WAIT_TOTAL_LOOPS) {396 fail("Verification result was not available.");397 }398 // no else.399 }400401 /* Result should be positive. */402 assertTrue(this.verificationResult);403404 /* Unregister as listener. */405 triggeredVerifier.removeListener(this);406 }407408 /**409 * <p>410 * A test case testing the Triggered Verification of the411 * {@link AbstractTriggeredVerifier} with a sub trigger of a super trigger412 * defined in a {@link Contract}.413 * </p>414 * 415 * @throws TreatyException416 * If thrown, the test case fails.417 * @throws URISyntaxException418 * If thrown, the test case fails.419 */420 @Test421 public void testVerification04() throws TreatyException, URISyntaxException {422423 /* Prepare test data. */424 TriggerRegistry triggerRegistry;425 triggerRegistry = new TriggerRegistry();426427 ContractRegistry contractRegistry;428 contractRegistry =429 new ContractRegistry(new ResourceManagerMock(), triggerRegistry);430431 Component consumerComponent;432 consumerComponent = new ComponentMock("consumercomponent");433434 Connector consumer;435 consumer =436 new ConnectorMock("consumercomponent.consumer", consumerComponent,437 ConnectorType.CONSUMER);438439 Component supplierComponent;440 supplierComponent = new ComponentMock("suppliercomponent");441442 Connector supplier;443 supplier =444 new ConnectorMock("suppliercomponent.supplier", supplierComponent,445 ConnectorType.SUPPLIER);446447 Contract contract;448 contract = this.createTestContract(TEST_CONTRACT_3);449450 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,451 consumer, Role.CONSUMER);452 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry453 .getContracts(consumer, Role.CONSUMER).iterator().next(), supplier,454 Role.SUPPLIER);455456 /* Create the verifier. */457 AbstractTriggeredVerifier triggeredVerifier;458 triggeredVerifier = new TriggeredVerifierMock();459460 /* Register as listener. */461 triggeredVerifier.addListener(this);462463 /* Reset the verification result. */464 this.verificationResult = null;465466 /* Should Trigger verification. */467 URI triggerType;468 triggerType = new URI(TriggerVocabularyMock.NAME_TRIGGER_1);469470 AbstractTriggerVocabulary triggerVocabulary;471 triggerVocabulary = new TriggerVocabularyMock();472 triggerVocabulary.addEventListener(triggeredVerifier);473 triggerRegistry.addTriggerVocabulary(triggerVocabulary);474475 Set<Contract> contracts;476 contracts =477 contractRegistry.getAffectedContracts(triggerType, consumerComponent);478479 triggerVocabulary.notifyEventListners(triggerType, contracts);480481 /* Wait for result. */482 int loops;483 loops = 0;484485 while (verificationResult == null) {486 /* Wait some time to improve CPU performance. */487 try {488 Thread.sleep(WAIT_PAUSE_LENGTH);489 }490491 catch (InterruptedException e) {492 fail("Cannot ensure that testcase behaves determinisitc. Test failed.");493 }494 // end catch.495496 loops++;497 if (loops > WAIT_TOTAL_LOOPS) {498 fail("Verification result was not available.");499 }500 // no else.501 }502503 /* Result should be positive. */504 assertTrue(this.verificationResult);505506 /* Unregister as listener. */507 triggeredVerifier.removeListener(this);508 }509510 /**511 * <p>512 * A test case testing the Triggered Verification of the513 * {@link AbstractTriggeredVerifier} with a trigger that is not a sub trigger514 * of a super trigger defined in a {@link Contract}.515 * </p>516 * 517 * @throws TreatyException518 * If thrown, the test case fails.519 * @throws URISyntaxException520 * If thrown, the test case fails.521 */522 @Test523 public void testVerification05() throws TreatyException, URISyntaxException {524525 /* Prepare test data. */526 TriggerRegistry triggerRegistry;527 triggerRegistry = new TriggerRegistry();528529 ContractRegistry contractRegistry;530 contractRegistry =531 new ContractRegistry(new ResourceManagerMock(), triggerRegistry);532533 Component consumerComponent;534 consumerComponent = new ComponentMock("consumercomponent");535536 Connector consumer;537 consumer =538 new ConnectorMock("consumercomponent.consumer", consumerComponent,539 ConnectorType.CONSUMER);540541 Component supplierComponent;542 supplierComponent = new ComponentMock("suppliercomponent");543544 Connector supplier;545 supplier =546 new ConnectorMock("suppliercomponent.supplier", supplierComponent,547 ConnectorType.SUPPLIER);548549 Contract contract;550 contract = this.createTestContract(TEST_CONTRACT_3);551552 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,553 consumer, Role.CONSUMER);554 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contractRegistry555 .getContracts(consumer, Role.CONSUMER).iterator().next(), supplier,556 Role.SUPPLIER);557558 /* Create the verifier. */559 AbstractTriggeredVerifier triggeredVerifier;560 triggeredVerifier = new TriggeredVerifierMock();561562 /* Register as listener. */563 triggeredVerifier.addListener(this);564565 /* Reset the verification result. */566 this.verificationResult = null;567568 /* Should not Trigger verification. */569 URI triggerType;570 triggerType = new URI(TriggerVocabularyMock.NAME_TRIGGER_2);571572 AbstractTriggerVocabulary triggerVocabulary;573 triggerVocabulary = new TriggerVocabularyMock();574 triggerVocabulary.addEventListener(triggeredVerifier);575 triggerRegistry.addTriggerVocabulary(triggerVocabulary);576577 Set<Contract> contracts;578 contracts =579 contractRegistry.getAffectedContracts(triggerType, consumerComponent);580581 triggerVocabulary.notifyEventListners(triggerType, contracts);582583 /* Wait for result. */584 int loops;585 loops = 0;586587 while (verificationResult == null) {588 /* Wait some time to improve CPU performance. */589 try {590 Thread.sleep(WAIT_PAUSE_LENGTH);591 }592593 catch (InterruptedException e) {594 fail("Cannot ensure that testcase behaves determinisitc. Test failed.");595 }596 // end catch.597598 loops++;599 if (loops > WAIT_TOTAL_LOOPS) {600 break;601 }602 // no else.603 }604605 /* Result should be null. */606 assertNull(this.verificationResult);607608 /* Unregister as listener. */609 triggeredVerifier.removeListener(this);610 }611612 /**613 * <p>614 * A helper method that initializes a simple {@link Contract} used during615 * testing.616 * </p>617 * 618 * @param The619 * name of the {@link Contract} file that shall be created.620 * @return A simple {@link Contract} used during testing.621 */622 private Contract createTestContract(String fileName) {623624 Contract result;625 result = null;626627 URL location;628 location = null;629630 /* Try to read the contract. */631 try {632 File file;633 file = new File(fileName);634635 location = file.toURI().toURL();636637 ContractReader reader;638 reader = new XMLContractReader();639640 result = reader.read(location.openStream(), VocabularyMock.INSTANCE);641 result.setLocation(location);642 }643644 catch (TreatyException e) {645 fail("Exception loading contract from " + location + ":" + e.getMessage());646 }647648 catch (IOException e) {649 fail("Exception loading contract from " + location + ":" + e.getMessage());650 }651652 return result;653 } ...

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.function.Consumer;3public class ConsumerExample {4 public static void main(String[] args) {5 Consumer<Integer> display = a -> System.out.println(a);6 display.accept(10);7 }8}9package mock.contract;10import java.util.function.Consumer;11public class ConsumerExample {12 public static void main(String[] args) {13 Consumer<Integer> modify = a -> System.out.println(a * 2);14 modify.accept(10);15 }16}17package mock.contract;18import java.util.function.Consumer;19public class ConsumerExample {20 public static void main(String[] args) {21 Consumer<Integer> display = a -> System.out.println(a);22 Consumer<Integer> modify = a -> System.out.println(a * 2);23 display.andThen(modify).accept(10);24 }25}26package mock.contract;27import java.util.function.Consumer;28public class ConsumerExample {29 public static void main(String[] args) {30 Consumer<Integer> display = a -> System.out.println(a);31 Consumer<Integer> modify = a -> System.out.println(a * 2);32 display.andThen(modify).accept(10);33 }34}35package mock.contract;36import java.util.function.Consumer;37public class ConsumerExample {38 public static void main(String[] args) {

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.function.Consumer;3public class ConsumerDemo {4 public static void main(String[] args) {5 Consumer<String> consumer = s -> System.out.println(s);6 consumer.accept("Hello");7 }8}

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.function.Consumer;3public class ConsumerMethod {4 public static void main(String[] args) {5 Consumer<String> c = s -> System.out.println(s);6 c.accept("Hello");7 }8}9package mock.contract;10import java.util.function.Predicate;11public class PredicateMethod {12 public static void main(String[] args) {13 Predicate<Integer> p = i -> i%2==0;14 System.out.println(p.test(10));15 }16}17package mock.contract;18import java.util.function.Function;19public class FunctionMethod {20 public static void main(String[] args) {21 Function<Integer, Integer> f = i -> i*i;22 System.out.println(f.apply(10));23 }24}25package mock.contract;26import java.util.function.Supplier;27public class SupplierMethod {28 public static void main(String[] args) {29 Supplier<String> s = () -> "Hello";30 System.out.println(s.get());31 }32}33package mock.contract;34import java.util.function.UnaryOperator;35public class UnaryOperatorMethod {36 public static void main(String[] args) {37 UnaryOperator<Integer> u = i -> i*i;38 System.out.println(u.apply(10));39 }40}41package mock.contract;42import java.util.function.BinaryOperator;43public class BinaryOperatorMethod {44 public static void main(String[] args) {45 BinaryOperator<Integer> b = (i,j) -> i+j;46 System.out.println(b.apply(10,20));47 }48}49package mock.contract;50import java.util.function.BiConsumer;51public class BiConsumerMethod {52 public static void main(String[] args) {53 BiConsumer<Integer,Integer> b = (i,j) -> System.out.println(i+j);54 b.accept(10,20);55 }56}

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1import mock.contract.Consumer;2public class 4 {3public static void main(String[] args) {4Consumer consumer = new Consumer();5consumer.accept("Hello");6}7}8package mock.contract;9public class Consumer {10public void accept(String message) {11System.out.println(message);12}13}

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.function.Consumer;3public class ConsumerDemo {4public static void main(String[] args) {5Consumer<String> c = s -> System.out.println(s);6c.accept("Hello");7}8}9package mock.contract;10import java.util.function.Supplier;11public class SupplierDemo {12public static void main(String[] args) {13Supplier<String> s = () -> "Hello";14System.out.println(s.get());15}16}17package mock.contract;18import java.util.function.Predicate;19public class PredicateDemo {20public static void main(String[] args) {21Predicate<String> p = s -> s.length() > 5;22System.out.println(p.test("Hello"));23}24}25package mock.contract;26import java.util.function.Function;27public class FunctionDemo {28public static void main(String[] args) {29Function<String, Integer> f = s -> s.length();30System.out.println(f.apply("Hello"));31}32}33package mock.contract;34import java.util.function.BiConsumer;35public class BiConsumerDemo {36public static void main(String[] args) {37BiConsumer<String, Integer> b = (s, i) -> System.out.println(s + i);38b.accept("Hello", 5);39}40}41package mock.contract;42import java.util.function.BiFunction;43public class BiFunctionDemo {44public static void main(String[] args) {45BiFunction<String, Integer, String> b = (s, i) -> s + i;46System.out.println(b.apply("Hello", 5));47}48}49package mock.contract;50import java.util.function.BiPredicate;51public class BiPredicateDemo {52public static void main(String[] args) {53BiPredicate<String, String> b = (s1, s2) -> s1.equals(s2);

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.function.Consumer;3public class ConsumerDemo {4public static void main(String[] args) {5Consumer<Integer> c = i -> System.out.println(i);6c.accept(10);7}8}9package mock.contract;10import java.util.function.Supplier;11public class SupplierDemo {12public static void main(String[] args) {13Supplier<Integer> s = () -> 10;14System.out.println(s.get());15}16}17package mock.contract;18import java.util.function.Predicate;19public class PredicateDemo {20public static void main(String[] args) {21Predicate<Integer> p = i -> i > 10;22System.out.println(p.test(20));23}24}25package mock.contract;26import java.util.function.Function;27public class FunctionDemo {28public static void main(String[] args) {29Function<Integer, Integer> f = i -> i * i;30System.out.println(f.apply(10));31}32}33package mock.contract;34import java.util.function.BiConsumer;35public class BiConsumerDemo {36public static void main(String[] args) {37BiConsumer<Integer, Integer> bc = (i, j) -> System.out.println(i + j);38bc.accept(10, 20);39}40}41package mock.contract;42import java.util.function.BiFunction;43public class BiFunctionDemo {44public static void main(String[] args) {45BiFunction<Integer, Integer, Integer> bf = (i, j) -> i + j;46System.out.println(bf.apply(10, 20));47}48}49package mock.contract;50import java.util.function.BiPredicate;51public class BiPredicateDemo {52public static void main(String[] args) {53BiPredicate<Integer, Integer> bp = (i, j) -> i > j;54System.out.println(bp.test(10

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.function.Consumer;3public class ConsumerDemo {4 public static void main(String[] args) {5 Consumer<String> c = s -> System.out.println(s);6 Producer p = new Producer();7 p.produce(c);8 }9}10package mock.contract;11import java.util.function.Consumer;12public class ConsumerDemo {13 public static void main(String[] args) {14 Consumer<String> c = s -> System.out.println(s);15 Producer p = new Producer();16 p.produce(c);17 }18}19package mock.contract;20import java.util.function.Consumer;21public class ConsumerDemo {22 public static void main(String[] args) {23 Consumer<String> c = s -> System.out.println(s);24 Producer p = new Producer();25 p.produce(c);26 }27}28package mock.contract;29import java.util.function.Consumer;30public class ConsumerDemo {31 public static void main(String[] args) {32 Consumer<String> c = s -> System.out.println(s);33 Producer p = new Producer();34 p.produce(c);35 }36}

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1public class Consumer {2 public static void main(String[] args) {3 MockContract mockContract = MockContract.load("0x123", web3j, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);4 mockContract.consume("0x123").send();5 }6}7public class Consumer {8 public static void main(String[] args) {9 MockContract mockContract = MockContract.load("0x123", web3j, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT);10 mockContract.consume("0x123").send();11 }12}13public class Deployer {14 public static void main(String[] args) throws Exception {15 Credentials credentials = WalletUtils.loadCredentials("<your-wallet-password>", "<your-wallet-file-path>");16 MockContract contract = MockContract.deploy(web3j, credentials, ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT).send();17 System.out.println("Contract Address: " + contract.getContractAddress());18 }19}20public class Consumer {21 public static void main(String[] args) throws Exception {

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1import java.util.function.Consumer;2import mock.contract.Consumer;3public class 4 {4public static void main(String[] args) {5Consumer c = new Consumer();6c.accept("Hello");7}8}9Mockito library provides a lot of methods to mock classes and interfaces. The Mockito.mock() method is used to mock a class or an interface. The Mockito.when() method is used to define the behavior of the mock object. The Mockito.verify() method is used to verify the behavior of the mock object. The Mockito.inOrder() method is used to verify the order of the method calls. The Mockito.times() method is used to verify the number of times a method is called. The Mockito.any() method is used to verify the method arguments. The Mockito.spy() method is used to spy on the real objects. The Mockito.doReturn() method is used to define the behavior of the spy object. The Mockito.doThrow() method is used to define the behavior of the spy object. The Mockito.doNothing() method is used to define the behavior of the spy object. The Mockito.doAnswer() method is used to define the behavior of the spy object. The Mockito.doCallRealMethod() method is used to define the behavior of the spy object. The Mockito.doNothing().when() method is used to define the behavior of the spy object. The Mockito.doThrow().when() method is used to define the behavior of the spy object. The Mockito.doAnswer().when() method is used to define the behavior of the spy object. The Mockito.doReturn().when() method is used to define the behavior of the spy object. The Mockito.doCallRealMethod().when() method is used to define the behavior of the spy object. The Mockito.reset() method is used to reset the mock object. The Mockito.never() method is used to verify the behavior of the mock object. The Mockito.times() method is used to verify the behavior of the mock object. The Mockito.atLeastOnce() method is used to verify the behavior of the mock object. The Mockito.atLeast() method is used to verify the behavior of the mock object. The Mockito.atMost() method is used to verify the behavior of the mock object. The Mockito.only() method is used to verify the behavior of the mock object. The Mockito.timeout() method is used to verify the behavior of the mock object. The Mockito.after() method is used to verify the behavior of the mock object. The Mockito.in

Full Screen

Full Screen

Consumer

Using AI Code Generation

copy

Full Screen

1import mock.contract.Consumer;2import mock.contract.Provider;3import mock.contract.ProviderFactory;4import mock.provider.ProviderImpl;5import java.util.function.Consumer;6import java.util.function.Supplier;7public class ConsumerTest {8 public static void main(String[] args) {9 ProviderFactory factory = ProviderImpl::new;10 Provider provider = factory.create();11 Consumer<String> consumer = provider.getConsumer();12 consumer.accept("Hello World");13 }14}15import mock.contract.Provider;16import mock.contract.ProviderFactory;17import mock.provider.ProviderImpl;18import java.util.function.Consumer;19import java.util.function.Supplier;20public class SupplierTest {21 public static void main(String[] args) {22 ProviderFactory factory = ProviderImpl::new;23 Provider provider = factory.create();24 Supplier<String> supplier = provider.getSupplier();25 String value = supplier.get();26 System.out.println(value);27 }28}29import mock.contract.Consumer;30import mock.contract.Provider;31import mock.contract.ProviderFactory;32import mock.provider.ProviderImpl;33import java.util.function.Consumer;34import java.util.function.Supplier;35public class BiConsumerTest {36 public static void main(String[] args) {37 ProviderFactory factory = ProviderImpl::new;38 Provider provider = factory.create();39 Consumer<String, String> consumer = provider.getBiConsumer();40 consumer.accept("Hello", "World");41 }42}43import mock.contract.Provider;44import mock.contract.ProviderFactory;45import mock.provider.ProviderImpl;46import java.util.function.Consumer;47import java.util.function.Supplier;48public class BiFunctionTest {49 public static void main(String[] args) {50 ProviderFactory factory = ProviderImpl::new;51 Provider provider = factory.create();52 BiFunction<String, String, String> biFunction = provider.getBiFunction();53 String value = biFunction.apply("Hello", "World");54 System.out.println(value);55 }56}57import mock.contract.Provider;58import mock.contract.ProviderFactory;59import mock.provider.ProviderImpl;60import java

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Karate automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful