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

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

Source:ContractRegistryTests.java Github

copy

Full Screen

...122 legistlatorMock =123 new ConnectorMock("Legislator 1", componentMock, ConnectorType.CONSUMER);124125 Contract contract;126 contract = this.createTestContract(TEST_CONTRACT_01);127128 ResourceManagerMock resourceManagerMock;129 resourceManagerMock = new ResourceManagerMock();130 ContractRegistry contractRegistry;131 contractRegistry =132 new ContractRegistry(resourceManagerMock, triggerRegistry);133134 /* Add the contract. */135 try {136 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,137 legistlatorMock, Role.LEGISLATOR);138 }139140 catch (TreatyException e) {141 fail("Unexpected TreatyException: " + e.getMessage());142 }143 // end catch.144145 /* The registry should know the contract. */146 assertTrue(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)147 .contains(contract));148 /* The contract should have constraints. */149 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.LEGISLATOR)150 .iterator().next().getConstraints().isEmpty());151 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.CONSUMER)152 .contains(contract));153 assertFalse(contractRegistry.getContracts(legistlatorMock, Role.SUPPLIER)154 .contains(contract));155156 /* The legislator should be set as owner of the contract. */157 assertNotNull(contract.getOwner());158 assertEquals(legistlatorMock, contract.getOwner());159160 /* Remove the contract. */161 try {162 contractRegistry.updateContract(UpdateType.REMOVE_CONTRACT, contract,163 legistlatorMock, Role.LEGISLATOR);164 }165166 catch (TreatyException e) {167 fail("Unexpected TreatyException: " + e.getMessage());168 }169 // end catch.170171 assertEquals(0, contractRegistry.getContracts(legistlatorMock,172 Role.LEGISLATOR).size());173 assertEquals(0, contractRegistry.getContracts(legistlatorMock,174 Role.CONSUMER).size());175 assertEquals(0, contractRegistry.getContracts(legistlatorMock,176 Role.SUPPLIER).size());177 }178179 /**180 * <p>181 * Tests the method182 * {@link ContractRegistry#updateContract(net.java.treaty.contractregistry.ContractRegistry.UpdateType, net.java.treaty.Contract, net.java.treaty.Connector, net.java.treaty.Role)}183 * by adding and removing a {@link Role#CONSUMER} {@link Contract} to the184 * {@link ContractRegistry}.185 * </p>186 */187 @Test188 public void testUpdateRegistry02() {189190 ComponentMock componentMock;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);16541655 ResourceManagerMock resourceManagerMock;1656 resourceManagerMock = new ResourceManagerMock();1657 ContractRegistry contractRegistry;1658 contractRegistry =1659 new ContractRegistry(resourceManagerMock, triggerRegistry);16601661 /* Add the consumer contract. */1662 try {1663 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1664 consumerMock, Role.CONSUMER);1665 }16661667 catch (TreatyException e) {1668 fail("Unexpected TreatyException: " + e.getMessage());1669 }1670 // end catch.16711672 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1673 consumerComponentMock).size());1674 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1675 supplier1ComponentMock).size());1676 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1677 supplier2ComponentMock).size());16781679 /* Add a supplier contract. */1680 try {1681 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1682 supplierMock1, Role.SUPPLIER);1683 }16841685 catch (TreatyException e) {1686 fail("Unexpected TreatyException: " + e.getMessage());1687 }1688 // end catch.16891690 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1691 consumerComponentMock).size());1692 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1693 supplier1ComponentMock).size());1694 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1695 supplier2ComponentMock).size());16961697 /* Add a supplier contract. */1698 try {1699 contractRegistry.updateContract(UpdateType.ADD_CONTRACT, contract,1700 supplierMock2, Role.SUPPLIER);1701 }17021703 catch (TreatyException e) {1704 fail("Unexpected TreatyException: " + e.getMessage());1705 }1706 // end catch.17071708 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1709 consumerComponentMock).size());1710 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1711 supplier1ComponentMock).size());1712 assertEquals(0, contractRegistry.getAffectedContracts(parentTrigger1,1713 supplier2ComponentMock).size());1714 }17151716 /**1717 * <p>1718 * A helper method that initializes a simple {@link Contract} used during1719 * testing.1720 * </p>1721 * 1722 * @param fileName1723 * The file Name of the {@link Contract} that shall be created.1724 * @return A simple {@link Contract} used during testing.1725 */1726 private Contract createTestContract(String fileName) {17271728 Contract result;1729 result = null;17301731 URL location;1732 location = null;17331734 /* Try to read the contract. */1735 try {1736 File file;1737 file = new File(fileName);17381739 location = file.toURI().toURL();1740 ...

Full Screen

Full Screen

Source:ContractNegotiationIntegrationTest.java Github

copy

Full Screen

