Java Code Examples for org.apache.camel.component.mock.MockEndpoint#setAssertPeriod()
The following examples show how to use
org.apache.camel.component.mock.MockEndpoint#setAssertPeriod() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSHIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSSHConsumer() throws Exception { String conUrl = TestUtils.getResourceValue(getClass(), "/ssh-connection"); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("ssh://admin@%s?username=admin&password=admin&pollCommand=echo Hello Kermit", conUrl) .to("mock:end"); } }); camelctx.start(); try { MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:end", MockEndpoint.class); mockEndpoint.expectedMessageCount(1); mockEndpoint.setAssertPeriod(100); mockEndpoint.expectedBodiesReceived("Hello Kermit" + System.lineSeparator()); } finally { camelctx.close(); } }
Example 2
Source File: EMailReadRouteTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testImapEMailRouteWrongPassword() throws Exception { server = imapServer(); Connector mailConnector = RouteUtils.createEMailConnector(server, new PropertyBuilder<String>() .property(PROTOCOL, Protocol.IMAP.id()) .property(SECURE_TYPE, SecureType.SSL_TLS.id()) .property(HOST, server.getHost()) .property(PORT, Integer.toString(server.getPort())) .property(USER, TEST_ADDRESS) .property(PASSWORD, "ReallyWrongPassword")); Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction); Integration mailIntegration = RouteUtils.createIntegrationWithMock(mailStep); RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration); context.addRoutes(routes); MockEndpoint result = RouteUtils.initMockEndpoint(context); // // No messages returned due to wrong password // result.setAssertPeriod(2000L); result.setMinimumExpectedMessageCount(0); context.start(); result.assertIsSatisfied(); }
Example 3
Source File: EMailReadRouteTest.java From syndesis with Apache License 2.0 | 5 votes |
@Test public void testImapEMailRouteWithFolder() throws Exception { server = imapServer(); server.generateFolder(TEST_ADDRESS, TEST_PASSWORD, TEST_FOLDER); Connector mailConnector = RouteUtils.createEMailConnector(server, new PropertyBuilder<String>() .property(PROTOCOL, Protocol.IMAP.id()) .property(HOST, server.getHost()) .property(PORT, Integer.toString(server.getPort())) .property(USER, TEST_ADDRESS) .property(PASSWORD, TEST_PASSWORD) .property(FOLDER, TEST_FOLDER)); Step mailStep = RouteUtils.createEMailStep(mailConnector, this::createConnectorAction); Integration mailIntegration = RouteUtils.createIntegrationWithMock(mailStep); RouteBuilder routes = RouteUtils.newIntegrationRouteBuilder(mailIntegration); context.addRoutes(routes); MockEndpoint result = RouteUtils.initMockEndpoint(context); result.setAssertPeriod(2000L); result.setMinimumExpectedMessageCount(server.getEmailCountInFolder(TEST_ADDRESS, TEST_PASSWORD, TEST_FOLDER)); context.start(); result.assertIsSatisfied(); List<EMailMessageModel> emails = server.getEmailsInFolder(TEST_ADDRESS, TEST_PASSWORD, TEST_FOLDER); for (int i = 0; i < emails.size(); ++i) { RouteUtils.testResult(result, i, emails.get(i)); } }
Example 4
Source File: GangliaIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void sendDefaultConfigurationShouldSucceed() throws Exception { CamelContext camelctx = assertSingleCamelContext(); ProducerTemplate template = camelctx.createProducerTemplate(); Integer port = template.requestBody("direct:getPort", null, Integer.class); MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class); mockEndpoint.setMinimumExpectedMessageCount(0); mockEndpoint.setAssertPeriod(100L); mockEndpoint.whenAnyExchangeReceived(new Processor() { @Override public void process(Exchange exchange) throws Exception { Ganglia_metadata_msg metadataMessage = exchange.getIn().getBody(Ganglia_metadata_msg.class); if (metadataMessage != null) { Assert.assertEquals(DEFAULT_METRIC_NAME, metadataMessage.gfull.metric.name); Assert.assertEquals(DEFAULT_TYPE.getGangliaType(), metadataMessage.gfull.metric.type); Assert.assertEquals(DEFAULT_SLOPE.getGangliaSlope(), metadataMessage.gfull.metric.slope); Assert.assertEquals(DEFAULT_UNITS, metadataMessage.gfull.metric.units); Assert.assertEquals(DEFAULT_TMAX, metadataMessage.gfull.metric.tmax); Assert.assertEquals(DEFAULT_DMAX, metadataMessage.gfull.metric.dmax); } else { Ganglia_value_msg valueMessage = exchange.getIn().getBody(Ganglia_value_msg.class); if (valueMessage != null) { Assert.assertEquals("28.0", valueMessage.gstr.str); Assert.assertEquals("%s", valueMessage.gstr.fmt); } else { Assert.fail("Mock endpoint should only receive non-null metadata or value messages"); } } } }); template.sendBody(String.format("ganglia:localhost:%d?mode=UNICAST", port), "28.0"); mockEndpoint.assertIsSatisfied(); }
Example 5
Source File: EventBehaviourTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Tests that the content update policy is triggered correctly for the first * event. */ @Test public void onContentUpdatePolicyFirstEventNF() throws Exception { this.policyFired = false; String endpointUri = getMockEndpointUri(); MockEndpoint mockEndpoint = camelContext.getEndpoint(endpointUri, MockEndpoint.class); mockEndpoint.setAssertPeriod(500); retryingTransactionHelper.doInTransaction(() -> { BehaviourDefinition<ClassBehaviourBinding> classBehaviour = null; try { setupTestData(); EventBehaviour eventBehaviour = new EventBehaviour(eventProducer, endpointUri, this, "createOnContentUpdateEvent", Behaviour.NotificationFrequency.FIRST_EVENT); // Register interest in the content update event for a versionable node classBehaviour = this.policyComponent.bindClassBehaviour(ContentServicePolicies.OnContentUpdatePolicy.QNAME, ContentModel.ASPECT_VERSIONABLE, eventBehaviour); // First check that the policy is not fired when the versionable aspect is not // present ContentWriter contentWriter = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter.putContent("content update one"); assertFalse(this.policyFired); this.newContent = false; // Now check that the policy is fired when the versionable aspect is present this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null); ContentWriter contentWriter2 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter2.putContent("content update two"); assertTrue(this.policyFired); this.policyFired = false; // Check that the policy is not fired when using a non updating content writer ContentWriter contentWriter3 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, false); contentWriter3.putContent("content update three"); assertFalse(this.policyFired); // Now check that the policy isn't fired when the versionable aspect is present // (because it's triggered only for the first event regardless how many times it // is updated in that transaction) this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null); ContentWriter contentWriter4 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter4.putContent("content update four"); assertFalse(this.policyFired); // Assert that the endpoint didn't receive any message // Event is sent only on transaction commit. mockEndpoint.setExpectedCount(0); mockEndpoint.assertIsSatisfied(); } finally { if (classBehaviour != null) { this.policyComponent.removeClassDefinition(classBehaviour); } } return null; }); // Assert that the endpoint received 1 messages mockEndpoint.setExpectedCount(1); mockEndpoint.assertIsSatisfied(); }
Example 6
Source File: EventBehaviourTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Tests that the content update policy is triggered correctly for every event. */ @Test public void onContentUpdatePolicyEveryEventNF() throws Exception { this.policyFired = false; String endpointUri = getMockEndpointUri(); MockEndpoint mockEndpoint = camelContext.getEndpoint(endpointUri, MockEndpoint.class); mockEndpoint.setAssertPeriod(500); retryingTransactionHelper.doInTransaction(() -> { BehaviourDefinition<ClassBehaviourBinding> classBehaviour = null; try { setupTestData(); EventBehaviour eventBehaviour = new EventBehaviour(eventProducer, endpointUri, this, "createOnContentUpdateEvent", Behaviour.NotificationFrequency.EVERY_EVENT); // Register interest in the content update event for a versionable node classBehaviour = this.policyComponent.bindClassBehaviour(ContentServicePolicies.OnContentUpdatePolicy.QNAME, ContentModel.ASPECT_VERSIONABLE, eventBehaviour); // First check that the policy is not fired when the versionable aspect is not // present ContentWriter contentWriter = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter.putContent("content update one"); assertFalse(this.policyFired); this.newContent = false; // Now check that the policy is fired when the versionable aspect is present this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null); ContentWriter contentWriter2 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter2.putContent("content update two"); assertTrue(this.policyFired); this.policyFired = false; // Check that the policy is not fired when using a non updating content writer ContentWriter contentWriter3 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, false); contentWriter3.putContent("content update three"); assertFalse(this.policyFired); // Now check that the policy is fired when the versionable aspect is present this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null); ContentWriter contentWriter4 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter4.putContent("content update four"); assertTrue(this.policyFired); this.policyFired = false; try { eventBehaviour.disable(); ContentWriter contentWriter5 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter5.putContent("content update five"); assertFalse(this.policyFired); } finally { eventBehaviour.enable(); } // Assert that the endpoint didn't receive any message // Event is sent only on transaction commit. mockEndpoint.setExpectedCount(0); mockEndpoint.assertIsSatisfied(); } finally { if (classBehaviour != null) { this.policyComponent.removeClassDefinition(classBehaviour); } } return null; }); // Assert that the endpoint received 2 messages. mockEndpoint.setExpectedCount(2); mockEndpoint.assertIsSatisfied(); }
Example 7
Source File: EventBehaviourTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Tests that the content update policy is triggered correctly for transaction * commit (the default notification frequency). */ @Test public void onContentUpdatePolicyTxnCommitNF() throws Exception { this.policyFired = false; String endpointUri = getMockEndpointUri(); MockEndpoint mockEndpoint = camelContext.getEndpoint(endpointUri, MockEndpoint.class); mockEndpoint.setAssertPeriod(500); retryingTransactionHelper.doInTransaction(() -> { BehaviourDefinition<ClassBehaviourBinding> classBehaviour = null; try { setupTestData(); EventBehaviour eventBehaviour = new EventBehaviour(eventProducer, endpointUri, this, "createOnContentUpdateEvent", Behaviour.NotificationFrequency.TRANSACTION_COMMIT); // Register interest in the content update event for a versionable node classBehaviour = this.policyComponent.bindClassBehaviour(ContentServicePolicies.OnContentUpdatePolicy.QNAME, ContentModel.ASPECT_VERSIONABLE, eventBehaviour); // First check that the policy is not fired when the versionable aspect is not // present ContentWriter contentWriter = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter.putContent("content update one"); assertFalse(this.policyFired); this.newContent = false; // The policy is fired when the versionable aspect is present (on transaction // commit) this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null); ContentWriter contentWriter2 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter2.putContent("content update two"); assertFalse(this.policyFired); // Check that the policy is not fired when using a non updating content writer ContentWriter contentWriter3 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, false); contentWriter3.putContent("content update three"); assertFalse(this.policyFired); // The policy is fired when the versionable aspect is present (on transaction // commit) this.nodeService.addAspect(this.contentNodeRef, ContentModel.ASPECT_VERSIONABLE, null); ContentWriter contentWriter4 = this.contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true); contentWriter4.putContent("content update four"); assertFalse(this.policyFired); // Assert that the endpoint didn't receive any message // Event is sent only on transaction commit. mockEndpoint.setExpectedCount(0); mockEndpoint.assertIsSatisfied(); } finally { if (classBehaviour != null) { this.policyComponent.removeClassDefinition(classBehaviour); } } return null; }); // Assert that the endpoint received 1 messages // Event is created once per transaction regardless how many times it is updated mockEndpoint.setExpectedCount(1); mockEndpoint.assertIsSatisfied(); }
Example 8
Source File: TransactionAwareEventProducerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void send() throws Exception { String endpointUri = getMockEndpointUri(); MockEndpoint mockEndpoint = camelContext.getEndpoint(endpointUri, MockEndpoint.class); mockEndpoint.setAssertPeriod(500); String stringMessage = "stringMessage"; OnContentUpdatePolicyEvent objectMessage = new OnContentUpdatePolicyEvent(); objectMessage.setId(GUID.generate()); objectMessage.setType(EventType.CONTENT_UPDATED.toString()); objectMessage.setTimestamp(System.currentTimeMillis()); retryingTransactionHelper.doInTransaction(() -> { eventProducer.send(endpointUri, stringMessage); // Assert that the endpoint didn't receive any message // Event is sent only on transaction commit. mockEndpoint.setExpectedCount(0); mockEndpoint.assertIsSatisfied(); eventProducer.send(endpointUri, objectMessage); // Assert that the endpoint didn't receive any message // Event is sent only on transaction commit. mockEndpoint.setExpectedCount(0); mockEndpoint.assertIsSatisfied(); return null; }); // Assert that the endpoint received 2 messages mockEndpoint.setExpectedCount(2); mockEndpoint.assertIsSatisfied(); // Get the sent string message String stringMessageSent = (String) mockEndpoint.getExchanges().get(0).getIn().getBody(); assertNotNull(stringMessageSent); assertEquals(stringMessage, stringMessageSent); // Get the sent json marshaled object message String jsonMessageSent = (String) mockEndpoint.getExchanges().get(1).getIn().getBody(); assertNotNull(jsonMessageSent); OnContentUpdatePolicyEvent objectMessageSent = messagingObjectMapper.readValue(jsonMessageSent, OnContentUpdatePolicyEvent.class); assertNotNull(objectMessageSent); assertEquals(objectMessage.getId(), objectMessageSent.getId()); assertEquals(objectMessage.getType(), objectMessageSent.getType()); assertEquals(objectMessage.getTimestamp(), objectMessageSent.getTimestamp()); }