public void testMultipleLifecycleStrategies() throws Exception { CamelContext context = createCamelContext(); context.start(); Component log = new LogComponent(); context.addComponent("log", log); context.addEndpoint("log:/foo", log.createEndpoint("log://foo")); context.removeComponent("log"); context.stop(); List<String> expectedEvents = Arrays.asList( "onContextStart", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop"); assertEquals(expectedEvents, dummy1.getEvents()); assertEquals(expectedEvents, dummy2.getEvents()); }
public String componentParameterJsonSchema(String componentName) throws Exception { // favor using pre generated schema if component has that String json = context.getComponentParameterJsonSchema(componentName); if (json == null) { // okay this requires having the component on the classpath and being instantiated Component component = context.getComponent(componentName); if (component != null) { ComponentConfiguration configuration = component.createComponentConfiguration(); json = configuration.createParameterJsonSchema(); } } return json; }
public List<String> completeEndpointPath( String componentName, Map<String, Object> endpointParameters, String completionText) throws Exception { if (completionText == null) { completionText = ""; } Component component = context.getComponent(componentName, false); if (component != null) { ComponentConfiguration configuration = component.createComponentConfiguration(); configuration.setParameters(endpointParameters); return configuration.completeEndpointPath(completionText); } else { return new ArrayList<String>(); } }
@Test public void testConfiguration() throws Exception { Component component = context().getComponent(componentName); ComponentConfiguration configuration = component.createComponentConfiguration(); SortedMap<String, ParameterConfiguration> parameterConfigurationMap = configuration.getParameterConfigurationMap(); if (verbose) { Set<Map.Entry<String, ParameterConfiguration>> entries = parameterConfigurationMap.entrySet(); for (Map.Entry<String, ParameterConfiguration> entry : entries) { String name = entry.getKey(); ParameterConfiguration config = entry.getValue(); LOG.info("Has name: {} with type {}", name, config.getParameterType().getName()); } } assertParameterConfig(configuration, "format", PayloadFormat.class); assertParameterConfig(configuration, "sObjectName", String.class); assertParameterConfig(configuration, "sObjectFields", String.class); assertParameterConfig(configuration, "updateTopic", boolean.class); configuration.setParameter("format", PayloadFormat.XML); configuration.setParameter("sObjectName", "Merchandise__c"); configuration.setParameter("sObjectFields", "Description__c,Total_Inventory__c"); configuration.setParameter("updateTopic", false); // operation name is base uri configuration.setBaseUri("getSObject"); SalesforceEndpoint endpoint = assertIsInstanceOf(SalesforceEndpoint.class, configuration.createEndpoint()); final SalesforceEndpointConfig endpointConfig = endpoint.getConfiguration(); assertEquals("endpoint.format", PayloadFormat.XML, endpointConfig.getFormat()); assertEquals("endpoint.sObjectName", "Merchandise__c", endpointConfig.getSObjectName()); assertEquals( "endpoint.sObjectFields", "Description__c,Total_Inventory__c", endpointConfig.getSObjectFields()); assertEquals("endpoint.updateTopic", false, endpointConfig.isUpdateTopic()); }
/** * Constructs a fully-initialized DefaultEndpoint instance. This is the preferred method of * constructing an object from Java code (as opposed to Spring beans, etc.). * * @param endpointUri the full URI used to create this endpoint * @param component the component that created this endpoint */ protected DefaultEndpoint(String endpointUri, Component component) { this.camelContext = component == null ? null : component.getCamelContext(); this.component = component; this.setEndpointUri(endpointUri); }
@Test public void testEndpointCompletion() throws Exception { Component component = context().getComponent(componentName); ComponentConfiguration configuration = component.createComponentConfiguration(); // get operation names assertCompletionOptions( configuration.completeEndpointPath(""), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "createSObject", "updateSObject", "deleteSObject", "getSObjectWithId", "upsertSObject", "deleteSObjectWithId", "getBlobField", "query", "queryMore", "queryAll", "search", "apexCall", "recent", "createJob", "getJob", "closeJob", "abortJob", "createBatch", "getBatch", "getAllBatches", "getRequest", "getResults", "createBatchQuery", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "executeSyncReport", "executeAsyncReport", "getReportInstances", "getReportResults", "limits", "approval", "approvals", "[PushTopicName]"); // get filtered operation names assertCompletionOptions( configuration.completeEndpointPath("get"), "getVersions", "getResources", "getGlobalObjects", "getBasicInfo", "getDescription", "getSObject", "getSObjectWithId", "getBlobField", "getJob", "getBatch", "getAllBatches", "getRequest", "getResults", "getQueryResultIds", "getQueryResult", "getRecentReports", "getReportDescription", "getReportInstances", "getReportResults"); /* TODO support parameter completion // get ALL REST operation parameters // TODO support operation specific parameter completion assertCompletionOptions(configuration.completeEndpointPath("getSObject?"), "apiVersion", "httpClient", "format", "sObjectName", "sObjectId", "sObjectFields", "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch"); // get filtered REST parameters assertCompletionOptions(configuration.completeEndpointPath("getSObject?format=XML&"), "apiVersion", "httpClient", "sObjectName", "sObjectId", "sObjectFields", "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch"); // get ALL Bulk operation parameters // TODO support operation specific parameter completion assertCompletionOptions(configuration.completeEndpointPath("createJob?"), "apiVersion", "httpClient", "sObjectQuery", "contentType", "jobId", "batchId", "resultId"); // get filtered Bulk operation parameters assertCompletionOptions(configuration.completeEndpointPath("createJob?contentType=XML&"), "apiVersion", "httpClient", "sObjectQuery", "jobId", "batchId", "resultId"); // get ALL topic parameters for consumers assertCompletionOptions(configuration.completeEndpointPath("myTopic?"), "apiVersion", "httpClient", "updateTopic", "notifyForFields", "notifyForOperations"); // get filtered topic parameters for consumers assertCompletionOptions(configuration.completeEndpointPath("myTopic?updateTopic=true&"), "apiVersion", "httpClient", "notifyForFields", "notifyForOperations"); // get parameters from partial name assertCompletionOptions(configuration.completeEndpointPath("getSObject?sObject"), "sObjectName", "sObjectId", "sObjectFields", "sObjectIdName", "sObjectIdValue", "sObjectBlobFieldName", "sObjectClass", "sObjectQuery", "sObjectSearch"); */ // get sObjectName values, from scanned DTO packages assertCompletionOptions( configuration.completeEndpointPath("getSObject?sObjectName="), "Account", "Tasks__c", "Line_Item__c", "Merchandise__c", "Document", "MSPTest"); // get sObjectFields values, from scanned DTO assertCompletionOptions( configuration.completeEndpointPath("getSObject?sObjectName=Merchandise__c&sObjectFields="), "Description__c", "Price__c", "Total_Inventory__c", "attributes", "Id", "OwnerId", "IsDeleted", "Name", "CreatedDate", "CreatedById", "LastModifiedDate", "LastModifiedById", "SystemModstamp", "LastActivityDate", "LastViewedDate", "LastReferencedDate"); // get sObjectClass values, from scanned DTO packages assertCompletionOptions( configuration.completeEndpointPath("getSObject?sObjectClass="), Account.class.getName(), Tasks__c.class.getName(), Line_Item__c.class.getName(), Merchandise__c.class.getName(), Document.class.getName(), MSPTest.class.getName(), QueryRecordsLine_Item__c.class.getName()); }