1/*2 * Copyright (c) 2021 Fraunhofer Institute for Software and Systems Engineering3 *4 * This program and the accompanying materials are made available under the5 * terms of the Apache License, Version 2.0 which is available at6 * https://www.apache.org/licenses/LICENSE-2.07 *8 * SPDX-License-Identifier: Apache-2.09 *10 * Contributors:11 * Fraunhofer Institute for Software and Systems Engineering - initial API and implementation12 * Microsoft Corporation - introduced Awaitility13 *14 */15package org.eclipse.dataspaceconnector.contract.negotiation;16import org.eclipse.dataspaceconnector.common.util.junit.annotations.ComponentTest;17import org.eclipse.dataspaceconnector.spi.contract.negotiation.observe.ContractNegotiationListener;18import org.eclipse.dataspaceconnector.spi.result.Result;19import org.eclipse.dataspaceconnector.spi.types.domain.contract.agreement.ContractAgreement;20import org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiation;21import org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractOfferRequest;22import org.eclipse.dataspaceconnector.spi.types.domain.contract.offer.ContractOffer;23import org.junit.jupiter.api.Disabled;24import org.junit.jupiter.api.Test;25import java.time.Duration;26import static org.assertj.core.api.Assertions.assertThat;27import static org.awaitility.Awaitility.await;28import static org.eclipse.dataspaceconnector.spi.types.domain.contract.negotiation.ContractNegotiationStates.CONFIRMED;29import static org.mockito.ArgumentMatchers.any;30import static org.mockito.ArgumentMatchers.eq;31import static org.mockito.Mockito.atLeastOnce;32import static org.mockito.Mockito.mock;33import static org.mockito.Mockito.times;34import static org.mockito.Mockito.verify;35import static org.mockito.Mockito.when;36@ComponentTest37class ContractNegotiationIntegrationTest extends AbstractContractNegotiationIntegrationTest {38 private static final Duration DEFAULT_TEST_TIMEOUT = Duration.ofSeconds(15);39 private static final Duration DEFAULT_POLL_INTERVAL = Duration.ofMillis(100);40 private final ContractNegotiationListener negotiationListenerMock = mock(ContractNegotiationListener.class);41 @Test42 void testNegotiation_initialOfferAccepted() {43 consumerNegotiationId = null;44 ContractOffer offer = getContractOffer();45 when(validationService.validate(token, offer)).thenReturn(Result.success(offer));46 when(validationService.validate(eq(token), any(ContractAgreement.class),47 any(ContractOffer.class))).thenReturn(true);48 // Create and register listeners for provider and consumer49 providerObservable.registerListener(negotiationListenerMock);50 consumerObservable.registerListener(negotiationListenerMock);51 // Start provider and consumer negotiation managers52 providerManager.start();53 consumerManager.start();54 // Create an initial request and trigger consumer manager55 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()56 .connectorId("connectorId")57 .connectorAddress("connectorAddress")58 .contractOffer(offer)59 .protocol("protocol")60 .build();61 consumerManager.initiate(request);62 await().atMost(DEFAULT_TEST_TIMEOUT)63 .pollInterval(DEFAULT_POLL_INTERVAL)64 .untilAsserted(() -> {65 assertThat(consumerNegotiationId).isNotNull();66 var consumerNegotiation = consumerStore.find(consumerNegotiationId);67 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);68 // Assert that provider and consumer have the same offers and agreement stored69 assertNegotiations(consumerNegotiation, providerNegotiation, 1);70 assertThat(consumerNegotiation.getState()).isEqualTo(CONFIRMED.code());71 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());72 assertThat(consumerNegotiation.getContractAgreement()).isEqualTo(providerNegotiation.getContractAgreement());73 // verify that the preConfirmed event has occurred twice - once for cons. once for prov74 verify(negotiationListenerMock, times(2)).preConfirmed(any());75 verify(validationService, atLeastOnce()).validate(token, offer);76 verify(validationService, atLeastOnce()).validate(eq(token), any(ContractAgreement.class), any(ContractOffer.class));77 });78 // Stop provider and consumer negotiation managers79 providerManager.stop();80 consumerManager.stop();81 }82 @Test83 void testNegotiation_initialOfferDeclined() {84 consumerNegotiationId = null;85 ContractOffer offer = getContractOffer();86 when(validationService.validate(token, offer)).thenReturn(Result.success(offer));87 // Create and register listeners for provider and consumer88 providerObservable.registerListener(negotiationListenerMock);89 consumerObservable.registerListener(negotiationListenerMock);90 // Start provider and consumer negotiation managers91 providerManager.start();92 consumerManager.start();93 // Create an initial request and trigger consumer manager94 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()95 .connectorId("connectorId")96 .connectorAddress("connectorAddress")97 .contractOffer(offer)98 .protocol("protocol")99 .build();100 consumerManager.initiate(request);101 await().atMost(DEFAULT_TEST_TIMEOUT)102 .pollInterval(DEFAULT_POLL_INTERVAL)103 .untilAsserted(() -> {104 assertThat(consumerNegotiationId).isNotNull();105 var consumerNegotiation = consumerStore.find(consumerNegotiationId);106 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);107 // Assert that provider and consumer have the same offers stored108 assertNegotiations(consumerNegotiation, providerNegotiation, 1);109 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());110 // verify that the preConfirmed event has occurred twice - once for cons. once for prov111 verify(negotiationListenerMock, times(2)).preDeclined(any());112 // Assert that no agreement has been stored on either side113 assertThat(consumerNegotiation.getContractAgreement()).isNull();114 assertThat(providerNegotiation.getContractAgreement()).isNull();115 verify(validationService, atLeastOnce()).validate(token, offer);116 });117 // Stop provider and consumer negotiation managers118 providerManager.stop();119 consumerManager.stop();120 }121 @Test122 void testNegotiation_agreementDeclined() {123 consumerNegotiationId = null;124 var offer = getContractOffer();125 when(validationService.validate(token, offer)).thenReturn(Result.success(offer));126 when(validationService.validate(eq(token), any(ContractAgreement.class),127 any(ContractOffer.class))).thenReturn(false);128 // Create and register listeners for provider and consumer129 providerObservable.registerListener(negotiationListenerMock);130 consumerObservable.registerListener(negotiationListenerMock);131 // Start provider and consumer negotiation managers132 providerManager.start();133 consumerManager.start();134 // Create an initial request and trigger consumer manager135 var request = ContractOfferRequest.Builder.newInstance()136 .connectorId("connectorId")137 .connectorAddress("connectorAddress")138 .contractOffer(offer)139 .protocol("protocol")140 .build();141 consumerManager.initiate(request);142 await().atMost(DEFAULT_TEST_TIMEOUT)143 .pollInterval(DEFAULT_POLL_INTERVAL)144 .untilAsserted(() -> {145 assertThat(consumerNegotiationId).isNotNull();146 var consumerNegotiation = consumerStore.find(consumerNegotiationId);147 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);148 // Assert that provider and consumer have the same offers stored149 assertNegotiations(consumerNegotiation, providerNegotiation, 1);150 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());151 // Assert that no agreement has been stored on either side152 assertThat(consumerNegotiation.getContractAgreement()).isNull();153 assertThat(providerNegotiation.getContractAgreement()).isNull();154 // verify that the preConfirmed event has occurred twice - once for cons. once for prov155 verify(negotiationListenerMock, times(2)).preDeclined(any());156 verify(validationService, atLeastOnce()).validate(token, offer);157 verify(validationService, atLeastOnce()).validate(eq(token), any(ContractAgreement.class), any(ContractOffer.class));158 });159 // Stop provider and consumer negotiation managers160 providerManager.stop();161 consumerManager.stop();162 }163 @Test164 @Disabled165 void testNegotiation_counterOfferAccepted() {166 consumerNegotiationId = null;167 ContractOffer initialOffer = getContractOffer();168 ContractOffer counterOffer = getCounterOffer();169 when(validationService.validate(token, initialOffer)).thenReturn(Result.success(null));170 when(validationService.validate(token, counterOffer, initialOffer)).thenReturn(Result.success(null));171 when(validationService.validate(eq(token), any(ContractAgreement.class),172 eq(counterOffer))).thenReturn(true);173 // Create and register listeners for provider and consumer174 providerObservable.registerListener(negotiationListenerMock);175 consumerObservable.registerListener(negotiationListenerMock);176 // Start provider and consumer negotiation managers177 providerManager.start();178 consumerManager.start();179 // Create an initial request and trigger consumer manager180 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()181 .connectorId("connectorId")182 .connectorAddress("connectorAddress")183 .contractOffer(initialOffer)184 .protocol("protocol")185 .build();186 consumerManager.initiate(request);187 await().atMost(DEFAULT_TEST_TIMEOUT)188 .pollInterval(DEFAULT_POLL_INTERVAL)189 .untilAsserted(() -> {190 var consumerNegotiation = consumerStore.find(consumerNegotiationId);191 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);192 // Assert that provider and consumer have the same number of offers stored193 assertNegotiations(consumerNegotiation, providerNegotiation, 2);194 // Assert that initial offer is the same195 assertThat(consumerNegotiation.getContractOffers().get(0)).isEqualTo(providerNegotiation.getContractOffers().get(0));196 // Assert that counter offer is the same197 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());198 // Assert that same agreement is stored on both sides199 assertThat(consumerNegotiation.getContractAgreement()).isNotNull();200 assertThat(consumerNegotiation.getContractAgreement()).isEqualTo(providerNegotiation.getContractAgreement());201 verify(validationService, atLeastOnce()).validate(token, initialOffer);202 verify(validationService, atLeastOnce()).validate(token, counterOffer, initialOffer);203 verify(validationService, atLeastOnce()).validate(eq(token), any(ContractAgreement.class), any(ContractOffer.class));204 verify(negotiationListenerMock, times(2)).preConfirmed(any());205 });206 // Stop provider and consumer negotiation managers207 providerManager.stop();208 consumerManager.stop();209 }210 @Test211 @Disabled212 void testNegotiation_counterOfferDeclined() {213 consumerNegotiationId = null;214 ContractOffer initialOffer = getContractOffer();215 ContractOffer counterOffer = getCounterOffer();216 when(validationService.validate(token, initialOffer)).thenReturn(Result.success(null));217 when(validationService.validate(token, counterOffer, initialOffer)).thenReturn(Result.success(null));218 // Create and register listeners for provider and consumer219 providerObservable.registerListener(negotiationListenerMock);220 consumerObservable.registerListener(negotiationListenerMock);221 // Start provider and consumer negotiation managers222 providerManager.start();223 consumerManager.start();224 // Create an initial request and trigger consumer manager225 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()226 .connectorId("connectorId")227 .connectorAddress("connectorAddress")228 .contractOffer(initialOffer)229 .protocol("protocol")230 .build();231 consumerManager.initiate(request);232 // Wait for negotiation to finish with time out at 15 seconds233 await().atMost(DEFAULT_TEST_TIMEOUT)234 .pollInterval(DEFAULT_POLL_INTERVAL)235 .untilAsserted(() -> {236 var consumerNegotiation = consumerStore.find(consumerNegotiationId);237 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);238 // Assert that provider and consumer have the same number of offers stored239 assertNegotiations(consumerNegotiation, providerNegotiation, 2);240 // Assert that initial offer is the same241 assertThat(consumerNegotiation.getContractOffers().get(0)).isEqualTo(providerNegotiation.getContractOffers().get(0));242 // Assert that counter offer is the same243 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());244 // Assert that no agreement has been stored on either side245 assertThat(consumerNegotiation.getContractAgreement()).isNull();246 assertThat(providerNegotiation.getContractAgreement()).isNull();247 verify(validationService, atLeastOnce()).validate(token, initialOffer);248 verify(validationService, atLeastOnce()).validate(token, counterOffer, initialOffer);249 verify(validationService, atLeastOnce()).validate(eq(token), any(ContractAgreement.class), any(ContractOffer.class));250 verify(negotiationListenerMock, times(2)).preDeclined(any());251 });252 // Stop provider and consumer negotiation managers253 providerManager.stop();254 consumerManager.stop();255 }256 @Test257 @Disabled258 void testNegotiation_consumerCounterOfferAccepted() {259 consumerNegotiationId = null;260 // Create an initial contract offer and two counter offers261 ContractOffer initialOffer = getContractOffer();262 ContractOffer counterOffer = getCounterOffer();263 ContractOffer consumerCounterOffer = getConsumerCounterOffer();264 // Mock validation of initial offer on provider side => counter offer265 when(validationService.validate(token, initialOffer)).thenReturn(Result.success(null));266 //Mock validation of counter offer on consumer side => counter offer267 when(validationService.validate(token, counterOffer, initialOffer)).thenReturn(Result.success(null));268 //Mock validation of second counter offer on provider side => accept269 when(validationService.validate(token, consumerCounterOffer, counterOffer)).thenReturn(Result.success(null));270 // Mock validation of agreement on consumer side271 when(validationService.validate(eq(token), any(ContractAgreement.class),272 eq(consumerCounterOffer))).thenReturn(true);273 // Create and register listeners for provider and consumer274 providerObservable.registerListener(negotiationListenerMock);275 consumerObservable.registerListener(negotiationListenerMock);276 // Start provider and consumer negotiation managers277 providerManager.start();278 consumerManager.start();279 // Create an initial request and trigger consumer manager280 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()281 .connectorId("connectorId")282 .connectorAddress("connectorAddress")283 .contractOffer(initialOffer)284 .protocol("protocol")285 .build();286 consumerManager.initiate(request);287 // Wait for negotiation to finish with time out at 15 seconds288 await().atMost(DEFAULT_TEST_TIMEOUT)289 .pollInterval(DEFAULT_POLL_INTERVAL)290 .untilAsserted(() -> {291 var consumerNegotiation = consumerStore.find(consumerNegotiationId);292 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);293 // Assert that provider and consumer have the same number of offers stored294 assertNegotiations(consumerNegotiation, providerNegotiation, 3);295 // Assert that initial offer is the same296 assertThat(consumerNegotiation.getContractOffers().get(0)).isEqualTo(providerNegotiation.getContractOffers().get(0));297 // Assert that first counter offer is the same298 assertThat(consumerNegotiation.getContractOffers().get(1)).isEqualTo(providerNegotiation.getContractOffers().get(1));299 // Assert that second counter offer is the same300 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());301 // Assert that same agreement is stored on both sides302 assertThat(consumerNegotiation.getContractAgreement()).isNotNull();303 assertThat(consumerNegotiation.getContractAgreement()).isEqualTo(providerNegotiation.getContractAgreement());304 verify(validationService, atLeastOnce()).validate(token, initialOffer);305 verify(validationService, atLeastOnce()).validate(token, counterOffer, initialOffer);306 verify(validationService, atLeastOnce()).validate(token, consumerCounterOffer, counterOffer);307 verify(validationService, atLeastOnce()).validate(eq(token), any(ContractAgreement.class), eq(consumerCounterOffer));308 verify(negotiationListenerMock, times(2)).preConfirmed(any());309 });310 // Stop provider and consumer negotiation managers311 providerManager.stop();312 consumerManager.stop();313 }314 @Test315 @Disabled316 void testNegotiation_consumerCounterOfferDeclined() {317 consumerNegotiationId = null;318 // Create an initial contract offer and two counter offers319 ContractOffer initialOffer = getContractOffer();320 ContractOffer counterOffer = getCounterOffer();321 ContractOffer consumerCounterOffer = getConsumerCounterOffer();322 // Mock validation of initial offer on provider side => counter offer323 when(validationService.validate(token, initialOffer)).thenReturn(Result.success(null));324 //Mock validation of counter offer on consumer side => counter offer325 when(validationService.validate(token, counterOffer, initialOffer)).thenReturn(Result.success(null));326 //Mock validation of second counter offer on provider side => decline327 when(validationService.validate(token, consumerCounterOffer, counterOffer)).thenReturn(Result.success(null));328 // Create and register listeners for provider and consumer329 providerObservable.registerListener(negotiationListenerMock);330 consumerObservable.registerListener(negotiationListenerMock);331 // Start provider and consumer negotiation managers332 providerManager.start();333 consumerManager.start();334 // Create an initial request and trigger consumer manager335 ContractOfferRequest request = ContractOfferRequest.Builder.newInstance()336 .connectorId("connectorId")337 .connectorAddress("connectorAddress")338 .contractOffer(initialOffer)339 .protocol("protocol")340 .build();341 consumerManager.initiate(request);342 // Wait for negotiation to finish with time out at 15 seconds343 // Wait for negotiation to finish with time out at 15 seconds344 await().atMost(DEFAULT_TEST_TIMEOUT)345 .pollInterval(DEFAULT_POLL_INTERVAL)346 .untilAsserted(() -> {347 var consumerNegotiation = consumerStore.find(consumerNegotiationId);348 var providerNegotiation = providerStore.findForCorrelationId(consumerNegotiationId);349 // Assert that provider and consumer have the same number of offers stored350 assertNegotiations(consumerNegotiation, providerNegotiation, 3);351 // Assert that initial offer is the same352 assertThat(consumerNegotiation.getContractOffers().get(0)).isEqualTo(providerNegotiation.getContractOffers().get(0));353 // Assert that first counter offer is the same354 assertThat(consumerNegotiation.getContractOffers().get(1)).isEqualTo(providerNegotiation.getContractOffers().get(1));355 // Assert that second counter offer is the same356 assertThat(consumerNegotiation.getLastContractOffer()).isEqualTo(providerNegotiation.getLastContractOffer());357 // Assert that no agreement has been stored on either side358 assertThat(consumerNegotiation.getContractAgreement()).isNull();359 assertThat(providerNegotiation.getContractAgreement()).isNull();360 verify(validationService, atLeastOnce()).validate(token, initialOffer);361 verify(validationService, atLeastOnce()).validate(token, counterOffer, initialOffer);362 verify(validationService, atLeastOnce()).validate(token, consumerCounterOffer, counterOffer);363 verify(negotiationListenerMock, times(2)).preDeclined(any());364 });365 // Stop provider and consumer negotiation managers366 providerManager.stop();367 consumerManager.stop();368 }369 private void assertNegotiations(ContractNegotiation consumerNegotiation, ContractNegotiation providerNegotiation, int expectedSize) {370 assertThat(consumerNegotiation).isNotNull();371 assertThat(providerNegotiation).isNotNull();372 assertThat(consumerNegotiation.getContractOffers()).hasSize(expectedSize);373 assertThat(consumerNegotiation.getContractOffers().size()).isEqualTo(providerNegotiation.getContractOffers().size());374 }375}...

Full Screen

Full Screen

Source:TriggeredVerifierTest.java Github

copy

Full Screen

...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();636 ...

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.junit.runner.RunWith;3import org.mockito.Mock;4import org.mockito.junit.MockitoJUnitRunner;5import static org.mockito.Mockito.verify;6import static org.mockito.Mockito.times;7@RunWith(MockitoJUnitRunner.class)8public class 4 {9Consumer consumer;10public void testCreate() {11consumer.create();12verify(consumer, times(1)).create();13}14}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1public class 4 {2 public static void main(String[] args) {3 Consumer mock = mock(Consumer.class);4 when(mock.create(anyString())).thenReturn("Hello");5 String result = mock.create("World");6 System.out.println(result);7 }8}9public class 5 {10 public static void main(String[] args) {11 Consumer mock = mock(Consumer.class);12 when(mock.create(anyString())).thenReturn("Hello");13 String result = mock.create("World");14 System.out.println(result);15 }16}17public class 6 {18 public static void main(String[] args) {19 Consumer mock = mock(Consumer.class);20 when(mock.create(anyString())).thenReturn("Hello");21 String result = mock.create("World");22 System.out.println(result);23 }24}25public class 7 {26 public static void main(String[] args) {27 Consumer mock = mock(Consumer.class);28 when(mock.create(anyString())).thenReturn("Hello");29 String result = mock.create("World");30 System.out.println(result);31 }32}33public class 8 {34 public static void main(String[] args) {35 Consumer mock = mock(Consumer.class);36 when(mock.create(anyString())).thenReturn("Hello");37 String result = mock.create("World");38 System.out.println(result);39 }40}41public class 9 {42 public static void main(String[] args) {43 Consumer mock = mock(Consumer.class);44 when(mock.create(anyString())).thenReturn("Hello");45 String result = mock.create("World");46 System.out.println(result);47 }48}49public class 10 {50 public static void main(String[] args) {51 Consumer mock = mock(Consumer.class);52 when(mock.create(anyString())).thenReturn("Hello");53 String result = mock.create("

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1public class TestConsumer {2 public void testConsumer() {3 Consumer consumer = mock(Consumer.class);4 when(consumer.create()).thenReturn("Mocked Consumer");5 assertEquals("Mocked Consumer", consumer.create());6 }7}8public class TestConsumer {9 public void testConsumer() {10 Consumer consumer = mock(Consumer.class);11 when(consumer.create()).thenReturn("Mocked Consumer");12 assertEquals("Mocked Consumer", consumer.create());13 }14}15public class TestConsumer {16 public void testConsumer() {17 Consumer consumer = mock(Consumer.class);18 when(consumer.create()).thenReturn("Mocked Consumer");19 assertEquals("Mocked Consumer", consumer.create());20 }21}22public class TestConsumer {23 public void testConsumer() {24 Consumer consumer = mock(Consumer.class);25 when(consumer.create()).thenReturn("Mocked Consumer");26 assertEquals("Mocked Consumer", consumer.create());27 }28}29public class TestConsumer {30 public void testConsumer() {31 Consumer consumer = mock(Consumer.class);32 when(consumer.create()).thenReturn("Mocked Consumer");33 assertEquals("Mocked Consumer", consumer.create());34 }35}36public class TestConsumer {37 public void testConsumer() {38 Consumer consumer = mock(Consumer.class);39 when(consumer.create()).thenReturn("Mocked Consumer");40 assertEquals("Mocked Consumer", consumer.create());41 }42}43public class TestConsumer {44 public void testConsumer() {45 Consumer consumer = mock(Consumer.class);46 when(consumer.create()).thenReturn("Mocked Consumer");47 assertEquals("Mocked Consumer", consumer.create());48 }49}50public class TestConsumer {51 public void testConsumer()

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1Consumer consumer = mock(Consumer.class);2consumer.create("abc", "def", "ghi");3verify(consumer).create("abc", "def", "ghi");4verify(consumer, times(1)).create("abc", "def", "ghi");5verify(consumer, atLeastOnce()).create("abc", "def", "ghi");6verify(consumer, atLeast(1)).create("abc", "def", "ghi");7verify(consumer, atMost(1)).create("abc", "def", "ghi");8verify(consumer, atMostOnce()).create("abc", "def", "ghi");9verify(consumer, never()).create("abc", "def", "ghi");10verify(consumer, timeout(100)).create("abc", "def", "ghi");11verify(consumer, timeout(100).times(1)).create("abc", "def", "ghi");12verify(consumer, timeout(100).atLeastOnce()).create("abc", "def", "ghi");13verify(consumer, timeout(100).atLeast(1)).create("abc", "def", "ghi");14verify(consumer, timeout(100).atMost(1)).create("abc", "def", "ghi");15verify(consumer, timeout(100).atMostOnce()).create("abc", "def", "ghi");16verify(consumer, timeout(100).never()).create("abc", "def", "ghi");

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.ArrayList;3import java.util.List;4public class Consumer {5 public static void main(String[] args) {6 Producer p = new Producer();7 List<Integer> list = new ArrayList<Integer>();8 p.create(list);9 System.out.println(list);10 }11}12package mock.contract;13import java.util.ArrayList;14import java.util.List;15public class Producer {16 public static void main(String[] args) {17 Consumer c = new Consumer();18 List<Integer> list = new ArrayList<Integer>();19 c.retrieve(list);20 System.out.println(list);21 }22}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package mock.contract;2public class Producer {3 public void produce() {4 Consumer consumer = new Consumer();5 consumer.create();6 }7}8package mock.contract;9import static org.mockito.Mockito.*;10import org.junit.Test;11public class ProducerTest {12 public void testProduce() {13 Producer producer = new Producer();14 Consumer consumer = mock(Consumer.class);15 producer.setConsumer(consumer);16 producer.produce();17 verify(consumer).create();18 }19}20package mock.contract;21public class Producer {22 private Consumer consumer;23 public void setConsumer(Consumer consumer) {24 this.consumer = consumer;25 }26 public void produce() {27 consumer.create();28 }29}30package mock.contract;31import static org.mockito.Mockito.*;32import org.junit.Test;33public class ProducerTest {34 public void testProduce() {35 Producer producer = new Producer();36 Consumer consumer = mock(Consumer.class);37 producer.setConsumer(consumer);38 producer.produce();39 verify(consumer).create();40 }41}42package mock.contract;43public class Producer {44 private Consumer consumer;45 public void setConsumer(Consumer consumer) {46 this.consumer = consumer;47 }48 public void produce() {49 consumer.create();50 }51}52package mock.contract;53import static org.mockito.Mockito.*;54import org.junit.Test;55public class ProducerTest {56 public void testProduce() {57 Producer producer = new Producer();58 Consumer consumer = mock(Consumer.class);59 producer.setConsumer(consumer);60 producer.produce();61 verify(consumer).create();62 }63}64package mock.contract;

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.*;3import java.io.*;4public class Consumer {5public static void main(String[] args) throws IOException {6Producer p = new Producer();7p.create();8}9}10package mock.contract;11public class Producer {12public void create() {13System.out.println("create method");14}15}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import mock.contract.*;2import mock.*;3import mock.impl.*;4import mock.util.*;5import java.util.*;6import java.lang.reflect.*;7import java.lang.*;8import java.io.*;9import junit.framework.*;10{11public void test() throws Exception12{13Consumer mockConsumer = (Consumer)Mock.create(Consumer.class);14mockConsumer.consume("test");15Mock.replay(mockConsumer);16mockConsumer.consume("test");17Mock.verify(mockConsumer);18}19}20import mock.contract.*;21import mock.*;22import mock.impl.*;23import mock.util.*;24import java.util.*;25import java.lang.reflect.*;26import java.lang.*;27import java.io.*;28import junit.framework.*;29{30public void test() throws Exception31{32Consumer mockConsumer = (Consumer)Mock.create(Consumer.class);33mockConsumer.consume("test");34Mock.replay(mockConsumer);35mockConsumer.consume("test");36Mock.verify(mockConsumer);37}38}39import mock.contract.*;40import mock.*;41import mock.impl.*;42import mock.util.*;43import java.util.*;44import java.lang.reflect.*;45import java.lang.*;46import java.io.*;

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.jmock.*;2import org.jmock.core.*;3import org.jmock.core.constraint.*;4import org.jmock.core.matcher.*;5import org.jmock.core.stub.*;6import org.jmock.core.invocation.*;7import org.jmock.util.*;8import mock.contract.*;9import mock.impl.*;10import junit.framework.*;11{12 MockObjectConsumer moc;13 Consumer cons;14 Producer prod;15 public JMockTest(String name)16 {17 super(name);18 }19 public void setUp()20 {21 moc = new MockObjectConsumer();22 cons = (Consumer)moc.mock();23 prod = new Producer();24 }25 public void testProducer()26 {27 moc.expects(once()).method("consume").with(eq("Hello"));28 prod.produce(cons);29 }30}31import org.jmock.*;32import org.jmock.core.*;33import org.jmock.core.constraint.*;34import org.jmock.core.matcher.*;35import org.jmock.core.stub.*;36import org.jmock.core.invocation.*;37import org.jmock.util.*;38import mock.contract.*;39import mock.impl.*;40import junit.framework.*;41{42 MockObjectConsumer moc;43 Consumer cons;44 Producer prod;45 public JMockTest(String name)46 {47 super(name);48 }49 public void setUp()50 {51 moc = new MockObjectConsumer();52 cons = (Consumer)moc.mock();53 prod = new Producer();54 }55 public void testProducer()56 {57 moc.expects(once()).method("consume").with(eq("Hello"));58 prod.produce(cons);59 }60}61import org.jmock.*;62import org.jmock.core.*;63import org.jmock.core.constraint.*;64import org.jmock.core.matcher.*;65import org.j66public class ProducerTest {67 public void testProduce() {68 Producer producer = new Producer();69 Consumer consumer = mock(Consumer.class);70 producer.setConsumer(consumer);71 producer.produce();72 verify(consumer).create();73 }74}75package mock.contract;76public class Producer {77 private Consumer consumer;78 public void setConsumer(Consumer consumer) {79 this.consumer = consumer;80 }81 public void produce() {82 consumer.create();83 }84}85package mock.contract;86import static org.mockito.Mockito.*;87import org.junit.Test;88public class ProducerTest {89 public void testProduce() {90 Producer producer = new Producer();91 Consumer consumer = mock(Consumer.class);92 producer.setConsumer(consumer);93 producer.produce();94 verify(consumer).create();95 }96}97package mock.contract;

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1package mock.contract;2import java.util.*;3import java.io.*;4public class Consumer {5public static void main(String[] args) throws IOException {6Producer p = new Producer();7p.create();8}9}10package mock.contract;11public class Producer {12public void create() {13System.out.println("create method");14}15}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.jmock.*;2import org.jmock.core.*;3import org.jmock.core.constraint.*;4import org.jmock.core.matcher.*;5import org.jmock.core.stub.*;6import org.jmock.core.invocation.*;7import org.jmock.util.*;8import mock.contract.*;9import mock.impl.*;10import junit.framework.*;11{12 MockObjectConsumer moc;13 Consumer cons;14 Producer prod;15 public JMockTest(String name)16 {17 super(name);18 }19 public void setUp()20 {21 moc = new MockObjectConsumer();22 cons = (Consumer)moc.mock();23 prod = new Producer();24 }25 public void testProducer()26 {27 moc.expects(once()).method("consume").with(eq("Hello"));28 prod.produce(cons);29 }30}31import org.jmock.*;32import org.jmock.core.*;33import org.jmock.core.constraint.*;34import org.jmock.core.matcher.*;35import org.jmock.core.stub.*;36import org.jmock.core.invocation.*;37import org.jmock.util.*;38import mock.contract.*;39import mock.impl.*;40import junit.framework.*;41{42 MockObjectConsumer moc;43 Consumer cons;44 Producer prod;45 public JMockTest(String name)46 {47 super(name);48 }49 public void setUp()50 {51 moc = new MockObjectConsumer();52 cons = (Consumer)moc.mock();53 prod = new Producer();54 }55 public void testProducer()56 {57 moc.expects(once()).method("consume").with(eq("Hello"));58 prod.produce(cons);59 }60}61import org.jmock.*;62import org.jmock.core.*;63import org.jmock.core.constraint.*;64import org.jmock.core.matcher.*;65import org.j66import org.jmock.*;67org.j.corenstrait.*;68import org.jmock.core.matcher.*;69impor org.jmock.core.stub.*;70import org.jmock.coe.invoction.*;71import org.jmok.uil

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1*;2import mock.impl.*;3import junit.framework.*;4{5 MockObjectConsumer moc;6 onsumer c;7 Prodcer prod;8 public JMockTest(String nae)9 {10 sup(name)11 }12 public void setUp()13 {14 moc = new MockObjectConsumer();15 cons = (Consumer)moc.mock();16 prod = new Producer();17 }18 public vod testProducer()19 {20 oc.exects(nce()).method("consume").with(eq("Hello"));21 pod.produce(cons);22 }23}24import org.jmock.*;25import org.jmock.coe.*26import org.jmock.tore.maecher method of mock.contract.Consumer class27paport org.jckage mock.contract;28import java.util.*;29import java.io.*;30public class Consumer {31public static void main(String[] args) throws IOException {32Producer p = new Producer();33p.create();34}35}36package mock.contract;37public class Producer {38public void create() {39System.out.println("create method");40}41}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.jmock.*;2import org.jmock.core.*;3import org.jmock.core.constraint.*;4import org.jmock.core.matcher.*;5import org.jmock.core.stub.*;6import org.jmock.core.invocation.*;7import org.jmock.util.*;8import mock.contract.*;9import mock.impl.*;10import junit.framework.*;11{12 MockObjectConsumer moc;13 Consumer cons;14 Producer prod;15 public JMockTest(String name)16 {17 super(name);18 }19 public void setUp()20 {21 moc = new MockObjectConsumer();22 cons = (Consumer)moc.mock();23 prod = new Producer();24 }25 public void testProducer()26 {27 moc.expects(once()).method("consume").with(eq("Hello"));28 prod.produce(cons);29 }30}31import org.jmock.*;32import org.jmock.core.*;33import org.jmock.core.constraint.*;34import org.jmock.core.matcher.*;35import org.jmock.core.stub.*;36import org.jmock.core.invocation.*;37import org.jmock.util.*;38import mock.contract.*;39import mock.impl.*;40import junit.framework.*;41{42 MockObjectConsumer moc;43 Consumer cons;44 Producer prod;45 public JMockTest(String name)46 {47 super(name);48 }49 public void setUp()50 {51 moc = new MockObjectConsumer();52 cons = (Consumer)moc.mock();53 prod = new Producer();54 }55 public void testProducer()56 {57 moc.expects(once()).method("consume").with(eq("Hello"));58 prod.produce(cons);59 }60}61import org.jmock.*;62import org.jmock.core.*;63import org.jmock.core.constraint.*;64import org.jmock.core.matcher.*;65import org.j

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run Karate automation tests on LambdaTest cloud grid

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful