Best Karate code snippet using mock.contract.Consumer
Source:ContractRegistryTests.java
...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);
...
Source:TriggeredVerifierTest.java
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 }
...
Source:ContractListenerTest.java
...10import java.security.cert.CertificateException;11import java.util.Arrays;12import java.util.Collections;13import java.util.List;14import java.util.function.Consumer;15import java.util.regex.Pattern;16import java.util.stream.Collectors;17import org.bouncycastle.operator.OperatorCreationException;18import org.hyperledger.fabric.gateway.Contract;19import org.hyperledger.fabric.gateway.ContractEvent;20import org.hyperledger.fabric.gateway.Gateway;21import org.hyperledger.fabric.gateway.GatewayException;22import org.hyperledger.fabric.gateway.Network;23import org.hyperledger.fabric.gateway.TestUtils;24import org.hyperledger.fabric.gateway.impl.event.StubBlockEventSource;25import org.hyperledger.fabric.gateway.spi.Checkpointer;26import org.hyperledger.fabric.sdk.BlockEvent;27import org.hyperledger.fabric.sdk.BlockInfo;28import org.hyperledger.fabric.sdk.ChaincodeEvent;29import org.hyperledger.fabric.sdk.Peer;30import org.junit.jupiter.api.AfterEach;31import org.junit.jupiter.api.BeforeEach;32import org.junit.jupiter.api.Test;33import static org.assertj.core.api.Assertions.assertThat;34import static org.mockito.Mockito.any;35import static org.mockito.Mockito.mock;36import static org.mockito.Mockito.never;37import static org.mockito.Mockito.spy;38import static org.mockito.Mockito.times;39import static org.mockito.Mockito.verify;40import static org.mockito.Mockito.when;41public class ContractListenerTest {42 private static final TestUtils testUtils = TestUtils.getInstance();43 private Gateway gateway;44 private StubBlockEventSource blockSource;45 private Contract contract;46 private int transactionNumber = 1;47 private final String chaincodeId = "chaincodeId";48 private final String eventName = "eventName";49 private final Pattern eventNamePattern = Pattern.compile(Pattern.quote(eventName) + ".*");50 private final Consumer<ContractEvent> selfRemovingListener = new Consumer<ContractEvent>() {51 @Override52 public void accept(ContractEvent event) {53 contract.removeContractListener(this);54 }55 };56 @BeforeEach57 public void beforeEach() throws GatewayException, OperatorCreationException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, IOException {58 blockSource = new StubBlockEventSource(); // Must be created before network59 gateway = testUtils.newGatewayBuilder().connect();60 Network network = gateway.getNetwork("ch1");61 contract = network.getContract(chaincodeId);62 }63 @AfterEach64 public void afterEach() {65 blockSource.close();66 gateway.close();67 }68 private ChaincodeEvent mockChaincodeEvent(String chaincodeId, String name) {69 ChaincodeEvent result = mock(ChaincodeEvent.class);70 when(result.getChaincodeId()).thenReturn(chaincodeId);71 when(result.getEventName()).thenReturn(name);72 return result;73 }74 private void fireEvents(ChaincodeEvent... chaincodeEvents) {75 BlockEvent event = newBlockEvent(1, chaincodeEvents);76 blockSource.sendEvent(event);77 }78 /**79 * Create a block event containing each of the supplied chaincode events attached to a separate transaction within80 * the block.81 * @param blockNumber A block number.82 * @param chaincodeEvents Events to include in the block.83 * @return The block event that was fired.84 */85 private BlockEvent newBlockEvent(long blockNumber, ChaincodeEvent... chaincodeEvents) {86 Peer peer = testUtils.newMockPeer("peer1");87 List<BlockEvent.TransactionEvent> transactionEvents = Arrays.stream(chaincodeEvents)88 .map(chaincodeEvent -> {89 BlockInfo.TransactionEnvelopeInfo.TransactionActionInfo actionInfo = mock(BlockInfo.TransactionEnvelopeInfo.TransactionActionInfo.class);90 when(actionInfo.getEvent()).thenReturn(chaincodeEvent);91 return actionInfo;92 })93 .map(Collections::singletonList)94 .map(actionInfos -> {95 BlockEvent.TransactionEvent transactionEvent = testUtils.newValidMockTransactionEvent(peer, nextTransactionId());96 when(transactionEvent.getTransactionActionInfos()).thenReturn(actionInfos);97 return transactionEvent;98 })99 .collect(Collectors.toList());100 return testUtils.newMockBlockEvent(peer, blockNumber, transactionEvents);101 }102 private String nextTransactionId() {103 return "tx" + transactionNumber++;104 }105 @Test106 public void add_listener_returns_the_listener() {107 Consumer<ContractEvent> listener = event -> {};108 Consumer<ContractEvent> result = contract.addContractListener(listener);109 assertThat(result).isSameAs(listener);110 }111 @Test112 public void add_name_listener_returns_the_listener() {113 Consumer<ContractEvent> listener = event -> {};114 Consumer<ContractEvent> result = contract.addContractListener(listener, eventName);115 assertThat(result).isSameAs(listener);116 }117 @Test118 public void add_pattern_listener_returns_the_listener() {119 Consumer<ContractEvent> listener = event -> {};120 Consumer<ContractEvent> result = contract.addContractListener(listener, eventNamePattern);121 assertThat(result).isSameAs(listener);122 }123 @Test124 public void listener_receives_matching_events() {125 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());126 ChaincodeEvent event1 = mockChaincodeEvent(chaincodeId, eventName + 1);127 ChaincodeEvent event2 = mockChaincodeEvent(chaincodeId, eventName + 2);128 contract.addContractListener(listener, eventNamePattern);129 fireEvents(event1, event2);130 verify(listener, times(2)).accept(any(ContractEvent.class));131 }132 @Test133 public void listener_without_matcher_receives_all_events() {134 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());135 ChaincodeEvent event1 = mockChaincodeEvent(chaincodeId, eventName + 1);136 ChaincodeEvent event2 = mockChaincodeEvent(chaincodeId, eventName + 2);137 contract.addContractListener(listener);138 fireEvents(event1, event2);139 verify(listener, times(2)).accept(any(ContractEvent.class));140 }141 @Test142 public void listener_receives_events_with_specific_name() {143 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());144 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, eventName);145 contract.addContractListener(listener, eventName);146 fireEvents(event);147 verify(listener).accept(any(ContractEvent.class));148 }149 @Test150 public void null_events_are_ignored() {151 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());152 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, eventName);153 contract.addContractListener(listener);154 fireEvents(event, null);155 verify(listener, times(1)).accept(any(ContractEvent.class));156 }157 @Test158 public void listener_does_not_receive_event_names_not_matching_pattern() {159 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());160 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);161 contract.addContractListener(listener, eventNamePattern);162 fireEvents(event);163 verify(listener, never()).accept(any(ContractEvent.class));164 }165 @Test166 public void listener_does_not_receive_events_without_specific_name() {167 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());168 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);169 contract.addContractListener(listener, eventName);170 fireEvents(event);171 verify(listener, never()).accept(any(ContractEvent.class));172 }173 @Test174 public void listener_does_not_receive_events_from_other_contracts() {175 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());176 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);177 contract.addContractListener(listener, eventNamePattern);178 fireEvents(event);179 verify(listener, never()).accept(any(ContractEvent.class));180 }181 @Test182 public void listener_does_not_receive_events_from_uncommitted_transactions() {183 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());184 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, eventName);185 BlockEvent blockEvent = newBlockEvent(1, event);186 for (BlockEvent.TransactionEvent transactionEvent : blockEvent.getTransactionEvents()) {187 when(transactionEvent.isValid()).thenReturn(false);188 }189 contract.addContractListener(listener);190 blockSource.sendEvent(blockEvent);191 verify(listener, never()).accept(any(ContractEvent.class));192 }193 @Test194 public void removed_listener_does_not_receive_events() {195 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());196 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, eventName);197 contract.addContractListener(listener, eventNamePattern);198 contract.removeContractListener(listener);199 fireEvents(event);200 verify(listener, never()).accept(any(ContractEvent.class));201 }202 @Test203 public void listener_can_unregister_during_event_handling() {204 Consumer<ContractEvent> listener = spy(selfRemovingListener);205 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, eventName);206 contract.addContractListener(listener);207 fireEvents(event);208 fireEvents(event);209 verify(listener, times(1)).accept(any(ContractEvent.class));210 }211 @Test212 public void add_checkpoint_listener_returns_the_listener() throws IOException {213 Consumer<ContractEvent> listener = event -> {};214 Checkpointer checkpointer = new InMemoryCheckpointer();215 Consumer<ContractEvent> result = contract.addContractListener(checkpointer, listener);216 assertThat(result).isSameAs(listener);217 }218 @Test219 public void add_checkpoint_listener_with_event_name_returns_the_listener() throws IOException {220 Consumer<ContractEvent> listener = event -> {};221 Checkpointer checkpointer = new InMemoryCheckpointer();222 Consumer<ContractEvent> result = contract.addContractListener(checkpointer, listener, eventName);223 assertThat(result).isSameAs(listener);224 }225 @Test226 public void add_checkpoint_listener_with_event_pattern_returns_the_listener() throws IOException {227 Consumer<ContractEvent> listener = event -> {};228 Checkpointer checkpointer = new InMemoryCheckpointer();229 Consumer<ContractEvent> result = contract.addContractListener(checkpointer, listener, eventNamePattern);230 assertThat(result).isSameAs(listener);231 }232 @Test233 public void listener_with_new_checkpointer_receives_all_events() throws IOException {234 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());235 Checkpointer checkpointer = new InMemoryCheckpointer();236 ChaincodeEvent chaincodeEvent1 = mockChaincodeEvent(chaincodeId, eventName + 1);237 ChaincodeEvent chaincodeEvent2 = mockChaincodeEvent(chaincodeId, eventName + 2);238 BlockEvent blockEvent = newBlockEvent(1, chaincodeEvent1, chaincodeEvent2);239 contract.addContractListener(checkpointer, listener);240 blockSource.sendEvent(blockEvent);241 verify(listener, times(2)).accept(any(ContractEvent.class));242 }243 @Test244 public void listener_with_saved_checkpointer_resumes_from_previous_event() throws IOException {245 Consumer<ContractEvent> realtimeListener = event -> {};246 Consumer<ContractEvent> replayListener = spy(testUtils.stubContractListener());247 Checkpointer checkpointer = new InMemoryCheckpointer();248 ChaincodeEvent chaincodeEvent = mockChaincodeEvent(chaincodeId, eventName);249 BlockEvent blockEvent1 = newBlockEvent(1, chaincodeEvent);250 BlockEvent blockEvent2 = newBlockEvent(2, chaincodeEvent);251 contract.addContractListener(checkpointer, realtimeListener);252 blockSource.sendEvent(blockEvent1);253 contract.removeContractListener(realtimeListener);254 blockSource.sendEvent(blockEvent2);255 contract.addContractListener(checkpointer, replayListener);256 blockSource.sendEvent(blockEvent2); // Normally would be ignored as a duplicate block257 verify(replayListener, times(1)).accept(any(ContractEvent.class));258 }259 @Test260 public void listener_with_new_checkpointer_only_receives_events_with_specific_name() throws IOException {261 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());262 Checkpointer checkpointer = new InMemoryCheckpointer();263 ChaincodeEvent badEvent = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);264 ChaincodeEvent goodEvent = mockChaincodeEvent(chaincodeId, eventName);265 BlockEvent blockEvent = newBlockEvent(1, badEvent, goodEvent);266 contract.addContractListener(checkpointer, listener, eventName);267 blockSource.sendEvent(blockEvent);268 verify(listener, times(1)).accept(any(ContractEvent.class));269 }270 @Test271 public void listener_with_new_checkpointer_only_receives_events_matching_a_pattern() throws IOException {272 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());273 Checkpointer checkpointer = new InMemoryCheckpointer();274 ChaincodeEvent badEvent = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);275 ChaincodeEvent goodEvent1 = mockChaincodeEvent(chaincodeId, eventName + 1);276 ChaincodeEvent goodEvent2 = mockChaincodeEvent(chaincodeId, eventName + 2);277 BlockEvent blockEvent = newBlockEvent(1, badEvent, goodEvent1, goodEvent2);278 contract.addContractListener(checkpointer, listener, eventNamePattern);279 blockSource.sendEvent(blockEvent);280 verify(listener, times(2)).accept(any(ContractEvent.class));281 }282 @Test283 public void add_replay_listener_returns_the_listener() {284 Consumer<ContractEvent> listener = event -> {};285 Consumer<ContractEvent> result = contract.addContractListener(1, listener);286 assertThat(result).isSameAs(listener);287 }288 @Test289 public void add_replay_listener_with_event_name_returns_the_listener() {290 Consumer<ContractEvent> listener = event -> {};291 Consumer<ContractEvent> result = contract.addContractListener(1, listener, eventName);292 assertThat(result).isSameAs(listener);293 }294 @Test295 public void add_replay_listener_with_event_pattern_returns_the_listener() {296 Consumer<ContractEvent> listener = event -> {};297 Consumer<ContractEvent> result = contract.addContractListener(1, listener, eventNamePattern);298 assertThat(result).isSameAs(listener);299 }300 @Test301 public void replay_listener_receives_events_from_start_block() {302 Consumer<ContractEvent> replayListener = spy(testUtils.stubContractListener());303 ChaincodeEvent chaincodeEvent = mockChaincodeEvent(chaincodeId, eventName);304 BlockEvent blockEvent1 = newBlockEvent(1, chaincodeEvent);305 BlockEvent blockEvent2 = newBlockEvent(2, chaincodeEvent);306 contract.addContractListener(testUtils.stubContractListener());307 blockSource.sendEvent(blockEvent2); // Non-replay listeners will now only receive later blocks308 contract.addContractListener(2, replayListener);309 blockSource.sendEvent(blockEvent1); // Should be ignored310 blockSource.sendEvent(blockEvent2); // Should be received311 verify(replayListener, times(1)).accept(any(ContractEvent.class));312 }313 @Test314 public void replay_listener_with_event_name_receives_events_from_start_block() {315 Consumer<ContractEvent> replayListener = spy(testUtils.stubContractListener());316 ChaincodeEvent goodEvent = mockChaincodeEvent(chaincodeId, eventName);317 ChaincodeEvent badEvent = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);318 BlockEvent blockEvent1 = newBlockEvent(1, goodEvent);319 BlockEvent blockEvent2 = newBlockEvent(2, goodEvent);320 BlockEvent blockEvent3 = newBlockEvent(3, badEvent);321 contract.addContractListener(testUtils.stubContractListener());322 blockSource.sendEvent(blockEvent2); // Non-replay listeners will now only receive later blocks323 contract.addContractListener(2, replayListener, eventName);324 blockSource.sendEvent(blockEvent1); // Should be ignored325 blockSource.sendEvent(blockEvent2); // Should be received326 blockSource.sendEvent(blockEvent3); // Should be ignored327 verify(replayListener, times(1)).accept(any(ContractEvent.class));328 }329 @Test330 public void replay_listener_with_event_pattern_receives_events_from_start_block() {331 Consumer<ContractEvent> replayListener = spy(testUtils.stubContractListener());332 ChaincodeEvent goodEvent = mockChaincodeEvent(chaincodeId, eventName);333 ChaincodeEvent badEvent = mockChaincodeEvent(chaincodeId, "BAD_" + eventName);334 BlockEvent blockEvent1 = newBlockEvent(1, goodEvent);335 BlockEvent blockEvent2 = newBlockEvent(2, goodEvent);336 BlockEvent blockEvent3 = newBlockEvent(3, badEvent);337 contract.addContractListener(testUtils.stubContractListener());338 blockSource.sendEvent(blockEvent2); // Non-replay listeners will now only receive later blocks339 contract.addContractListener(2, replayListener, eventNamePattern);340 blockSource.sendEvent(blockEvent1); // Should be ignored341 blockSource.sendEvent(blockEvent2); // Should be received342 blockSource.sendEvent(blockEvent3); // Should be ignored343 verify(replayListener, times(1)).accept(any(ContractEvent.class));344 }345 @Test346 public void close_contract_removes_listeners() {347 Consumer<ContractEvent> listener = spy(testUtils.stubContractListener());348 ChaincodeEvent event = mockChaincodeEvent(chaincodeId, eventName);349 contract.addContractListener(listener);350 ((ContractImpl)contract).close();351 fireEvents(event);352 verify(listener, never()).accept(any(ContractEvent.class));353 }354}...
Consumer
Using AI Code Generation
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 c.accept("Hello World");7 }8}9package java.util.function;10import java.util.function.Consumer;11public class ConsumerDemo {12 public static void main(String[] args) {13 Consumer<String> c = s -> System.out.println(s);14 c.accept("Hello World");15 }16}17package java.util.function;18import java.util.function.Consumer;19public class ConsumerDemo {20 public static void main(String[] args) {21 Consumer<String> c = s -> System.out.println(s);22 c.accept("Hello World");23 }24}25package java.util.function;26import java.util.function.Consumer;27public class ConsumerDemo {28 public static void main(String[] args) {29 Consumer<String> c = s -> System.out.println(s);30 c.accept("Hello World");31 }32}33package java.util.function;34import java.util.function.Consumer;35public class ConsumerDemo {36 public static void main(String[] args) {37 Consumer<String> c = s -> System.out.println(s);38 c.accept("Hello World");39 }40}41package java.util.function;42import java.util.function.Consumer;43public class ConsumerDemo {44 public static void main(String[] args) {45 Consumer<String> c = s -> System.out.println(s);46 c.accept("Hello World");47 }48}49package java.util.function;50import java
Consumer
Using AI Code Generation
1import mock.contract.*;2public class 4 {3 public static void main(String[] args) {4 Consumer c = new Consumer();5 c.consume();6 }7}8import mock.contract.*;9public class 5 {10 public static void main(String[] args) {11 Consumer c = new Consumer();12 c.consume();13 }14}15import mock.contract.*;16public class 6 {17 public static void main(String[] args) {18 Consumer c = new Consumer();19 c.consume();20 }21}22import mock.contract.*;23public class 7 {24 public static void main(String[] args) {25 Consumer c = new Consumer();26 c.consume();27 }28}29import mock.contract.*;30public class 8 {31 public static void main(String[] args) {32 Consumer c = new Consumer();33 c.consume();34 }35}36import mock.contract.*;37public class 9 {38 public static void main(String[] args) {39 Consumer c = new Consumer();40 c.consume();41 }42}43import mock.contract.*;44public class 10 {45 public static void main(String[] args) {46 Consumer c = new Consumer();47 c.consume();48 }49}50import mock.contract.*;51public class 11 {52 public static void main(String[] args) {53 Consumer c = new Consumer();54 c.consume();55 }56}57import mock.contract.*;58public class 12 {59 public static void main(String[] args) {60 Consumer c = new Consumer();61 c.consume();62 }63}64import mock.contract.*;65public class 13 {66 public static void main(String[] args) {67 Consumer c = new Consumer();68 c.consume();69 }70}
Consumer
Using AI Code Generation
1import mock.contract.*;2public class 4 {3 public static void main(String[] args) {4 Consumer c = new Consumer();5 c.doSomething();6 }7}8import mock.contract.*;9public class 5 {10 public static void main(String[] args) {11 Provider p = new Provider();12 p.doSomething();13 }14}15import mock.contract.*;16public class 6 {17 public static void main(String[] args) {18 Consumer c = new Consumer();19 c.doSomething();20 }21}22import mock.contract.*;23public class 7 {24 public static void main(String[] args) {25 Consumer c = new Consumer();26 c.doSomething();27 }28}29import mock.contract.*;30public class 8 {31 public static void main(String[] args) {32 Consumer c = new Consumer();33 c.doSomething();34 }35}36import mock.contract.*;37public class 9 {38 public static void main(String[] args) {39 Consumer c = new Consumer();40 c.doSomething();41 }42}43import mock.contract.*;44public class 10 {45 public static void main(String[] args) {46 Consumer c = new Consumer();47 c.doSomething();48 }49}50import mock.contract.*;51public class 11 {52 public static void main(String[] args) {53 Consumer c = new Consumer();54 c.doSomething();55 }56}57import mock.contract.*;58public class 12 {59 public static void main(String[] args) {60 Consumer c = new Consumer();61 c.doSomething();62 }63}64import mock.contract.*;65public class 13 {66 public static void main(String[] args) {67 Consumer c = new Consumer();
Consumer
Using AI Code Generation
1import mock.contract.*;2import java.util.function.*;3public class 4{4public static void main(String[] args){5Consumer<String> c = s -> System.out.println(s);6c.accept("Hello");7}8}9import mock.contract.*;10import java.util.function.*;11public class 5{12public static void main(String[] args){13Supplier<String> s = () -> "Hello";14System.out.println(s.get());15}16}17import mock.contract.*;18import java.util.function.*;19public class 6{20public static void main(String[] args){21Predicate<String> p = s -> s.length() > 5;22System.out.println(p.test("Hello"));23}24}25import mock.contract.*;26import java.util.function.*;27public class 7{28public static void main(String[] args){29Function<String, Integer> f = s -> s.length();30System.out.println(f.apply("Hello"));31}32}33import mock.contract.*;34import java.util.function.*;35public class 8{36public static void main(String[] args){37UnaryOperator<String> u = s -> s.toUpperCase();38System.out.println(u.apply("Hello"));39}40}41import mock.contract.*;42import java.util.function.*;43public class 9{44public static void main(String[] args){45BinaryOperator<Integer> b = (a, b) -> a + b;46System.out.println(b.apply(2, 3));47}48}49import mock.contract.*;50import java.util.function.*;51public class 10{52public static void main(String[] args){53BiConsumer<String, String> b = (s1, s2) -> System.out.println(s1 + s2);54b.accept("Hello", "World");55}56}57import mock.contract.*;58import java.util.function.*;59public class 11{60public static void main(String[] args){61BiFunction<String, String, String> b = (s1, s2) -> s1 + s2;
Consumer
Using AI Code Generation
1package mock.contract;2import java.util.function.Consumer;3public class ConsumerTest {4public static void main(String[] args) {5Consumer<Integer> c = i -> System.out.println(i);6c.accept(100);7}8}9package mock.contract;10import java.util.function.Supplier;11public class SupplierTest {12public static void main(String[] args) {13Supplier<Integer> s = () -> (int) (Math.random() * 10);14System.out.println(s.get());15}16}17package mock.contract;18import java.util.function.Predicate;19public class PredicateTest {20public static void main(String[] args) {21Predicate<Integer> p = i -> i % 2 == 0;22System.out.println(p.test(10));23}24}25package mock.contract;26import java.util.function.Function;27public class FunctionTest {28public static void main(String[] args) {29Function<Integer, Integer> f = i -> i * i;30System.out.println(f.apply(5));31}32}33package mock.contract;34import java.util.function.BiConsumer;35public class BiConsumerTest {36public static void main(String[] args) {37BiConsumer<Integer, Integer> b = (i, j) -> System.out.println(i + j);38b.accept(10, 20);39}40}41package mock.contract;42import java.util.function.BiFunction;43public class BiFunctionTest {44public static void main(String[] args) {45BiFunction<Integer, Integer, Integer> b = (i, j) -> i * j;46System.out.println(b.apply(10, 20));47}48}49package mock.contract;50import java.util.function.BiPredicate;51public class BiPredicateTest {52public static void main(String[] args) {53BiPredicate<Integer, Integer> b = (i, j) -> (i + j) % 2 == 0;54System.out.println(b.test(10, 20));55}56}
Consumer
Using AI Code Generation
1import mock.contract.Consumer;2import mock.contract.Producer;3public class ConsumerImpl implements Consumer {4 public void consume(Producer producer) {5 System.out.println(producer.produce());6 }7}8import mock.contract.Consumer;9import mock.contract.Producer;10public class ConsumerImpl implements Consumer {11 public void consume(Producer producer) {12 System.out.println(producer.produce());13 }14}15import mock.contract.Consumer;16import mock.contract.Producer;17public class ConsumerImpl implements Consumer {18 public void consume(Producer producer) {19 System.out.println(producer.produce());20 }21}22import mock.contract.Consumer;23import mock.contract.Producer;24public class ConsumerImpl implements Consumer {25 public void consume(Producer producer) {26 System.out.println(producer.produce());27 }28}29import mock.contract.Consumer;30import mock.contract.Producer;31public class ConsumerImpl implements Consumer {32 public void consume(Producer producer) {33 System.out.println(producer.produce());34 }35}36import mock.contract.Consumer;37import mock.contract.Producer;38public class ConsumerImpl implements Consumer {39 public void consume(Producer producer) {40 System.out.println(producer.produce());41 }42}43import mock.contract.Consumer;44import mock.contract.Producer;45public class ConsumerImpl implements Consumer {46 public void consume(Producer producer) {47 System.out.println(producer.produce());48 }49}50import mock.contract.Consumer;51import mock.contract.Producer;52public class ConsumerImpl implements Consumer {53 public void consume(Producer producer) {54 System.out.println(producer.produce());55 }56}57import mock.contract.Consumer;58import mock.contract.Producer;59public class ConsumerImpl implements Consumer {60 public void consume(Producer producer) {61 System.out.println(producer.produce());62 }63}
Consumer
Using AI Code Generation
1import mock.contract.*;2import java.util.*;3import java.io.*;4class 4 {5 public static void main(String args[]) throws IOException {6 Consumer c = new Consumer();7 c.consume();8 }9}10package mock.contract;11import java.util.*;12import java.io.*;13public class Consumer {14 public void consume() throws IOException {15 Scanner sc = new Scanner(System.in);16 String fileName = sc.nextLine();17 System.out.println(fileName);18 File f = new File(fileName);19 BufferedReader br = new BufferedReader(new FileReader(f));20 String line;21 while ((line = br.readLine()) != null) {22 System.out.println(line);23 }24 }25}26import java.util.*;27import java.io.*;28import mock.contract.*;29import java.util.*;30import java.io.*;31class 1 {32 public static void main(String args[]) throws IOException {33 Consumer c = new Consumer();34 c.consume();35 }36}37package mock.contract;38import java.util.*;39import java.io.*;40public class Consumer {41 public void consume() throws IOException {42 Scanner sc = new Scanner(System.in);43 String fileName = sc.nextLine();44 System.out.println(fileName);45 File f = new File(fileName);46 BufferedReader br = new BufferedReader(new FileReader(f));47 String line;48 while ((line = br.readLine()) != null) {49 System.out.println(line);50 }51 }52}53import java.util.*;54import java.io.*;55import mock.contract.*;56import java.util.*;57import java.io.*;58class 2 {59 public static void main(String args[]) throws IOException {60 Consumer c = new Consumer();61 c.consume();62 }63}64package mock.contract;65import java.util.*;66import java.io.*;67public class Consumer {68 public void consume() throws IOException {69 Scanner sc = new Scanner(System.in);70 String fileName = sc.nextLine();71 System.out.println(fileName);72 File f = new File(fileName);73 BufferedReader br = new BufferedReader(new FileReader(f));74 String line;75 while ((line = br.readLine()) != null) {76 System.out.println(line);
Consumer
Using AI Code Generation
1import mock.contract.*;2import java.util.*;3import java.io.*;4import javax.xml.namespace.QName;5import javax.xml.rpc.Service;6import javax.xml.rpc.ServiceFactory;7import javax.xml.rpc.Call;8import javax.xml.rpc.ParameterMode;9import javax.xml.rpc.encoding.XMLType;10import javax.xml.rpc.encoding.SerializerFactory;11import javax.xml.rpc.encoding.Serializer;12import javax.xml.rpc.encoding.SerializerFactory;13import javax.xml.rpc.encoding.Seri
Consumer
Using AI Code Generation
1import mock.contract.*;2class Consumer {3public static void main(String[] args) {4MyInterface myInterface = new MyInterfaceImpl();5myInterface.myMethod();6}7}8In the above code, we have created the object of the class which implements the interface. Then, we are calling the myMethod() method of the interface. The output of the above code is:
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!